Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI on texture #340

Merged
merged 12 commits into from
Apr 25, 2023
10 changes: 9 additions & 1 deletion addons/armaos/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,12 @@ PREP(terminal_switchKeyboardLayout);
PREP(terminal_switchTerminalDesign);
PREP(terminal_setCommandLineByHistory);
PREP(terminal_setInputMode);
PREP(terminal_updateBatteryStatus);
PREP(terminal_updateBatteryStatus);

PREP(terminal_uiOnTex_init);
PREP(terminal_uiOnTex_updateAll);
PREP(terminal_uiOnTex_updateOutput);
PREP(terminal_uiOnTex_updateBatteryStatus);
PREP(terminal_uiOnTex_setTerminalDesign);
PREP(terminal_uiOnTex_setKeyboardLayout);
PREP(terminal_uiOnTex_addUpdateAllEventHandler);
15 changes: 15 additions & 0 deletions addons/armaos/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@
false // Setting will be marked as needing mission restart after being changed. (optional, default false) <BOOL>
] call CBA_fnc_addSetting;

/* ================================================================================ */

[
"AE3_UiOnTexture",
"CHECKBOX",
["STR_AE3_Main_CbaSettings_UiOnTextureName", "STR_AE3_Main_CbaSettings_UiOnTextureTooltip"],
"STR_AE3_ArmaOS_CbaSettings_ArmaOSCategoryName",
false,
nil, // "_isGlobal" flag. Set this to true to always have this setting synchronized between all clients in multiplayer
{
params ["_value"];
}, // function that will be executed once on mission start and every time the setting is changed.
false // Setting will be marked as needing mission restart after being changed. (optional, default false) <BOOL>
] call CBA_fnc_addSetting;

/* ================================================================================ */
8 changes: 7 additions & 1 deletion addons/armaos/functions/fnc_os_shutdown.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ if (!_ae3OptsSuccess) exitWith {};
_computer setVariable ["AE3_computer_mutex", objNull, true];
closeDialog 1;

private _handle = [_computer, [false]] call (_computer getVariable "AE3_power_fnc_turnOffWrapper");
private _handle = [_computer, [false]] call (_computer getVariable "AE3_power_fnc_turnOffWrapper");

/* ------------- UI on Texture ------------ */

_computer setVariable ["AE3_UiOnTexActive", false, true]; // reset var for all clients

/* ---------------------------------------- */
8 changes: 7 additions & 1 deletion addons/armaos/functions/fnc_os_standby.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ if (!_ae3OptsSuccess) exitWith {};
_computer setVariable ["AE3_computer_mutex", objNull, true];
closeDialog 1;

private _handle = [_computer] spawn (_computer getVariable "AE3_power_fnc_standbyWrapper");
private _handle = [_computer] spawn (_computer getVariable "AE3_power_fnc_standbyWrapper");

/* ------------- UI on Texture ------------ */

_computer setVariable ["AE3_UiOnTexActive", false, true]; // reset var for all clients

/* ---------------------------------------- */
8 changes: 8 additions & 0 deletions addons/armaos/functions/fnc_terminal_addEventHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ private _result = _consoleDialog displayAddEventHandler
_handleUpdateBatteryStatus = _display getVariable "AE3_handleUpdateBatteryStatus";
[_handleUpdateBatteryStatus] call CBA_fnc_removePerFrameHandler;


/* ------------- UI on Texture ------------ */

_handleUpdateUiOnTexture = _display getVariable "AE3_handleUpdateUiOnTexture";
[_handleUpdateUiOnTexture] call CBA_fnc_removePerFrameHandler;

/* ---------------------------------------- */

// Updates terminal variable for all
_terminal = _computer getVariable "AE3_terminal";
_computer setVariable ["AE3_terminal", _terminal, 2];
Expand Down
15 changes: 7 additions & 8 deletions addons/armaos/functions/fnc_terminal_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ private _consoleOutput = _consoleDialog displayCtrl 1100;
private _languageButton = _consoleDialog displayCtrl 1310;
private _designButton = _consoleDialog displayCtrl 1320;

/*
private _handle = [_computer] spawn AE3_power_fnc_showBatteryLevel;

private _ip = _computer getVariable ["AE3_ipAddress", "127.0.0.1"];

_consoleInput setVariable ["ip", _ip];
*/

[_computer, "AE3_filesystem"] call AE3_main_fnc_getRemoteVar;
[_computer, "AE3_filepointer"] call AE3_main_fnc_getRemoteVar;

