Skip to content

Commit

Permalink
setup framework for ui
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCandianVendingMachine committed Feb 23, 2025
1 parent 0b37266 commit 0b8a3d9
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 11 deletions.
73 changes: 72 additions & 1 deletion addons/laser_warning/GUI.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class RscObject;
class RscButton;
class RscText;
class RscControlsGroup;

class GVAR(pushButton): RscButton {
Expand All @@ -20,6 +21,19 @@ class GVAR(pushButton): RscButton {
text = "";
};

class GVAR(osb): RscText {
style = 2;
x = 0;
y = 0;
w = 0.1;
h = 0.08;
colorBackground[] = {0,0.1,0,1};
colorBackgroundDisabled[] = {0,0,0,0};
colorBackgroundActive[] = {0,0,0,0};
colorFocused[] = {0,0,0,0};
text = "foobar";
};

class GVAR(box_dialog) {
idd = -1;
enableSimulation = 1;
Expand All @@ -45,14 +59,71 @@ class GVAR(box_dialog) {
selection = "screen";
class Controls {
class Menu: RscControlsGroup {
idc = 300;
x = 0;
y = 0;
w = 1;
h = 1;
shadow = 0;
style = 16;
class Controls {

class Info: RscText {
style = 2;
idc = 301;
x = 0.125;
y = 0;
w = 0.75;
h = 1;
colorBackground[] = {0,0.2,0,1};
};
class osb1: GVAR(osb) {
idc = 311;
x = 0.01;
y = 0.08;
text = "osb1";
};
class osb2: GVAR(osb) {
idc = 312;
x = 0.01;
y = 0.278;
text = "osb2";
};
class osb3: GVAR(osb) {
idc = 313;
x = 0.01;
y = 0.4748;
text = "osb3";
};
class osb4: GVAR(osb) {
idc = 314;
x = 0.01;
y = 0.71;
text = "osb4";
};
class osb5: GVAR(osb) {
idc = 315;
x = 0.89;
y = 0.08;
text = "osb5";
};
class osb6: GVAR(osb) {
idc = 316;
x = 0.89;
y = 0.278;
text = "osb6";
};
class osb7: GVAR(osb) {
idc = 317;
x = 0.89;
y = 0.4748;
text = "osb7";
};
class osb8: GVAR(osb) {
idc = 318;
x = 0.89;
y = 0.71;
text = "osb8";
};
};
};
};
Expand Down
3 changes: 3 additions & 0 deletions addons/laser_warning/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PREP(ui_initScreen);
PREP(ui_initMenu);
PREP(ui_initDisplay);
PREP(ui_pfh);
PREP(ui_togglePower);
PREP(ui_pushButton);
Expand Down
6 changes: 3 additions & 3 deletions addons/laser_warning/data/model.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class CfgModels {
sectionsInherit = "Default";
class Animations {
class pb1 {
type = "translationY";
type = "translation";
source = "pb1";
AnimPeriod = 1;
selection = "pb1";
axis = "pb1_axis";
offset0 = 0;
offset1 = 0.3;
offset1 = 1.0;
};
class pb2: pb1 {
source = "pb2";
Expand Down Expand Up @@ -83,7 +83,7 @@ class CfgModels {
selection = "powerswitch";
axis = "power_axis";
angle0 = "rad 0";
angle1 = "rad 35";
angle1 = "rad 30";
};
class safetyswitch: powerswitch {
source = "SafetySwitch";
Expand Down
Binary file modified addons/laser_warning/data/screen_ca.paa
Binary file not shown.
Binary file added addons/laser_warning/data/screen_co.paa
Binary file not shown.
Binary file modified addons/laser_warning/data/screen_smdi.paa
Binary file not shown.
6 changes: 3 additions & 3 deletions addons/laser_warning/functions/fnc_default_boxState.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
params [["_powered", false]];
[
if (_powered) then { POWER_STATE_ON } else { POWER_STATE_OFF }, // Power
[], // Laser log
MENU_STATE_MAIN // UI state
[POWER_STATE_OFF, POWER_STATE_ON] select _powered, // Power
[], // Laser log
MENU_STATE_MAIN // UI state
]
32 changes: 32 additions & 0 deletions addons/laser_warning/functions/fnc_ui_create.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
(_display displayCtrl 100) ctrlSetPosition _base;
(_display displayCtrl 100) ctrlSetModelScale _scale;

[_display] call FUNC(ui_initDisplay);

_display displayAddEventHandler ["Unload", {
params ["_display", "_exitCode"];
private _pfh = _display getVariable [QGVAR(pfh), -1];
Expand All @@ -47,6 +49,36 @@
[] call FUNC(ui_togglePower);
};

private _fnc_pushButton = {
params ["_control"];
private _display = ctrlParent _control;
private _object = _display getVariable [QGVAR(object), objNull];
if (isNull _object) exitWith {};
private _idc = ctrlIDC _control;
private _pbSource = format ["pb%1", _idc % 10];
private _box = _display displayCtrl 100;
_box ctrlAnimateModel [_pbSource, 1.0];

if ([] call FUNC(isLwsPowered)) then {
[] call FUNC(ui_pushButton);
};
};

private _fnc_unpushButton = {
params ["_control"];
private _display = ctrlParent _control;
private _object = _display getVariable [QGVAR(object), objNull];
if (isNull _object) exitWith {};
private _idc = ctrlIDC _control;
private _pbSource = format ["pb%1", _idc % 10];
private _box = _display displayCtrl 100;
_box ctrlAnimateModel [_pbSource, 0.0];
};

(_display displayCtrl 212) ctrlAddEventHandler ["ButtonDown", _fnc_powerToggle];
{
(_display displayCtrl _x) ctrlAddEventHandler ["ButtonDown", _fnc_pushButton ];
(_display displayCtrl _x) ctrlAddEventHandler ["ButtonUp", _fnc_unpushButton];
} forEach [111, 112, 113, 114, 115, 116, 117, 118];

}, _this] call CBA_fnc_execNextFrame;
29 changes: 29 additions & 0 deletions addons/laser_warning/functions/fnc_ui_initDisplay.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "..\script_component.hpp"
/*
* Author: tcvm
* Initialises LWS display, given the state of some LWS
*
* Arguments:
* 0: Display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [displayNull] call ace_laser_warning_fnc_ui_initDisplay
*
* Public: No
*/
params ["_display"];

private _object = _display getVariable [QGVAR(object), objNull];
if (isNull _object) exitWith {};

private _boxState = _object getVariable [QGVAR(state_box), false call FUNC(default_boxState)];
_boxState params ["_powerState", "", "_menuState"];
[_display] call FUNC(ui_initScreen);
if (_powerState != POWER_STATE_OFF) then {
private _box = _display displayCtrl 100;
_box ctrlAnimateModel ["PowerSwitch", 1.0];
[_display] call FUNC(ui_initMenu);
};
17 changes: 17 additions & 0 deletions addons/laser_warning/functions/fnc_ui_initMenu.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "..\script_component.hpp"
/*
* Author: tcvm
* Initialises LWS menu page. Called on state change
*
* Arguments:
* 0: Display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [displayNull] call ace_laser_warning_fnc_ui_initMenu
*
* Public: No
*/
params ["_display"];
17 changes: 17 additions & 0 deletions addons/laser_warning/functions/fnc_ui_initScreen.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "..\script_component.hpp"
/*
* Author: tcvm
* Initialises LWS screen; usually just blacks out or turns on elements
*
* Arguments:
* 0: Display <DISPLAY>
*
* Return Value:
* None
*
* Example:
* [displayNull] call ace_laser_warning_fnc_ui_initScreen
*
* Public: No
*/
params ["_display"];
2 changes: 2 additions & 0 deletions addons/laser_warning/functions/fnc_ui_pfh.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
*/
params ["_args", "_pfhId"];
_args params ["_display"];
private _screen = _display displayCtrl 300;

7 changes: 3 additions & 4 deletions addons/laser_warning/functions/fnc_ui_togglePower.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
*/
params ["_args", "_pfhId"];

private _state = _object getVariable [QGVAR(state_box), []];
if (_state isEqualTo []) exitWith {};
private _state = _object getVariable [QGVAR(state_box), false call FUNC(default_boxState)];
private _box = _display displayCtrl 100;

_state params ["_powered"];
if (_powered == POWER_STATE_OFF) then {
_box ctrlAnimateModel ["PowerSwitch", 1.0];
_state set [0, POWER_STATE_STARTING];
_state set [2, MENU_STATE_MAIN];
if ((_display getVariable QGVAR(pfh)) < 0) then {
private _pfh = [LINKFUNC(ui_pfh), 0, [_display getVariable QGVAR(object), objNull]] call CBA_fnc_addPerFrameHandler;
if ((_display getVariable [QGVAR(pfh), -1]) < 0) then {
private _pfh = [LINKFUNC(ui_pfh), 0, [_display]] call CBA_fnc_addPerFrameHandler;
_display setVariable [QGVAR(pfh), _pfh];
};
} else {
Expand Down

0 comments on commit 0b8a3d9

Please sign in to comment.