Skip to content

Commit

Permalink
Add alt syntax to provide args to button clicked code on all menus
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorAU committed Nov 29, 2022
1 parent 19193c6 commit d557520
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 36 deletions.
3 changes: 2 additions & 1 deletion addon/systems/_common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ USE_CTRL(_ctrlInput,IDC_INPUT);
USE_CTRL(_ctrlButtonL,IDC_BUTTONL);
USE_CTRL(_ctrlButtonR,IDC_BUTTONR);

_display setVariable ["args",_args];
_display setVariable ["code",_code];
_display setVariable ["return",_return];
_ctrlTitle ctrlSetText _title;
Expand Down Expand Up @@ -58,4 +59,4 @@ _display displayAddEventHandler ["KeyDown",[
[_this#0,false] call ((_this#0) getVariable ['return',{}]);
};
}
] select _ctrlButtonLShown];
] select _ctrlButtonLShown];
12 changes: 7 additions & 5 deletions addon/systems/displayColorPicker.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
params [
["_parameters",[],[[]]],
["_title","",[""]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_button1","",[""]],
["_button2",0,[""]],
["_parentDisplay",displayNull,[displayNull]]
];
_parameters params [
["_color",[],[[],""]]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (!isNull _parentDisplay) then {
_parentDisplay createDisplay QUOTE(DISPLAY_NAME);
Expand All @@ -56,6 +57,7 @@ if (!isNull _parentDisplay) then {

private _return = {
params ["_display","_confirmed"];
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];

private _colorRGBA1 = _display getVariable ["selectedColor",[0,0,0,1]];
Expand All @@ -67,9 +69,9 @@ private _return = {
};

_display closeDisplay 2;
_code call {
private ["_display","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_code","_args"];
(_this#0) call (_this#1);
};
};

Expand Down Expand Up @@ -372,4 +374,4 @@ _ctrlToolboxMode lbSetCurSel _startColorType;

[] call FUNC("createGrid");
[] call FUNC("updateGridColor");
[] call FUNC("updateEdit");
[] call FUNC("updateEdit");
12 changes: 7 additions & 5 deletions addon/systems/displayGuiMessage.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
params [
["_parameters",[],[[]]],
["_title","",[""]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_button1","",[""]],
["_button2",0,[""]],
["_parentDisplay",displayNull,[displayNull]]
];
_parameters params [
["_text","",[""]]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (!isNull _parentDisplay) then {
_parentDisplay createDisplay QUOTE(DISPLAY_NAME);
Expand All @@ -31,11 +32,12 @@ if (!isNull _parentDisplay) then {

private _return = {
params ["_display","_confirmed"];
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];
_display closeDisplay 2;
_code call {
private ["_display","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_code","_args"];
(_this#0) call (_this#1);
};
};

Expand Down Expand Up @@ -83,4 +85,4 @@ _ctrlButtonL ctrlCommit 0;
private _ctrlButtonRPos = ctrlPosition _ctrlButtonR;
_ctrlButtonRPos set [1,_ctrlFooterPos#1 + PX_HA(1)];
_ctrlButtonR ctrlSetPosition _ctrlButtonRPos;
_ctrlButtonR ctrlCommit 0;
_ctrlButtonR ctrlCommit 0;
21 changes: 12 additions & 9 deletions addon/systems/displayListbox.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
params [
["_parameters",[],[[]]],
["_title","",[""]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_button1","",[""]],
["_button2",0,[""]],
["_parentDisplay",displayNull,[displayNull]]
Expand All @@ -23,6 +23,7 @@ _parameters params [
["_startIndex",0,[0]],
["_multiSel",false,[true]]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (!isNull _parentDisplay) then {
_parentDisplay createDisplay ([QUOTE(DISPLAY_NAME),QUOTE(JOIN(DISPLAY_NAME,Multi))] select _multiSel);
Expand All @@ -33,19 +34,21 @@ if (!isNull _parentDisplay) then {
private _return = [{
params ["_display","_confirmed"];
USE_CTRL(_ctrlInput,IDC_INPUT);
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];
if !_confirmed then {_ctrlInput lbSetCurSel -1};
private _index = lbCurSel _ctrlInput;
private _data = _ctrlInput lbData _index;
private _value = _ctrlInput lbValue _index;
_display closeDisplay 2;
_code call {
private ["_display","_ctrlInput","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_ctrlInput","_code","_args"];
(_this#0) call (_this#1);
};
},{
params ["_display","_confirmed"];
USE_CTRL(_ctrlInput,IDC_INPUT);
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];
if !_confirmed then {
for "_i" from 0 to (lbSize _ctrlInput - 1) do {
Expand All @@ -56,9 +59,9 @@ private _return = [{
private _data = _index apply {_ctrlInput lbData _x};
private _value = _index apply {_ctrlInput lbValue _x};
_display closeDisplay 2;
_code call {
private ["_display","_ctrlInput","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_ctrlInput","_code","_args"];
(_this#0) call (_this#1);
};
}] select _multiSel;

Expand All @@ -75,7 +78,7 @@ lbClear _ctrlInput;
["_data","",[""]],
["_value",-1,[0]]
];

_textLData params [["_text","",[""]],["_color",[1,1,1,1],[[]],4]];
private _index = _ctrlInput lbAdd _text;
_ctrlInput lbSetColor [_index,_color];
Expand Down Expand Up @@ -103,4 +106,4 @@ lbClear _ctrlInput;

private _index = 0 max _startIndex min (lbSize _ctrlInput - 1);
_ctrlInput lbSetCurSel _index;
if _multiSel then {_ctrlInput lbSetSelected [_index,true]};
if _multiSel then {_ctrlInput lbSetSelected [_index,true]};
18 changes: 11 additions & 7 deletions addon/systems/displayProgressBar.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
params [
["_parameters",[],[[]]],
["_title","Progress",[""]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_parentDisplay",displayNull,[displayNull]]
];
_parameters params [
Expand All @@ -29,6 +29,7 @@ _parameters params [
["_condition",{},[{}]],
["_onProgress",{},[{}]]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (_duration <= 0) exitWith {["Duration too short: %1",_duration] call BIS_fnc_error};

Expand Down Expand Up @@ -80,13 +81,15 @@ _parentDisplay displayAddEventHandler ["Unload",{
private _exit = {
USE_DISPLAY(THIS_DISPLAY);
private _parentDisplay = ctrlParent _display;


private _args = GVAR(args,[]);
private _code = GVAR(code,{});

removeMissionEventHandler ["EachFrame",GVAR(eachFrameID,-1)];
if GVAR(overlay,true) then {
ctrlDelete _display;
// wipe variables from parent display because we aren't closing it
SVAR(args,nil);
SVAR(code,nil);
SVAR(arguments,nil);
SVAR(condition,nil);
Expand All @@ -101,15 +104,16 @@ private _exit = {
_parentDisplay closeDisplay 0;
};

[_this == 0,_code] call {
[_this == 0,_args,_code] call {
// Wiping inherited local variables from scope
private ["_parentDisplay","_display","_canProgress","_progress","_ctrlBackground","_ctrlBar","_ctrlText","_code"];
private ["_parentDisplay","_display","_canProgress","_progress","_ctrlBackground","_ctrlBar","_ctrlText","_code","_args"];
params ["_completed"];
[] call (_this#1);
(_this#1) call (_this#2);
};
};

// Save data to parent display
SVAR(args,_args);
SVAR(code,_code);
SVAR(arguments,_arguments);
SVAR(condition,_condition);
Expand All @@ -132,7 +136,7 @@ private _eachFrameID = addMissionEventHandler ["EachFrame",{
private ["_display","_parentDisplay"];
(_this#0) call (_this#1);
};
if (!isNil "_canProgress" && {!(_canProgress isEqualType true) || {!_canProgress}}) exitWith {1 call GVAR(exit,{})};
if (!isNil "_canProgress" && {!(_canProgress isEqualType true) || {!_canProgress}}) exitWith {1 call GVAR(exit,{})};

GVAR(onProgress,{}) call {
// Wiping inherited local variables from scope
Expand All @@ -156,4 +160,4 @@ private _eachFrameID = addMissionEventHandler ["EachFrame",{
// Exit if complete
if (_progress == 1) then {0 call GVAR(exit,{})};
}];
SVAR(eachFrameID,_eachFrameID);
SVAR(eachFrameID,_eachFrameID);
12 changes: 7 additions & 5 deletions addon/systems/displaySlider.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ params [
["_parameters",[],[[]]],
["_title","",[""]],
["_formatVal",{},[{}]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_button1","",[""]],
["_button2",0,[""]],
["_parentDisplay",displayNull,[displayNull]]
Expand All @@ -24,6 +24,7 @@ _parameters params [
["_position",0,[0]],
["_speed",[1,1],[[]],2]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (!isNull _parentDisplay) then {
_parentDisplay createDisplay QUOTE(DISPLAY_NAME);
Expand All @@ -34,12 +35,13 @@ if (!isNull _parentDisplay) then {
private _return = {
params ["_display","_confirmed"];
USE_CTRL(_ctrlInput,IDC_INPUT);
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];
private _position = [-1,sliderPosition _ctrlInput] select _confirmed;
_display closeDisplay 2;
_code call {
private ["_display","_ctrlInput","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_ctrlInput","_code","_args"];
(_this#0) call (_this#1);
};
};

Expand All @@ -63,4 +65,4 @@ _ctrlInput sliderSetSpeed _speed;
_ctrlInput sliderSetPosition _position;
_ctrlInput ctrlAddEventHandler ["SliderPosChanged",{_this call ((_this#0) getVariable ["sliderPosChanged",{}])}];

[_ctrlInput,_position] call (_ctrlInput getVariable ["sliderPosChanged",{}]);
[_ctrlInput,_position] call (_ctrlInput getVariable ["sliderPosChanged",{}]);
10 changes: 6 additions & 4 deletions addon/systems/displayText.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
params [
["_parameters",[],[[]]],
["_title","",[""]],
["_code",{},[{}]],
["_code",{},[{},[]]],
["_button1","",[""]],
["_button2",0,[""]],
["_parentDisplay",displayNull,[displayNull]]
Expand All @@ -22,6 +22,7 @@ _parameters params [
["_multiLine",false,[true]],
["_startText","",[""]]
];
_code params [["_code",{},[{}]],["_args",[],[[]]]];

if (!isNull _parentDisplay) then {
_parentDisplay createDisplay ([QUOTE(DISPLAY_NAME),QUOTE(JOIN(DISPLAY_NAME,Multi))] select _multiLine);
Expand All @@ -32,12 +33,13 @@ if (!isNull _parentDisplay) then {
private _return = {
params ["_display","_confirmed"];
USE_CTRL(_ctrlInput,IDC_INPUT);
private _args = _display getVariable ["args",[]];
private _code = _display getVariable ["code",{}];
private _text = ["",ctrlText _ctrlInput] select _confirmed;
_display closeDisplay 2;
_code call {
private ["_display","_ctrlInput","_code"];
[] call _this;
[_args,_code] call {
private ["_display","_ctrlInput","_code","_args"];
(_this#0) call (_this#1);
};
};

Expand Down

0 comments on commit d557520

Please sign in to comment.