Expand Down Expand Up @@ -133,6 +125,13 @@ private _currentDesign = _designs select _currentDesignIndex;
private _handleUpdateBatteryStatus = [_computer, _consoleDialog] call AE3_armaos_fnc_terminal_updateBatteryStatus;
_consoleDialog setVariable ["AE3_handleUpdateBatteryStatus", _handleUpdateBatteryStatus];

/* ------------- UI on Texture ------------ */

private _handleUpdateUiOnTexture = [_computer, _consoleDialog] call AE3_armaos_fnc_terminal_uiOnTex_addUpdateAllEventHandler;
_consoleDialog setVariable ["AE3_handleUpdateUiOnTexture", _handleUpdateUiOnTexture];

/* ---------------------------------------- */

[_consoleDialog, _consoleOutput, _languageButton, _designButton] call AE3_armaos_fnc_terminal_addEventHandler;

_terminalBuffer = _terminal get "AE3_terminalBuffer";
Expand Down
13 changes: 12 additions & 1 deletion addons/armaos/functions/fnc_terminal_setKeyboardLayout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ else
["AE3_KeyboardLayout", _terminalKeyboardLayout, 0, "client", true] call CBA_settings_fnc_set;
};

_computer setVariable ["AE3_terminal", _terminal];
_computer setVariable ["AE3_terminal", _terminal];

/* ------------- UI on Texture ------------ */

if (AE3_UiOnTexture) then
{
private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange;

[_computer, _terminalKeyboardLayout] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_setKeyboardLayout", _playersInRange];
};

/* ---------------------------------------- */
15 changes: 14 additions & 1 deletion addons/armaos/functions/fnc_terminal_setTerminalDesign.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@ _consoleCtrl ctrlSetTextColor _fontColorConsole;
private _consoleOutput = _consoleDialog displayCtrl 1100;

// set focus to text field, otherwise focus stays on button and prohibits additional text input
ctrlSetFocus _consoleOutput;
ctrlSetFocus _consoleOutput;

/* ------------- UI on Texture ------------ */

