Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NewsTileComponent.c
Go to the documentation of this file.
2 {
3  [Attribute("Title")]
4  string m_sTitleName;
5 
6  [Attribute("Description")]
7  string m_sDescriptionName;
8 
9  [Attribute("Image")]
10  string m_sImageName;
11 
12  [Attribute("Author")]
13  string m_sAuthorName;
14 
15  [Attribute("Date")]
16  string m_sDateName;
17 
18  [Attribute("Footer")]
19  string m_sFooterName;
20 
21  [Attribute("Unread")]
22  string m_sUnreadImageName;
23 
24  [Attribute("Read")]
25  string m_sReadButtonName;
26 
27  Widget m_wFooter;
28  Widget m_wUnreadImage;
29  TextWidget m_wTitle;
30  TextWidget m_wAuthor;
31  TextWidget m_wDate;
32  TextWidget m_wDescription;
33  ref SCR_NewsEntry m_Entry;
34 
36 
37  ref ScriptInvoker m_OnRead = new ScriptInvoker();
38 
39  //------------------------------------------------------------------------------------------------
40  override void HandlerAttached(Widget w)
41  {
42  super.HandlerAttached(w);
43 
44  m_wUnreadImage = w.FindAnyWidget(m_sUnreadImageName);
45  m_wTitle = TextWidget.Cast(w.FindAnyWidget(m_sTitleName));
46  m_wAuthor = TextWidget.Cast(w.FindAnyWidget(m_sAuthorName));
47  m_wDate = TextWidget.Cast(w.FindAnyWidget(m_sDateName));
48  m_wDescription = TextWidget.Cast(w.FindAnyWidget(m_sDescriptionName));
49  m_wFooter = w.FindAnyWidget(m_sFooterName);
50 
51  if (!m_sReadButtonName.IsEmpty())
52  m_Read = SCR_InputButtonComponent.GetInputButtonComponent(m_sReadButtonName, w);
53 
54  if (m_Read)
55  m_Read.m_OnActivated.Insert(OnRead);
56 
57  if (!m_wFooter)
58  return;
59 
60  m_wFooter.SetOpacity(0);
61  m_wFooter.SetEnabled(false);
62 
63  SCR_ServicesStatusHelper.RefreshPing();
64  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusCheckFinished);
65 
66  UpdateConnectionButtons();
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  override void HandlerDeattached(Widget w)
71  {
72  super.HandlerDeattached(w);
73 
74  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusCheckFinished);
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override bool OnFocus(Widget w, int x, int y)
79  {
80  super.OnFocus(w, x, y);
81  if (m_wFooter)
82  {
83  m_wFooter.SetEnabled(true);
84  AnimateWidget.Opacity(m_wFooter, 1, m_fAnimationRate);
85  }
86 
87  SetRead();
88 
89  m_OnFocused.Invoke(this);
90  return false;
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  override bool OnFocusLost(Widget w, int x, int y)
95  {
96  super.OnFocusLost(w, x, y);
97  if (!m_wFooter)
98  return false;
99 
100  AnimateWidget.Opacity(m_wFooter, 0, m_fAnimationRate);
101  m_wFooter.SetEnabled(false);
102  return false;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
107  {
108  UpdateConnectionButtons();
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  protected void UpdateConnectionButtons()
113  {
114  SCR_InputButtonComponent.ForceConnectionButtonEnabled(m_Read, SCR_ServicesStatusHelper.IsBackendConnectionAvailable());
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  void SetRead()
119  {
120  if (!m_Entry || m_Entry.m_bRead)
121  return;
122 
123  m_Entry.m_bRead = true;
124  if (m_wUnreadImage)
125  AnimateWidget.Opacity(m_wUnreadImage, 0, UIConstants.FADE_RATE_DEFAULT);
126  }
127 
128  //------------------------------------------------------------------------------------------------
131  void ShowTile(SCR_NewsEntry entry)
132  {
133  m_wRoot.SetOpacity(entry != null);
134  m_wRoot.SetEnabled(entry != null);
135 
136  m_Entry = entry;
137  if (!entry)
138  return;
139 
140  if (m_wTitle)
141  m_wTitle.SetText(entry.m_Item.Title());
142 
143  if (m_wDescription)
144  m_wDescription.SetText(entry.m_Item.Excerpt());
145 
146  if (m_wAuthor)
147  m_wAuthor.SetText(entry.m_Item.Slug());
148 
149  if (m_wDate)
150  m_wDate.SetText(entry.m_Item.Date());
151 
152  string imagePreview = entry.m_Item.Path();
153 
154  if (m_wImage && !imagePreview.IsEmpty())
155  {
156  // Try to load image
157  bool loaded = m_wImage.LoadImageTexture(1, imagePreview);
158 
159  // Set image 0 - Placeholder if load image failed
160  // Set image 1 - Downloaded image
161  m_wImage.SetImage(loaded);
162 
163  // Refresh the size
164  int sx, sy;
165  m_wImage.GetImageSize(loaded, sx, sy);
166  m_wImage.SetSize(sx, sy);
167  }
168 
169  if (m_wUnreadImage)
170  m_wUnreadImage.SetOpacity(!entry.m_bRead);
171  }
172 
173  //------------------------------------------------------------------------------------------------
174  void OnRead()
175  {
176  SetRead();
177  m_OnRead.Invoke(this);
178  }
179 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_TileBaseComponent
Definition: SCR_TileBaseComponent.c:1
UIConstants
Definition: Constants.c:130
SCR_NewsTileComponent
Definition: SCR_NewsTileComponent.c:1
m_Entry
SCR_MapJournalUI m_Entry
SCR_NewsEntry
Definition: SCR_NewsSubMenu.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
m_wImage
protected ImageWidget m_wImage
Definition: SCR_BackendImageComponent.c:248
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1