-
Notifications
You must be signed in to change notification settings - Fork 149
/
fnc_initDisplay3DEN.sqf
98 lines (76 loc) · 3.56 KB
/
fnc_initDisplay3DEN.sqf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "script_component.hpp"
private _fnc_resetMissionSettings = {
GVAR(mission) call CBA_fnc_deleteNamespace;
GVAR(mission) = [] call CBA_fnc_createNamespace;
// --- read mission settings file
GVAR(missionConfig) call CBA_fnc_deleteNamespace;
GVAR(missionConfig) = [] call CBA_fnc_createNamespace;
private _missionConfig = "";
if (getMissionConfigValue [QGVAR(hasSettingsFile), false] in [true, 1]) then {
_missionConfig = preprocessFile MISSION_SETTINGS_FILE;
if (_missionConfig isEqualTo "") then {
INFO_1("Mission Config: File [%1] not found or empty.",MISSION_SETTINGS_FILE);
} else {
INFO_1("Mission Config: File [%1] loaded successfully.",MISSION_SETTINGS_FILE);
};
};
{
_x params ["_setting", "_value", "_priority"];
GVAR(missionConfig) setVariable [_setting, [_value, _priority]];
} forEach ([_missionConfig, false] call FUNC(parse));
{
private _setting = _x;
private _settingInfo = GVAR(missionConfig) getVariable _setting;
if (isNil "_settingInfo") then {
private _settingsHash = findDisplay 313 getVariable [QGVAR(hash), HASH_NULL];
_settingInfo = [_settingsHash, toLower _setting] call CBA_fnc_hashGet;
};
if (!isNil "_settingInfo") then {
_settingInfo params ["_value", "_priority"];
// convert boolean to number
_priority = [0, 1, 2] select _priority;
if ([_setting, _value] call FUNC(check)) then {
GVAR(mission) setVariable [_setting, [_value, _priority]];
};
};
} forEach GVAR(allSettings);
QGVAR(refreshAllSettings) call CBA_fnc_localEvent;
};
add3DENEventHandler ["OnMissionPreview", _fnc_resetMissionSettings];
add3DENEventHandler ["OnMissionPreviewEnd", compile format ["0 spawn {isNil %1}", _fnc_resetMissionSettings]]; // delay a bit for preInit to run
private _fnc_resetMissionSettingsMissionChanged = compile format [
'findDisplay 313 setVariable [QGVAR(hash), "Scenario" get3DENMissionAttribute QGVAR(hash)]; call %1',
_fnc_resetMissionSettings
];
add3DENEventHandler ["OnMissionNew", _fnc_resetMissionSettingsMissionChanged];
add3DENEventHandler ["OnMissionLoad", _fnc_resetMissionSettingsMissionChanged];
// Missions crash on dedicated servers if there is a file missing during init.
// Thus we check if the mission settings file exists when saving / exporting
// the mission instead and set a flag. The 3den eventhandlers for saving a
// mission fire after the mission was saved, so we have to repeat the action
// after we update the flag.
#define MESSGAE_SAVED 0
#define MESSGAE_AUTOSAVED 1
#define MESSAGE_EXPORTED_SP 5
#define MESSAGE_EXPORTED_MP 6
add3DENEventHandler ["OnMessage", {
params ["_message"];
if !(_message in [MESSGAE_SAVED, MESSAGE_EXPORTED_SP, MESSAGE_EXPORTED_MP]) exitWith {};
INFO("Checking mission settings file ...");
private _fileExists = FILE_EXISTS(MISSION_SETTINGS_FILE);
private _fileExistedPreviously = "Scenario" get3DENMissionAttribute QGVAR(hasSettingsFile);
if (_fileExists isNotEqualTo _fileExistedPreviously) then {
set3DENMissionAttributes [["Scenario", QGVAR(hasSettingsFile), _fileExists]];
switch (_message) do {
case MESSGAE_SAVED: {
do3DENAction "MissionSave";
};
case MESSAGE_EXPORTED_SP: {
do3DENAction "MissionExportSP";
};
case MESSAGE_EXPORTED_MP: {
do3DENAction "MissionExportMP";
};
};
};
}];