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

Give each app their own ControlsGroup #3

Merged
merged 2 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion addons/tacphone/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PREP(loadPhone);
PREP(loadPhone);
PREP(switchToApp);
34 changes: 2 additions & 32 deletions addons/tacphone/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,8 @@

#include "initKeybinds.inc.sqf"

//#TODO this is leftover and not used, could be useful though
[QGVAR(loadApp), {
params ["_classname","_display"];

private _getAppConfig = {
private _cfg = missionConfigFile >> QGVAR(apps) >> _this;
if (isNull _cfg) then {
_cfg = configFile >> QGVAR(apps) >> _this;
};
_cfg // Might be configNull if no app was actually found
};

private _newAppCfg = _classname call _getAppConfig;

if (GVAR(app_selected) != "") then {
private _oldAppCfg = GVAR(app_selected) call _getAppConfig;

// Notify app that its closing
private _function = getText (_oldAppCfg >> QGVAR(onClose)); //#TODO handle entry not existing?
private _code = missionNamespace getVariable [_function,""];
if (_code isEqualTo "") exitWith {}; // Incorrect function name
[_display] call _code; //#TODO maybe pass the new app's classname, so it knows why its being closed?

GVAR(app_selected) = ""; // None open now
};

systemChat str _classname;

GVAR(app_selected) = _classname; // We will now get into it

private _function = getText (_newAppCfg >> QGVAR(createApp));

private _code = missionNamespace getVariable [_function,""];
if (_code isEqualTo "") exitWith {}; // Incorrect function name
[_display] call _code;
[_display, _classname] call FUNC(switchToApp);
}] call CBA_fnc_addEventHandler;
8 changes: 4 additions & 4 deletions addons/tacphone/apps/bft/functions/fnc_createApp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* Public: No
*/

params ["_display"];
params ["_display", "_appSection"];

