7 [
Attribute(
"{7E4D962E3084CD77}Configs/ServerBrowser/ServerHosting/Dialogs/ServerConfigDialogs.conf", UIWidgets.ResourceAssignArray)]
8 protected ResourceName m_sDialogs;
10 protected const string NAME_ENTRY =
"name";
11 protected const string FILE_NAME_ENTRY =
"fileName";
12 protected const string SCENARIO_SELECTION_ENTRY =
"scenarioId";
13 protected const string SCENARIO_MOD_SELECTION_ENTRY =
"scenarioModId";
14 protected const string PLAYER_LIMIT_ENTRY =
"maxPlayers";
15 protected const string BATTLEYE =
"battlEye";
16 protected const string CROSSPLAY =
"crossPlatform";
17 protected const string SIMPLE_PORT =
"publicPortSimple";
20 protected const string SERVER_NAME_BASE =
"%1 %2";
21 protected const string FILE_NAME_BASE =
"Config_%1";
22 protected const string DEFAULT_SCENARIO =
"{ECC61978EDCC2B5A}Missions/23_Campaign.conf";
31 protected SCR_WidgetListEntrySlider m_PlayerListSlider;
33 protected bool m_bNameEdited;
34 protected bool m_bFileNameEdited;
37 protected ref array<ref SCR_ScenarioSources> m_aScenarioSources = {};
40 protected ref ScriptInvoker<string> m_OnScenarioSelected;
41 protected ref ScriptInvoker<string> m_OnPortChanged;
44 protected void InvokeOnScenarioSelected(
string itemId)
46 if (m_OnScenarioSelected)
47 m_OnScenarioSelected.Invoke(itemId);
51 ScriptInvoker GetOnScenarioSelected()
53 if (!m_OnScenarioSelected)
54 m_OnScenarioSelected =
new ScriptInvoker();
56 return m_OnScenarioSelected;
60 ScriptInvoker GetOnPortChanged()
63 m_OnPortChanged =
new ScriptInvoker();
65 return m_OnPortChanged;
73 override void HandlerAttached(Widget w)
75 super.HandlerAttached(w);
80 m_wScrollWidget = ScrollLayoutWidget.Cast(w);
89 protected void FillScenarios()
100 m_PlayerListSlider = SCR_WidgetListEntrySlider.Cast(FindEntry(PLAYER_LIMIT_ENTRY));
108 m_NameEdit.GetEditBoxComponent().m_OnChanged.Insert(OnNameChanged);
111 if (m_SimplePortEdit)
112 m_SimplePortEdit.GetEditBoxComponent().m_OnChanged.Insert(OnSimplePortChanged);
115 if (!m_ScenarioSelect)
119 FillScenarioSources();
122 array<ref SCR_LocalizedProperty> options = {};
124 for (
int i = 0, count = m_aScenarioSources.Count(); i < count; i++)
126 MissionWorkshopItem scenario = m_aScenarioSources[i].m_Scenario;
131 options.Insert(scenarioOption);
134 m_ScenarioSelect.SetOptions(options);
137 m_ScenarioSelect.GetSelectionComponent().m_OnChanged.Insert(OnSelectScenario);
140 int defaultId = SetSelectedScenarioById(DEFAULT_SCENARIO);
141 m_ScenarioSelect.SelectOption(defaultId);
142 OnSelectScenario(
null, defaultId);
149 protected void FillScenarioSources()
152 array<MissionWorkshopItem> allMissions = {};
153 GetGame().GetBackendApi().GetWorkshop().GetPageScenarios(allMissions, 0, 4096);
156 array<MissionWorkshopItem> missions = {};
158 for (
int i = 0, count = allMissions.Count(); i < count; i++)
165 WorkshopItem scenarioAddon = allMissions[i].GetOwner();
178 if (item && item.GetAnyDependencyMissing() || item.GetCorrupted())
182 missions.Insert(allMissions[i]);
186 SCR_Sorting<MissionWorkshopItem, SCR_CompareMissionName>.HeapSort(missions);
189 for (
int i = 0, count = missions.Count(); i < count; i++)
191 InsertScenarioToMap(missions[i], missions[i].
GetOwner());
198 protected void InsertScenarioToMap(MissionWorkshopItem scenario, WorkshopItem modOwner)
203 int scenarioIndex = -1;
205 for (
int i = 0, count = m_aScenarioSources.Count(); i < count; i++)
207 MissionWorkshopItem mission = m_aScenarioSources[i].m_Scenario;
210 if (mission && scenario.Id() == mission.Id())
219 if (scenarioIndex != -1)
222 m_aScenarioSources[scenarioIndex].m_aMods.Insert(modOwner);
233 protected int SetSelectedScenarioById(
string scenarioId)
235 array<ref SCR_LocalizedProperty> scenarios = {};
236 m_ScenarioSelect.GetOptions(scenarios);
238 for (
int i = 0, count = m_aScenarioSources.Count(); i < count; i++)
253 protected void ConsoleSetup()
260 m_BattleyeSelect.SetValue(
"0");
261 m_CrossplaySelect.SetValue(
"1");
264 m_BattleyeSelect.GetEntryRoot().SetVisible(
false);
265 m_CrossplaySelect.GetEntryRoot().SetVisible(
false);
273 void SelectScenario(notnull MissionWorkshopItem scenario)
275 array<MissionWorkshopItem> missionItemsAll =
new array<MissionWorkshopItem>;
276 GetGame().GetBackendApi().GetWorkshop().GetPageScenarios(missionItemsAll, 0, 4096);
278 if (m_ScenarioSelect)
280 int selected = SetSelectedScenarioById(scenario.Id());
282 m_ScenarioSelect.SelectOption(selected);
288 MissionWorkshopItem GetSelectedScenario()
290 if (!m_ScenarioSelect)
293 array<MissionWorkshopItem> missionItemsAll =
new array<MissionWorkshopItem>;
294 GetGame().GetBackendApi().GetWorkshop().GetPageScenarios(missionItemsAll, 0, 4096);
296 for (
int i = 0, count = missionItemsAll.Count(); i < count; i++)
299 string name = selected.m_sPropertyName;
301 if (missionItemsAll[i].Id() == name)
303 return missionItemsAll[i];
312 WorkshopItem GetScenarioOwnerMod()
314 if (!m_ScenarioSelect)
317 array<MissionWorkshopItem> missionItemsAll =
new array<MissionWorkshopItem>;
318 GetGame().GetBackendApi().GetWorkshop().GetPageScenarios(missionItemsAll, 0, 4096);
327 for (
int i = 0, count = missionItemsAll.Count(); i < count; i++)
329 WorkshopItem ownerItem = missionItemsAll[i].GetOwner();
333 if (ownerItem.Id() == property.m_sPropertyName)
347 FindEntry(
"name").SetValue(config.game.name);
348 FindEntry(
"maxPlayers").SetValue(config.game.maxPlayers.ToString());
349 FindEntry(
"password").SetValue(config.game.password);
350 FindEntry(
"passwordAdmin").SetValue(config.game.passwordAdmin);
357 if (gamePropertiesSCr)
360 FindEntry(
"disableThirdPerson").SetValue(
SCR_JsonApiStructHandler.BoolToString(gamePropertiesSCr.disableThirdPerson));
362 FindEntry(
"VONDisableDirectSpeechUI").SetValue(
SCR_JsonApiStructHandler.BoolToString(gamePropertiesSCr.VONDisableDirectSpeechUI));
363 FindEntry(
"VONCanTransmitCrossFaction").SetValue(
SCR_JsonApiStructHandler.BoolToString(gamePropertiesSCr.VONCanTransmitCrossFaction));
364 FindEntry(
"serverMaxViewDistance").SetValue(gamePropertiesSCr.serverMaxViewDistance.ToString());
365 FindEntry(
"networkViewDistance").SetValue(gamePropertiesSCr.networkViewDistance.ToString());
366 FindEntry(
"serverMinGrassDistance").SetValue(gamePropertiesSCr.serverMinGrassDistance.ToString());
370 m_ScenarioSelect.SelectOption(SetSelectedScenarioById(config.game.scenarioId));
375 void ScrollToTheEntry(notnull Widget w)
378 float entryX, entryY;
379 w.GetScreenPos(entryX, entryY);
383 m_wList.GetScreenSize(listW, listH);
387 m_wList.GetScreenPos(listX, listY);
390 float scrollW, scrollH;
391 m_wScrollWidget.GetScreenSize(scrollW, scrollH);
394 float outView = listH - scrollH;
395 float relPos = entryY - listY;
397 float pos = 1 - (outView - relPos) / outView;
398 m_wScrollWidget.SetSliderPos(0, pos);
402 void SetPort(
string port)
404 m_SimplePortEdit.SetValue(port);
414 m_bNameEdited = !text.IsEmpty();
421 m_OnPortChanged.Invoke(text);
427 m_bFileNameEdited = !text.IsEmpty();
433 if (!m_ScenarioSelect || !m_ScenarioModSelect)
436 int selecteScenario = m_ScenarioSelect.GetSelectedOption();
437 array<ref SCR_LocalizedProperty> ownerMods = {};
441 if (m_aScenarioSources[selected].m_aMods)
442 count = m_aScenarioSources[selected].m_aMods.Count();
444 for (
int i = 0; i < count; i++)
446 WorkshopItem mod = m_aScenarioSources[selected].m_aMods[i];
450 string name = m_aScenarioSources[selected].m_aMods[i].Name();
451 string id = m_aScenarioSources[selected].m_aMods[i].Id();
457 if (!ownerMods || ownerMods.IsEmpty() || ownerMods[0] ==
null)
464 m_ScenarioModSelect.SetOptions(ownerMods);
465 m_ScenarioModSelect.SelectOption(0);
468 m_ScenarioModSelect.SetInteractive(ownerMods.Count() > 1);
471 MissionWorkshopItem scenario = GetSelectedScenario();
474 GenerateName(scenario);
476 if (!m_bFileNameEdited)
477 GenerateFileName(scenario);
479 SetupPlayerLimit(scenario.GetPlayerCount());
481 InvokeOnScenarioSelected(scenario.Id());
486 protected void GenerateName(notnull MissionWorkshopItem scenario)
491 string name =
string.Format(SERVER_NAME_BASE,
SCR_Global.GetProfileName(), scenario.Name());
493 m_NameEdit.SetValue(name);
494 m_NameEdit.ClearInvalidInput();
497 protected const string CHAR_BLACK_LIST =
"<>:\/\|?*.";
501 string GenerateFileName(notnull MissionWorkshopItem scenario)
503 string scenarioTranslation = WidgetManager.Translate(scenario.Name());
504 string fileName =
string.Format(FILE_NAME_BASE, scenarioTranslation);
505 fileName.Replace(
" ",
"");
508 for (
int i = 0, count = CHAR_BLACK_LIST.Length(); i < count; i++)
510 fileName.Replace(CHAR_BLACK_LIST[i],
"");
517 protected void SetupPlayerLimit(
int limit)
519 if (!m_PlayerListSlider)
522 m_PlayerListSlider.SetRange(1, limit);
525 int value = m_PlayerListSlider.ValueAsString().ToInt();
528 m_PlayerListSlider.SetValue(limit.ToString());
536 ResourceName GetDialogs()
546 MissionWorkshopItem m_Scenario;
548 ref array<WorkshopItem> m_aMods;