Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
ServerHostingUI.c
Go to the documentation of this file.
7
8class ServerHostingUI : SCR_TabDialog
9{
10 protected const string JSON_POSTFIX = ".json";
11
12 protected const string DIALOG_OVERRIDE = "#AR-ServerHosting_OverrideWarning";
13 protected const string DIALOG_SAVED = "#AR-ServerHosting_SaveSuccessful";
14
15 protected const string COLOR_TAG = "<color rgba='%1'>";
16 protected const string COLOR_TAG_END = "</color>";
17
18 protected ref SCR_DSConfig m_DSConfig = new SCR_DSConfig();
19 protected static ref SCR_DSConfig s_TemporaryConfig;
20
21 // Config widget wrapper components
24
26
29
30 // Values
31 protected string m_sUnifiedPort; // Unified port used acress sub menu to define port from basic in advanced settings and vice versa
32 protected string m_sFileName;
33
34 // TODO: move tab specific stuff to a child of SCR_SuperMenuComponent (low priority)
35 //------------------------------------------------------------------------------------------------
37 {
38 super.OnMenuOpen(preset);
39
40 // Server setting list
41 m_ConfigListSubMenu = SCR_ServerHostingSettingsSubMenu.Cast(m_SuperMenuComponent.GetSubMenu(SCR_EServerHostingDialogTabs.SETTINGS));
43
44 // Mods
45 m_ConfigMods = SCR_ServerHostingModSubMenu.Cast(m_SuperMenuComponent.GetSubMenu(SCR_EServerHostingDialogTabs.MODS));
46
47 m_ConfigMods.GetEventOnWorkshopButtonActivate().Insert(OnWorkshopOpenActivate);
48 m_ConfigMods.GetOnRequestDefaultScenario().Insert(SelectDefaultScenario);
49
50 // Advanced settings
51 m_AdvancedSubMenu = SCR_ServerHostingSettingsSubMenu.Cast(m_SuperMenuComponent.GetSubMenu(SCR_EServerHostingDialogTabs.ADVANCED_SETTINGS));
53
54 // Default IP and port
55 GetGame().GetBackendApi().SetDefaultIpPort(m_DSConfig);
57
58 // Setup buttons
59 m_ConfigListSubMenu.GetOnHost().Insert(OnHostServerClick);
60 m_ConfigListSubMenu.GetOnSave().Insert(OnSaveTemplateClick);
61
62 m_AdvancedSubMenu.GetOnHost().Insert(OnHostServerClick);
63 m_AdvancedSubMenu.GetOnSave().Insert(OnSaveTemplateClick);
64
65 // Restore config
66 if (s_TemporaryConfig)
67 {
68 m_ConfigList.FillFromDSConfig(s_TemporaryConfig);
69 m_AdvancedSettings.FillFromDSConfig(s_TemporaryConfig);
70 m_ConfigMods.EnableModsFromDSConfig(s_TemporaryConfig);
71 s_TemporaryConfig = null;
72 }
73 else
74 {
76 }
77
78 // Setup menu listeners
79 m_ConfigList.GetOnPortChanged().Insert(OnSubMenuChangePort);
80 m_ConfigList.GetOnScenarioSelected().Insert(OnScenarioSelected);
81
82 m_AdvancedSettings.GetOnPortChanged().Insert(OnSubMenuChangePort);
83 }
84
85 //------------------------------------------------------------------------------------------------
87 protected bool VerifyAndStoreConfig()
88 {
90 {
91 #ifdef SB_DEBUG
92 Print("Missing config references");
93 #endif
94
95 return false;
96 }
97
98 // Check all values validity
99 Widget invalidEntry = m_ConfigList.GetInvalidEntry();
100 int invalidTab = 0;
101
102 if (!invalidEntry)
103 {
104 invalidEntry = m_AdvancedSettings.GetInvalidEntry();
105 invalidTab = 2;
106 }
107
108 if (invalidEntry)
109 {
110 // Show problematic tab
111 if (m_SuperMenuComponent.GetTabView().m_iSelectedTab != invalidTab)
112 m_SuperMenuComponent.GetTabView().ShowTab(invalidTab);
113
114 // Move to invalid entry
115 GetGame().GetWorkspace().SetFocusedWidget(invalidEntry);
116 m_ConfigList.ScrollToTheEntry(invalidEntry);
117
118 return false;
119 }
120
121 // Store
122 array<ref SCR_WidgetListEntry> properties = m_ConfigList.GetInitialEntryList();
123 array<ref SCR_WidgetListEntry> advanced = m_AdvancedSettings.GetInitialEntryList();
124 for (int i = 0, count = advanced.Count(); i < count; i++)
125 {
126 properties.Insert(advanced[i]);
127 }
128
129 array<ref DSMod> mods = m_ConfigMods.SelectedModsList();
130 WorkshopItem scenarioMod = m_ConfigList.GetScenarioOwnerMod();
131
132 m_DSConfig.StoreFullJson(properties, mods, scenarioMod);
133 return true;
134 }
135
136 //------------------------------------------------------------------------------------------------
138 {
139 dialog.m_OnConfirm.Remove(OnOverrideConfirm);
140 SaveConfig();
141 }
142
143 //------------------------------------------------------------------------------------------------
144 // Callbacks
145 //------------------------------------------------------------------------------------------------
146 //------------------------------------------------------------------------------------------------
147 protected void OnHostServerClick()
148 {
149 if (!m_DSConfig || !m_ConfigList)
150 return;
151
152 // Check properties
154 return;
155
156 // Check connection - prevent host
158 {
159 SCR_ServerHostingDialogs.CreateNoConnectionDialog();
160 return;
161 }
162
163 // Host scenario
164 protected ref MissionWorkshopItem hostedScenario = m_ConfigList.GetSelectedScenario();
165
166 if (hostedScenario)
167 SCR_ScenarioUICommon.TryHostScenario(hostedScenario, m_DSConfig);
168
169 GameSessionStorage.s_Data["m_iRejoinAttempt"] = "0";
170
171 // Save current menu
172 MenuBase lastMenu = GetGame().GetMenuManager().GetTopMenu();
173
174 if (ServerBrowserMenuUI.Cast(lastMenu))
175 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.ServerBrowserMenu, -1, SCR_EMenuLoadingAdditionalDialog.SERVER_HOSTING);
176 else if (SCR_ScenarioMenu.Cast(lastMenu))
177 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.ScenarioMenu, -1, SCR_EMenuLoadingAdditionalDialog.SERVER_HOSTING);
178 }
179
180 //------------------------------------------------------------------------------------------------
181 protected void OnSaveTemplateClick()
182 {
184 return;
185
187 }
188
189 //------------------------------------------------------------------------------------------------
191 protected void DisplaySaveDialog()
192 {
193 SCR_ServerConfigSaveDialog dialog = SCR_ServerHostingDialogs.CreateSaveConfirmDialog();
194 dialog.m_OnConfirm.Insert(OnSaveDialogConfirm);
195
196 // Generate
197 string name = m_ConfigList.GenerateFileName(m_ConfigList.GetSelectedScenario());
198 dialog.SetFileNameText(name);
199 }
200
201 //------------------------------------------------------------------------------------------------
203 {
205 m_sFileName = saveDialog.GetFileNameText();
206
207 // Check if name is in config
208 array<string> configs = {};
209 GetGame().GetBackendApi().GetAvailableConfigs(configs);
210 string name = m_sFileName;
211
212 // Go though locally saved configs
213 for (int i = 0, count = configs.Count(); i < count; i++)
214 {
215 if (name + JSON_POSTFIX == configs[i])
216 {
217 // Display config exists
218 SCR_ConfigurableDialogUi overrideDialog = SCR_ServerHostingDialogs.CreateSaveOverrideDialog();
219
220 string color = string.Format(COLOR_TAG, UIColors.FormatColor(UIColors.CONTRAST_COLOR));
221 string msg = WidgetManager.Translate(DIALOG_OVERRIDE, name, color, COLOR_TAG_END);
222 overrideDialog.SetMessage(msg);
223 overrideDialog.m_OnConfirm.Insert(OnOverrideConfirm);
224
225 return;
226 }
227 }
228
229 // Save
230 SaveConfig();
231 }
232
233 //------------------------------------------------------------------------------------------------
235 {
236 string configName = m_sFileName + JSON_POSTFIX;
237 bool saved = GetGame().GetBackendApi().SaveDSConfig(m_DSConfig, configName);
238
239 if (saved)
240 {
241 // Show success dialog
242 SCR_ConfigurableDialogUi dialog = SCR_ServerHostingDialogs.CreateSaveSuccessDialog();
243
244 array<string> paths = {};
245 GetGame().GetBackendApi().GetAvailableConfigPaths(paths);
246
247 // Find right path and show message about file path
248 array<string> configs = {};
249 GetGame().GetBackendApi().GetAvailableConfigs(configs);
250 string name = m_sFileName;
251
252 foreach (int i, string config : configs)
253 {
254 if (name + JSON_POSTFIX != config)
255 continue;
256
257 string color = string.Format(COLOR_TAG, UIColors.FormatColor(UIColors.CONTRAST_COLOR));
258 string msg = WidgetManager.Translate(DIALOG_SAVED, paths[i], color, COLOR_TAG_END);
259
260 if (dialog)
261 dialog.SetMessage(msg);
262
263 break;
264 }
265
266 }
267 else
268 {
269 SCR_ServerHostingDialogs.CreateSaveFailedDialog();
270 }
271 }
272
273 //------------------------------------------------------------------------------------------------
274 protected void OnWorkshopOpenActivate()
275 {
277 SCR_MenuToolsLib.CloseAllMenus({MainMenuUI, ContentBrowserUI});
278 }
279
280 //------------------------------------------------------------------------------------------------
282 protected void AllMenuClosed()
283 {
285
286 // Store and close
287 array<ref SCR_WidgetListEntry> properties = m_ConfigList.GetInitialEntryList();
288 array<ref SCR_WidgetListEntry> advanced = m_AdvancedSettings.GetInitialEntryList();
289 for (int i = 0, count = advanced.Count(); i < count; i++)
290 properties.Insert(advanced[i]);
291
292 array<ref DSMod> mods = m_ConfigMods.SelectedModsList();
293 WorkshopItem scenarioMod = m_ConfigList.GetScenarioOwnerMod();
294
295 m_DSConfig.StoreFullJson(properties, mods, scenarioMod);
296 s_TemporaryConfig = m_DSConfig;
297
298 Close();
299
300 // Open workshop
301 ContentBrowserUI workshopUI = ContentBrowserUI.Cast(GetGame().GetMenuManager().GetTopMenu());
302 if (!workshopUI)
303 SCR_WorkshopUiCommon.TryOpenWorkshop();
304 }
305
306 //------------------------------------------------------------------------------------------------
308 protected void OnSubMenuChangePort(string port)
309 {
310 m_sUnifiedPort = port;
311
314 }
315
316 //------------------------------------------------------------------------------------------------
318 {
319 if (m_ConfigMods)
320 m_ConfigMods.SetScenario(scenario);
321 }
322
323 //------------------------------------------------------------------------------------------------
324 // API
325 //------------------------------------------------------------------------------------------------
326 //------------------------------------------------------------------------------------------------
328 void SelectScenario(notnull MissionWorkshopItem scenario)
329 {
330 if (!m_ConfigList)
331 return;
332
333 m_ConfigList.SelectScenario(scenario);
334 }
335
336 //------------------------------------------------------------------------------------------------
339 {
340 if (!m_ConfigList)
341 return;
342
343 m_ConfigList.SelectDefaultScenario();
344 }
345
346 //------------------------------------------------------------------------------------------------
347 static SCR_DSConfig GetTemporaryConfig()
348 {
349 return s_TemporaryConfig;
350 }
351}
void AllMenuClosed()
Callback for when all additional menu are closed and top menu is main menu.
ChimeraMenuPreset
Menu presets.
ArmaReforgerScripted GetGame()
Definition game.c:1398
@ SETTINGS
SCR_EMenuLoadingAdditionalDialog
override void OnMenuOpen()
ref SCR_DSConfig m_DSConfig
const string DIALOG_OVERRIDE
void SelectScenario(notnull MissionWorkshopItem scenario)
Select scenario in scenario selection dropdown.
ref SCR_ServerConfigAdvancedComponent m_AdvancedSettings
void OnWorkshopOpenActivate()
bool VerifyAndStoreConfig()
Verify and store all info into config - return true if all config properties are valid.
void DisplaySaveDialog()
Show dialog with file name settings and confirmation.
const string DIALOG_SAVED
ref SCR_ServerHostingSettingsSubMenu m_AdvancedSubMenu
void SelectDefaultScenario()
Select scenario in scenario selection dropdown.
void OnSubMenuChangePort(string port)
Call when sub menu change port setting to propagete unified port on multiple places.
ref SCR_ServerHostingModSubMenu m_ConfigMods
enum SCR_EServerHostingDialogTabs JSON_POSTFIX
void OnSaveTemplateClick()
string m_sFileName
ref SCR_ServerHostingSettingsSubMenu m_ConfigListSubMenu
void OnScenarioSelected(MissionWorkshopItem scenario)
void OnHostServerClick()
string m_sUnifiedPort
void SaveConfig()
void OnSaveDialogConfirm(SCR_ConfigurableDialogUi dialog)
const string COLOR_TAG
void OnOverrideConfirm(SCR_ConfigurableDialogUi dialog)
ref SCR_ServerConfigListComponent m_ConfigList
SCR_EServerHostingDialogTabs
@ MODS
@ ADVANCED_SETTINGS
const string COLOR_TAG_END
GameSessionStorage is used to store data for whole lifetime of game executable run....
static ScriptInvoker GetEventOnAllMenuClosed()
static void CloseAllMenus(array< typename > menus)
Close all menus that are not of selected class.
Workshop Item instance.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.