if (AE3_UiOnTexture) then
{
private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange;

private _computer = _consoleOutput getVariable "AE3_computer";

[_computer, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_setTerminalDesign", _playersInRange];
};

/* ---------------------------------------- */
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Adds an 5 Sec Per-Frame-Event-Handler for the "UI on texture" feature. This will update all contents regularly.
*
* Arguments:
* 1: Computer <OBJECT>
* 2: Console <DIALOG>
*
* Results:
* None
*/

params ["_computer", "_consoleDialog"];

private _updateInterval = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to update regularly? Isn't everything pushed when it changes?

Copy link
Owner Author

@y0014984 y0014984 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, everything is pushed, but if player A uses the Terminal and only reads it without any interaction, there is nothing to push. If player B enters the circle, he won't see the actual content/interface. Imagine a player is not sitting in front of his real life computer and blocking the laptop, or thinking very long about the next command or perhaps unconciousness. That's why there will be an auto-push-interval.


_handle =
[
{
(_this select 0) params ["_computer", "_consoleDialog"];

if (AE3_UiOnTexture) then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why apply the per frame handler, if the feature is disabled?

Copy link
Owner Author

@y0014984 y0014984 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called once. Otherwise I would need another place to check regularly, if the feature is enabled or not. For me this is the easiest way of implementation to add the check directly to the event handler. But if you have any suggestion to do it better, I would be happy if you tell me.

{
private _playersInRange = [3, _computer] call AE3_main_fnc_getPlayersInRange;

private _languageButtonCtrl = _consoleDialog displayCtrl 1310;
private _batteryButtonCtrl = _consoleDialog displayCtrl 1050;
private _headerBackgroundCtrl = _consoleDialog displayCtrl 900;
private _consoleBackgroundCtrl = _consoleDialog displayCtrl 910;
private _headerCtrl = _consoleDialog displayCtrl 1000;
private _consoleCtrl = _consoleDialog displayCtrl 1100;

private _output = ctrlText _consoleCtrl;
private _terminalKeyboardLayout = ctrlText _languageButtonCtrl;
private _value = ctrlText _batteryButtonCtrl;
private _bgColorHeader = ctrlBackgroundColor _headerBackgroundCtrl;
private _bgColorConsole = ctrlBackgroundColor _consoleBackgroundCtrl;
private _fontColorHeader = ctrlTextColor _headerCtrl;
private _fontColorConsole = ctrlTextColor _consoleCtrl;

private _terminal = _computer getVariable "AE3_terminal";

private _terminalBufferVisable = _terminal get "AE3_terminalBufferVisable";
private _size = _terminal get "AE3_terminalSize";

[_computer, _terminalBufferVisable, _size, _terminalKeyboardLayout, _bgColorHeader, _bgColorConsole, _fontColorHeader, _fontColorConsole, _value] remoteExec ["AE3_armaos_fnc_terminal_uiOnTex_updateAll", _playersInRange];
};
},
_updateInterval,
[_computer, _consoleDialog]
] call CBA_fnc_addPerFrameHandler;

_handle;
29 changes: 29 additions & 0 deletions addons/armaos/functions/fnc_terminal_uiOnTex_init.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Initializes the texture on the given object for the "UI on texture" feature.
*
* Arguments:
* 1: Computer <OBJECT>
*
* Results:
* None
*/

params ["_computer"];

/* -------------- WORKAROUND -------------- */

// Workaround: We need to preload the UI, so the used images are also preloaded; otherwise the
// images creates a "Cannot load mipmap" error on first usage with the UI2Texture feature
// See these tickets:
// https://feedback.bistudio.com/T171035
// https://feedback.bistudio.com/T170766

private _tmpDisplay = findDisplay 46 createDisplay "AE3_ArmaOS_Main_Dialog";
_tmpDisplay closeDisplay 1;

/* ---------------------------------------- */

_computer setObjectTexture [1, "#(rgb,1024,1024,1)ui('AE3_ArmaOS_Main_Dialog','AE3_UiOnTexture')"];

_computer setVariable ["AE3_UiOnTexActive", true]; // local variable on computer object is sufficient

26 changes: 26 additions & 0 deletions addons/armaos/functions/fnc_terminal_uiOnTex_setKeyboardLayout.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Updates the keyboard layout of the terminal for the "UI on texture" feature.
*
* Arguments:
* 1: Computer <OBJECT>
* 2: Keyboard Layout <STRING>
*
* Results:
* None
*/

params ["_computer", "_terminalKeyboardLayout"];

private _uiOnTexActive = _computer getVariable ["AE3_UiOnTexActive", false]; // local variable on computer object is sufficient

if (!_uiOnTexActive) then { [_computer] spawn AE3_armaos_fnc_terminal_uiOnTex_init; };

waitUntil { !isNull findDisplay "AE3_UiOnTexture" };

private _uiOnTextureDisplay = findDisplay "AE3_UiOnTexture";

private _uiOnTextureLanguageCtrl = _uiOnTextureDisplay displayCtrl 1310; // Language Control

_uiOnTextureLanguageCtrl ctrlSetText _terminalKeyboardLayout;

displayUpdate _uiOnTextureDisplay;
47 changes: 47 additions & 0 deletions addons/armaos/functions/fnc_terminal_uiOnTex_setTerminalDesign.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Updates the design of the terminal for the "UI on texture" feature.
*
* Arguments:
* 1: Computer <OBJECT>
* 2: Background Color Header <COLOR>
* 3: Background Color Console <COLOR>
* 4: Font Color Header <COLOR>
* 5: Font Color Console <COLOR>
*
* Results:
* None
*/

params ["_computer", "_bgColorHeader", "_bgColorConsole", "_fontColorHeader", "_fontColorConsole"];

private _uiOnTexActive = _computer getVariable ["AE3_UiOnTexActive", false]; // local variable on computer object is sufficient

if (!_uiOnTexActive) then { [_computer] spawn AE3_armaos_fnc_terminal_uiOnTex_init; };

waitUntil { !isNull findDisplay "AE3_UiOnTexture" };

private _uiOnTextureDisplay = findDisplay "AE3_UiOnTexture";

private _uiOnTextureHeaderBackgroundCtrl = _uiOnTextureDisplay displayCtrl 900;
private _uiOnTextureConsoleBackgroundCtrl = _uiOnTextureDisplay displayCtrl 910;

private _uiOnTextureHeaderCtrl = _uiOnTextureDisplay displayCtrl 1000;
private _uiOnTextureConsoleCtrl = _uiOnTextureDisplay displayCtrl 1100;

private _uiOnTextureLanguageButtonCtrl = _uiOnTextureDisplay displayCtrl 1310;
private _uiOnTextureDesignButtonCtrl = _uiOnTextureDisplay displayCtrl 1320;
private _uiOnTextureBatteryButtonCtrl = _uiOnTextureDisplay displayCtrl 1050;
private _uiOnTextureCloseButtonCtrl = _uiOnTextureDisplay displayCtrl 1300;

_uiOnTextureHeaderBackgroundCtrl ctrlSetBackgroundColor _bgColorHeader;
_uiOnTextureConsoleBackgroundCtrl ctrlSetBackgroundColor _bgColorConsole;

_uiOnTextureHeaderCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureLanguageButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureDesignButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureBatteryButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureCloseButtonCtrl ctrlSetTextColor _fontColorHeader;

_uiOnTextureConsoleCtrl ctrlSetTextColor _fontColorConsole;

displayUpdate _uiOnTextureDisplay;
85 changes: 85 additions & 0 deletions addons/armaos/functions/fnc_terminal_uiOnTex_updateAll.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Updates all content of the terminal for the "UI on texture" feature.
*
* Arguments:
* 1: Computer <OBJECT>
* 2: Terminal Buffer Visable <ARRAY>
* 3: Size <NUMBER>
* 4: Keyboard Layout <STRING>
* 5: Background Color Header <COLOR>
* 6: Background Color Console <COLOR>
* 7: Font Color Header <COLOR>
* 8: Font Color Console <COLOR>
* 9: Battery Symbol Path <STRING>
*
* Results:
* None
*/


params ["_computer", "_terminalBufferVisable", "_size", "_terminalKeyboardLayout", "_bgColorHeader", "_bgColorConsole", "_fontColorHeader", "_fontColorConsole", "_value"];

private _uiOnTexActive = _computer getVariable ["AE3_UiOnTexActive", false]; // local variable on computer object is sufficient

if (!_uiOnTexActive) then { [_computer] spawn AE3_armaos_fnc_terminal_uiOnTex_init; };

waitUntil { !isNull findDisplay "AE3_UiOnTexture" };

private _uiOnTextureDisplay = findDisplay "AE3_UiOnTexture";

/* ---------------------------------------- */

private _uiOnTextureHeaderBackgroundCtrl = _uiOnTextureDisplay displayCtrl 900;
private _uiOnTextureConsoleBackgroundCtrl = _uiOnTextureDisplay displayCtrl 910;

private _uiOnTextureHeaderCtrl = _uiOnTextureDisplay displayCtrl 1000;
private _uiOnTextureConsoleCtrl = _uiOnTextureDisplay displayCtrl 1100;

private _uiOnTextureLanguageButtonCtrl = _uiOnTextureDisplay displayCtrl 1310;
private _uiOnTextureDesignButtonCtrl = _uiOnTextureDisplay displayCtrl 1320;
private _uiOnTextureBatteryButtonCtrl = _uiOnTextureDisplay displayCtrl 1050;
private _uiOnTextureCloseButtonCtrl = _uiOnTextureDisplay displayCtrl 1300;

_uiOnTextureHeaderBackgroundCtrl ctrlSetBackgroundColor _bgColorHeader;
_uiOnTextureConsoleBackgroundCtrl ctrlSetBackgroundColor _bgColorConsole;

_uiOnTextureHeaderCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureLanguageButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureDesignButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureBatteryButtonCtrl ctrlSetTextColor _fontColorHeader;
_uiOnTextureCloseButtonCtrl ctrlSetTextColor _fontColorHeader;

_uiOnTextureConsoleCtrl ctrlSetTextColor _fontColorConsole;

/* ---------------------------------------- */

private _uiOnTextureBatteryCtrl = _uiOnTextureDisplay displayCtrl 1050; // Battery Control

_uiOnTextureBatteryCtrl ctrlSetText _value;

/* ---------------------------------------- */

private _uiOnTextureOutputCtrl = _uiOnTextureDisplay displayCtrl 1100; // Console Output Control

// We need to compose the text again because we can't read the structuredText from the existing control,
// like we do on the other controls. StructuredText is set-only.

private _output = [];
{
private _buffer = composeText [_x, lineBreak];
_buffer setAttributes ["size", str _size, "font", "EtelkaMonospacePro"];
_output pushBack _buffer;
} forEach _terminalBufferVisable;

_uiOnTextureOutputCtrl ctrlSetStructuredText (composeText _output);


/* ---------------------------------------- */

private _uiOnTextureLanguageCtrl = _uiOnTextureDisplay displayCtrl 1310; // Language Control

_uiOnTextureLanguageCtrl ctrlSetText _terminalKeyboardLayout;

/* ---------------------------------------- */

displayUpdate _uiOnTextureDisplay;
Loading