8 [
Attribute(defvalue:
"4",
desc:
"If more then this amount tabs are shown then the text will be hidden and only icon will be shown")]
9 protected int m_iMaxTabsUntilImageOnly;
12 protected int m_iTabTextAndImageWidth;
15 protected int m_iTabImageOnlyWidth;
18 protected string m_sTabWidgetName;
21 protected string m_sContentHolderWidgetName;
24 protected string m_sNoAttributeNoteName;
27 protected string m_sButtonCloseButtonName;
30 protected string m_sButtonCloseAndSaveButtonName;
33 protected string m_sButtonResetWidgetName;
36 protected string m_sOutsideWindowCloseButtonName;
39 protected string m_sButtonEndGameCloseName;
42 protected string m_sButtonEndGameAcceptName;
45 protected string m_sGamepadToggleAttributeButtonName;
48 protected string m_sTitleHeaderWidgetName;
50 [
Attribute(
"#AR-AttributesDialog_TitlePage_Photo_Text")]
53 [
Attribute(
"#AR-AttributesDialog_TitlePage_Admin_Text")]
56 [
Attribute(
"#AR-AttributesDialog_TitlePage_FactionOnly_Text")]
65 [
Attribute(
"#AR-AttributesDialog_TitlePage_Entity_Text")]
68 [
Attribute(
"#AR-AttributesDialog_TitlePage_Editing_Text")]
71 [
Attribute(
"2",
"If more types then given type, m_sMultiEntitiesTitle will be used as text")]
72 protected int m_iEntityTypesUntilMulti;
74 [
Attribute(
desc:
"A List of translated names for entity types which is also used to display the order of entity types (Eg if multiple which one to show first)")]
75 protected ref array<ref SCR_EntityAttributeTitleType> m_aEntityTypeNames;
77 [
Attribute(
"{E2CBA6F76AAA42AF}UI/Fonts/Roboto/Roboto_Regular.fnt")]
78 protected string m_sFontForHeaderEntityAmount;
91 protected string m_sSfxClickedOutsideWindow_Comfirm;
94 protected string m_sSfxClickedOutsideWindow_Cancel;
97 protected string m_sSfxOnOpenDialog;
100 protected string m_sSfxOnCloseDialog;
102 protected bool m_bIsEndGame;
105 protected bool m_bIsGlobalAttribute;
110 protected Widget m_ContentHolder;
111 protected Widget m_ButtonCloseAndSaveButton;
112 protected Widget m_ButtonCloseButton;
118 protected SCR_AttributesManagerEditorComponent m_AttributesManager;
120 protected int m_iCurrentTab = -1;
121 protected ref array<ResourceName> m_CategoryConfigs;
122 protected ResourceName m_currentCategory;
123 protected bool m_bTabImageOnly;
126 protected bool m_bHasConflictingAttributes;
128 protected void ButtonClose()
133 menu.RemoveAutoClose();
137 if (m_AttributesManager)
138 m_AttributesManager.ConfirmEditing();
141 protected void OnCancelEndGame()
146 menu.RemoveAutoClose();
150 if (m_AttributesManager)
151 m_AttributesManager.CancelEditing();
154 protected void EndGamePopupComfirm()
156 if (m_AttributesManager)
157 m_AttributesManager.ConfirmEditing();
160 protected void OnAcceptEndGame()
166 dlg.m_OnConfirm.Insert(EndGamePopupComfirm);
170 protected void ButtonReset()
172 if (m_AttributesManager)
173 m_AttributesManager.Reset(
true);
176 protected void OnReset()
179 m_ResetButton.SetEnabled(
false);
181 if (m_ButtonCloseAndSaveButton && m_ButtonCloseButton)
183 m_ButtonCloseButton.SetVisible(
true);
184 m_ButtonCloseAndSaveButton.SetVisible(
false);
185 m_sSfxOnCloseDialog = m_sSfxClickedOutsideWindow_Cancel;
190 protected void ButtonAttributeEnableToggle()
192 if (m_GamepadFocusAttribute)
193 m_GamepadFocusAttribute.ToggleEnableAttributeTickbox();
198 void OnAttributeChanged()
201 m_ResetButton.SetEnabled(
true);
203 if (m_ButtonCloseAndSaveButton && m_ButtonCloseButton)
205 m_ButtonCloseButton.SetVisible(
false);
206 m_ButtonCloseAndSaveButton.SetVisible(
true);
207 m_sSfxOnCloseDialog = m_sSfxClickedOutsideWindow_Comfirm;
211 protected void RefreshAttributes()
213 SetHasConflictingAttribute(
false);
218 WorkspaceWidget workspace =
GetGame().GetWorkspace();
219 if (!workspace)
return;
221 if (!m_ContentHolder)
return;
223 if (!m_AttributesManager)
return;
226 while (m_ContentHolder.GetChildren())
228 delete m_ContentHolder.GetChildren();
231 if (m_currentCategory !=
string.Empty)
234 array<SCR_BaseEditorAttribute> attributes =
new array<SCR_BaseEditorAttribute>;
235 m_AttributesManager.GetEditedAttributes(attributes);
239 if (attribute.GetCategoryConfig() != m_currentCategory)
continue;
241 ResourceName
layout = attribute.GetLayout();
242 if (
layout.IsEmpty())
continue;
244 Widget attributeWidget = workspace.CreateWidgets(
layout, m_ContentHolder);
245 if (!attributeWidget)
continue;
250 attributesUI.Init(attributeWidget, attribute);
251 attributesUI.SetFromVar(attribute.GetVariable());
254 if (attribute.GetHasConflictingValues())
255 attributesUI.GetOnAttributeUIFocusChanged().Insert(SetGamepadAttributeFocus);
257 attributesUI.GetOnAttributeChanged().Insert(OnAttributeChanged);
261 if (!m_bHasConflictingAttributes && attribute.GetHasConflictingValues())
262 SetHasConflictingAttribute(
true);
270 if (m_bTabImageOnly && m_iCurrentTab > -1)
272 m_TabViewComponent.ShowTabText(m_iCurrentTab,
false, m_iTabImageOnlyWidth);
273 m_TabViewComponent.ShowTabText(tabIndex,
true, m_iTabTextAndImageWidth);
276 if (m_CategoryConfigs.Count() == 0)
279 if (m_iCurrentTab != tabIndex)
281 m_iCurrentTab = tabIndex;
283 m_currentCategory = m_CategoryConfigs[tabIndex];
286 if (m_bIsGlobalAttribute)
287 m_AttributesManager.SetCurrentCategory(m_currentCategory);
291 ResourceName GetCurrentCategory()
293 return m_currentCategory;
295 void SetWidgetVisible(
bool visible)
300 if (visible) RefreshAttributes();
302 widget.SetVisible(visible);
303 widget.SetEnabled(visible);
309 m_GamepadFocusAttribute = attributeUI;
310 m_GamepadToggleEnableButton.SetEnabled(m_GamepadFocusAttribute !=
null && m_GamepadFocusAttribute.GetTickboxEnabled());
313 protected void SetHasConflictingAttribute(
bool hasConflicting)
315 m_bHasConflictingAttributes = hasConflicting;
317 if (m_GamepadToggleEnableButton)
318 m_GamepadToggleEnableButton.GetRootWidget().SetVisible(m_bHasConflictingAttributes && !
GetGame().
GetInputManager().IsUsingMouseAndKeyboard());
321 void InitWidget(array<ResourceName> categoryConfigs, array<ref SCR_EditorAttributeCategory> categories)
325 m_AttributesManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent));
326 if (!m_AttributesManager)
return;
331 WorkspaceWidget workspace =
GetGame().GetWorkspace();
332 if (!workspace)
return;
334 Widget tabWidget = widget.FindAnyWidget(m_sTabWidgetName);
335 if (!tabWidget)
return;
338 if (!m_TabViewComponent)
return;
339 m_TabViewComponent.GetOnChanged().Insert(OnCurrentTabChanged);
341 m_ContentHolder = widget.FindAnyWidget(m_sContentHolderWidgetName);
342 if (!m_ContentHolder)
return;
345 if (onReset) onReset.Insert(ButtonReset);
347 Widget resetButton = widget.FindAnyWidget(m_sButtonResetWidgetName);
351 m_ResetButton.SetEnabled(
false);
354 ScriptInvoker onToggle =
ButtonActionComponent.GetOnAction(widget, m_sGamepadToggleAttributeButtonName);
355 if (onToggle) onToggle.Insert(ButtonAttributeEnableToggle);
357 Widget gamePadToggle = widget.FindAnyWidget(m_sGamepadToggleAttributeButtonName);
362 if (m_GamepadToggleEnableButton)
363 m_GamepadToggleEnableButton.SetEnabled(
false);
367 SetHasConflictingAttribute(m_bHasConflictingAttributes);
369 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
371 m_CategoryConfigs = categoryConfigs;
374 ResourceName currentCategory = m_AttributesManager.GetCurrentCategory();
376 if (categoryConfigs.IsEmpty())
378 Widget noAttributes = widget.FindAnyWidget(m_sNoAttributeNoteName);
380 noAttributes.SetVisible(
true);
383 bool globalAttributesSet =
false;
386 foreach (
int i, ResourceName categoryConfig: categoryConfigs)
388 m_TabViewComponent.AddTab(
string.Empty, categories[i].
GetInfo().
GetName(),
true, categories[i].
GetInfo().GetIconPath());
390 if (!globalAttributesSet)
392 globalAttributesSet =
true;
393 m_bIsGlobalAttribute = categories[i].GetIsGlobalAttributeCategory();
397 array<Managed> editedItems =
new array<Managed>;
398 int count = m_AttributesManager.GetEditedItems(editedItems);
400 InputManager inputManager =
GetGame().GetInputManager();
403 m_sSfxOnCloseDialog = m_sSfxClickedOutsideWindow_Cancel;
410 Widget closeButton = widget.FindAnyWidget(m_sButtonEndGameCloseName);
411 Widget acceptButton = widget.FindAnyWidget(m_sButtonEndGameAcceptName);
415 closeButton.SetVisible(
true);
419 onClose.Insert(OnCancelEndGame);
423 acceptButton.SetVisible(
true);
427 onAccept.Insert(OnAcceptEndGame);
430 ScriptInvoker onWindowClose =
ButtonActionComponent.GetOnAction(widget, m_sOutsideWindowCloseButtonName);
432 onWindowClose.Insert(OnCancelEndGame);
435 m_ResetButton.SetVisible(
false);
437 inputManager.AddActionListener(
"EditorAttributeClose", EActionTrigger.DOWN, OnCancelEndGame);
441 m_ButtonCloseButton = widget.FindAnyWidget(m_sButtonCloseButtonName);
442 m_ButtonCloseAndSaveButton = widget.FindAnyWidget(m_sButtonCloseAndSaveButtonName);
444 if (m_ButtonCloseButton)
446 m_ButtonCloseButton.SetVisible(
true);
450 onClose.Insert(ButtonClose);
452 if (m_ButtonCloseAndSaveButton)
456 onClose.Insert(ButtonClose);
458 m_ButtonCloseAndSaveButton.SetVisible(
false);
461 ScriptInvoker onWindowClose =
ButtonActionComponent.GetOnAction(widget, m_sOutsideWindowCloseButtonName);
463 onWindowClose.Insert(ButtonClose);
465 inputManager.AddActionListener(
"EditorAttributeClose", EActionTrigger.DOWN, ButtonClose);
469 m_TabViewComponent.Init();
472 if (m_TabViewComponent.GetTabCount() > m_iMaxTabsUntilImageOnly)
474 m_bTabImageOnly =
true;
475 m_TabViewComponent.ShowAllTabsText(
false, m_iTabImageOnlyWidth);
479 if (m_bIsGlobalAttribute)
481 int currentIndex = Math.Max(m_CategoryConfigs.Find(currentCategory), 0);
482 m_TabViewComponent.ShowTab(currentIndex,
true,
false);
485 m_AttributesManager.GetOnResetAttributes().Insert(OnReset);
487 SetHeaderText(RichTextWidget.Cast(widget.FindAnyWidget(m_sTitleHeaderWidgetName)));
493 gameMode.GetOnGameModeEnd().Insert(OnCancelEndGame);
498 protected void SetHeaderText(RichTextWidget header)
504 array<Managed> editedItems =
new array<Managed>;
505 int count = m_AttributesManager.GetEditedItems(editedItems);
510 header.SetTextFormat(
"%1", m_sEditingTitlePart);
513 array<EEditableEntityType> types =
new array<EEditableEntityType>;
514 array<int> typeCounts =
new array<int>;
518 bool showTypes =
true;
519 bool sameNames =
true;
520 bool oneGroup =
true;
521 string name =
string.Empty;
525 foreach (Managed item: editedItems)
532 if (SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(editableEntity.GetOwner()) > 0)
538 if (name ==
string.Empty)
541 name = editableEntity.GetDisplayName();
545 else if ((name != editableEntity.GetDisplayName() && editableEntity.GetEntityType() !=
EEditableEntityType.TASK) || (editableEntity.GetEntityType() ==
EEditableEntityType.TASK && name != m_sTaskTitle))
563 if (SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(editableEntity.GetOwner()) > 0)
570 if (groupEntity ==
null)
571 groupEntity = editableEntity.GetParentEntity();
572 else if (groupEntity !=
null && groupEntity != editableEntity.GetParentEntity())
578 if (groupEntity !=
null && groupEntity != editableEntity)
581 groupEntity = editableEntity;
588 int index = types.Find(entityType);
592 types.Insert(entityType);
593 typeCounts.Insert(1);
595 if (types.Count() > m_iEntityTypesUntilMulti)
613 SetHeaderPart(header, name, count,
false);
620 SetHeaderPart(header, groupEntity.GetDisplayName(), 0 ,
false);
621 SetHeaderPart(header, TranslateEntityType(types[characterIndex]), typeCounts[characterIndex],
true);
626 bool firstShown =
false;
627 int indexHighestPriority;
628 int typeNameCount = m_aEntityTypeNames.Count();
630 while (types.Count() > 0)
632 int typesCount = types.Count();
633 int currentPriority =
int.MAX;
635 for(
int i = 0; i < typesCount; i++)
640 currentPriority = -1;
641 indexHighestPriority = i;
646 for(
int t = 0; t < typeNameCount; t++)
648 if (m_aEntityTypeNames[t].
GetType() == types[i])
650 if (t < currentPriority)
653 indexHighestPriority = i;
661 SetHeaderPart(header, TranslateEntityType(types[indexHighestPriority]), typeCounts[indexHighestPriority], firstShown);
662 types.Remove(indexHighestPriority);
663 typeCounts.Remove(indexHighestPriority);
670 SetHeaderPart(header, m_sMultiEntitiesTitle, count,
false);
689 header.SetText(m_sAdminModeTitle);
701 header.SetText(m_sFactionOnlyTitle);
707 header.SetText(m_sEndGameTitle);
726 header.SetText(m_sPhotoModeTitle);
732 SCR_EditablePlayerDelegateComponent playerDelegate = SCR_EditablePlayerDelegateComponent.Cast(editedItems[0]);
735 header.SetTextFormat(
"%1", m_sEditingTitlePart);
736 SetHeaderPart(header,
GetGame().GetPlayerManager().GetPlayerName(playerDelegate.GetPlayerID()), 0,
false);
744 header.SetTextFormat(
"%1", m_sEditingTitlePart);
750 int playerID = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(editableEntity.GetOwner());
753 SetHeaderPart(header,
GetGame().GetPlayerManager().GetPlayerName(playerID), 0,
false);
760 SetHeaderPart(header, m_sTaskTitle, 1,
false);
765 SetHeaderPart(header, editableEntity.GetDisplayName(), 0,
false);
768 SetHeaderPart(header, editableEntity.GetDisplayName(), 1,
false);
773 protected void SetHeaderPart(RichTextWidget textWidget,
string name,
int count,
bool showSeperator)
776 textWidget.SetTextFormat(
"%1 -", textWidget.GetText());
778 textWidget.SetTextFormat(
"%1 %2", textWidget.GetText(), name);
781 textWidget.SetTextFormat(
"%2 <font name=\"%3\"><color rgba=\"226,168,79,255\">#AR-ValueUnit_Short_Times</color></font>", count.ToString(), textWidget.GetText(), m_sFontForHeaderEntityAmount);
788 return "#AR-AttributesDialog_TitlePage_Player_Text";
794 if (titleType.GetType() ==
type)
795 return titleType.GetTypeName();
799 Print(
string.Format(
"Couldn't find type: %1 in m_aEntityTypeNames",
typename.EnumToString(
EEditableEntityType,
type)), LogLevel.ERROR);
803 protected void OnInputDeviceIsGamepad(
bool isGamepad)
806 SetHasConflictingAttribute(m_bHasConflictingAttributes);
809 override void HandlerDeattached(Widget w)
811 if (m_AttributesManager)
813 m_AttributesManager.GetOnResetAttributes().Remove(OnReset);
816 if (m_TabViewComponent)
817 m_TabViewComponent.GetOnChanged().Remove(OnCurrentTabChanged);
820 InputManager inputManager =
GetGame().GetInputManager();
824 inputManager.RemoveActionListener(
"EditorAttributeClose", EActionTrigger.DOWN, OnCancelEndGame);
826 inputManager.RemoveActionListener(
"EditorAttributeClose", EActionTrigger.DOWN, ButtonClose);
833 gameMode.GetOnGameModeEnd().Remove(OnCancelEndGame);
858 return m_UiInfo.GetName();