diff --git a/addons/viewdistance/ACE_Settings.hpp b/addons/viewdistance/ACE_Settings.hpp index 572358876a..48e5f7324e 100644 --- a/addons/viewdistance/ACE_Settings.hpp +++ b/addons/viewdistance/ACE_Settings.hpp @@ -1,9 +1,24 @@ class ACE_Settings { - class GVAR(viewdistance) { + class GVAR(changeAllowed) { + typeName = "BOOL"; + value = 1; + displayName = "Allow View Distance Changing"; + description = "Enables changing in game view distance"; + }; + class GVAR(top_limit) { + typeName = "SCALAR"; + values[] = {0,1,2,3,4,5,6,7,8,9,10,11}; // correspond to the index values + displayName = "View Distance Limit"; + description = "Sets the top limit for all clients"; + }; + class GVAR(newViewDistance) { typeName = "SCALAR"; isClientSettable = 1; - values[] = {1500,2000,2500,3000,3500,4000,5000,6000,7000,8000,9000,10000}; - displayName = "View Distance"; // has to be changed to string table type - description = "Change View Distance"; + //value = 1; + values[] = {"1500","2000","2500","3000","3500","4000","5000","6000","7000","8000","9000","10000"}; + displayName = "Change View Distance"; + description = "Changes in game view distance"; }; -}; \ No newline at end of file +}; + +// To do: include string table style displayName & description. \ No newline at end of file diff --git a/addons/viewdistance/CfgEventHandlers.hpp b/addons/viewdistance/CfgEventHandlers.hpp index f0a9f14d91..0f1d8878ba 100644 --- a/addons/viewdistance/CfgEventHandlers.hpp +++ b/addons/viewdistance/CfgEventHandlers.hpp @@ -4,3 +4,9 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + +class Extended_PostInit_EventHandlers { + class ADDON { + init = QUOTE(call COMPILE_FILE(XEH_postInit)); + }; +}; \ No newline at end of file diff --git a/addons/viewdistance/XEH_postInit.sqf b/addons/viewdistance/XEH_postInit.sqf new file mode 100644 index 0000000000..8f1fd94fc3 --- /dev/null +++ b/addons/viewdistance/XEH_postInit.sqf @@ -0,0 +1,4 @@ +#include "script_component.hpp" + +if (!hasInterface || !GVAR(enabled)) exitWith {}; +[] call FUNC(initViewDistance); \ No newline at end of file diff --git a/addons/viewdistance/XEH_preInit.sqf b/addons/viewdistance/XEH_preInit.sqf index 69abb46fa9..4da9b33c83 100644 --- a/addons/viewdistance/XEH_preInit.sqf +++ b/addons/viewdistance/XEH_preInit.sqf @@ -2,6 +2,8 @@ ADDON = false; -PREP(empty); +PREP(returnViewDistanceValue); +PREP(changeViewDistance); +PREP(initViewDistance); -ADDON = true; +ADDON = true; \ No newline at end of file diff --git a/addons/viewdistance/config.cpp b/addons/viewdistance/config.cpp index dcffe0f257..86453c5be3 100644 --- a/addons/viewdistance/config.cpp +++ b/addons/viewdistance/config.cpp @@ -13,4 +13,4 @@ class CfgPatches { }; #include "CfgEventHandlers.hpp" -#include "ACE_Settings.hpp" \ No newline at end of file +#include "ACE_Settings.hpp" \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_changeViewDistance.sqf b/addons/viewdistance/functions/fnc_changeViewDistance.sqf index 4543be000b..f28ce70e3d 100644 --- a/addons/viewdistance/functions/fnc_changeViewDistance.sqf +++ b/addons/viewdistance/functions/fnc_changeViewDistance.sqf @@ -4,21 +4,38 @@ * * * Arguments: - * 0: View Distance Setting (SCALAR) + * None * * Return Value: * None * * Example: - * [1500] call ace_common_fnc_imanexample + * [] call ace_viewdistance_fnc_changeViewDistance; * * Public: No */ #include "script_component.hpp" -private ["_new_view_distance"]; +private ["_new_view_distance_index","_new_view_distance"]; -_new_view_distance = _this select 0; +_new_view_distance_index = GVAR(newViewDistance); -player setViewDistance (_new_view_distance); \ No newline at end of file +_new_view_distance = [_new_view_distance_index] call FUNC(returnViewDistanceValue); + +/* +hint format ["DEBUG: Player: %1 new view distance index: %2 new view distance value: %3",(name player),_new_view_distance_index,_new_view_distance]; +diag_log format ["DEBUG: Player: %1 new view distance index: %2 new view distance value: %3",(name player),_new_view_distance_index,_new_view_distance]; +*/ + + +// To do: add a check against a sever or module top limit here. + +if !GVAR(changeAllowed) then +{ + hint "You cannot change the view distance!" +} +else +{ + setViewDistance _new_view_distance; +}; \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_initViewDistance.sqf b/addons/viewdistance/functions/fnc_initViewDistance.sqf new file mode 100644 index 0000000000..2a419fe7fc --- /dev/null +++ b/addons/viewdistance/functions/fnc_initViewDistance.sqf @@ -0,0 +1,24 @@ +/* + * Author: Winter + * Sets the player's current view distance according to allowed values. + * + * + * Arguments: + * 0: View Distance Setting (SCALAR) + * + * Return Value: + * None + * + * Example: + * [1500] call ace_common_fnc_imanexample + * + * Public: No + */ + +#include "script_component.hpp" + +["SettingChanged",{ + if (_this select 0 == QGVAR(newViewDistance)) then { + [] call FUNC(changeViewDistance); + }; +},true] call ace_common_fnc_addEventHandler; \ No newline at end of file diff --git a/addons/viewdistance/functions/fnc_returnViewDistanceValue.sqf b/addons/viewdistance/functions/fnc_returnViewDistanceValue.sqf new file mode 100644 index 0000000000..7d55062c65 --- /dev/null +++ b/addons/viewdistance/functions/fnc_returnViewDistanceValue.sqf @@ -0,0 +1,42 @@ +/* + * Author: Winter + * Returns the view distance value according to the given index + * + * + * Arguments: + * 0: View Distance Index (SCALAR) + * + * Return Value: + * View Distance (SCALAR) + * + * Example: + * [2] call ace_viewdistance_fnc_returnViewDistanceValue; + * + * Public: Yes + */ + +#include "script_component.hpp" + +private ["_index","_return"]; + +_index = _this select 0; +_return = 0; + +switch (_index) do +{ + case 0: {_return = 1500}; + case 1: {_return = 2000}; + case 2: {_return = 2500}; + case 3: {_return = 3000}; + case 4: {_return = 3500}; + case 5: {_return = 4000}; + case 6: {_return = 5000}; + case 7: {_return = 6000}; + case 8: {_return = 7000}; + case 9: {_return = 8000}; + case 10: {_return = 9000}; + case 11: {_return = 10000}; + default {hint "something broke!";}; +}; + +_return; \ No newline at end of file