- Add a dispatcher web view and layout switching - Route group role updates and dispatcher hydration through the UI bridge - Refresh top bar and hide map/side panel outside operations mode
287 lines
11 KiB
Plaintext
287 lines
11 KiB
Plaintext
#include "..\script_component.hpp"
|
|
|
|
/*
|
|
* File: fnc_initUIBridge.sqf
|
|
* Author: IDSolutions
|
|
* Date: 2026-03-28
|
|
* Public: No
|
|
*
|
|
* Description:
|
|
* Initializes the CAD UI bridge for sidepanel browser state and CAD event routing.
|
|
*
|
|
* Arguments:
|
|
* None
|
|
*
|
|
* Return Value:
|
|
* CAD UI bridge object [HASHMAP OBJECT]
|
|
*
|
|
* Example:
|
|
* call forge_client_cad_fnc_initUIBridge
|
|
*/
|
|
|
|
#pragma hemtt ignore_variables ["_self"]
|
|
private _webUIDeclarations = call EFUNC(common,initWebUIBridge);
|
|
private _webUIBridgeDeclaration = _webUIDeclarations get "bridgeDeclaration";
|
|
|
|
GVAR(CADUIBridgeBaseClass) = compileFinal createHashMapFromArray [
|
|
["#base", _webUIBridgeDeclaration],
|
|
["#type", "CADUIBridgeBaseClass"],
|
|
["#create", compileFinal {
|
|
_self set ["dispatcherReady", false];
|
|
_self set ["topBarReady", false];
|
|
}],
|
|
["getActiveBrowserControl", compileFinal {
|
|
private _display = uiNamespace getVariable [QGVAR(Display), displayNull];
|
|
if (isNull _display) exitWith {
|
|
_self call ["setActiveBrowserControl", [controlNull]];
|
|
controlNull
|
|
};
|
|
|
|
private _control = _display displayCtrl 1005;
|
|
_self call ["setActiveBrowserControl", [_control]];
|
|
_control
|
|
}],
|
|
["getTopBarControl", compileFinal {
|
|
private _display = uiNamespace getVariable [QGVAR(Display), displayNull];
|
|
if (isNull _display) exitWith { controlNull };
|
|
|
|
_display displayCtrl 1002
|
|
}],
|
|
["getBottomBarControl", compileFinal {
|
|
private _display = uiNamespace getVariable [QGVAR(Display), displayNull];
|
|
if (isNull _display) exitWith { controlNull };
|
|
|
|
_display displayCtrl 1003
|
|
}],
|
|
["getMapControl", compileFinal {
|
|
private _display = uiNamespace getVariable [QGVAR(Display), displayNull];
|
|
if (isNull _display) exitWith { controlNull };
|
|
|
|
_display displayCtrl 1001
|
|
}],
|
|
["getDispatcherControl", compileFinal {
|
|
private _display = uiNamespace getVariable [QGVAR(Display), displayNull];
|
|
if (isNull _display) exitWith { controlNull };
|
|
|
|
_display displayCtrl 1006
|
|
}],
|
|
["hasOpenScreen", compileFinal {
|
|
private _screen = _self call ["getScreen", []];
|
|
private _control = _self call ["getActiveBrowserControl", []];
|
|
!(isNull _control) && { _screen call ["isReady", []] }
|
|
}],
|
|
["isDispatcher", compileFinal {
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
|
|
private _session = GVAR(CADRepository) getOrDefault ["session", createHashMap];
|
|
_session getOrDefault ["isDispatcher", false]
|
|
}],
|
|
["applyLayout", compileFinal {
|
|
private _mode = if (isNil QGVAR(CADRepository)) then {
|
|
"operations"
|
|
} else {
|
|
GVAR(CADRepository) getOrDefault ["mode", "operations"]
|
|
};
|
|
|
|
private _mapCtrl = _self call ["getMapControl", []];
|
|
private _bottomBarCtrl = _self call ["getBottomBarControl", []];
|
|
private _sidePanelCtrl = _self call ["getActiveBrowserControl", []];
|
|
private _dispatcherCtrl = _self call ["getDispatcherControl", []];
|
|
|
|
if !(isNull _mapCtrl) then { _mapCtrl ctrlShow (_mode isEqualTo "operations"); };
|
|
if !(isNull _bottomBarCtrl) then { _bottomBarCtrl ctrlShow true; };
|
|
if !(isNull _sidePanelCtrl) then { _sidePanelCtrl ctrlShow (_mode isEqualTo "operations"); };
|
|
if !(isNull _dispatcherCtrl) then { _dispatcherCtrl ctrlShow (_mode isEqualTo "dispatch"); };
|
|
|
|
_self call ["refreshTopBarState", []];
|
|
_self call ["refreshDispatcher", []];
|
|
true
|
|
}],
|
|
["setMode", compileFinal {
|
|
params [["_mode", "operations", [""]]];
|
|
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
|
|
private _targetMode = _mode;
|
|
if !(_targetMode in ["operations", "dispatch"]) then {
|
|
_targetMode = "operations";
|
|
};
|
|
|
|
if (_targetMode isEqualTo "dispatch" && !(_self call ["isDispatcher", []])) then {
|
|
_targetMode = "operations";
|
|
};
|
|
|
|
GVAR(CADRepository) call ["setMode", [_targetMode]];
|
|
_self call ["applyLayout", []]
|
|
}],
|
|
["refreshTopBarState", compileFinal {
|
|
if !(_self getOrDefault ["topBarReady", false]) exitWith { false };
|
|
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
|
|
private _topBarCtrl = _self call ["getTopBarControl", []];
|
|
if (isNull _topBarCtrl) exitWith { false };
|
|
|
|
private _session = +(GVAR(CADRepository) getOrDefault ["session", createHashMap]);
|
|
private _currentGroup = GVAR(CADRepository) call ["getCurrentGroup", []];
|
|
private _payload = createHashMapFromArray [
|
|
["mode", GVAR(CADRepository) getOrDefault ["mode", "operations"]],
|
|
["session", _session],
|
|
["currentGroup", _currentGroup]
|
|
];
|
|
|
|
_topBarCtrl ctrlWebBrowserAction ["ExecJS", format [
|
|
"window.cadTopbar && window.cadTopbar.receiveState(%1);",
|
|
toJSON _payload
|
|
]];
|
|
true
|
|
}],
|
|
["refreshDispatcher", compileFinal {
|
|
if !(_self getOrDefault ["dispatcherReady", false]) exitWith { false };
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
|
|
private _dispatcherCtrl = _self call ["getDispatcherControl", []];
|
|
if (isNull _dispatcherCtrl) exitWith { false };
|
|
|
|
private _payload = GVAR(CADRepository) call ["getHydratePayload", []];
|
|
_dispatcherCtrl ctrlWebBrowserAction ["ExecJS", format [
|
|
"window.cadDispatcher && window.cadDispatcher.receiveHydrate(%1);",
|
|
toJSON _payload
|
|
]];
|
|
true
|
|
}],
|
|
["handleReady", compileFinal {
|
|
params [["_control", controlNull, [controlNull]], ["_data", createHashMap, [createHashMap]]];
|
|
|
|
private _screen = _self call ["getScreen", []];
|
|
_screen call ["setControl", [_control]];
|
|
_screen call ["markReady", [true]];
|
|
_self call ["flushPendingEvents", []];
|
|
|
|
_self call ["requestHydrate", []];
|
|
_self call ["refreshHydrate", []];
|
|
_self call ["refreshTopBarState", []];
|
|
true
|
|
}],
|
|
["handleClose", compileFinal {
|
|
_self set ["dispatcherReady", false];
|
|
_self set ["topBarReady", false];
|
|
|
|
private _screen = _self call ["getScreen", []];
|
|
_screen call ["dispose", []];
|
|
true
|
|
}],
|
|
["handleTopBarReady", compileFinal {
|
|
_self set ["topBarReady", true];
|
|
_self call ["refreshTopBarState", []]
|
|
}],
|
|
["handleDispatcherReady", compileFinal {
|
|
_self set ["dispatcherReady", true];
|
|
_self call ["refreshDispatcher", []]
|
|
}],
|
|
["requestHydrate", compileFinal {
|
|
[SRPC(cad,requestHydrateCad), [getPlayerUID player]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["requestAssignTask", compileFinal {
|
|
params [["_taskID", "", [""]], ["_groupID", "", [""]], ["_note", "", [""]]];
|
|
|
|
if (_taskID isEqualTo "" || { _groupID isEqualTo "" }) exitWith { false };
|
|
|
|
[SRPC(cad,requestAssignCadTask), [getPlayerUID player, _taskID, _groupID, _note]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["requestAcknowledgeTask", compileFinal {
|
|
params [["_taskID", "", [""]]];
|
|
|
|
if (_taskID isEqualTo "") exitWith { false };
|
|
|
|
[SRPC(cad,requestAcknowledgeCadTask), [getPlayerUID player, _taskID]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["requestDeclineTask", compileFinal {
|
|
params [["_taskID", "", [""]]];
|
|
|
|
if (_taskID isEqualTo "") exitWith { false };
|
|
|
|
[SRPC(cad,requestDeclineCadTask), [getPlayerUID player, _taskID]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["requestGroupStatus", compileFinal {
|
|
params [["_groupID", "", [""]], ["_status", "", [""]]];
|
|
|
|
if (_groupID isEqualTo "" || { _status isEqualTo "" }) exitWith { false };
|
|
|
|
[SRPC(cad,requestUpdateCadGroupStatus), [getPlayerUID player, _groupID, _status]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["requestGroupRole", compileFinal {
|
|
params [["_groupID", "", [""]], ["_role", "", [""]]];
|
|
|
|
if (_groupID isEqualTo "" || { _role isEqualTo "" }) exitWith { false };
|
|
|
|
[SRPC(cad,requestUpdateCadGroupRole), [getPlayerUID player, _groupID, _role]] call CFUNC(serverEvent);
|
|
true
|
|
}],
|
|
["refreshHydrate", compileFinal {
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
GVAR(CADRepository) call ["pushHydratePayload", [_self]]
|
|
}],
|
|
["handleHydrateResponse", compileFinal {
|
|
params [["_payload", createHashMap, [createHashMap]]];
|
|
|
|
if (isNil QGVAR(CADRepository)) exitWith { false };
|
|
|
|
GVAR(CADRepository) call ["setHydratePayload", [_payload]];
|
|
if !(_self call ["isDispatcher", []]) then {
|
|
GVAR(CADRepository) call ["setMode", ["operations"]];
|
|
};
|
|
|
|
_self call ["refreshHydrate", []];
|
|
_self call ["refreshTopBarState", []];
|
|
_self call ["refreshDispatcher", []];
|
|
_self call ["applyLayout", []]
|
|
}],
|
|
["handleAssignmentResponse", compileFinal {
|
|
params [["_result", createHashMap, [createHashMap]]];
|
|
|
|
if (_self getOrDefault ["dispatcherReady", false]) then {
|
|
private _dispatcherCtrl = _self call ["getDispatcherControl", []];
|
|
if !(isNull _dispatcherCtrl) then {
|
|
_dispatcherCtrl ctrlWebBrowserAction ["ExecJS", format [
|
|
"window.cadDispatcher && window.cadDispatcher.setStatus(%1, %2);",
|
|
str (_result getOrDefault ["message", "Task request processed."]),
|
|
str ([ "error", "success" ] select (_result getOrDefault ["success", false]))
|
|
]];
|
|
};
|
|
};
|
|
|
|
_self call ["sendEvent", ["cad::assignment::response", createHashMapFromArray [
|
|
["message", _result getOrDefault ["message", "Task request processed."]],
|
|
["success", _result getOrDefault ["success", false]]
|
|
]]]
|
|
}],
|
|
["handleGroupUpdateResponse", compileFinal {
|
|
params [["_result", createHashMap, [createHashMap]]];
|
|
|
|
if (_self getOrDefault ["dispatcherReady", false]) then {
|
|
private _dispatcherCtrl = _self call ["getDispatcherControl", []];
|
|
if !(isNull _dispatcherCtrl) then {
|
|
_dispatcherCtrl ctrlWebBrowserAction ["ExecJS", format [
|
|
"window.cadDispatcher && window.cadDispatcher.setStatus(%1, %2);",
|
|
str (_result getOrDefault ["message", "Group update processed."]),
|
|
str ([ "error", "success" ] select (_result getOrDefault ["success", false]))
|
|
]];
|
|
};
|
|
};
|
|
|
|
_self call ["sendEvent", ["cad::group::response", createHashMapFromArray [
|
|
["message", _result getOrDefault ["message", "Group update processed."]],
|
|
["success", _result getOrDefault ["success", false]]
|
|
]]]
|
|
}]
|
|
];
|
|
|
|
GVAR(CADUIBridge) = createHashMapObject [GVAR(CADUIBridgeBaseClass)];
|
|
GVAR(CADUIBridge)
|