diff --git a/addons/spectator/XEH_PREP.hpp b/addons/spectator/XEH_PREP.hpp index ddca0c226c..20a261b66c 100644 --- a/addons/spectator/XEH_PREP.hpp +++ b/addons/spectator/XEH_PREP.hpp @@ -14,6 +14,7 @@ PREP(ui_draw3D); PREP(ui_fadeList); PREP(ui_getTreeDataIndex); PREP(ui_handleChildDestroyed); +PREP(ui_handleContextMenu); PREP(ui_handleKeyDown); PREP(ui_handleKeyUp); PREP(ui_handleListClick); diff --git a/addons/spectator/functions/fnc_ui_handleContextMenu.sqf b/addons/spectator/functions/fnc_ui_handleContextMenu.sqf new file mode 100644 index 0000000000..3dc8c89032 --- /dev/null +++ b/addons/spectator/functions/fnc_ui_handleContextMenu.sqf @@ -0,0 +1,42 @@ +/* + * Author: SilentSpike + * Function used to handle creating the context menu upon right clicking the units list + * + * Expected behaviour: + * Right clicking the list creates a context menu with relevant toggles and entries at the cursor position + * + * Arguments: + * 0: List + * 1: Mouse button + * 1: X Coordinate + * 1: Y Coordinate + * 1: Shift + * 1: Ctrl + * 1: Alt + * + * Return Value: + * None + * + * Example: + * [false, _this] call ace_spectator_fnc_ui_handleListClick + * + * Public: No + */ +#include "script_component.hpp" + +params ["_list", "_button", "_x", "_y"]; + +// Don't create more than one context menu +if !(isNull (GETUVAR(GVAR(context),controlNull))) exitWith {}; + +// Right clicked +if (_button == 1) then { + private _menu = (ctrlParent _list) ctrlCreate [QGVAR(contextMenu), -1]; + + _menu ctrlSetPosition [_x,_y]; + _menu ctrlCommit 0; + + ctrlSetFocus _menu; + + SETUVAR(GVAR(context),_menu); +}; diff --git a/addons/spectator/functions/fnc_ui_handleListClick.sqf b/addons/spectator/functions/fnc_ui_handleListClick.sqf index 9616e77cac..f8316c3459 100644 --- a/addons/spectator/functions/fnc_ui_handleListClick.sqf +++ b/addons/spectator/functions/fnc_ui_handleListClick.sqf @@ -20,7 +20,7 @@ */ #include "script_component.hpp" -params ["_dblClick","_params"]; +params ["_dblClick", "_params"]; _params params ["_list","_index"]; private _handled = false; diff --git a/addons/spectator/script_component.hpp b/addons/spectator/script_component.hpp index b4e7c82ac8..75b625d3e0 100644 --- a/addons/spectator/script_component.hpp +++ b/addons/spectator/script_component.hpp @@ -138,3 +138,5 @@ #define CTRL_WIDGET_WEAPON (SPEC_DISPLAY displayCtrl IDC_WIDGET_WEAPON) #define IDC_WIDGET_THROWABLE 60042 #define CTRL_WIDGET_THROWABLE (SPEC_DISPLAY displayCtrl IDC_WIDGET_THROWABLE) + +#define IDC_CONTEXT 60050 diff --git a/addons/spectator/ui.hpp b/addons/spectator/ui.hpp index 7a49c72a86..067a77926a 100644 --- a/addons/spectator/ui.hpp +++ b/addons/spectator/ui.hpp @@ -1,3 +1,6 @@ +#include "\A3\ui_f\hpp\defineDIKCodes.inc" + +class CtrlMenu; class RscButton; class RscControlsGroup; class RscControlsGroupNoScrollbars; @@ -12,6 +15,48 @@ class RscToolbox; class RscTree; class EGVAR(common,CompassControl); +class GVAR(contextMenu): CtrlMenu { + idc = IDC_CONTEXT; + + colorBackground[] = {0.1,0.1,0.1,1}; + class Items { + items[] = {"Toggles"}; + class Toggles { + text = "Toggles"; + items[] = { + "ToggleLight", + "ToggleInfo", + "ToggleTags", + "ToggleProjectiles" + }; + }; + class ToggleLight { + text = "Toggle Lights"; + action = QUOTE([ARR_2(displayNull, DIK_L)] call FUNC(ui_handleKeyDown)); + shortcuts[] = { DIK_L }; + picture="\a3\3DEN\Data\Displays\Display3DEN\ToolBar\flashlight_off_ca.paa"; + }; + class ToggleInfo { + text = "Toggle Widget"; + action = QUOTE([ARR_2(displayNull, DIK_I)] call FUNC(ui_handleKeyDown)); + shortcuts[] = { DIK_I }; + }; + class ToggleTags { + text = "Toggle Icons"; + action = QUOTE([ARR_2(displayNull, DIK_O)] call FUNC(ui_handleKeyDown)); + shortcuts[] = { DIK_O }; + }; + class ToggleProjectiles { + text = "Toggle Projectiles"; + action = QUOTE([ARR_2(displayNull, DIK_P)] call FUNC(ui_handleKeyDown)); + shortcuts[] = { DIK_P }; + }; + class Default { + enable = 0; + }; + }; +}; + // Based on RscDisplayEGSpectator (sadly Arma doesn't like display inheritance) class GVAR(display) { idd = IDD_SPEC_DISPLAY; @@ -48,6 +93,7 @@ class GVAR(display) { class List: RscTree { idc = IDC_LIST; + onMouseButtonDown = QUOTE(_this call FUNC(ui_handleContextMenu)); onMouseEnter = QUOTE([false] call FUNC(ui_fadeList)); onMouseExit = QUOTE([true] call FUNC(ui_fadeList)); onTreeSelChanged = QUOTE([ARR_2(false,_this)] call FUNC(ui_handleListClick)); @@ -76,7 +122,6 @@ class GVAR(display) { class Tabs: RscToolbox { idc = IDC_TABS; - //onToolBoxSelChanged = QUOTE(_this call FUNC(ui_handleTabSelected)); onMouseEnter = QUOTE([false] call FUNC(ui_fadeList)); onMouseExit = QUOTE([true] call FUNC(ui_fadeList));