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

Split Homescreen app into subfolder #2

Merged
merged 1 commit into from
Jan 31, 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
34 changes: 26 additions & 8 deletions addons/tacphone/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@
[QGVAR(loadApp), {
params ["_classname","_display"];

private _cfg = configFile >> QGVAR(apps) >> _classname;
if (isNull _cfg) then {
_cfg = missionConfigFile >> QGVAR(apps) >> _classname;
if (isNull _cfg) exitWith {}; // No app was actually found
private _getAppConfig = {
private _cfg = configFile >> QGVAR(apps) >> _this;
if (isNull _cfg) then {
_cfg = missionConfigFile >> QGVAR(apps) >> _this;
};
_cfg // Might be configNull if no app was actually found
};
private _function = getText (_cfg >> "function");

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;

[{ctrlDelete GVAR(home_background);}, []] call CBA_fnc_execNextFrame;

}] call CBA_fnc_addEventHandler;
4 changes: 2 additions & 2 deletions addons/tacphone/ace_tacphone_apps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class GVAR(apps) {
displayName = "Battlespace Management";
displayNameShort = "BM";
icon = "\A3\ui_f\data\map\markers\nato\c_unknown.paa"; // 1:1 aspect ratio. Image TBD
function = QFUNC(loadBFT);
GVAR(createApp) = QFUNC(loadBFT);
};
class Messaging {
scope = 2;
displayName = "Beacon";
displayNameShort = "BCN";
icon = "\A3\ui_f\data\map\markers\nato\c_ship.paa"; // Image TBD
function = QFUNC(loadMessaging);
GVAR(createApp) = QFUNC(loadMessaging);
};
};
17 changes: 17 additions & 0 deletions addons/tacphone/apps/homescreen/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
2 changes: 2 additions & 0 deletions addons/tacphone/apps/homescreen/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREP(createApp);
PREP(onClose);
3 changes: 3 additions & 0 deletions addons/tacphone/apps/homescreen/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

//#include "initKeybinds.inc.sqf"
11 changes: 11 additions & 0 deletions addons/tacphone/apps/homescreen/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

//#include "initSettings.inc.sqf"

ADDON = true;
3 changes: 3 additions & 0 deletions addons/tacphone/apps/homescreen/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
11 changes: 11 additions & 0 deletions addons/tacphone/apps/homescreen/ace_tacphone_apps.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class EGVAR(tacphone,apps) {
class Homescreen { // Name TBD
scope = 2;
displayName = "Home Screen";
displayNameShort = "HS";
icon = "\A3\ui_f\data\map\markers\nato\c_unknown.paa"; // 1:1 aspect ratio. Image TBD

EGVAR(tacphone,createApp) = QFUNC(createApp);
EGVAR(tacphone,onClose) = QFUNC(onClose);
};
};
19 changes: 19 additions & 0 deletions addons/tacphone/apps/homescreen/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {};
author = ECSTRING(common,ACETeam);
authors[] = {"KJW"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "ace_tacphone_apps.hpp"
#include "CfgEventHandlers.hpp"
//#include "gui.hpp"
80 changes: 80 additions & 0 deletions addons/tacphone/apps/homescreen/functions/fnc_createApp.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "..\script_component.hpp"
/*
* Author: KJW
* Initializes the App
*
* Arguments:
* TacPhone main display
*
* Return Value:
* None
*
* Example:
* [] call ace_tacphone_homescreen_fnc_createApp
*
* Public: No
*/

params ["_display"];

GVAR(home_appsection) = _display ctrlCreate ["RscControlsGroupNoScrollbars", -1];

//#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;

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

private _apps = "getNumber (_x >> 'scope') > 0" configClasses (configFile >> QEGVAR(tacphone,apps));
_apps = _apps + ("getNumber (_x >> 'scope') > 0" configClasses (missionConfigFile >> QEGVAR(tacphone,apps)));
_apps = _apps apply {[configName _x, getText (_x >> "displayName"), getText (_x >> "displayNameShort"), getText (_x >> "icon")]};

private _page = 0;

private _columns = 5;
private _rows = 3;

private _spacingX = 0.15;
private _spacingY = 0.15;
GVAR(home_background_apps) = [];

{
_x params ["_classname", "_displayName","_displayNameShort","_picture"];

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)];

