private void AddDistrictOptionsButton(DistrictWorldInfoPanel infoPanel, out UIButton button, Vector3 offset) { button = UIUtils.CreateToggleButton(infoPanel.component, offset, UIAlignAnchor.BottomLeft, (component, e) => { InstanceID instanceID = (InstanceID)infoPanel.GetType() .GetField("m_InstanceID", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(infoPanel); var district = DistrictManager.instance.m_districts.m_buffer[instanceID.District]; try { if (CustomDistrictOptionsPanelWrapper == null || instanceID.District != SelectedDistrictID) { CustomDistrictOptionsPanelWrapper = district.GenerateDistrictOptions(instanceID.District); } else { CustomDistrictOptionsPanelWrapper.isVisible = false; UIUtils.DeepDestroy(CustomDistrictOptionsPanelWrapper); } } catch (Exception ex) { DebugHelper.Log( $"Couldn't Generate District Options for {DistrictManager.instance.GetDistrictName(instanceID.District)}. {ex.Message} - {ex.StackTrace}"); } if (component.hasFocus) { component.Unfocus(); } }); }
public override void Update() { base.Update(); var instanceId = (InstanceID)AdvancedDistrictOptionsTool.instance.DistrictWorldInfoPanel.GetType() .GetField("m_InstanceID", BindingFlags.Instance | BindingFlags.NonPublic) ?.GetValue(AdvancedDistrictOptionsTool.instance.DistrictWorldInfoPanel); if (instanceId.District != AdvancedDistrictOptionsTool.instance.SelectedDistrictID) { UIUtils.DeepDestroy(this); } }
private void SetupControls() { name = "AdvancedDistrictOptionsTitleBar"; isVisible = false; canFocus = true; isInteractive = true; relativePosition = Vector3.zero; width = parent.width; height = 40f; DragHandle = AddUIComponent <UIDragHandle>(); DragHandle.height = height; DragHandle.relativePosition = Vector3.zero; DragHandle.target = parent; DragHandle.eventMouseUp += (c, e) => { AdvancedDistrictOptionsMod.Settings.PanelX = parent.relativePosition.x; AdvancedDistrictOptionsMod.Settings.PanelY = parent.relativePosition.y; AdvancedDistrictOptionsMod.Settings.Save(); }; _titleLabel = AddUIComponent <UILabel>(); _titleLabel.text = DistrictManager.instance.GetDistrictName(AdvancedDistrictOptionsTool.instance.SelectedDistrictID); _titleLabel.textScale = 0.9f; _titleLabel.isInteractive = false; _closeButton = AddUIComponent <UIButton>(); _closeButton.size = new Vector2(20, 20); _closeButton.relativePosition = new Vector3(width - _closeButton.width - 10f, 10f); _closeButton.normalBgSprite = "DeleteLineButton"; _closeButton.hoveredBgSprite = "DeleteLineButtonHovered"; _closeButton.pressedBgSprite = "DeleteLineButtonPressed"; _closeButton.eventClick += (component, param) => { if (AllowedDistrictsPanelWrapper.Instance != null) { DistrictOptionsPanel.Instance.AllowedDistrictPanelWrapper.isVisible = false; UIUtils.DeepDestroy(DistrictOptionsPanel.Instance.AllowedDistrictPanelWrapper); } AdvancedDistrictOptionsTool.instance.CustomDistrictOptionsPanelWrapper.isVisible = false; UIUtils.DeepDestroy(AdvancedDistrictOptionsTool.instance.CustomDistrictOptionsPanelWrapper); }; }
public static DistrictOptionsPanelWrapper GenerateDistrictOptions(this District district, byte id) { try { AdvancedDistrictOptionsTool.instance.SelectedDistrictID = id; if (AdvancedDistrictOptionsTool.instance.CustomDistrictOptionsPanelWrapper != null) { UIUtils.DeepDestroy(AdvancedDistrictOptionsTool.instance.CustomDistrictOptionsPanelWrapper); } return(UIView.GetAView().AddUIComponent(typeof(DistrictOptionsPanelWrapper)) as DistrictOptionsPanelWrapper); } catch (Exception e) { DebugHelper.Log($"Couldn't Generate District Options for {DistrictManager.instance.GetDistrictName(id)}. {e.Message} - {e.StackTrace}"); return(null); } }
public override void OnDestroy() { base.OnDestroy(); UIUtils.DeepDestroy(this); }
private void Setup() { name = "AdvancedDistrictOptionsPanel"; isVisible = false; canFocus = true; isInteractive = true; relativePosition = new Vector3(0f, UiTitleBar.Instance.height); width = parent.width; Inputs = new List <UIComponent>(); _labels = new List <UILabel>(); float widestWidth = 0f; var fields = typeof(DistrictOptions).GetFields(); foreach (var field in fields) { if (field.FieldType != typeof(bool)) { continue; } var label = AddUIComponent <UILabel>(); label.name = field.Name + "Label"; label.text = UIUtils.FieldNames[field.Name]; label.textScale = 0.9f; label.isInteractive = false; try { Inputs.Add(UIUtils.CreateCheckBox(this, field.Name)); _labels.Add(label); if (label.width + UIUtils.FieldWidth + UIUtils.FieldMargin * 6 > widestWidth) { widestWidth = label.width + UIUtils.FieldWidth + UIUtils.FieldMargin * 6; } } catch (Exception e) { DebugHelper.Log($"Couldn't create Checkbox for {field.Name}. {e.Message} - {e.StackTrace}"); } } Inputs.Sort((x, y) => x.name.CompareTo(y.name)); _labels.Sort((x, y) => x.name.CompareTo(y.name)); Inputs.Add(UIUtils.CreateButton(this, "Districts", (component, e) => { if (DistrictOptionsPanel.Instance.AllowedDistrictPanelWrapper != null) { UIUtils.DeepDestroy(DistrictOptionsPanel.Instance.AllowedDistrictPanelWrapper); } DistrictOptionsPanel.Instance.AllowedDistrictPanelWrapper = UIView.GetAView().AddUIComponent(typeof(AllowedDistrictsPanelWrapper)) as AllowedDistrictsPanelWrapper; })); width = DistrictOptionsPanelWrapper.Instance.width = UiTitleBar.Instance.width = UiTitleBar.Instance.DragHandle.width = widestWidth; UiTitleBar.Instance.RecenterElements(); Align(); height = Inputs.Count * (UIUtils.FieldHeight + UIUtils.FieldMargin) + UIUtils.FieldMargin * 3; DistrictOptionsPanelWrapper.Instance.height = height + UiTitleBar.Instance.height; DistrictOptionsPanelWrapper.Instance.relativePosition = new Vector3( AdvancedDistrictOptionsMod.Settings.PanelX, AdvancedDistrictOptionsMod.Settings.PanelY); isVisible = DistrictOptionsPanelWrapper.Instance.isVisible = UiTitleBar.Instance.isVisible = UiTitleBar.Instance.DragHandle.isVisible = true; }