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