GVAR(home_background_apps) pushBack [_app,_appLabel];

_app ctrlSetText _picture;
_appLabel ctrlSetText _displayNameShort;

private _coordX = _column * _spacingX;
private _coordY = _row * _spacingY;

_app ctrlSetPosition [_coordX, _coordY, 0.1, 0.1];
_appLabel ctrlSetPosition [_coordX+0.025, _coordY+0.06, 0.1, 0.1]; // Just need to center the text in this textbox... Dunno how.

_app setVariable [QEGVAR(tacphone,appClassname), _classname];
_app setVariable [QEGVAR(tacphone,display), _display];

_app ctrlAddEventHandler ["MouseButtonClick",{
params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];
private _appClassname = _control getVariable [QEGVAR(tacphone,appClassname),""];
private _display = _control getVariable [QEGVAR(tacphone,display),displayNull];

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

_app ctrlCommit 0;
_appLabel ctrlCommit 0;

} forEach (_apps select [_page, 15]);
24 changes: 24 additions & 0 deletions addons/tacphone/apps/homescreen/functions/fnc_onClose.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "..\script_component.hpp"
/*
* Author: KJW
* Handle the app being closed
*
* Arguments:
* TacPhone main display
*
* Return Value:
* None
*
* Example:
* [] call ace_tacphone_homescreen_fnc_onClose
*
* Public: No
*/

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;
9 changes: 9 additions & 0 deletions addons/tacphone/apps/homescreen/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file is only for use within ACE, you would not use this when creating 3rd party apps in stand-alone PBO's

#define APPNAME homescreen
#define COMPONENT_BEAUTIFIED Tacphone App ABC

#include "..\script_component.hpp"

#define PHONE_WIDTH 0.75
#define PHONE_HEIGHT 0.5
41 changes: 41 additions & 0 deletions addons/tacphone/apps/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

// This file is only for use within ACE, you would not use this when creating 3rd party apps in stand-alone PBO's

// Before including this file, you need to
// #define APPNAME abc // This is the subfolder in the tacphone/apps/ folder
// #define COMPONENT_BEAUTIFIED Tacphone App ABC

#define COMPONENT DOUBLES(tacphone,APPNAME)


#include "\z\ace\addons\main\script_mod.hpp"

// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

#ifdef DEBUG_ENABLED_TACPHONE // Enabling debug for Tacphone, enables it for all apps too
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_TACPHONE
#define DEBUG_SETTINGS DEBUG_SETTINGS_TACPHONE
#endif

#include "\z\ace\addons\main\script_macros.hpp"

// We need to change some things because we are using a subfolder

#undef GVAR
#define GVAR(var1) DOUBLES(TRIPLES(PREFIX,tacphone,APPNAME),var1)
#undef PATHTO
#define PATHTO(var1) PATHTO_SYS(PREFIX,tacphone\apps\APPNAME,var1)
#undef PATHTOF
#define PATHTOF(var1) PATHTOF_SYS(PREFIX,tacphone\apps\APPNAME,var1)
#undef COMPILE_SCRIPT
#define COMPILE_SCRIPT(var1) compileScript ['PATHTO_SYS(PREFIX,tacphone\apps\APPNAME,var1)']
#undef COMPILE_FILE_SYS
#define COMPILE_FILE_SYS(var1,var2,var3) COMPILE_FILE2_SYS('PATHTO_SYS(var1,tacphone\apps\APPNAME,var3)')
#undef COMPILE_FILE_CFG_SYS
#define COMPILE_FILE_CFG_SYS(var1,var2,var3) COMPILE_FILE2_CFG_SYS('PATHTO_SYS(var1,tacphone\apps\APPNAME,var3)')