GVAR(appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1];
private _fullSize = [0, 0, (ctrlPosition _appSection)#2, (ctrlPosition _appSection)#3];

//#TODO this should be [0,0, (ctrlPosition _parent)#2, (ctrlPosition_parent)#3] and the parent gives us a controlsgroup to insert our things into
GVAR(appsection) ctrlSetPosition [(1-PHONE_WIDTH)/2, (1-PHONE_HEIGHT)/2, PHONE_WIDTH, PHONE_HEIGHT];
GVAR(appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1, _appSection];
GVAR(appsection) ctrlSetPosition _fullSize;
GVAR(appsection) ctrlCommit 0;

_map = _display ctrlCreate [QEGVAR(tacphone,mapControl), -1, GVAR(appsection)];
Expand Down
6 changes: 2 additions & 4 deletions addons/tacphone/apps/bft/functions/fnc_onClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@
params ["_display"];

systemChat "BFT closed";
[{
// All app icons are children of appsection so we'll be deleting them too
ctrlDelete GVAR(appsection);
}, []] call CBA_fnc_execNextFrame;
// We simply clear out the app section
ctrlDelete GVAR(appsection);
8 changes: 4 additions & 4 deletions addons/tacphone/apps/groups/functions/fnc_createApp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* Public: No
*/

params ["_display"];
params ["_display", "_appSection"];

GVAR(appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1];
private _fullSize = [0, 0, (ctrlPosition _appSection)#2, (ctrlPosition _appSection)#3];

//#TODO this should be [0,0, (ctrlPosition _parent)#2, (ctrlPosition_parent)#3] and the parent gives us a controlsgroup to insert our things into
GVAR(appsection) ctrlSetPosition [(1-PHONE_WIDTH)/2, (1-PHONE_HEIGHT)/2, PHONE_WIDTH, PHONE_HEIGHT];
GVAR(appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1, _appSection];
GVAR(appsection) ctrlSetPosition _fullSize;
GVAR(appsection) ctrlCommit 0;

/*
Expand Down
6 changes: 2 additions & 4 deletions addons/tacphone/apps/groups/functions/fnc_onClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@
params ["_display"];

systemChat "Group Management closed";
[{
// All app icons are children of appsection so we'll be deleting them too
ctrlDelete GVAR(appsection);
}, []] call CBA_fnc_execNextFrame;
// We simply clear out the app section
ctrlDelete GVAR(appsection);
20 changes: 10 additions & 10 deletions addons/tacphone/apps/homescreen/functions/fnc_createApp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
* Public: No
*/

params ["_display"];
params ["_display", "_appSection"];

GVAR(home_appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1];
private _fullSize = [0, 0, (ctrlPosition _appSection)#2, (ctrlPosition _appSection)#3];

//#TODO this should be [0,0, (ctrlPosition _parent)#2, (ctrlPosition_parent)#3] and the parent gives us a controlsgroup to insert our things into
GVAR(home_appsection) ctrlSetPosition [(1-PHONE_WIDTH)/2, (1-PHONE_HEIGHT)/2, PHONE_WIDTH, PHONE_HEIGHT];
GVAR(home_appsection) ctrlCommit 0;
GVAR(appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1, _appSection];
GVAR(appsection) ctrlSetPosition _fullSize;
GVAR(appsection) ctrlCommit 0;

private _background = _display ctrlCreate ["RscPicture", -1, GVAR(home_appsection)];
_background ctrlSetPosition [0, 0, (ctrlPosition GVAR(home_appsection))#2, (ctrlPosition GVAR(home_appsection))#3];
private _background = _display ctrlCreate ["RscPicture", -1, GVAR(appsection)];
_background ctrlSetPosition _fullSize;
_background ctrlSetText /*"#(rgb,1,1,1)color(0.1,0.1,0.1,1)"*/ QPATHTOF(data\background_banana.paa);
_background ctrlCommit 0;

Expand All @@ -47,8 +47,8 @@ GVAR(home_background_apps) = [];
private _column = _forEachIndex mod _columns;
private _row = floor (_forEachIndex/_columns);

private _app = _display ctrlCreate ["RscActivePicture", -1, GVAR(home_appsection)];
private _appLabel = _display ctrlCreate ["RscText", -1, GVAR(home_appsection)];
private _app = _display ctrlCreate ["RscActivePicture", -1, GVAR(appsection)];
private _appLabel = _display ctrlCreate ["RscText", -1, GVAR(appsection)];

GVAR(home_background_apps) pushBack [_app,_appLabel];

Expand All @@ -70,7 +70,7 @@ GVAR(home_background_apps) = [];
private _display = _control getVariable [QEGVAR(tacphone,display),displayNull];

if (_appClassname isNotEqualTo "") then {
[QEGVAR(tacphone,loadApp),[_appClassname,_display]] call CBA_fnc_localEvent;
[_display, _appClassname] call EFUNC(tacphone,switchToApp);
};
}];

Expand Down
9 changes: 5 additions & 4 deletions addons/tacphone/apps/homescreen/functions/fnc_onClose.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
params ["_display"];

systemChat "Homescreen closed";
[{
// All app icons are children of appsection so we'll be deleting them too
ctrlDelete GVAR(home_appsection);
}, []] call CBA_fnc_execNextFrame;

//#TODO when "Back to previous app" functionality is implemented, we want to just ctrlShow hide the appsection, then in createApp we can re-show the existing control

// We simply clear out the app section
ctrlDelete GVAR(appsection);
16 changes: 11 additions & 5 deletions addons/tacphone/functions/fnc_loadPhone.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ This is absolutely not even slightly feature complete nor organised.
*/

private _emptyDisplay = findDisplay 46 createDisplay "RscDisplayEmpty";
GVAR(background) = _emptyDisplay ctrlCreate ["RscPicture", -1];
private _background = _emptyDisplay ctrlCreate ["RscPicture", -1];

private _phoneWidth = PHONE_WIDTH+0.1;
private _phoneHeight = PHONE_HEIGHT+0.1;
GVAR(background) ctrlSetPosition [(1-_phoneWidth)/2, (1-_phoneHeight)/2, _phoneWidth, _phoneHeight];
GVAR(background) ctrlSetText "#(rgb,1,1,1)color(0.3,0.3,0.3,1)";
GVAR(background) ctrlCommit 0;
_background ctrlSetPosition [(1-_phoneWidth)/2, (1-_phoneHeight)/2, _phoneWidth, _phoneHeight];
_background ctrlSetText "#(rgb,1,1,1)color(0.3,0.3,0.3,1)";
_background ctrlCommit 0;

// This will be the container, in which all apps content will be created. The phone itself has no control over its contents (besides deleting all of it)
//#TODO this should not be a global variable, for one it doesn't serialize in missionNamespace, second it prevents us from having multiple phone displays open at the same time
GVAR(appsection) = _emptyDisplay ctrlCreate ["RscControlsGroupNoScrollbars", -1];
GVAR(appsection) ctrlSetPosition [(1-PHONE_WIDTH)/2, (1-PHONE_HEIGHT)/2, PHONE_WIDTH, PHONE_HEIGHT];
GVAR(appsection) ctrlCommit 0;

//#TODO remember app that was last opened when phone was closed

GVAR(app_selected) = "";

// Switch to Homescreen, which is the default app
[QGVAR(loadApp),["Homescreen",_emptyDisplay]] call CBA_fnc_localEvent;
[_emptyDisplay, "Homescreen"] call FUNC(switchToApp);
60 changes: 60 additions & 0 deletions addons/tacphone/functions/fnc_switchToApp.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "..\script_component.hpp"
/*
* Author: KJW
* Switches the TacPhone to a different app
* Closes currently active app, opens new one
*
* Arguments:
* TacPhone to switch the app on <DISPLAY>
* Classname of the new app to be switched to <STRING>
*
* Return Value:
* None
*
* Example:
* [_display, "Homescreen"] call ace_tacphone_fnc_switchToApp
*
* Public: No
*/

params ["_display", "_classname"];

private _getAppConfig = {
private _cfg = missionConfigFile >> QGVAR(apps) >> _this;
if (isNull _cfg) then {
_cfg = configFile >> QGVAR(apps) >> _this;
};
_cfg // Might be configNull if no app was actually found
};

private _newAppCfg = _classname call _getAppConfig;

// First close the currently open app
if (GVAR(app_selected) != "") then {
private _oldAppCfg = GVAR(app_selected) call _getAppConfig;

// Notify app that its closing
private _function = getText (_oldAppCfg >> QGVAR(onClose)); //#TODO handle entry not existing?
private _code = missionNamespace getVariable [_function, ""];
if (_code isEqualTo "") exitWith {}; // Incorrect function name
[_display, GVAR(appsection)] call _code; //#TODO maybe pass the new app's classname, so it knows why its being closed?

GVAR(app_selected) = ""; // None open now
};

// Now no apps are open, previous apps might have left controls behind, we cannot delete them because their onClose might be async and still need them
// but we can at least make sure they are not visible
{ _x ctrlShow false; } forEach allControls GVAR(appsection);


// Now we open the new app

systemChat str _classname;

GVAR(app_selected) = _classname; // We will now get into it

private _function = getText (_newAppCfg >> QGVAR(createApp));

private _code = missionNamespace getVariable [_function, ""];
if (_code isEqualTo "") exitWith {}; // Incorrect function name
[_display, GVAR(appsection)] call _code;
Loading