From 81d854c56a4887449a4e2b5c91d0acf3fe0b5b80 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Tue, 17 May 2016 23:31:10 +0100 Subject: [PATCH] Add group side zeus module The module is placed on a unit in order to switch the side of that unit's group. A "simple" dialog is used to select the new side. The dialog code is a little ugly to say the least. --- addons/zeus/CfgVehicles.hpp | 5 + addons/zeus/XEH_PREP.hpp | 2 + addons/zeus/config.cpp | 1 + addons/zeus/functions/fnc_moduleGroupSide.sqf | 45 ++++++++ addons/zeus/functions/fnc_ui_groupSide.sqf | 107 ++++++++++++++++++ addons/zeus/ui/RscAttributes.hpp | 87 +++++++++++++- 6 files changed, 243 insertions(+), 4 deletions(-) create mode 100644 addons/zeus/functions/fnc_moduleGroupSide.sqf create mode 100644 addons/zeus/functions/fnc_ui_groupSide.sqf diff --git a/addons/zeus/CfgVehicles.hpp b/addons/zeus/CfgVehicles.hpp index 3a9b7b8670..5e88023dde 100644 --- a/addons/zeus/CfgVehicles.hpp +++ b/addons/zeus/CfgVehicles.hpp @@ -120,6 +120,11 @@ class CfgVehicles { displayName = "Global AI Skill"; curatorInfoType = QGVAR(RscGlobalSetSkill); }; + class GVAR(moduleGroupSide): GVAR(moduleBase) { + curatorCanAttach = 1; + displayName = "Group Side"; + curatorInfoType = QGVAR(RscGroupSide); + }; class GVAR(moduleSetMedic): GVAR(moduleBase) { curatorCanAttach = 1; displayName = CSTRING(ModuleSetMedic_DisplayName); diff --git a/addons/zeus/XEH_PREP.hpp b/addons/zeus/XEH_PREP.hpp index a72f220d31..d171b3679c 100644 --- a/addons/zeus/XEH_PREP.hpp +++ b/addons/zeus/XEH_PREP.hpp @@ -9,6 +9,7 @@ PREP(moduleAddSpareTrack); PREP(moduleAddSpareWheel); PREP(moduleCaptive); PREP(moduleGlobalSetSkill); +PREP(moduleGroupSide); PREP(moduleSetMedic); PREP(moduleSetMedicalVehicle); PREP(moduleSetMedicalFacility); @@ -17,6 +18,7 @@ PREP(moduleTeleportPlayers); PREP(moduleUnconscious); PREP(moduleZeusSettings); PREP(ui_globalSetSkill); +PREP(ui_groupSide); PREP(ui_teleportPlayers); PREP(ui_vehCargo); PREP(zeusAttributes); diff --git a/addons/zeus/config.cpp b/addons/zeus/config.cpp index 560a6f8073..1b47046fd9 100644 --- a/addons/zeus/config.cpp +++ b/addons/zeus/config.cpp @@ -4,6 +4,7 @@ class CfgPatches { class ADDON { units[] = { QGVAR(moduleGlobalSetSkill), + QGVAR(moduleGroupSide), QGVAR(moduleTeleportPlayers) }; weapons[] = {}; diff --git a/addons/zeus/functions/fnc_moduleGroupSide.sqf b/addons/zeus/functions/fnc_moduleGroupSide.sqf new file mode 100644 index 0000000000..fa37ca3463 --- /dev/null +++ b/addons/zeus/functions/fnc_moduleGroupSide.sqf @@ -0,0 +1,45 @@ +/* + * Author: SilentSpike + * Zeus module function to change side of a group on dialog confirmation + * + * Arguments: + * 0: Unit to target + * 1: Chosen side + * + * Return Value: + * None + * + * Example: + * [this, west] call ace_zeus_fnc_moduleGroupSide + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_unit","_newSide"]; +private _side = side _unit; + +// Nothing to do here +if (_side == _newSide) exitWith {}; + +private _oldGroup = group _unit; +private _newGroup = createGroup _newSide; + +// Pretty hacky, will replace units return group with this new group if unconcious +if (GETVAR(_unit,ACE_isUnconscious,false) && {GETMVAR(EGVAR(medical,moveUnitsFromGroupOnUnconscious),false)}) then { + private _previousGroupsList = _unit getVariable [QEGVAR(common,previousGroupSwitchTo), []]; + + { + if ("ACE_isUnconscious" == (_x select 2)) exitWith { + _x set [0,_newGroup]; + _x set [1,_newSide]; + _previousGroupsList set [_forEachIndex, _x]; + }; + } forEach _previousGroupsList; + + _unit setVariable [QEGVAR(common,previousGroupSwitchTo), _previousGroupsList, true]; +} else { + (units _unit) joinSilent _newGroup; + deleteGroup _oldGroup; +}; diff --git a/addons/zeus/functions/fnc_ui_groupSide.sqf b/addons/zeus/functions/fnc_ui_groupSide.sqf new file mode 100644 index 0000000000..d7ad41e6c4 --- /dev/null +++ b/addons/zeus/functions/fnc_ui_groupSide.sqf @@ -0,0 +1,107 @@ +#include "script_component.hpp" +#define IDCs [31201,31200,31202,31203] + +disableSerialization; + +params ["_control"]; + +//Generic Init: +private _display = ctrlparent _control; +private _ctrlButtonOK = _display displayctrl 1; //IDC_OK +private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull); +TRACE_1("logicObject",_logic); + +_control ctrlRemoveAllEventHandlers "setFocus"; + +//Validate the module target: +private _unit = effectiveCommander (attachedTo _logic); +private _side = side _unit; + +scopeName "Main"; +private _fnc_errorAndClose = { + params ["_msg"]; + _display closeDisplay 0; + deleteVehicle _logic; + [_msg] call EFUNC(common,displayTextStructured); + breakOut "Main"; +}; + +switch (false) do { + case (_unit isKindOf "CAManBase"): { + [LSTRING(OnlyInfantry)] call _fnc_errorAndClose; + }; + case (alive _unit): { + [LSTRING(OnlyAlive)] call _fnc_errorAndClose; + }; + case (_side in [west,east,independent,civilian]): { + ["Unit must belong to an appropriate side"] call _fnc_errorAndClose; + }; +}; + +//Specific on-load stuff: +private _idcActive = 31200 + ([west,east,independent,civilian] find _side); +SETVAR(_display,oldSide,_idcActive - 31200); +SETVAR(_display,newSide,_idcActive - 31200); + +private _fnc_onSelection = { + params [["_activeCtrl", controlNull, [controlNull]]]; + + private _display = ctrlParent _activeCtrl; + if (isNull _display) exitWith {}; + + // Update the button scales and colours on selection + { + private _ctrl = _display displayCtrl _x; + private _color = _ctrl getVariable "color"; + private _scale = 1; + + if (ctrlIDC _activeCtrl == _x) then { + _color set [3,1]; + _scale = 1.2 + } else { + _color set [3,0.5]; + }; + + _ctrl ctrlSetTextColor _color; + [_ctrl,_scale,0.1] call BIS_fnc_ctrlSetScale; + } forEach IDCs; + + // Store selected button index for confirmation + SETVAR(_display,newSide,(ctrlIDC _activeCtrl) - 31200); +}; + +// Initalize buttons with colour and scale +{ + private _ctrl = _display displayCtrl _x; + private _color = [_forEachIndex] call BIS_fnc_sideColor; + _ctrl setVariable ["color", _color]; + _ctrl ctrlSetActiveColor _color; + _color set [3,0.5]; + + if (ctrlIDC _ctrl == _idcActive) then { + [_ctrl,1.2,0] call BIS_fnc_ctrlSetScale; + _color set [3,1]; + }; + + _ctrl ctrlSetTextColor _color; + + _ctrl ctrlAddEventHandler ["buttonclick", _fnc_onSelection]; +} forEach IDCs; + +private _fnc_onConfirm = { + params [["_ctrlButtonOK", controlNull, [controlNull]]]; + + private _display = ctrlparent _ctrlButtonOK; + if (isNull _display) exitWith {}; + + private _logic = GETMVAR(BIS_fnc_initCuratorAttributes_target,objnull); + if (isNull _logic) exitWith {}; + + private _unit = effectiveCommander (attachedTo _logic); + private _side = [west,east,independent,civilian] select (GETVAR(_display,newSide,GETVAR(_display,oldSide,0))); + + [_unit, _side] call FUNC(moduleGroupSide); + deleteVehicle _logic; +}; + +_ctrlButtonOK ctrlAddEventHandler ["buttonClick", _fnc_onConfirm]; diff --git a/addons/zeus/ui/RscAttributes.hpp b/addons/zeus/ui/RscAttributes.hpp index f5e4b88ad3..c2b19a22f2 100644 --- a/addons/zeus/ui/RscAttributes.hpp +++ b/addons/zeus/ui/RscAttributes.hpp @@ -2,9 +2,11 @@ class RscControlsGroup; class RscControlsGroupNoScrollbars; class RscText; class RscListbox; +class RscCombo; class RscEdit; class RscXSliderH; class RscCheckBox; +class RscActivePicture; class RscDisplayAttributes { class Controls { @@ -113,6 +115,83 @@ class GVAR(RscGlobalSetSkill): RscDisplayAttributes { }; }; +class GVAR(RscGroupSide): RscDisplayAttributes { + onLoad = QUOTE([ARR_3('onLoad', _this, QUOTE(QGVAR(RscGroupSide)))] call FUNC(zeusAttributes)); + onUnload = QUOTE([ARR_3('onUnload', _this, QUOTE(QGVAR(RscGroupSide)))] call FUNC(zeusAttributes)); + class Controls: Controls { + class Background: Background {}; + class Title: Title {}; + class Content: Content { + class Controls { + class GroupSide: RscControlsGroupNoScrollbars { + onSetFocus = QUOTE(_this call FUNC(ui_groupSide)); + idc = 26422; + x = 0; + y = 0; + w = W_PART(26); + h = H_PART(2.5); + class controls { + class Title: RscText { + idc = 31002; + text = "$STR_disp_arcunit_side"; + x = 0; + y = 0; + w = W_PART(10); + h = H_PART(2.5); + colorBackground[] = {0,0,0,0.5}; + }; + class Background: RscText { + idc = 31000; + x = W_PART(10); + y = 0; + w = W_PART(16); + h = H_PART(2.5); + colorBackground[] = {1,1,1,0.1}; + }; + class BLUFOR: RscActivePicture { + idc = 31200; + text = "\a3\Ui_f\data\Map\Markers\NATO\b_unknown.paa"; + x = W_PART(12.5); + y = H_PART(0.25); + w = W_PART(2); + h = H_PART(2); + tooltip = "$STR_WEST"; + }; + class OPFOR: BLUFOR { + idc = 31201; + text = "\a3\Ui_f\data\Map\Markers\NATO\o_unknown.paa"; + x = W_PART(15.5); + y = H_PART(0.25); + w = W_PART(2); + h = H_PART(2); + tooltip = "$STR_EAST"; + }; + class Independent: BLUFOR { + idc = 31202; + text = "\a3\Ui_f\data\Map\Markers\NATO\n_unknown.paa"; + x = W_PART(18.5); + y = H_PART(0.25); + w = W_PART(2); + h = H_PART(2); + tooltip = "$STR_guerrila"; + }; + class Civilian: BLUFOR { + idc = 31203; + text = "\a3\Ui_f\data\Map\Markers\NATO\n_unknown.paa"; + x = W_PART(21.5); + y = H_PART(0.25); + w = W_PART(2); + h = H_PART(2); + tooltip = "$STR_Civilian"; + }; + }; + }; + }; + }; + class ButtonOK: ButtonOK {}; + class ButtonCancel: ButtonCancel {}; + }; +}; class GVAR(RscTeleportPlayers): RscDisplayAttributes { onLoad = QUOTE([ARR_3('onLoad', _this, QUOTE(QGVAR(RscTeleportPlayers)))] call FUNC(zeusAttributes)); @@ -130,7 +209,7 @@ class GVAR(RscTeleportPlayers): RscDisplayAttributes { w = W_PART(26); h = H_PART(8.5); class controls { - class Title1: RscText { + class Title: RscText { idc = -1; text = "Teleport Player"; toolTip = "Teleport selected player to module position"; @@ -140,21 +219,21 @@ class GVAR(RscTeleportPlayers): RscDisplayAttributes { h = H_PART(1); colorBackground[] = {0,0,0,0.5}; }; - class Value1: RscListbox { + class Unit: RscListbox { idc = 16189; x = 0; y = H_PART(1.1); w = W_PART(26); h = H_PART(5.9); }; - class Title2: Title1 { + class Label: Title { idc = -1; text = "Teleport Group"; toolTip = "Teleports all units in group"; y = H_PART(7.1); w = W_PART(10); }; - class Value2: RscCheckBox { + class UseGroup: RscCheckBox { idc = 16188; x = W_PART(10.1); y = H_PART(7.1);