public static void ApplyText(UICheckboxDropDown dd, string text) { UIButton uibutton = (UIButton)dd.triggerButton; var padding = uibutton.textPadding; padding.left = 5; padding.right = 21; uibutton.text = text; // must set text to mearure text once and only once. using (UIFontRenderer uifontRenderer = ObtainTextRenderer(uibutton)) { float p2uRatio = uibutton.GetUIView().PixelsToUnits(); var widths = uifontRenderer.GetCharacterWidths(text); float x = widths.Sum() / p2uRatio; //Log.Debug($"{uifontRenderer}.GetCharacterWidths(\"{text}\")->{widths.ToSTR()}"); //if (x > uibutton.width - 42) // uibutton.textHorizontalAlignment = UIHorizontalAlignment.Left; //else // uibutton.textHorizontalAlignment = UIHorizontalAlignment.Center; if (x > uibutton.width - uibutton.textPadding.horizontal) { for (int n = 4; n < text.Length; ++n) { float x2 = widths.Take(n).Sum() / p2uRatio + 15; // 15 = width of ... if (x2 > uibutton.width - 21) { text = text.Substring(0, n - 1) + "..."; break; } } } } uibutton.text = text; }
public static void Populate(UICheckboxDropDown dropdown, long flags, Type enumType) { try { var values = EnumBitMaskExtensions.GetPow2Values(enumType); foreach (IConvertible flag in values) { bool hasFlag = (flags & flag.ToInt64()) != 0; var itemInfo = enumType.GetEnumMemberInfo(flag); bool hide = itemInfo.HasAttribute <HideAttribute>(); hide &= ModSettings.HideIrrelavant; hide &= !hasFlag; if (hide) { continue; // hide } dropdown.AddItem( item: Enum.GetName(enumType, flag), isChecked: hasFlag, userData: flag); } } catch (Exception ex) { ex.Log(); } }
internal static void Populate(UICheckboxDropDown dropdown, FlagDataT[] flagDatas) { foreach (FlagDataT flagData in flagDatas) { Populate(dropdown, flagData.GetValueLong(), flagData.EnumType); } }
static void HandleMouseDown(UICheckboxDropDown c, UIMouseEventParameter p) { if (p.buttons == UIMouseButton.Right) { c.ClosePopup(); p.Use(); } }
protected override void OnAfterDropdownClose(UICheckboxDropDown checkboxdropdown) { try { SetValue(GetCheckedFlags()); UpdateText(); } catch (Exception ex) { ex.Log(); } }
public static UICheckboxDropDown CreateCheckboxDropDown(UIComponent parent) { UICheckboxDropDown dropDown = parent.AddUIComponent <UICheckboxDropDown>(); dropDown.atlas = GetAtlas("Ingame"); dropDown.size = new Vector2(120f, 30f); dropDown.listBackground = "GenericPanelLight"; dropDown.itemHeight = 30; dropDown.itemHover = "ListItemHover"; dropDown.itemHighlight = "ListItemHighlight"; dropDown.normalBgSprite = "ButtonMenu"; dropDown.disabledBgSprite = "ButtonMenuDisabled"; dropDown.hoveredBgSprite = "ButtonMenuHovered"; dropDown.focusedBgSprite = "ButtonMenu"; dropDown.listWidth = 120; dropDown.listHeight = 350; dropDown.foregroundSpriteMode = UIForegroundSpriteMode.Stretch; dropDown.popupColor = new Color32(45, 52, 61, 255); dropDown.popupTextColor = new Color32(170, 170, 170, 255); dropDown.zOrder = 1; dropDown.textScale = 0.8f; dropDown.verticalAlignment = UIVerticalAlignment.Middle; dropDown.horizontalAlignment = UIHorizontalAlignment.Left; dropDown.textFieldPadding = new RectOffset(8, 0, 8, 0); dropDown.itemPadding = new RectOffset(14, 0, 8, 0); dropDown.uncheckedSprite = "check-unchecked"; dropDown.checkedSprite = "check-checked"; UIButton button = dropDown.AddUIComponent <UIButton>(); dropDown.triggerButton = button; button.atlas = GetAtlas("Ingame"); button.text = ""; button.size = dropDown.size; button.relativePosition = new Vector3(0f, 0f); button.textVerticalAlignment = UIVerticalAlignment.Middle; button.textHorizontalAlignment = UIHorizontalAlignment.Left; button.normalFgSprite = "IconDownArrow"; button.hoveredFgSprite = "IconDownArrowHovered"; button.pressedFgSprite = "IconDownArrowPressed"; button.focusedFgSprite = "IconDownArrowFocused"; button.disabledFgSprite = "IconDownArrowDisabled"; button.foregroundSpriteMode = UIForegroundSpriteMode.Fill; button.horizontalAlignment = UIHorizontalAlignment.Right; button.verticalAlignment = UIVerticalAlignment.Middle; button.zOrder = 0; button.textScale = 0.8f; dropDown.eventSizeChanged += new PropertyChangedEventHandler <Vector2>((c, t) => { button.size = t; dropDown.listWidth = (int)t.x; }); return(dropDown); }
public override void Awake() { base.Awake(); size = new Vector2(370, 54); atlas = TextureUtil.Ingame; //backgroundSprite = "GenericPanelWhite"; //color = Color.white; Label = AddUIComponent <UILabel>(); Label.relativePosition = new Vector2(0, 6); DropDown = AddUIComponent <UICheckboxDropDown>(); EditorMultiSelectDropDown.Init(DropDown); DropDown.relativePosition = new Vector2(width - DropDown.width, 28); DropDown.eventAfterDropdownClose += DropdownClose; }
public static int GetHoverIndex(this UICheckboxDropDown dd) { var popup = fPopop.GetValue(dd) as UIScrollablePanel; //Log.Debug("GetHoverIndex() popup=" + Popup); if (popup == null || !popup.isVisible) { return(-1); } foreach (var c in popup.GetComponentsInChildren <UICheckBox>()) { if (c.containsMouse) { return((int)c.objectUserData); } } return(-1); }
public static void Populate(UICheckboxDropDown dropdown, int flags, Type enumType) { var values = EnumBitMaskExtensions.GetPow2ValuesI32(enumType); foreach (int flag in values) { bool hasFlag = (flags & flag) != 0; // TODO hide lane flags based on set/get. var itemInfo = enumType.GetEnumMember(flag); bool hide = itemInfo.HasAttribute <HideAttribute>(); hide &= ModSettings.HideIrrelavant; hide &= !hasFlag; if (hide) { continue; // hide } dropdown.AddItem( item: Enum.GetName(enumType, flag), isChecked: hasFlag, userData: flag); } }
public override void Awake() { try { base.Awake(); size = new Vector2(370, 54); atlas = TextureUtil.Ingame; color = new Color32(87, 97, 100, 255); Label = AddUIComponent <UILabel>(); Label.relativePosition = new Vector2(0, 6); DropDown = AddUIComponent <UICheckboxDropDown>(); EditorMultiSelectDropDown.Init(DropDown); DropDown.relativePosition = new Vector2(width - DropDown.width, 28); DropDown.eventAfterDropdownClose += OnAfterDropdownClose; DropDown.eventCheckedChanged += DropDown_eventCheckedChanged; NetInfoExtionsion.Net.OnCustomFlagRenamed += Refresh; isInteractive = true; } catch (Exception ex) { ex.Log(); } }
internal static void Init(UICheckboxDropDown dd) { try { LogCalled(); dd.size = new Vector2(370, 22); dd.verticalAlignment = UIVerticalAlignment.Middle; dd.horizontalAlignment = UIHorizontalAlignment.Center; dd.builtinKeyNavigation = true; dd.atlas = TextureUtil.InMapEditor; dd.normalBgSprite = "TextFieldPanel"; dd.uncheckedSprite = "check-unchecked"; dd.checkedSprite = "check-checked"; dd.listBackground = "GenericPanelWhite"; dd.listWidth = 188; dd.listHeight = 900; dd.clampListToScreen = true; dd.listPosition = UICheckboxDropDown.PopupListPosition.Automatic; dd.itemHeight = 25; dd.itemHover = "ListItemHover"; dd.itemHighlight = "ListItemHighlight"; dd.popupColor = Color.black; dd.popupTextColor = Color.white; dd.triggerButton = dd.AddUIComponent <UIButton>(); UIButton triggerBtn = dd.triggerButton as UIButton; triggerBtn.size = dd.size; triggerBtn.textVerticalAlignment = UIVerticalAlignment.Middle; triggerBtn.textHorizontalAlignment = UIHorizontalAlignment.Left; triggerBtn.atlas = TextureUtil.Ingame; triggerBtn.normalFgSprite = "IconDownArrow"; triggerBtn.hoveredFgSprite = "IconDownArrowHovered"; triggerBtn.pressedFgSprite = "IconDownArrowPressed"; triggerBtn.normalBgSprite = "TextFieldPanel"; triggerBtn.foregroundSpriteMode = UIForegroundSpriteMode.Scale; triggerBtn.horizontalAlignment = UIHorizontalAlignment.Right; triggerBtn.verticalAlignment = UIVerticalAlignment.Middle; triggerBtn.relativePosition = new Vector3(0, 0); // Scrollbar dd.listScrollbar = dd.AddUIComponent <UIScrollbar>(); dd.listScrollbar.width = 12f; dd.listScrollbar.height = dd.listHeight; dd.listScrollbar.orientation = UIOrientation.Vertical; dd.listScrollbar.pivot = UIPivotPoint.TopRight; dd.listScrollbar.thumbPadding = new RectOffset(0, 0, 5, 5); dd.listScrollbar.minValue = 0; dd.listScrollbar.value = 0; dd.listScrollbar.incrementAmount = dd.listHeight / 10; dd.listScrollbar.AlignTo(dd, UIAlignAnchor.TopRight); dd.listScrollbar.autoHide = true; // false ? dd.listScrollbar.isVisible = false; UISlicedSprite tracSprite = dd.listScrollbar.AddUIComponent <UISlicedSprite>(); tracSprite.relativePosition = Vector2.zero; tracSprite.autoSize = true; tracSprite.size = tracSprite.parent.size; tracSprite.fillDirection = UIFillDirection.Vertical; tracSprite.spriteName = "ScrollbarTrack"; dd.listScrollbar.trackObject = tracSprite; UISlicedSprite thumbSprite = tracSprite.AddUIComponent <UISlicedSprite>(); thumbSprite.relativePosition = Vector2.zero; thumbSprite.fillDirection = UIFillDirection.Vertical; thumbSprite.autoSize = true; thumbSprite.width = thumbSprite.parent.width - 8; thumbSprite.spriteName = "ScrollbarThumb"; dd.listScrollbar.thumbObject = thumbSprite; dd.eventDropdownOpen += OnDropDownOpen; triggerBtn.buttonsMask |= UIMouseButton.Right; dd.eventMouseDown += (_, p) => HandleMouseDown(dd, p); } catch (Exception ex) { Log.Exception(ex); } }
static void OnDropDownOpen( UICheckboxDropDown checkboxdropdown, UIScrollablePanel popup, ref bool overridden) => popup.eventMouseDown += (_, p) => HandleMouseDown(checkboxdropdown, p);
private void DropdownClose(UICheckboxDropDown checkboxdropdown) { SetValue(GetCheckedFlags()); UpdateText(); UIButton button = DropDown.triggerButton as UIButton; }
protected abstract void OnAfterDropdownClose(UICheckboxDropDown checkboxdropdown);
/// <summary> /// Layout the GUI. /// </summary> public override void Start() { base.Start(); name = GetType().Name; backgroundSprite = "MenuPanel2"; size = new Vector2(m_componentWidth + 2 * m_componentPadding, 200); UITitle = AttachUILabelTo(this, 3, 3, height: 25); UITitle.textAlignment = UIHorizontalAlignment.Center; UITitle.textScale = 1.0f; UICloseButton = AttachUIButtonTo(this, 372, 0); UIBuildingIdLabel = AttachUILabelTo(this, 3, 28, text: $"Building Id: "); UIBuildingId = AttachUITextFieldTo(this, 3, 28, 78); UIHomeDistrict = AttachUILabelTo(this, 3, 48); UIServices = AttachUILabelTo(this, 3, 68); var buttonTemplate = GetUITabstripButtonTemplate(this); UIInputMode = AttachUITabstripTo(this, 3, 88); UIOutgoingTab = UIInputMode.AddTab("Outgoing", buttonTemplate, true); UIIncomingTab = UIInputMode.AddTab("Incoming", buttonTemplate, true); if (Settings.enableCustomVehicles) { UIVehiclesTab = UIInputMode.AddTab("Vehicles", buttonTemplate, true); } UIGlobalTab = UIInputMode.AddTab("Global", buttonTemplate, true); UIAllLocalAreasCheckBox = AttachUICheckBoxTo(this, 113, 88); UIAllLocalAreasCheckBox.label = AttachUILabelTo(UIAllLocalAreasCheckBox, -110, 0); UIAllOutsideConnectionsCheckBox = AttachUICheckBoxTo(this, 336, 88); UIAllOutsideConnectionsCheckBox.label = AttachUILabelTo(UIAllOutsideConnectionsCheckBox, -173, 0); UISupplyReserveLabel = AttachUILabelTo(this, 3, 108, text: $"Supply Reserve: "); UISupplyReserve = AttachUITextFieldTo(this, 3, 108, 112); UISupplyChainLabel = AttachUILabelTo(this, 3, 128, text: $"Supply Chain: "); UISupplyChain = AttachUITextFieldTo(this, 3, 128, 111); UIDistrictsSummary = AttachUILabelTo(this, 3, 148); UIDistrictsSummary.zOrder = 0; UIDistrictsDropDown = AttachUICheckboxDropDownTo(this, 3, 148 + 3); UIDistrictsDropDown.eventDropdownOpen += UIEventDropdownOpen; UIDistrictsDropDown.eventDropdownClose += UIEventDropdownClose; UIVehicleDefaultsCheckBox = AttachUICheckBoxTo(this, 141, 88); UIVehicleDefaultsCheckBox.label = AttachUILabelTo(UIVehicleDefaultsCheckBox, -138, 0); UIVehiclesSummary = AttachUILabelTo(this, 3, 148); UIVehiclesSummary.zOrder = 0; UIVehiclesDropDown = AttachUICheckboxDropDownTo(this, 3, 148 + 3); UIVehiclesDropDown.eventDropdownOpen += UIEventDropdownOpen; UIVehiclesDropDown.eventDropdownClose += UIEventDropdownClose; GlobalIntensityLabel = AttachUILabelTo(this, 3, 88, text: "Outside Connection Intensity:"); GlobalIntensity = AttachUITextFieldTo(this, 3, 29, 213); GlobalOutsideToOutsideMaxPercLabel = AttachUILabelTo(this, 3, 88, text: "Outside To Outside Max Perc:"); GlobalOutsideToOutsideMaxPerc = AttachUITextFieldTo(this, 3, 29, 213); m_FullscreenContainer = UIView.Find("FullScreenContainer"); m_FullscreenContainer.AttachUIComponent(gameObject); if (Camera.main != null) { m_CameraTransform = Camera.main.transform; } }