From 183aac191117d762983d251346d7854693696ee7 Mon Sep 17 00:00:00 2001 From: jokoho48 Date: Fri, 14 Aug 2015 01:55:54 +0200 Subject: [PATCH] Code cleanup of Kestrel 4500 module. --- addons/kestrel4500/XEH_preInit.sqf | 18 ++++ .../functions/fnc_buttonPressed.sqf | 4 +- addons/kestrel4500/functions/fnc_canShow.sqf | 6 +- .../kestrel4500/functions/fnc_collectData.sqf | 33 +++----- .../functions/fnc_createKestrelDialog.sqf | 4 +- .../functions/fnc_displayKestrel.sqf | 84 +++++++++++-------- .../functions/fnc_generateOutputData.sqf | 40 +++++---- .../functions/fnc_measureWindSpeed.sqf | 3 +- .../functions/fnc_onCloseDialog.sqf | 15 ++++ .../functions/fnc_onCloseDisplay.sqf | 15 ++++ .../functions/fnc_restoreUserData.sqf | 2 +- .../functions/fnc_storeUserData.sqf | 4 +- .../functions/fnc_updateDisplay.sqf | 30 ++----- .../functions/fnc_updateImpellerState.sqf | 4 +- 14 files changed, 150 insertions(+), 112 deletions(-) diff --git a/addons/kestrel4500/XEH_preInit.sqf b/addons/kestrel4500/XEH_preInit.sqf index 7b36167a16..b7d66cbb94 100644 --- a/addons/kestrel4500/XEH_preInit.sqf +++ b/addons/kestrel4500/XEH_preInit.sqf @@ -17,3 +17,21 @@ PREP(updateDisplay); PREP(updateImpellerState); ADDON = true; + +FUNC(updateMemory) = { + params ["_slot", "_value"]; + GVAR(MIN) set [_slot, (GVAR(MIN) select _slot) min _value]; + GVAR(MAX) set [_slot, _value max (GVAR(MAX) select _slot)]; + GVAR(TOTAL) set [_slot, (GVAR(TOTAL) select _slot) + _value]; +}; + +FUNC(dayOfWeek) = { + private "_table"; + params ["_year", "_month", "_day"]; + + _table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]; + if (_month < 3) then { + _year = _year - 1; + }; + (_year + floor(_year/4) - floor(_year/100) + floor(_year/400) + (_table select (_month - 1)) + _day) % 7 +}; diff --git a/addons/kestrel4500/functions/fnc_buttonPressed.sqf b/addons/kestrel4500/functions/fnc_buttonPressed.sqf index 8f38568462..83c471092a 100644 --- a/addons/kestrel4500/functions/fnc_buttonPressed.sqf +++ b/addons/kestrel4500/functions/fnc_buttonPressed.sqf @@ -3,10 +3,10 @@ * Handles the Kestrel 4500 dialog button actions * * Arguments: - * buttonID + * button ID * * Return Value: - * Nothing + * None * * Example: * 2 call ace_kestrel4500_fnc_buttonPressed diff --git a/addons/kestrel4500/functions/fnc_canShow.sqf b/addons/kestrel4500/functions/fnc_canShow.sqf index 0c9e29f9bc..f563138f5c 100644 --- a/addons/kestrel4500/functions/fnc_canShow.sqf +++ b/addons/kestrel4500/functions/fnc_canShow.sqf @@ -3,13 +3,13 @@ * Tests if the Kestrel 4500 can be shown * * Arguments: - * Nothing + * None * * Return Value: - * canShow (bool) + * canShow * * Example: - * [mode] call ace_kestrel4500_fnc_canShow + * call ace_kestrel4500_fnc_canShow * * Public: No */ diff --git a/addons/kestrel4500/functions/fnc_collectData.sqf b/addons/kestrel4500/functions/fnc_collectData.sqf index 244e719b37..2e25fbcf60 100644 --- a/addons/kestrel4500/functions/fnc_collectData.sqf +++ b/addons/kestrel4500/functions/fnc_collectData.sqf @@ -3,18 +3,19 @@ * Gathers the weather data for the Kestrel 4500 * * Arguments: - * Nothing + * None * * Return Value: - * Nothing + * None * * Example: + * call ace_kestrel4500_fnc_collectData * * Public: No */ #include "script_component.hpp" -private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_updateMemory", "_windSpeed", "_crosswind", "_headwind"]; +private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_altitude", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_windSpeed", "_crosswind", "_headwind"]; _playerDir = getDir ACE_player; _playerAltitude = (getPosASL ACE_player) select 2; _temperature = _playerAltitude call EFUNC(weather,calculateTemperatureAtHeight); @@ -35,25 +36,19 @@ if (isNil QGVAR(MIN) || isNil QGVAR(MAX)) then { { GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1]; -} forEach [1, 5, 6, 7, 8, 9, 10, 11, 12, 13]; +} count [1, 5, 6, 7, 8, 9, 10, 11, 12, 13]; -_fnc_updateMemory = { - PARAMS_2(_slot,_value); - GVAR(MIN) set [_slot, (GVAR(MIN) select _slot) min _value]; - GVAR(MAX) set [_slot, _value max (GVAR(MAX) select _slot)]; - GVAR(TOTAL) set [_slot, (GVAR(TOTAL) select _slot) + _value]; -}; -[0, _playerDir] call _fnc_updateMemory; +[0, _playerDir] call FUNC(updateMemory); if (GVAR(MinAvgMaxMode) == 1) then { { GVAR(ENTRIES) set [_x, (GVAR(ENTRIES) select _x) + 1]; - } forEach [2, 3, 4]; + } count [2, 3, 4]; // Wind SPD _windSpeed = call FUNC(measureWindSpeed); - [2, _windSpeed] call _fnc_updateMemory; + [2, _windSpeed] call FUNC(updateMemory); // CROSSWIND _crosswind = 0; @@ -62,7 +57,7 @@ if (GVAR(MinAvgMaxMode) == 1) then { } else { _crosswind = abs(sin(GVAR(RefHeading)) * _windSpeed); }; - [3, _crosswind] call _fnc_updateMemory; + [3, _crosswind] call FUNC(updateMemory); // HEADWIND _headwind = 0; @@ -80,12 +75,4 @@ if (GVAR(MinAvgMaxMode) == 1) then { GVAR(TOTAL) set [4, (GVAR(TOTAL) select 4) + _headwind]; }; -[5, _temperature] call _fnc_updateMemory; -[6, _chill] call _fnc_updateMemory; -[7, _humidity] call _fnc_updateMemory; -[8, _heatIndex] call _fnc_updateMemory; -[9, _dewPoint] call _fnc_updateMemory; -[10, _wetBulb] call _fnc_updateMemory; -[11, _barometricPressure] call _fnc_updateMemory; -[12, _altitude] call _fnc_updateMemory; -[13, _densityAltitude] call _fnc_updateMemory; +{ _x call FUNC(updateMemory); true } count [[5, _temperature],[6, _chill],[7, _humidity],[8, _heatIndex],[9, _dewPoint],[10, _wetBulb],[11, _barometricPressure],[12, _altitude],[13, _densityAltitude]]; diff --git a/addons/kestrel4500/functions/fnc_createKestrelDialog.sqf b/addons/kestrel4500/functions/fnc_createKestrelDialog.sqf index 289d0825fc..23ca70543b 100644 --- a/addons/kestrel4500/functions/fnc_createKestrelDialog.sqf +++ b/addons/kestrel4500/functions/fnc_createKestrelDialog.sqf @@ -3,7 +3,7 @@ * Opens the Kestrel 4500 dialog * * Arguments: - * Nothing + * None * * Return Value: * Nothing @@ -29,7 +29,7 @@ createDialog 'Kestrel4500_Display'; GVAR(Kestrel4500) = false; [_this select 1] call CBA_fnc_removePerFrameHandler; }; - + [] call FUNC(updateDisplay); }, 1, _this select 0] call CBA_fnc_addPerFrameHandler; diff --git a/addons/kestrel4500/functions/fnc_displayKestrel.sqf b/addons/kestrel4500/functions/fnc_displayKestrel.sqf index 679ecce6af..63a162a7b0 100644 --- a/addons/kestrel4500/functions/fnc_displayKestrel.sqf +++ b/addons/kestrel4500/functions/fnc_displayKestrel.sqf @@ -3,12 +3,13 @@ * Shows the Kestrel 4500 as rsc title * * Arguments: - * Nothing + * None * * Return Value: * Nothing * * Example: + * call ace_kestrel4500_fnc_displayKestrell * * Public: No */ @@ -50,49 +51,66 @@ if (GVAR(Kestrel4500) && dialog) then { GVAR(Overlay) = true; -[{ +[{ // abort condition if (!GVAR(Overlay) || {!(("ACE_Kestrel4500" in (uniformItems ACE_player)) || ("ACE_Kestrel4500" in (vestItems ACE_player)))}) exitWith { GVAR(Overlay) = false; 3 cutText ["", "PLAIN"]; [_this select 1] call CBA_fnc_removePerFrameHandler; }; - + if (ACE_diagTime > GVAR(updateTimer)) then { GVAR(updateTimer) = ACE_diagTime + 1; - + private ["_outputData"]; _outputData = [] call FUNC(generateOutputData); - + 3 cutRsc ["RscKestrel4500", "PLAIN", 1, false]; - - __ctrlTop ctrlSetText (_outputData select 0); - __ctrlCenterBig ctrlSetText (_outputData select 1); - - __ctrlTop ctrlSetText (_outputData select 0); - __ctrlCenterBig ctrlSetText (_outputData select 1); - __ctrlCenter ctrlSetText (_outputData select 2); - - __ctrlCenterLine1Left ctrlSetText (_outputData select 3); - __ctrlCenterLine2Left ctrlSetText (_outputData select 4); - __ctrlCenterLine3Left ctrlSetText (_outputData select 5); + _outputData params [ + "_ctrlTop", + "_ctrlCenterBig", + "_ctrlCenter", + "_ctrlCenterLine1Left", + "_ctrlCenterLine2Left", + "_ctrlCenterLine3Left", + "_ctrlCenterLine1Right", + "_ctrlCenterLine2Right", + "_ctrlCenterLine3Right", + "_ctrlInfoLine1", + "_ctrlInfoLine2", + "_ctrlBottomBig", + "_ctrlCenterLine1", + "_ctrlCenterLine2", + "_ctrlCenterLine3", + "_ctrlCenterLine4", + "_ctrlCenterLine5", + "_ctrlCenterLine6" + ]; - __ctrlCenterLine1Right ctrlSetText (_outputData select 6); - __ctrlCenterLine2Right ctrlSetText (_outputData select 7); - __ctrlCenterLine3Right ctrlSetText (_outputData select 8); + __ctrlTop ctrlSetText _ctrlTop; + __ctrlCenterBig ctrlSetText _ctrlCenterBig; + __ctrlCenter ctrlSetText _ctrlCenter; + + __ctrlCenterLine1Left ctrlSetText _ctrlCenterLine1Left; + __ctrlCenterLine2Left ctrlSetText _ctrlCenterLine2Left; + __ctrlCenterLine3Left ctrlSetText _ctrlCenterLine3Left; + + __ctrlCenterLine1Right ctrlSetText _ctrlCenterLine1Right; + __ctrlCenterLine2Right ctrlSetText _ctrlCenterLine2Right; + __ctrlCenterLine3Right ctrlSetText _ctrlCenterLine3Right; + + __ctrlInfoLine1 ctrlSetText _ctrlInfoLine1; + __ctrlInfoLine2 ctrlSetText _ctrlInfoLine2; + + __ctrlBottomBig ctrlSetText _ctrlBottomBig ; + + __ctrlCenterLine1 ctrlSetText _ctrlCenterLine1; + __ctrlCenterLine2 ctrlSetText _ctrlCenterLine2; + __ctrlCenterLine3 ctrlSetText _ctrlCenterLine3; + __ctrlCenterLine4 ctrlSetText _ctrlCenterLine4; + __ctrlCenterLine5 ctrlSetText _ctrlCenterLine5; + __ctrlCenterLine6 ctrlSetText _ctrlCenterLine6; - __ctrlInfoLine1 ctrlSetText (_outputData select 9); - __ctrlInfoLine2 ctrlSetText (_outputData select 10); - - __ctrlBottomBig ctrlSetText (_outputData select 11); - - __ctrlCenterLine1 ctrlSetText (_outputData select 12); - __ctrlCenterLine2 ctrlSetText (_outputData select 13); - __ctrlCenterLine3 ctrlSetText (_outputData select 14); - __ctrlCenterLine4 ctrlSetText (_outputData select 15); - __ctrlCenterLine5 ctrlSetText (_outputData select 16); - __ctrlCenterLine6 ctrlSetText (_outputData select 17); - if (GVAR(referenceHeadingMenu) == 1) then { if (GVAR(referenceHeadingAutoSet)) then { __ctrlCenterLine3 ctrlSetTextColor [0, 0, 0, 0.6]; @@ -106,10 +124,10 @@ GVAR(Overlay) = true; __ctrlCenterLine4 ctrlSetTextColor [0, 0, 0, 1.0]; }; }; - + call FUNC(updateImpellerState); __ctrlKestrel4500 ctrlSetText format [QUOTE(PATHTOF(UI\Kestrel4500_%1.paa)), floor(GVAR(ImpellerState) % 7)]; - + }, 0.01, []] call CBA_fnc_addPerFrameHandler; true diff --git a/addons/kestrel4500/functions/fnc_generateOutputData.sqf b/addons/kestrel4500/functions/fnc_generateOutputData.sqf index d61a1f48e4..de62da31ff 100644 --- a/addons/kestrel4500/functions/fnc_generateOutputData.sqf +++ b/addons/kestrel4500/functions/fnc_generateOutputData.sqf @@ -3,12 +3,29 @@ * Generates the Kestrel 4500 output text. * * Arguments: - * Nothing + * None * * Return Value: - * [top , centerBig , CenterLine1Left , CenterLine2Left , CenterLine3Left , CenterLine1Right , CenterLine2Right , CenterLine3Right , InfoLine1 , InfoLine2 ] + * 0: top + * 1: centerBig + * 2: CenterLine1Left + * 3: CenterLine2Left + * 4: CenterLine3Left + * 5: CenterLine1Right + * 6: CenterLine2Right + * 7: CenterLine3Right + * 8: InfoLine1 + * 9: InfoLine2 + * 10: Bottom Big + * 11: Center Line 1 + * 11: Center Line 2 + * 12: Center Line 3 + * 13: Center Line 4 + * 14: Center Line 5 + * 15: Center Line 6 * * Example: + * _var = call ace_kestrell4500_fnc_generateOutputData * * Public: No */ @@ -16,7 +33,7 @@ if (ACE_diagTime - GVAR(headingSetDisplayTimer) < 0.8) exitWith {["", "", " Heading Set", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]}; -private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_fnc_dayOfWeek", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"]; +private ["_playerDir", "_playerAltitude", "_temperature", "_humidity", "_barometricPressure", "_airDensity", "_densityAltitude", "_chill", "_heatIndex", "_dewPoint", "_wetBulb", "_dayString", "_monthString", "_windSpeed", "_windDir", "_textTop", "_textCenterBig", "_textCenter", "_textCenterLine1Left", "_textCenterLine2Left", "_textCenterLine3Left", "_textCenterLine1Right", "_textCenterLine2Right", "_textCenterLine3Right", "_textInfoLine1", "_textInfoLine2", "_textBottomBig", "_textCenterLine1", "_textCenterLine2", "_textCenterLine3", "_textCenterLine4", "_textCenterLine5", "_textCenterLine6"]; [] call FUNC(collectData); @@ -59,19 +76,6 @@ _heatIndex = [_temperature, _humidity] call EFUNC(weather,calculateHeatIndex); _dewPoint = [_temperature, _humidity] call EFUNC(weather,calculateDewPoint); _wetBulb = [_temperature, _barometricPressure, _humidity] call EFUNC(weather,calculateWetBulb); -_fnc_dayOfWeek = { - private ["_year", "_month", "_day", "_table"]; - _year = _this select 0; - _month = _this select 1; - _day = _this select 2; - - _table = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]; - if (_month < 3) then { - _year = _year - 1; - }; - (_year + floor(_year/4) - floor(_year/100) + floor(_year/400) + (_table select (_month - 1)) + _day) % 7 -}; - GVAR(Direction) = 4 * floor(_playerDir / 90); if (_playerDir % 90 > 10) then { GVAR(Direction) = GVAR(Direction) + 1}; if (_playerDir % 90 > 35) then { GVAR(Direction) = GVAR(Direction) + 1}; @@ -82,8 +86,8 @@ GVAR(Direction) = GVAR(Direction) % 16; if (GVAR(referenceHeadingMenu) == 0) then { switch (GVAR(Menu)) do { case 0: { // Date - EXPLODE_3_PVT(date,_year,_month,_day); - _dayString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] select (date call _fnc_dayOfWeek); + date params ["_year", "_month", "_day"]; + _dayString = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] select (date call FUNC(dayOfWeek)); _monthString = localize (["str_january","str_february","str_march","str_april","str_may","str_june","str_july","str_august","str_september","str_october","str_november","str_december"] select (_month - 1)); _textTop = _dayString; _textCenter = format["%1 %2 %3", _day, _monthString, _year]; diff --git a/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf b/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf index 73b4e228d6..2a8a4bbbb3 100644 --- a/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf +++ b/addons/kestrel4500/functions/fnc_measureWindSpeed.sqf @@ -3,12 +3,13 @@ * Measures the wind speed, stores the information in GVAR(MeasuredWindSpeed) and updates GVAR(ImpellerState) * * Arguments: - * Nothing + * None * * Return Value: * wind speed * * Example: + * call ace_kestrel4500_fnc_canShow * * Public: No */ diff --git a/addons/kestrel4500/functions/fnc_onCloseDialog.sqf b/addons/kestrel4500/functions/fnc_onCloseDialog.sqf index a45a9decc3..11fa76ff18 100644 --- a/addons/kestrel4500/functions/fnc_onCloseDialog.sqf +++ b/addons/kestrel4500/functions/fnc_onCloseDialog.sqf @@ -1,3 +1,18 @@ +/* + * Author: Ruthberg + * Called if Kestrell Dialog is closed + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_kestrel4500_fnc_onCloseDialog + * + * Public: No + */ #include "script_component.hpp" uiNamespace setVariable ['Kestrel4500_Display', nil]; diff --git a/addons/kestrel4500/functions/fnc_onCloseDisplay.sqf b/addons/kestrel4500/functions/fnc_onCloseDisplay.sqf index efb60b322a..9228aedcef 100644 --- a/addons/kestrel4500/functions/fnc_onCloseDisplay.sqf +++ b/addons/kestrel4500/functions/fnc_onCloseDisplay.sqf @@ -1,3 +1,18 @@ +/* + * Author: Ruthberg + * Called if Kestrell Display is closed + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_kestrel4500_fnc_onCloseDisplay + * + * Public: No + */ #include "script_component.hpp" uiNamespace setVariable ['RscKestrel4500', nil]; diff --git a/addons/kestrel4500/functions/fnc_restoreUserData.sqf b/addons/kestrel4500/functions/fnc_restoreUserData.sqf index 0ce463ad67..c1d9c0ebb3 100644 --- a/addons/kestrel4500/functions/fnc_restoreUserData.sqf +++ b/addons/kestrel4500/functions/fnc_restoreUserData.sqf @@ -6,7 +6,7 @@ * Nothing * * Return Value: - * Nothing + * None * * Example: * call ace_kestrel4500_fnc_restore_user_data diff --git a/addons/kestrel4500/functions/fnc_storeUserData.sqf b/addons/kestrel4500/functions/fnc_storeUserData.sqf index a5d069b31d..80fa219a3c 100644 --- a/addons/kestrel4500/functions/fnc_storeUserData.sqf +++ b/addons/kestrel4500/functions/fnc_storeUserData.sqf @@ -3,10 +3,10 @@ * Saves user data into profileNamespace * * Arguments: - * Nothing + * None * * Return Value: - * Nothing + * None * * Example: * call ace_kestrel4500_fnc_store_user_data diff --git a/addons/kestrel4500/functions/fnc_updateDisplay.sqf b/addons/kestrel4500/functions/fnc_updateDisplay.sqf index 90f77f5f6a..e63b18bcfc 100644 --- a/addons/kestrel4500/functions/fnc_updateDisplay.sqf +++ b/addons/kestrel4500/functions/fnc_updateDisplay.sqf @@ -3,10 +3,10 @@ * Updates the Kestrel 4500 dialog text boxes. * * Arguments: - * Nothing + * None * * Return Value: - * Nothing + * None * * Example: * @@ -22,29 +22,9 @@ private ["_outputData"]; _outputData = [] call FUNC(generateOutputData); -ctrlSetText [74100, _outputData select 0]; -ctrlSetText [74200, _outputData select 1]; -ctrlSetText [74201, _outputData select 2]; - -ctrlSetText [74300, _outputData select 3]; -ctrlSetText [74301, _outputData select 4]; -ctrlSetText [74302, _outputData select 5]; - -ctrlSetText [74303, _outputData select 6]; -ctrlSetText [74304, _outputData select 7]; -ctrlSetText [74305, _outputData select 8]; - -ctrlSetText [74400, _outputData select 9]; -ctrlSetText [74401, _outputData select 10]; - -ctrlSetText [74500, _outputData select 11]; - -ctrlSetText [74600, _outputData select 12]; -ctrlSetText [74601, _outputData select 13]; -ctrlSetText [74602, _outputData select 14]; -ctrlSetText [74603, _outputData select 15]; -ctrlSetText [74604, _outputData select 16]; -ctrlSetText [74605, _outputData select 17]; +{ + ctrlSetText [_x , _outputData select _foreachindex]; +} forEach [74100, 74200, 74201, 74300, 74301, 74302, 74303, 74304, 74305, 74400, 74401, 74500, 74600, 74601, 74602, 74603, 74604, 74605]; if (GVAR(referenceHeadingMenu) == 1) then { if (GVAR(referenceHeadingAutoSet)) then { diff --git a/addons/kestrel4500/functions/fnc_updateImpellerState.sqf b/addons/kestrel4500/functions/fnc_updateImpellerState.sqf index 075ed80080..75a0d10f4c 100644 --- a/addons/kestrel4500/functions/fnc_updateImpellerState.sqf +++ b/addons/kestrel4500/functions/fnc_updateImpellerState.sqf @@ -3,10 +3,10 @@ * Updates the Kestrel 4500 Impeller state * * Arguments: - * Nothing + * None * * Return Value: - * Nothing + * None * * Example: *