75 changes: 5 additions & 70 deletions addons/tacphone/functions/fnc_loadPhone.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,74 +32,9 @@ GVAR(background) ctrlSetPosition [(1-_phoneWidth)/2, (1-_phoneHeight)/2, _phoneW
GVAR(background) ctrlSetText "#(rgb,1,1,1)color(0.3,0.3,0.3,1)";
GVAR(background) ctrlCommit 0;

GVAR(app_selected) = ""; // May be worth making the home screen just the default app rather than special handling..?
//#TODO remember app that was last opened when phone was closed

if (GVAR(app_selected) isEqualTo "") then {
GVAR(home_background) = _emptyDisplay ctrlCreate ["RscPicture", -1];
GVAR(home_background) ctrlSetPosition [(1-PHONE_WIDTH)/2, (1-PHONE_HEIGHT)/2, PHONE_WIDTH, PHONE_HEIGHT];
GVAR(home_background) ctrlSetText /*"#(rgb,1,1,1)color(0.1,0.1,0.1,1)"*/ QPATHTOF(data\background_banana.paa);
GVAR(home_background) ctrlCommit 0;
GVAR(home_background) ctrlAddEventHandler ["Destroy", {
{
_x params ["_app","_appLabel"];
ctrlDelete _app;
ctrlDelete _appLabel;
} forEach GVAR(home_background_apps);
}];

private _apps = "getNumber (_x >> 'scope') > 0" configClasses (configFile >> QGVAR(apps));
_apps = _apps + ("getNumber (_x >> 'scope') > 0" configClasses (missionConfigFile >> QGVAR(apps)));
_apps = _apps apply {[configName _x, getText (_x >> "displayName"), getText (_x >> "displayNameShort"), getText (_x >> "icon")]};

private _page = 0;

private _columns = 5;
private _rows = 3;

private _spacingX = 0.15;
private _spacingY = 0.15;

private _startX = ((1-PHONE_WIDTH)/2)+0.025;
private _startY = (1-PHONE_HEIGHT)/2;

GVAR(home_background_apps) = [];

{
_x params ["_classname", "_displayName","_displayNameShort","_picture"];

private _column = _forEachIndex mod _columns;
private _row = floor (_forEachIndex/_columns);

private _app = _emptyDisplay ctrlCreate ["RscActivePicture", -1, GVAR(home_background)];
private _appLabel = _emptyDisplay ctrlCreate ["RscText", -1, _app];

_apps pushBack [_app,_appLabel];

_app ctrlSetText _picture;
_appLabel ctrlSetText _displayNameShort;

private _coordX = _startX + (_column * _spacingX);
private _coordY = _startY + (_row * _spacingY);

_app ctrlSetPosition [_coordX, _coordY, 0.1, 0.1];
_appLabel ctrlSetPosition [_coordX+0.025, _coordY+0.06, 0.1, 0.1]; // Just need to center the text in this textbox... Dunno how.

_app setVariable [QGVAR(appClassname),_classname];
_app setVariable [QGVAR(display),_emptyDisplay];

_app ctrlAddEventHandler ["MouseButtonClick",{
params ["_control", "_button", "_xPos", "_yPos", "_shift", "_ctrl", "_alt"];
private _appClassname = _control getVariable [QGVAR(appClassname),""];
private _display = _control getVariable [QGVAR(display),displayNull];
if (_appClassname isNotEqualTo "") then {
[QGVAR(loadApp),[_appClassname,_display]] call CBA_fnc_localEvent;
GVAR(app_selected) = _appClassname;
systemChat str _appClassname;
};
}];

_app ctrlCommit 0;
_appLabel ctrlCommit 0;

} forEach (_apps select [_page, 15]);
};
GVAR(app_selected) = "";

// Switch to Homescreen, which is the default app
[QGVAR(loadApp),["Homescreen",_emptyDisplay]] call CBA_fnc_localEvent;
2 changes: 0 additions & 2 deletions addons/tacphone/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

#define DEBUG_INIT_SPEEDS

#ifdef DEBUG_ENABLED_TACPHONE
#define DEBUG_MODE_FULL
#endif
Expand Down
Loading