Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GroupFlagSelectionMenu.c
Go to the documentation of this file.
2 {
3  protected const int MAX_COLUMNS = 6;
4  protected const float ICONS_SCALE = 0.75;
5 
6  protected const ResourceName BUTTON_IMAGE = "{6BBBE8F27E385D3B}UI/layouts/WidgetLibrary/Groups/WLib_GroupFlagButtonImage.layout";
7 
8  //------------------------------------------------------------------------------------------------
9  override void OnMenuOpen()
10  {
11  super.OnMenuOpen();
12  InitGroupFlagSelectionMenu(MAX_COLUMNS, BUTTON_IMAGE);
13  }
14 
15  //------------------------------------------------------------------------------------------------
16  override void OnMenuUpdate(float tDelta)
17  {
18  super.OnMenuUpdate(tDelta);
19 
20  GetGame().GetInputManager().ActivateContext("InteractableDialogContext");
21  }
22 
23  //------------------------------------------------------------------------------------------------
24  override void OnConfirm()
25  {
26  // This is handled by the tiles themselves
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  void CloseDialog()
31  {
32  CloseAnimated();
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  void InitGroupFlagSelectionMenu(int maxColumns, ResourceName widget)
37  {
38  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
39  if(!groupManager)
40  return;
41 
42  int row = 1;
43  int col = 1;
44 
45  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
46  if (!factionManager)
47  return;
48 
49  SCR_Faction playerFaction = SCR_Faction.Cast(factionManager.GetLocalPlayerFaction());
50  if (!playerFaction)
51  return;
52 
53  OverlayWidget con = OverlayWidget.Cast(GetRootWidget().FindAnyWidget("Content"));
54 
55  GridLayoutWidget content = GridLayoutWidget.Cast(con.FindAnyWidget("ContentGrid"));
56  if (!content)
57  return;
58 
59  ResourceName imageSet = playerFaction.GetGroupFlagImageSet();
60  array<ResourceName> textures = {};
61  playerFaction.GetGroupFlagTextures(textures);
62 
63  if (!textures.IsEmpty())
64  {
65  for(int i = 0, count = textures.Count(); i < count; i++)
66  {
67  Widget contentButton = GetGame().GetWorkspace().CreateWidgets(widget, content);
68  if (!contentButton)
69  continue;
70 
71  SCR_GroupFlagImageComponent imageButton = SCR_GroupFlagImageComponent.Cast(contentButton.FindHandler(SCR_GroupFlagImageComponent));
72  if (!imageButton)
73  continue;
74 
75  if (col > maxColumns)
76  {
77  row++;
78  col = 1;
79  }
80 
81  GridSlot.SetRow(contentButton, row);
82  GridSlot.SetColumn(contentButton, col);
83 
84  ResourceName resource = textures[i];
85  if (resource.IsEmpty())
86  continue;
87 
88  imageButton.GetImageWidget().LoadImageTexture(0, textures[i]);
89  imageButton.Resize(ICONS_SCALE);
90  imageButton.m_OnClicked.Insert(SetGroupFlag);
91  imageButton.SetImageID(i);
92  imageButton.SetIsFromImageset(false);
93 
94  col++;
95  }
96  }
97 
98  if (!imageSet.IsEmpty())
99  {
100  array<string> flagNames = {};
101  playerFaction.GetFlagNames(flagNames);
102 
103  for(int i = 0; i < flagNames.Count(); i++)
104  {
105  Widget contentButton = GetGame().GetWorkspace().CreateWidgets(widget, content);
106  if (!contentButton)
107  continue;
108 
109  SCR_GroupFlagImageComponent imageButton = SCR_GroupFlagImageComponent.Cast(contentButton.FindHandler(SCR_GroupFlagImageComponent));
110  if (!imageButton)
111  continue;
112 
113  if (col > maxColumns)
114  {
115  row++;
116  col = 1;
117  }
118 
119  GridSlot.SetRow(contentButton, row);
120  GridSlot.SetColumn(contentButton, col);
121 
122  ResourceName resource = playerFaction.GetGroupFlagImageSet();
123  if (resource.IsEmpty())
124  continue;
125 
126  imageButton.GetImageWidget().LoadImageFromSet(0, resource, flagNames[i]);
127  imageButton.Resize(ICONS_SCALE);
128  imageButton.m_OnClicked.Insert(SetGroupFlag);
129  imageButton.SetImageID(i);
130  imageButton.SetImageSet(flagNames[i]);
131  imageButton.SetIsFromImageset(true);
132  col++;
133  }
134  }
135 
136 
137  Widget cancelButton = GetRootWidget().FindAnyWidget("Cancel");
138 
139  SCR_InputButtonComponent cancel = SCR_InputButtonComponent.Cast(cancelButton.FindHandler(SCR_InputButtonComponent));
140  cancel.m_OnClicked.Insert(CloseDialog);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void SetGroupFlag(SCR_ButtonBaseComponent button)
145  {
146 
147  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
148  if(!groupManager)
149  return;
150 
151  SCR_PlayerControllerGroupComponent playerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
152  if (!playerGroupController)
153  return;
154 
155  SCR_AIGroup group = groupManager.FindGroup(playerGroupController.GetGroupID());
156  if (!group)
157  return;
158 
159  SCR_GroupFlagImageComponent imageButton = SCR_GroupFlagImageComponent.Cast(button.GetRootWidget().FindHandler(SCR_GroupFlagImageComponent));
160  if (!imageButton)
161  return;
162 
163  bool isFromImageset = imageButton.GetIsFromImageset();
164  playerGroupController.RequestSetGroupFlag(group.GetGroupID(), imageButton.GetImageID(), isFromImageset);
165 
166  CloseAnimated();
167  }
168 }
SCR_GroupFlagImageComponent
Definition: SCR_GroupFlagImageComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
DialogUI
Definition: DialogUI.c:1
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_GroupFlagSelectionMenu
Definition: SCR_GroupFlagSelectionMenu.c:1
SCR_Faction
Definition: SCR_Faction.c:6
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1