private UIColorField CreateColorField(UIComponent parent) { if (colorFIeldTemplate == null) { UIComponent template = UITemplateManager.Get("LineTemplate"); if (template == null) { return(null); } colorFIeldTemplate = template.Find <UIColorField>("LineColor"); if (colorFIeldTemplate == null) { return(null); } } UIColorField cF = Instantiate(colorFIeldTemplate.gameObject).GetComponent <UIColorField>(); parent.AttachUIComponent(cF.gameObject); cF.name = "PainterColorField"; cF.AlignTo(parent, UIAlignAnchor.TopRight); cF.relativePosition += new Vector3(-40f, 43f, 0f); cF.size = new Vector2(26f, 26f); cF.pickerPosition = UIColorField.ColorPickerPosition.RightBelow; cF.eventSelectedColorChanged += EventSelectedColorChangedHandler; cF.eventColorPickerOpen += EventColorPickerOpenHandler; return(cF); }
public static UIColorField CreateColorField(UIComponent parent) { // Creating a ColorField from scratch is tricky. Cloning an existing one instead. if (_colorFIeldTemplate == null) { // Get the LineTemplate (PublicTransportDetailPanel) UIComponent template = UITemplateManager.Get("LineTemplate"); if (template == null) { return(null); } // Extract the ColorField _colorFIeldTemplate = template.Find <UIColorField>("LineColor"); if (_colorFIeldTemplate == null) { return(null); } } UIColorField colorField = UnityEngine.Object.Instantiate <GameObject>(_colorFIeldTemplate.gameObject).GetComponent <UIColorField>(); parent.AttachUIComponent(colorField.gameObject); colorField.size = new Vector2(40f, 26f); colorField.pickerPosition = UIColorField.ColorPickerPosition.LeftAbove; return(colorField); }
public static UIColorField CreateColorField(this UIComponent parent, string text, Vector2 position) { UIComponent template = UITemplateManager.Get("LineTemplate"); if (template == null) { return(null); } UIColorField colorFIeldTemplate = template.Find <UIColorField>("LineColor"); if (colorFIeldTemplate == null) { return(null); } UIColorField colorField = Object.Instantiate(colorFIeldTemplate.gameObject).GetComponent <UIColorField>(); parent.AttachUIComponent(colorField.gameObject); colorField.name = "PainterColorField"; colorField.AlignTo(parent, UIAlignAnchor.TopRight); colorField.position = position; colorField.size = new Vector2(40f, 40f); colorField.pickerPosition = UIColorField.ColorPickerPosition.RightBelow; return(colorField); }
private static void AddNewStopTemplate() { var go = new GameObject(); UIPanel panel = go.AddComponent <UIPanel>(); panel.size = new Vector2(36, 36); UIButton button = UITemplateManager.Get <UIButton>("StopButton"); panel.AttachUIComponent(button.gameObject); button.relativePosition = Vector2.zero; button.name = "StopButton"; UILabel uilabel = button.Find <UILabel>("PassengerCount"); panel.AttachUIComponent(uilabel.gameObject); uilabel.relativePosition = new Vector3(32, 12); uilabel.processMarkup = true; uilabel.isVisible = true; uilabel.minimumSize = new Vector2(180, 50); uilabel.verticalAlignment = UIVerticalAlignment.Middle; UIPanel connectionPanel = panel.AddUIComponent <UIPanel>(); connectionPanel.name = "ConnectionPanel"; connectionPanel.relativePosition = new Vector3(-50, 5); connectionPanel.size = new Vector3(50, 40); connectionPanel.autoLayout = true; connectionPanel.wrapLayout = true; connectionPanel.autoLayoutDirection = LayoutDirection.Vertical; connectionPanel.autoLayoutStart = LayoutStart.TopRight; UILabel distLabel = panel.AddUIComponent <UILabel>(); distLabel.name = "Distance"; distLabel.relativePosition = new Vector3(-12, 37); distLabel.textAlignment = UIHorizontalAlignment.Center; distLabel.textScale = 0.65f; distLabel.suffix = "m"; distLabel.useOutline = true; distLabel.minimumSize = new Vector2(60, 0); distLabel.outlineColor = Color.black; KlyteMonoUtils.CreateUIElement(out UITextField lineNameField, panel.transform, "StopNameField", new Vector4(uilabel.relativePosition.x, uilabel.relativePosition.y, 180, 50)); lineNameField.maxLength = 256; lineNameField.isVisible = false; lineNameField.verticalAlignment = UIVerticalAlignment.Middle; lineNameField.horizontalAlignment = UIHorizontalAlignment.Left; lineNameField.selectionSprite = "EmptySprite"; lineNameField.builtinKeyNavigation = true; lineNameField.textScale = uilabel.textScale; lineNameField.padding.top = 14; lineNameField.padding.bottom = 24; KlyteMonoUtils.InitButtonFull(lineNameField, false, "TextFieldPanel"); TLMUiTemplateUtils.GetTemplateDict()["StopButtonPanel"] = panel; }
private void CreateColorPicker() { UIColorField field = UITemplateManager.Get <UIPanel>("LineTemplate").Find <UIColorField>("LineColor"); field = Instantiate <UIColorField>(field); UIColorPicker picker = Instantiate <UIColorPicker>(field.colorPicker); picker.eventColorUpdated += OnColorUpdated; picker.color = NetworkSkinPanelController.Color.SelectedColor; picker.component.color = GUIColor; UIPanel pickerPanel = picker.component as UIPanel; pickerPanel.backgroundSprite = ""; picker.component.size = new Vector2(254f, 217f); AttachUIComponent(picker.gameObject); colorPicker = picker; }
private void AddColorSample() { if (!(UITemplateManager.Get("LineTemplate") is UIComponent template)) { return; } var colorFieldTemplate = template.Find <UIColorField>("LineColor"); ColorSample = Instantiate(colorFieldTemplate.gameObject).GetComponent <UIColorField>(); Control.AttachUIComponent(ColorSample.gameObject); ColorSample.anchor = UIAnchorStyle.None; ColorSample.size = new Vector2(26f, 28f); ColorSample.eventSelectedColorChanged += SelectedColorChanged; ColorSample.eventColorPickerOpen += ColorPickerOpen; }
public static bool EnsureColorFieldTemplate() { if (m_colorFieldTemplate == null) { UIComponent uIComponent = UITemplateManager.Get("LineTemplate"); if (uIComponent == null) { return(false); } m_colorFieldTemplate = uIComponent.Find <UIColorField>("LineColor"); if (m_colorFieldTemplate == null) { return(false); } } return(true); }
private void AddToList(ushort buildingID, ref int count) { SVMBuildingInfoItem <T> buildingInfoItem; Type implClassBuildingLine = SVMUtils.GetImplementationForGenericType(typeof(SVMBuildingInfoItem <>), typeof(T)); if (count >= mainPanel.components.Count) { var temp = UITemplateManager.Get <PublicTransportLineInfo>(kLineTemplate).gameObject; GameObject.Destroy(temp.GetComponent <PublicTransportLineInfo>()); buildingInfoItem = (SVMBuildingInfoItem <T>)temp.AddComponent(implClassBuildingLine); mainPanel.AttachUIComponent(buildingInfoItem.gameObject); } else { buildingInfoItem = (SVMBuildingInfoItem <T>)mainPanel.components[count].GetComponent(implClassBuildingLine); } buildingInfoItem.buildingId = buildingID; buildingInfoItem.RefreshData(); count++; }
public static UIColorField AddColorPicker(UIComponent component) { var colorField = Object.Instantiate <UIColorField>( UITemplateManager.Get <UIPanel>("LineTemplate") .Find <UIColorField>("LineColor") ); component.AttachUIComponent(colorField.gameObject); colorField.width = 40f; colorField.height = 25f; colorField.color = new Color32(50, 50, 50, 255); colorField.normalBgSprite = "ColorPickerOutline"; colorField.normalFgSprite = "ColorPickerColor"; colorField.enabled = true; colorField.eventColorPickerOpen += (UIColorField field, UIColorPicker picker, ref bool overriden) => { field.isInteractive = false; }; colorField.eventColorPickerClose += (UIColorField field, UIColorPicker picker, ref bool overriden) => { field.isInteractive = true; }; return(colorField); }
private VWVehicleInfoItem AddToList(string infoName, ref int count) { VWVehicleInfoItem buildingInfoItem; if (count >= mainPanel.components.Count) { var temp = UITemplateManager.Get <PublicTransportLineInfo>(kLineTemplate).gameObject; GameObject.Destroy(temp.GetComponent <PublicTransportLineInfo>()); buildingInfoItem = temp.AddComponent <VWVehicleInfoItem>(); mainPanel.AttachUIComponent(buildingInfoItem.gameObject); } else { buildingInfoItem = mainPanel.components[count].GetComponent <VWVehicleInfoItem>(); } buildingInfoItem.prefabName = infoName; buildingInfoItem.RefreshData(); count++; return(buildingInfoItem); }
private void AddToList(ushort lineID, ref int count) { TLMLineListItem <T> lineInfoItem; Type implClassBuildingLine = ImplClassChildren; if (count >= mainPanel.components.Count) { var temp = UITemplateManager.Get <PublicTransportLineInfo>(kLineTemplate).gameObject; GameObject.Destroy(temp.GetComponent <PublicTransportLineInfo>()); lineInfoItem = (TLMLineListItem <T>)temp.AddComponent(implClassBuildingLine); mainPanel.AttachUIComponent(lineInfoItem.gameObject); } else { lineInfoItem = (TLMLineListItem <T>)mainPanel.components[count].GetComponent(implClassBuildingLine); } lineInfoItem.lineID = lineID; lineInfoItem.RefreshData(true, true); count++; }
private void AddToList(ushort buildingId, bool secondary, ref int count) { TLMDepotListItem <T> lineInfoItem; Type implClass = ImplClassChildren; if (count >= mainPanel.components.Count) { var temp = UITemplateManager.Get <PublicTransportLineInfo>(kLineTemplate).gameObject; GameObject.Destroy(temp.GetComponent <PublicTransportLineInfo>()); lineInfoItem = (TLMDepotListItem <T>)temp.AddComponent(implClass); mainPanel.AttachUIComponent(lineInfoItem.gameObject); } else { lineInfoItem = mainPanel.components[count].GetComponent <TLMDepotListItem <T> >(); } lineInfoItem.buildingId = buildingId; lineInfoItem.secondary = secondary; lineInfoItem.Invalidate(); lineInfoItem.RefreshData(); count++; }
private void CreateUIElements() { _topPanel = AddUIComponent <UIPanel>(); string colorButtonTooltip = Translation.Instance.GetTranslation(TranslationID.TOOLTIP_OPENCOLORPICKER); _colorButton = UIUtils.CreateButton(_topPanel, new Vector2(22.0f, 22.0f), tooltip: colorButtonTooltip, backgroundSprite: "WhiteRect", atlas: UISprites.DefaultAtlas); _colorLabel = _topPanel.AddUIComponent <UILabel>(); string loadTooltip = Translation.Instance.GetTranslation(TranslationID.TOOLTIP_LOADFROMTHEME); _loadButton = UIUtils.CreateButton(_topPanel, new Vector2(22.0f, 22.0f), tooltip: loadTooltip, backgroundSprite: "ThemesIcon", atlas: UISprites.Atlas); string resetTooltip = Translation.Instance.GetTranslation(TranslationID.TOOLTIP_RESET); _resetButton = UIUtils.CreateButton(_topPanel, new Vector2(22.0f, 22.0f), tooltip: resetTooltip, backgroundSprite: "", foregroundSprite: "UndoIcon", atlas: UISprites.Atlas); _savedSwatches = Data.GetSavedSwatches(ColorID); if (Mod.InGame) { var field = UITemplateManager.Get <UIPanel>("LineTemplate").Find <UIColorField>("LineColor"); field = Instantiate(field); _colorPicker = Instantiate(field.colorPicker); AttachUIComponent(_colorPicker.gameObject); var hsb = _colorPicker.component.Find <UITextureSprite>("HSBField"); var hue = _colorPicker.component.Find <UISlider>("HueSlider"); hsb.relativePosition = new Vector3(55.0f, 7.0f); hue.relativePosition = new Vector3(267.0f, 7.0f); } _rgbPanel = AddUIComponent <PanelBase>(); _buttonsPanel = AddUIComponent <PanelBase>(); _closeButton = _buttonsPanel.AddUIComponent <ButtonPanel>(); _saveButton = _buttonsPanel.AddUIComponent <ButtonPanel>(); RefreshSavedSwatchesPanel(); this.CreateSpace(1.0f, 0.1f); color = UIColor; autoFitChildrenHorizontally = true; }
public static UIColorField CreateColorField(UIComponent parent) { if (m_colorFieldTemplate == null) { UIComponent uIComponent = UITemplateManager.Get("LineTemplate"); if (uIComponent == null) { return(null); } m_colorFieldTemplate = uIComponent.Find <UIColorField>("LineColor"); if (m_colorFieldTemplate == null) { return(null); } } var go = GameObject.Instantiate(m_colorFieldTemplate.gameObject, parent.transform); UIColorField component = go.GetComponent <UIColorField>(); component.pickerPosition = UIColorField.ColorPickerPosition.RightAbove; component.transform.SetParent(parent.transform); component.eventColorPickerOpen += DefaultColorPickerHandler; component.size = new Vector2(28, 28); return(component); }
public static void RefreshPlugins() { if (improvedModsPanelExists) { return; } var modsList = GameObject.Find("ModsList"); if (modsList == null) { return; } var uiView = GameObject.FindObjectOfType <UIView>(); var plugins = PluginManager.instance.GetPluginsInfo(); Dictionary <PluginManager.PluginInfo, string> pluginNames = new Dictionary <PluginManager.PluginInfo, string>(); Dictionary <PluginManager.PluginInfo, string> pluginDescriptions = new Dictionary <PluginManager.PluginInfo, string>(); Dictionary <PluginManager.PluginInfo, TimeSpan> pluginLastUpdatedTimeDelta = new Dictionary <PluginManager.PluginInfo, TimeSpan>(); Dictionary <PluginManager.PluginInfo, TimeSpan> pluginSubscribedTimeDelta = new Dictionary <PluginManager.PluginInfo, TimeSpan>(); foreach (var current in plugins) { IUserMod[] instances = _pluginInstancesCache[current]; if (instances.Length == 0) { Debug.LogErrorFormat("User assembly \"{0}\" does not implement the IUserMod interface!"); continue; } pluginNames.Add(current, instances[0].Name); pluginDescriptions.Add(current, instances[0].Description); pluginLastUpdatedTimeDelta.Add(current, GetPluginLastModifiedDelta(current)); pluginSubscribedTimeDelta.Add(current, GetPluginCreatedDelta(current)); } UIComponent uIComponent = modsList.GetComponent <UIComponent>(); UITemplateManager.ClearInstances("ModEntryTemplate"); var pluginsSorted = PluginManager.instance.GetPluginsInfo().ToArray(); if (sortMode == SortMode.Alphabetical) { Array.Sort(pluginsSorted, (a, b) => pluginNames[a].CompareTo(pluginNames[b])); } else if (sortMode == SortMode.LastUpdated) { Array.Sort(pluginsSorted, (a, b) => pluginLastUpdatedTimeDelta[a].CompareTo(pluginLastUpdatedTimeDelta[b])); } else if (sortMode == SortMode.LastSubscribed) { Array.Sort(pluginsSorted, (a, b) => pluginSubscribedTimeDelta[a].CompareTo(pluginSubscribedTimeDelta[b])); } int count = 0; foreach (var current in pluginsSorted) { if (!pluginNames.ContainsKey(current)) { continue; } PackageEntry packageEntry = UITemplateManager.Get <PackageEntry>("ModEntryTemplate"); uIComponent.AttachUIComponent(packageEntry.gameObject); packageEntry.entryName = String.Format("{0} (by {{0}})", pluginNames[current]); packageEntry.entryActive = current.isEnabled; packageEntry.pluginInfo = current; packageEntry.publishedFileId = current.publishedFileID; packageEntry.RequestDetails(); var panel = packageEntry.gameObject.GetComponent <UIPanel>(); panel.size = new Vector2(panel.size.x, 24.0f); panel.color = count % 2 == 0 ? panel.color : new Color32 ((byte)(panel.color.r * 0.60f), (byte)(panel.color.g * 0.60f), (byte)(panel.color.b * 0.60f), panel.color.a); var name = (UILabel)panel.Find("Name"); name.textScale = 0.85f; name.tooltip = pluginDescriptions[current]; name.textColor = count % 2 == 0 ? blackColor : whiteColor; name.textScaleMode = UITextScaleMode.ControlSize; name.position = new Vector3(30.0f, 2.0f, name.position.z); var view = (UIButton)panel.Find("View"); view.size = new Vector2(84.0f, 20.0f); view.textScale = 0.7f; view.text = "WORKSHOP"; view.position = new Vector3(1011.0f, -2.0f, view.position.z); var share = (UIButton)panel.Find("Share"); share.size = new Vector2(84.0f, 20.0f); share.textScale = 0.7f; share.isVisible = false; share.position = new Vector3(1103.0f, -2.0f, share.position.z); share.isVisible = true; var lastUpdated = (UILabel)panel.Find("LastUpdated"); if (lastUpdated == null) { lastUpdated = uiView.AddUIComponent(typeof(UILabel)) as UILabel; } lastUpdated.name = "LastUpdated"; lastUpdated.autoSize = false; lastUpdated.size = new Vector2(400.0f, 18.0f); lastUpdated.textAlignment = UIHorizontalAlignment.Right; lastUpdated.textColor = blackColor; lastUpdated.textScale = 0.8f; lastUpdated.text = String.Format("Last update: {0}", DateTimeUtil.TimeSpanToString(pluginLastUpdatedTimeDelta[current])); lastUpdated.AlignTo(panel, UIAlignAnchor.TopRight); lastUpdated.relativePosition = new Vector3(600.0f, 6.0f, 0.0f); var delete = (UIButton)panel.Find("Delete"); delete.size = new Vector2(24.0f, 24.0f); delete.position = new Vector3(1195.0f, delete.position.y, delete.position.z); var active = (UICheckBox)panel.Find("Active"); active.position = new Vector3(4.0f, active.position.y, active.position.z); var onOff = (UILabel)active.Find("OnOff"); onOff.enabled = false; count++; } refreshModContents = true; }
// Updated code thanks to TPB- @TODO implement! private static void CreateUI(UIComponent parent, string name) { UIColorField field = UITemplateManager.Get <UIPanel>("LineTemplate").Find <UIColorField>("LineColor"); field = UnityEngine.Object.Instantiate <UIColorField>(field); field.isVisible = false; field.name = "PropPickerColorField"; UIColorPicker picker = UnityEngine.Object.Instantiate <UIColorPicker>(field.colorPicker); picker.eventColorUpdated += ChangeSelectionColors; picker.color = Color.white; picker.component.color = Color.white; picker.name = name; UIPanel pickerPanel = picker.component as UIPanel; pickerPanel.backgroundSprite = "InfoPanelBack"; pickerPanel.isVisible = false; picker.component.size = new Vector2(254f, 226f); // ?/ parent.AttachUIComponent(picker.gameObject); pickerPanel.absolutePosition = UIToolOptionPanel.instance.m_viewOptions.absolutePosition - new Vector3(329, 147); Db.l("Prop Picker color picker instantiated"); FieldInfo f = typeof(UIToolOptionPanel).GetField("m_alignTools", BindingFlags.Instance | BindingFlags.NonPublic); UIButton AlignTools = f.GetValue(UIToolOptionPanel.instance) as UIButton; UIPanel AlignToolsPanel = UIToolOptionPanel.instance.m_alignToolsPanel; FieldInfo fa = typeof(UIToolOptionPanel).GetField("m_single", BindingFlags.Instance | BindingFlags.NonPublic); UIButton Single = fa.GetValue(UIToolOptionPanel.instance) as UIButton; FieldInfo fb = typeof(UIToolOptionPanel).GetField("m_marquee", BindingFlags.Instance | BindingFlags.NonPublic); UIButton Marquee = fb.GetValue(UIToolOptionPanel.instance) as UIButton; Single.zOrder = 7; Marquee.zOrder = 7; UIToolOptionPanel.instance.m_filtersPanelList.height = 240f; // @TODO - Make this modular, please! I need to put more buttons here later and I need to make a single singleton manager for all of my mods. UIPanel extraToolBackground = AlignToolsPanel.AddUIComponent <UIPanel>(); extraToolBackground.size = new Vector2(26, 70); extraToolBackground.clipChildren = true; extraToolBackground.relativePosition = new Vector3(5, -37); extraToolBackground.backgroundSprite = "InfoPanelBack"; extraToolBackground.name = "ElektrixModsMenu"; extraToolBackground.zOrder = 0; AlignTools.tooltip = "More Tools"; UIToolOptionPanel.instance.clipChildren = false; UIComponent[] t = UIToolOptionPanel.instance.GetComponentsInChildren <UIPanel>(); for (int i = 0; i < t.Length; i++) { t[i].clipChildren = false; } UIMultiStateButton propPickerButton = AlignToolsPanel.AddUIComponent <UIMultiStateButton>(); propPickerButton.name = "PropPickerButton"; propPickerButton.tooltip = "Prop Painter"; propPickerButton.spritePadding = new RectOffset(2, 2, 2, 2); propPickerButton.playAudioEvents = true; propPickerButton.relativePosition = new Vector3(0, -45); var GetIconsAtlas = typeof(UIToolOptionPanel).GetMethod("GetIconsAtlas", BindingFlags.Instance | BindingFlags.NonPublic); propPickerButton.atlas = GetIconsAtlas.Invoke(UIToolOptionPanel.instance, new object[] { }) as UITextureAtlas; propPickerButton.backgroundSprites.AddState(); propPickerButton.foregroundSprites.AddState(); propPickerButton.backgroundSprites[0].normal = "OptionBase"; propPickerButton.backgroundSprites[0].focused = "OptionBase"; propPickerButton.backgroundSprites[0].hovered = "OptionBaseHovered"; propPickerButton.backgroundSprites[0].pressed = "OptionBasePressed"; propPickerButton.backgroundSprites[0].disabled = "OptionBaseDisabled"; propPickerButton.foregroundSprites[0].normal = "EyeDropper"; propPickerButton.backgroundSprites[1].normal = "OptionBaseFocused"; propPickerButton.backgroundSprites[1].focused = "OptionBaseFocused"; propPickerButton.backgroundSprites[1].hovered = "OptionBaseHovered"; propPickerButton.backgroundSprites[1].pressed = "OptionBasePressed"; propPickerButton.backgroundSprites[1].disabled = "OptionBaseDisabled"; propPickerButton.foregroundSprites[1].normal = "EyeDropper"; propPickerButton.size = new Vector2(36, 36); propPickerButton.activeStateIndex = 0; propPickerButton.eventClicked += (component, eventParam) => { Db.l("Button state " + propPickerButton.activeStateIndex); pickerPanel.isVisible = propPickerButton.activeStateIndex == 1; UIToolOptionPanel.instance.m_filtersPanelList.height = 240f; Db.w("Tried to make color picker visible/invisible"); }; Db.l("Prop Picker button instantiated"); PropPainterManager.instance.colorField = field; PropPainterManager.instance.colorPicker = picker; PropPainterManager.instance.propPainterButton = propPickerButton; PropPainterManager.instance.colorPanel = pickerPanel; }