Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AddonsExportSubMenuComponent.c
Go to the documentation of this file.
1 
7 {
8  JSON,
9  CLI
10 }
11 
12 class SCR_AddonsExportSubMenuComponent : SCR_SubMenuBase
13 {
14  [Attribute("0", UIWidgets.ComboBox, "Used format for submenu", "", ParamEnumArray.FromEnum(EAddonExportFormat))]
15  protected EAddonExportFormat m_iUsedFormat;
16 
18 
19  protected string m_sGeneratedText;
20 
22 
23  //---------------------------------------------------------------------------------------------------
24  // Override
25  //---------------------------------------------------------------------------------------------------
26  //---------------------------------------------------------------------------------------------------
27  override void HandlerAttached(Widget w)
28  {
29  super.HandlerAttached(w);
30 
31  m_Widgets.Init(w);
32  }
33 
34  //---------------------------------------------------------------------------------------------------
35  override void OnTabShow()
36  {
37  super.OnTabShow();
38 
39  if (!m_NavCopyComponent)
40  {
41  m_NavCopyComponent = CreateNavigationButton("MenuSelect", "#AR-Workshop_AddonsExportCopyBtn", true);
42  m_NavCopyComponent.m_OnActivated.Insert(CopyToClipboard);
43  }
44 
45  switch (m_iUsedFormat)
46  {
47  case EAddonExportFormat.JSON: GenerateJSONFormat(); break;
48  case EAddonExportFormat.CLI: GenerateCLIFormat(); break;
49  }
50  }
51 
52  //---------------------------------------------------------------------------------------------------
53  // Protected
54  //---------------------------------------------------------------------------------------------------
55  //---------------------------------------------------------------------------------------------------
57  protected void DisplayText(string text)
58  {
59  m_Widgets.m_GenContent.SetText(text);
60  m_Widgets.m_ScrollLayout.SetSliderPos(0,0);
61  }
62 
63  //------------------------------------------------------------------------------------------------
65  protected string GenerateAddonJson(SCR_WorkshopItem item)
66  {
67  return string.Format(
68  "\t{\n\t\t\%1: %2,\n\t\t%3: %4,\n\t\t%5: %6\n\t}",
69  qstr("modId"), qstr(item.GetId()),
70  qstr("name"), qstr(item.GetName()),
71  qstr("version"), qstr(item.GetCurrentLocalRevision().GetVersion()) );
72  }
73 
74  // Puts quotes around a string
75  static string qstr(string s)
76  {
77  return string.Format("\"%1\"", s);
78  }
79 
80  //---------------------------------------------------------------------------------------------------
81  // Actions
82  //---------------------------------------------------------------------------------------------------
83  //---------------------------------------------------------------------------------------------------
86  {
87  auto offlineAddons = SCR_AddonManager.GetInstance().GetOfflineAddons();
88  array<ref SCR_WorkshopItem> enabledAddons = SCR_AddonManager.SelectItemsBasic(offlineAddons, EWorkshopItemQuery.ENABLED);
89 
90  string s;
91 
92  if (!enabledAddons.IsEmpty())
93  {
94  s = s + GenerateAddonJson(enabledAddons[0]);
95 
96  for (int i = 1; i < enabledAddons.Count(); i++)
97  s = s + ",\n" + GenerateAddonJson(enabledAddons[i]);
98  }
99 
100  m_sGeneratedText = s;
102  }
103 
104  //---------------------------------------------------------------------------------------------------
107  {
108  string cli = "-addons ";
109 
110  auto offlineAddons = SCR_AddonManager.GetInstance().GetOfflineAddons();
111  array<ref SCR_WorkshopItem> enabledAddons = SCR_AddonManager.SelectItemsBasic(offlineAddons, EWorkshopItemQuery.ENABLED);
112 
113  if (!enabledAddons.IsEmpty())
114  {
115  cli = cli + enabledAddons[0].GetId();
116  for (int i = 1; i < enabledAddons.Count(); i++)
117  cli = cli + ", " + enabledAddons[i].GetId();
118  }
119 
120  m_sGeneratedText = cli;
122  }
123 
124  //---------------------------------------------------------------------------------------------------
127  {
128  System.ExportToClipboard(m_sGeneratedText);
129  }
130 
131  //---------------------------------------------------------------------------------------------------
132  // API
133  //---------------------------------------------------------------------------------------------------
134  //---------------------------------------------------------------------------------------------------
136  {
137  return m_sGeneratedText;
138  }
139 }
DisplayText
protected void DisplayText(string text)
Display text in widgets.
Definition: SCR_AddonsExportSubMenuComponent.c:57
HandlerAttached
override void HandlerAttached(Widget w)
Definition: SCR_AddonsExportSubMenuComponent.c:27
m_Widgets
protected ref SCR_AddonsExportSubMenuWidgets m_Widgets
Definition: SCR_AddonsExportSubMenuComponent.c:17
m_sGeneratedText
protected string m_sGeneratedText
Definition: SCR_AddonsExportSubMenuComponent.c:19
JSON
JSON
Definition: SCR_AddonsExportSubMenuComponent.c:2
OnTabShow
override void OnTabShow()
Definition: SCR_AddonsExportSubMenuComponent.c:35
GetId
int GetId()
Definition: SCR_MapJournalUI.c:265
CopyToClipboard
void CopyToClipboard()
Copy currently generated text to clipboard.
Definition: SCR_AddonsExportSubMenuComponent.c:126
Attribute
enum EAddonExportFormat Attribute("0", UIWidgets.ComboBox, "Used format for submenu", "", ParamEnumArray.FromEnum(EAddonExportFormat))] protected EAddonExportFormat m_iUsedFormat
SCR_SubMenuBase
Definition: SCR_SubMenuBase.c:6
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
GenerateCLIFormat
void GenerateCLIFormat()
Generate text with list of enabled addons ids.
Definition: SCR_AddonsExportSubMenuComponent.c:106
m_NavCopyComponent
protected SCR_InputButtonComponent m_NavCopyComponent
Definition: SCR_AddonsExportSubMenuComponent.c:21
CLI
CLI
Definition: SCR_AddonsExportSubMenuComponent.c:4
SCR_AddonsExportSubMenuWidgets
Definition: SCR_AddonsExportSubMenuWidgets.c:4
GenerateJSONFormat
void GenerateJSONFormat()
Generate text for enbled addons in json format for server config.
Definition: SCR_AddonsExportSubMenuComponent.c:85
GenerateAddonJson
protected string GenerateAddonJson(SCR_WorkshopItem item)
Generate text of addon in json config format.
Definition: SCR_AddonsExportSubMenuComponent.c:65
EAddonExportFormat
EAddonExportFormat
Definition: SCR_AddonsExportSubMenuComponent.c:6
SCR_AddonManager
Definition: SCR_AddonManager.c:72
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
GetGeneratedText
string GetGeneratedText()
Definition: SCR_AddonsExportSubMenuComponent.c:135