Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapJournalUI.c
Go to the documentation of this file.
1 // todo@lk: figure out what to call this, journal is probably not the best choice, idiot
3 {
4  protected SCR_JournalSetupConfig m_JournalConfig;
5 
6  [Attribute("EntryList")]
7  protected string m_sEntryList;
8 
9  protected Widget m_wEntryList;
10 
11  [Attribute("EntryLayout")]
12  protected string m_sEntryLayout;
13 
14  protected Widget m_wEntryLayout;
15 
16  protected ref array<SCR_MapJournalUIButton> m_aEntries = {};
17  protected int m_iCurrentEntryId = -1;
18 
19  [Attribute("JournalFrame", desc: "Root frame widget name")]
20  protected string m_sRootWidgetName;
21 
22  protected Widget m_wJournalFrame;
23 
24  [Attribute("exclamationCircle", desc: "Toolmenu imageset quad name")]
25  protected string m_sToolMenuIconName;
26 
27  protected SCR_MapToolMenuUI m_ToolMenu;
28  protected SCR_MapToolEntry m_ToolMenuEntry;
29 
30  protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp;
31 
32  [Attribute("MapTaskListFrame", desc: "Map task list frame widget name")]
33  protected string m_sMapTaskListFrame;
34 
35  [Attribute("faction", desc: "Map task list imageset quad name")]
36  protected string m_sTaskListToolMenuIconName;
37 
38  //We'll store the bool in order to know if is it the first opening or not
39  protected bool m_bFirstOpening = true;
40 
41  //------------------------------------------------------------------------------------------------
42  override void Init()
43  {
44  SCR_RespawnBriefingComponent briefingComp = SCR_RespawnBriefingComponent.GetInstance();
45  if (!briefingComp)
46  return;
47 
48  if (!briefingComp.LoadJournalConfig())
49  return;
50 
51  m_JournalConfig = briefingComp.GetJournalSetup();
52  if (!m_JournalConfig)
53  return;
54 
55  m_ToolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
56  if (m_ToolMenu)
57  {
58  m_ToolMenuEntry = m_ToolMenu.RegisterToolMenuEntry(SCR_MapToolMenuUI.s_sToolMenuIcons, m_sToolMenuIconName, 1);
59  m_ToolMenuEntry.m_OnClick.Insert(ToggleVisible);
60  m_ToolMenuEntry.SetEnabled(true);
61  }
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override void OnMapOpen(MapConfiguration config)
66  {
67  super.OnMapOpen(config);
68 
69  if (!m_JournalConfig)
70  return;
71 
72  m_wJournalFrame = m_RootWidget.FindAnyWidget(m_sRootWidgetName);
73 
74  m_wEntryList = m_RootWidget.FindAnyWidget(m_sEntryList);
75  if (!m_wEntryList)
76  return;
77 
78  m_wEntryLayout = m_RootWidget.FindAnyWidget(m_sEntryLayout);
79  if (!m_wEntryLayout)
80  return;
81 
82  PlayerController pc = GetGame().GetPlayerController();
83  if (!pc)
84  return;
85 
88  return;
89 
90  m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Insert(OnPlayerFactionResponse);
91 
92  GetJournalForPlayer();
93 
94  ToggleVisible();
95 
96  if (m_bFirstOpening)
97  {
98  //if opened for the first time, use the value from config
99  ShowEntryByID(m_JournalConfig.GetJournalEntryToBeShown());
100  m_bFirstOpening = false;
101  }
102  else
103  {
104  //if opened the second and other times, use the last opened one
105  ShowEntryByID(m_iCurrentEntryId);
106  }
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  protected void OnPlayerFactionResponse(SCR_PlayerFactionAffiliationComponent component, int factionIndex, bool response)
111  {
112  if (response)
113  {
114  m_wEntryLayout.SetVisible(false);
115  GetJournalForPlayer();
116  }
117  }
118 
119  //------------------------------------------------------------------------------------------------
121  protected void ToggleVisible()
122  {
123  if (!m_wJournalFrame || !m_ToolMenu)
124  return;
125 
126  array<ref SCR_MapToolEntry> menuEntries = {};
127  menuEntries = m_ToolMenu.GetMenuEntries();
128  if (!menuEntries && menuEntries.IsEmpty())
129  return;
130 
131  foreach (SCR_MapToolEntry toolEntry : menuEntries)
132  {
133  if (toolEntry.GetImageSet() != m_sTaskListToolMenuIconName)
134  continue;
135 
136  Widget mapTaskListFrame = m_RootWidget.FindAnyWidget(m_sMapTaskListFrame);
137  if (mapTaskListFrame && mapTaskListFrame.IsVisible())
138  {
139  mapTaskListFrame.SetVisible(false);
140  toolEntry.SetActive(false);
141 
142  SCR_UITaskManagerComponent m_UITaskManager = SCR_UITaskManagerComponent.GetInstance();
143  if (m_UITaskManager)
144  m_UITaskManager.Action_TasksClose();
145  }
146  }
147 
148  bool visible = m_wJournalFrame.IsVisible();
149  m_wJournalFrame.SetVisible(!visible);
150  if (m_ToolMenuEntry)
151  m_ToolMenuEntry.SetActive(!visible);
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  protected void GetJournalForPlayer()
156  {
157  Widget child = m_wEntryList.GetChildren();
158  while (child)
159  {
160  Widget sibling = child.GetSibling();
161  delete child;
162  child = sibling;
163  }
164 
165  m_iCurrentEntryId = -1;
166 
167  FactionKey factionKey = FactionKey.Empty;
169  {
170  Faction plyFaction = m_PlyFactionAffilComp.GetAffiliatedFaction();
171  if (plyFaction)
172  factionKey = plyFaction.GetFactionKey();
173  }
174 
175  SCR_JournalConfig factionJournal = m_JournalConfig.GetJournalConfig(factionKey);
176  if (!factionJournal)
177  return;
178 
179  array<ref SCR_JournalEntry> journalEntries = factionJournal.GetEntries();
180  SCR_JournalEntry entry;
181  Widget e;
182  SCR_MapJournalUIButton entryBtn;
183  WorkspaceWidget workspace = GetGame().GetWorkspace();
184  for (int entryId = 0; entryId < journalEntries.Count(); ++entryId)
185  {
186  entry = journalEntries[entryId];
187  e = workspace.CreateWidgets(entry.GetEntryButtonLayout(), m_wEntryList);
188  entryBtn = SCR_MapJournalUIButton.Cast(e.FindHandler(SCR_MapJournalUIButton));
189  entryBtn.SetContent(entry.GetEntryName());
190  entryBtn.SetEntry(entry, entryId);
191  entryBtn.m_OnClicked.Insert(ShowEntry);
192  m_aEntries.Insert(entryBtn);
193  }
194  }
195 
196  //------------------------------------------------------------------------------------------------
199  protected void ShowEntryByID(int id)
200  {
201  if (id < 0)
202  return;
203  SCR_MapJournalUIButton entryBtn;
204  Widget child = m_wEntryList.GetChildren();
205  while (child)
206  {
207  entryBtn = SCR_MapJournalUIButton.Cast(child.FindHandler(SCR_MapJournalUIButton));
208  if (!entryBtn)
209  continue;
210 
211  if (entryBtn.GetId() == id)
212  {
213  ShowEntry(entryBtn);
214  break;
215  }
216 
217  child = child.GetSibling();
218  }
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  protected void ShowEntry(SCR_MapJournalUIButton journalBtn)
223  {
224  if (journalBtn.GetId() == m_iCurrentEntryId)
225  {
226  m_wEntryLayout.SetVisible(!m_wEntryLayout.IsVisible());
227  }
228  else
229  {
230  Widget child = m_wEntryLayout.GetChildren();
231  if (child)
232  delete child;
233 
234  m_iCurrentEntryId = journalBtn.GetId();
235  journalBtn.ShowEntry(m_wEntryLayout);
236  m_wEntryLayout.SetVisible(true);
237  }
238  }
239 }
240 
241 class SCR_MapJournalUIButton : SCR_ButtonComponent
242 {
243  protected SCR_JournalEntry m_Entry;
244  protected int m_iEntryId;
245 
246  //------------------------------------------------------------------------------------------------
249  void SetEntry(SCR_JournalEntry entry, int id)
250  {
251  m_Entry = entry;
252  m_iEntryId = id;
253  }
254 
255  //------------------------------------------------------------------------------------------------
258  void ShowEntry(Widget target)
259  {
260  m_Entry.SetEntryLayoutTo(target);
261  }
262 
263  //------------------------------------------------------------------------------------------------
265  int GetId()
266  {
267  return m_iEntryId;
268  }
269 }
SCR_JournalSetupConfig
Definition: SCR_JournalConfig.c:12
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_RootWidget
protected Widget m_RootWidget
Definition: SCR_BinocularsComponent.c:10
GetId
int GetId()
Definition: SCR_MapJournalUI.c:265
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapDrawingUI.c:182
SCR_JournalConfig
Definition: SCR_JournalConfig.c:45
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_Entry
SCR_MapJournalUI m_Entry
SCR_MapToolEntry
Map tool menu entry data class.
Definition: SCR_MapToolMenuUI.c:2
m_PlyFactionAffilComp
protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
Definition: SCR_DeployMenuBase.c:119
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
SCR_ButtonComponent
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
Definition: SCR_ButtonComponent.c:4
m_aEntries
protected ref array< ref SCR_TextsTaskManagerEntry > m_aEntries
Definition: SCR_TextsTaskManagerComponent.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_iEntryId
protected int m_iEntryId
Definition: SCR_MapJournalUI.c:244
Faction
Definition: Faction.c:12
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
SetEntry
void SetEntry(SCR_JournalEntry entry, int id)
Definition: SCR_MapJournalUI.c:249
SCR_JournalEntry
Definition: SCR_JournalConfig.c:65
ShowEntry
void ShowEntry(Widget target)
Definition: SCR_MapJournalUI.c:258
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
SCR_MapJournalUI
Definition: SCR_MapJournalUI.c:2
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389