Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CareerProfileHUD.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_CareerProfileHUD: ScriptedWidgetComponent
3 {
4  protected Widget m_wRootWidget;
5  protected SCR_ButtonTextComponent m_EditAppearance;
6 
7  [Attribute()]
8  protected ref array<ResourceName> m_aBackgroundImages;
9 
10  [Attribute()]
11  protected ref array<ResourceName> m_aRankImages;
12 
13  protected ImageWidget m_RankImageWidget;
14  protected RichTextWidget m_RankLevel;
15  protected RichTextWidget m_LevelProgress, m_PlayerLevel;
16  protected ImageWidget m_BackgroundUserPictureImageWidget;
17  protected SCR_WLibProgressBarComponent m_ProgressBar;
18 
19  [Attribute("0", "auto", "Min progress bar value")]
20  protected int m_iMinBarValue;
21 
22  [Attribute("100", "auto", "Value to display when progress is 0")]
23  protected int m_iMinRepresentativeValue;
24 
25  [Attribute("10000", "auto", "Max progress bar value")]
26  protected int m_iMaxBarValue;
27 
28  [Attribute("{9F18C476AB860F3B}Prefabs/World/Game/ItemPreviewManager.et")]
29  protected ResourceName previewManagerResource;
30 
31  [Attribute("{5B1996C05B1E51A4}Prefabs/Characters/Factions/BLUFOR/US_Army/Character_US_AR.et")]
32  protected ResourceName loadoutResource;
33 
34  //------------------------------------------------------------------------------------------------
35  protected override void HandlerAttached(Widget w)
36  {
37  m_wRootWidget = w;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  void PrepareHUD(string rankImageName, string rankLevelName, string backgroundUserPictureName, string CharacterLoadoutName, string LevelProgressName, string PlayerLevelName, string ProgressBarName, string EditAppearanceButtonName)
42  {
43  if (!m_wRootWidget)
44  return;
45 
46  if (rankImageName.IsEmpty())
47  m_RankImageWidget = ImageWidget.Cast(m_wRootWidget.FindAnyWidget(rankImageName));
48 
49  if (rankLevelName != "")
50  m_RankLevel = RichTextWidget.Cast(m_wRootWidget.FindAnyWidget(rankLevelName));
51 
52  if (backgroundUserPictureName != "")
53  m_BackgroundUserPictureImageWidget = ImageWidget.Cast(m_wRootWidget.FindAnyWidget(backgroundUserPictureName));
54 
55  if (CharacterLoadoutName != "")
56  {
57  Widget characterLoadout = m_wRootWidget.FindAnyWidget(CharacterLoadoutName);
58  if (characterLoadout)
59  {
60  SCR_LoadoutPreviewComponent characterLoadoutHandler = SCR_LoadoutPreviewComponent.Cast(characterLoadout.FindHandler(SCR_LoadoutPreviewComponent));
61  if (characterLoadoutHandler)
62  {
63  ItemPreviewManagerEntity previewManager = characterLoadoutHandler.GetPreviewManagerEntity();
64  ItemPreviewWidget previewWidget = characterLoadoutHandler.GetItemPreviewWidget();
65 
66  if (previewManager && previewWidget)
67  {
68  characterLoadoutHandler.SetPreviewManagerEntity(previewManager);
69  characterLoadoutHandler.SetItemPreviewWidget(previewWidget);
70 
71  previewManager.SetPreviewItemFromPrefab(previewWidget, loadoutResource);
72  characterLoadoutHandler.SetReloadLoadout(false);
73  }
74  }
75  }
76  }
77 
78  if (ProgressBarName != "")
79  {
80  m_ProgressBar = SCR_WLibProgressBarComponent.GetProgressBar(ProgressBarName, m_wRootWidget, true);
81 
82  if (!m_ProgressBar)
83  return;
84 
85  m_ProgressBar.SetMin(m_iMinBarValue);
86  m_ProgressBar.SetMax(m_iMaxBarValue);
87 
88  if (LevelProgressName != "")
89  m_LevelProgress = RichTextWidget.Cast(m_wRootWidget.FindAnyWidget(LevelProgressName));
90 
91  if (PlayerLevelName != "")
92  m_PlayerLevel = RichTextWidget.Cast(m_wRootWidget.FindAnyWidget(PlayerLevelName));
93  }
94 
95  if (EditAppearanceButtonName != "")
96  {
97  m_EditAppearance = SCR_ButtonTextComponent.GetButtonText(EditAppearanceButtonName, m_wRootWidget);
98  if (!m_EditAppearance)
99  return;
100 
101  m_EditAppearance.m_OnClicked.Insert(OnEditAppearance);
102  }
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  void OnEditAppearance()
107  {
108  GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.CreditsMenu); //To remove
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  void SetLevelProgressGain(float f)
113  {
114  RichTextWidget levelProgressGain = RichTextWidget.Cast(m_wRootWidget.FindAnyWidget("LevelGained"));
115  if (!levelProgressGain)
116  return;
117 
118  if (f != 0)
119  {
120  levelProgressGain.SetText("+"+f);
121  levelProgressGain.SetEnabled(true);
122  levelProgressGain.SetVisible(true);
123  return;
124  }
125 
126  levelProgressGain.SetText("");
127  levelProgressGain.SetEnabled(false);
128  levelProgressGain.SetVisible(false);
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  void SetPlayerRank(int rank)
133  {
134  if (rank < 0)
135  return;
136  else if (rank == 0)
137  rank = 1;
138 
139  if (m_RankLevel)
140  m_RankLevel.SetTextFormat("#AR-CareerProfile_RankTitle",rank);
141 
142  if (m_RankImageWidget && m_aRankImages && m_aRankImages.Count() >= rank)
143  SCR_WLibComponentBase.SetTexture(m_RankImageWidget, m_aRankImages[rank-1], string.Empty);
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  void SetRandomBackgroundPicture()
148  {
149  if (m_BackgroundUserPictureImageWidget && m_aBackgroundImages.Count()>0)
150  {
151  m_BackgroundUserPictureImageWidget.SetColor(Color.FromSRGBA(255,255,255,204)); //60% opacity
152  SCR_WLibComponentBase.SetTexture(m_BackgroundUserPictureImageWidget, m_aBackgroundImages[Math.RandomInt(0,m_aBackgroundImages.Count())], string.Empty);
153  }
154 
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  void SetPlayerLevel(int n)
159  {
160  if (m_PlayerLevel)
161  m_PlayerLevel.SetTextFormat("#AR-CareerProfile_PlayerLv",n);
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  void SetProgressBarValue(int n)
166  {
167  if (n < m_iMinBarValue || n > m_iMaxBarValue)
168  return;
169 
170  if (m_LevelProgress)
171  m_LevelProgress.SetText ("" + n + "/" + m_iMaxBarValue);
172 
173  if (m_ProgressBar)
174  {
175  if (n > m_iMinRepresentativeValue)
176  m_ProgressBar.SetValue(n);
177  else
178  m_ProgressBar.SetValue(m_iMinRepresentativeValue);
179  }
180  }
181 }
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CareerProfileHUD
Definition: SCR_CareerProfileHUD.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonTextComponent
Definition: SCR_ButtonTextComponent.c:2
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
ItemPreviewWidget
Definition: ItemPreviewWidget.c:12
SCR_LoadoutPreviewComponent
Definition: SCR_LoadoutPreviewComponent.c:1
SCR_WLibProgressBarComponent
Minimalist progress bar.
Definition: SCR_WLibProgressBar.c:3