4 protected ref Color m_cSelectedColor;
7 protected ref Color m_cDefaultColor;
9 protected const string STR_DEFAULT_NAME =
"Preset ";
12 protected SCR_WorkshopAddonPreset m_Preset;
14 protected bool m_bSelected =
false;
17 protected SCR_ModularButtonComponent m_ButtonComponent;
23 protected ref ScriptInvoker<SCR_AddonLinePresetComponent, string> Event_OnNameChanged;
24 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnNameEditStart;
25 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnNameEditLeave;
26 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnFocus;
27 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnFocusLost;
28 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnLoad;
29 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnOverride;
30 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnDelete;
31 protected ref ScriptInvoker<SCR_AddonLinePresetComponent> Event_OnButtonClick;
34 protected void InvokeEventOnButtonClick()
36 if (Event_OnButtonClick)
37 Event_OnButtonClick.Invoke(
this);
41 ScriptInvoker GetEventOnButtonClick()
43 if (!Event_OnButtonClick)
44 Event_OnButtonClick =
new ScriptInvoker();
46 return Event_OnButtonClick;
50 protected void InvokeEventOnNameChanged(
string arg0)
52 if (Event_OnNameChanged)
53 Event_OnNameChanged.Invoke(
this, arg0);
57 ScriptInvoker GetEventOnNameChanged()
59 if (!Event_OnNameChanged)
60 Event_OnNameChanged =
new ScriptInvoker();
62 return Event_OnNameChanged;
66 protected void InvokeEventOnNameEditStart()
68 if (Event_OnNameEditStart)
69 Event_OnNameEditStart.Invoke(
this);
71 InvokeEventOnButtonClick();
75 ScriptInvoker GetEventOnNameEditStart()
77 if (!Event_OnNameEditStart)
78 Event_OnNameEditStart =
new ScriptInvoker();
80 return Event_OnNameEditStart;
84 protected void InvokeEventOnNameEditLeave()
86 if (Event_OnNameEditLeave)
87 Event_OnNameEditLeave.Invoke(
this);
91 ScriptInvoker GetEventOnNameEditLeave()
93 if (!Event_OnNameEditLeave)
94 Event_OnNameEditLeave =
new ScriptInvoker();
96 return Event_OnNameEditLeave;
100 protected void InvokeEventOnFocus()
103 Event_OnFocus.Invoke(
this);
107 ScriptInvoker GetEventOnFocus()
110 Event_OnFocus =
new ScriptInvoker();
112 return Event_OnFocus;
116 protected void InvokeEventOnFocusLost()
118 if (Event_OnFocusLost)
119 Event_OnFocusLost.Invoke(
this);
123 ScriptInvoker GetEventOnFocusLost()
125 if (!Event_OnFocusLost)
126 Event_OnFocusLost =
new ScriptInvoker();
128 return Event_OnFocusLost;
132 protected void InvokeEventOnLoad()
135 Event_OnLoad.Invoke(
this);
137 InvokeEventOnButtonClick();
141 ScriptInvoker GetEventOnLoad()
144 Event_OnLoad =
new ScriptInvoker();
150 protected void InvokeEventOnOverride()
152 if (Event_OnOverride)
153 Event_OnOverride.Invoke(
this);
155 InvokeEventOnButtonClick();
159 ScriptInvoker GetEventOnOverride()
161 if (!Event_OnOverride)
162 Event_OnOverride =
new ScriptInvoker();
164 return Event_OnOverride;
168 protected void InvokeEventOnDelete()
171 Event_OnDelete.Invoke(
this);
173 InvokeEventOnButtonClick();
177 ScriptInvoker GetEventOnDelete()
180 Event_OnDelete =
new ScriptInvoker();
182 return Event_OnDelete;
190 override void HandlerAttached(Widget w)
192 super.HandlerAttached(w);
196 ShowEditWidget(
false);
199 m_ButtonComponent = SCR_ModularButtonComponent.FindComponent(w);
202 m_Widgets.m_EditNameButtonComponent.m_OnClicked.Insert(StartEditName);
203 m_Widgets.m_LoadButtonComponent.m_OnClicked.Insert(InvokeEventOnLoad);
204 m_Widgets.m_OverrideButtonComponent.m_OnClicked.Insert(InvokeEventOnOverride);
205 m_Widgets.m_DeleteButtonComponent.m_OnClicked.Insert(InvokeEventOnDelete);
211 override void HandlerDeattached(Widget w)
213 super.HandlerDeattached(w);
219 override bool OnDoubleClick(Widget w,
int x,
int y,
int button)
221 super.OnDoubleClick(w, x, y, button);
230 override bool OnFocus(Widget w,
int x,
int y)
232 super.OnFocus(w, x, y);
234 InvokeEventOnFocus();
239 override bool OnFocusLost(Widget w,
int x,
int y)
241 super.OnFocusLost(w, x, y);
242 InvokeEventOnFocusLost();
249 protected void OnDialogClose(
DialogUI dialog)
264 #ifdef DEBUG_WORKSHOP
265 Print(
"Missing m_NameEdit!");
273 if (m_ButtonComponent)
274 m_ButtonComponent.SetIsFocusOnMouseEnter(
false);
276 ShowEditWidget(
true);
277 GetGame().GetWorkspace().SetFocusedWidget(
m_Widgets.m_EditNameComponent.GetEditBoxWidget());
280 m_Widgets.m_EditNameComponent.ActivateWriteMode();
284 GetGame().GetInputManager().AddActionListener(
UIConstants.MENU_ACTION_BACK, EActionTrigger.PRESSED, OnEditNameCancel);
286 m_Widgets.m_EditNameComponent.m_OnConfirm.Insert(OnEditNameConfirm);
287 m_Widgets.m_EditNameComponent.m_OnFocusChangedEditBox.Insert(OnEditNameCancel);
289 InvokeEventOnNameEditStart();
293 protected void ShowEditWidget(
bool edit)
305 protected void RemoveEditActions()
307 m_Widgets.m_EditNameComponent.m_OnConfirm.Remove(OnEditNameConfirm);
308 m_Widgets.m_EditNameComponent.m_OnFocusChangedEditBox.Remove(OnEditNameCancel);
310 m_Widgets.m_EditNameComponent.ClearInteractionState();
314 protected void OnEditNameConfirm()
316 EditNameFinishedStateReset();
318 InvokeEventOnNameChanged(
m_Widgets.m_EditNameComponent.GetValue());
326 protected void OnEditNameCancel()
336 EditNameFinishedStateReset();
338 ShowEditWidget(
false);
341 InvokeEventOnNameEditLeave();
345 protected void EditNameFinishedStateReset()
347 GetGame().GetInputManager().RemoveActionListener(
UIConstants.MENU_ACTION_BACK, EActionTrigger.PRESSED, OnEditNameCancel);
350 if (m_ButtonComponent)
351 m_ButtonComponent.SetIsFocusOnMouseEnter(
true);
355 protected void ShowButtons(
bool show)
358 m_Widgets.m_OverrideButton.SetVisible(show);
361 m_Widgets.m_EditNameButton.SetVisible(show);
364 m_Widgets.m_DeleteButton.SetVisible(show);
369 protected string DefaultName()
371 int count =
SCR_AddonManager.GetInstance().GetPresetStorage().GetPresets().Count();
372 string name = STR_DEFAULT_NAME + count;
377 while (name || fallback > 0)
386 name = STR_DEFAULT_NAME + count;
400 SCR_WorkshopAddonPreset GetPreset()
406 void SetPreset(SCR_WorkshopAddonPreset preset)
414 ShowModCount(
m_Preset.GetAddonCount());
418 void ShowWarning(
bool show)
420 m_Widgets.m_SizeWarning.SetVisible(show);
424 void ShowModCount(
int count)
426 m_Widgets.m_TxtAddonsCount.SetText(count.ToString());
430 void ShowDefaultName()
432 m_Widgets.m_NameText.SetText(DefaultName());
442 void SetSelected(
bool selected)
444 if (m_ButtonComponent)
445 m_ButtonComponent.SetToggled(selected);
453 m_Widgets.m_NameText.SetColor(m_cSelectedColor);
455 m_Widgets.m_NameText.SetColor(m_cDefaultColor);