public override void Start() { float cumulativeHeight = 0; UILabel labelRadius = AddUIComponent <UILabel>(); labelRadius.textScale = 0.9f; labelRadius.text = "Main axis:"; labelRadius.relativePosition = new Vector2(8, cumulativeHeight); labelRadius.tooltip = "Press SHIFT +/- to adjust"; labelRadius.SendToBack(); Radius1tf = AddUIComponent <NumericTextField>(); Radius1tf.relativePosition = new Vector2(width - Radius1tf.width - 8, cumulativeHeight); Radius1tf.tooltip = "Press SHIFT +/- to adjust"; Radius1tf.DefaultVal = RADIUS1_DEF; Radius1tf.text = RADIUS1_DEF.ToString(); cumulativeHeight += Radius1tf.height + 8; labelRadius = AddUIComponent <UILabel>(); labelRadius.textScale = 0.9f; labelRadius.text = "Minor axis:"; labelRadius.relativePosition = new Vector2(8, cumulativeHeight); labelRadius.tooltip = "Press CTRL +/- to adjust"; labelRadius.SendToBack(); Radius2tf = AddUIComponent <NumericTextField>(); Radius2tf.relativePosition = new Vector2(204 - Radius1tf.width - 8, cumulativeHeight); Radius2tf.tooltip = "Press CTRL +/- to adjust"; Radius2tf.DefaultVal = RADIUS2_DEF; Radius2tf.text = RADIUS2_DEF.ToString(); cumulativeHeight += Radius2tf.height + 8; var buildButton = UIUtil.CreateButton(this); buildButton.text = "Build"; buildButton.relativePosition = new Vector2(8, cumulativeHeight); buildButton.playAudioEvents = false; buildButton.eventClick += (c, p) => { EllipseTool.Instance.BuildEllipse(); }; cumulativeHeight += buildButton.height + 8; var controlVertices = UIUtil.CreateCheckBox(this); controlVertices.name = "RAB_controlVertices"; controlVertices.label.text = "Insert control points"; controlVertices.tooltip = "Control points are inserted on main axes to keep the ellipse in shape. See workshop page"; controlVertices.isChecked = EllipseTool.Instance.ControlVertices; controlVertices.relativePosition = new Vector3(8, cumulativeHeight); controlVertices.eventCheckChanged += (c, state) => { EllipseTool.Instance.ControlVertices = state; }; cumulativeHeight += controlVertices.height + 8; height = cumulativeHeight; }
public override void Start() { float cumulativeHeight = 0; UILabel labelRadius = AddUIComponent <UILabel>(); labelRadius.textScale = 0.9f; labelRadius.text = "Radius:"; labelRadius.relativePosition = new Vector2(8, cumulativeHeight); labelRadius.tooltip = "Press +/- to adjust"; labelRadius.SendToBack(); RadiusField = AddUIComponent <NumericTextField>(); RadiusField.relativePosition = new Vector2(width - RadiusField.width - 8, cumulativeHeight); RadiusField.tooltip = "Press +/- to adjust"; RadiusField.MaxVal = RoundAboutBuilder.UnlimitedRadius.value ? RADIUS_MAX_VAL_UNLIMITED : RADIUS_MAX_VAL; cumulativeHeight += RadiusField.height + 8; UIButton button = UIUtil.CreateButton(this); button.text = "Free Cursor Mode..."; button.tooltip = "Create roundabouts anywhere (Warning! Roads won't be removed or connected)"; button.relativePosition = new Vector2(8, cumulativeHeight); button.width = width - 16; button.eventClick += (c, p) => { UIWindow.instance.SwitchTool(FreeCursorTool.Instance); }; cumulativeHeight += button.height + 8; if (RoundAboutBuilder.LegacyEllipticRoundabouts.value) { button = UIUtil.CreateButton(this); button.text = "Elliptic Roundabout..."; button.relativePosition = new Vector2(8, cumulativeHeight); button.width = width - 16; button.eventClick += (c, p) => { UIWindow.instance.SwitchTool(EllipseTool.Instance); }; cumulativeHeight += button.height + 8; } label = AddUIComponent <UILabel>(); label.text = "Tip: Use Fine Road Tool for elevated roads"; label.wordWrap = true; label.textScale = 0.9f; label.autoSize = false; label.width = width - 16; label.height = 48; label.relativePosition = new Vector2(8, cumulativeHeight); label.SendToBack(); cumulativeHeight += label.height; height = cumulativeHeight; UIWindow.instance.SwitchWindow(this); }
private void CreateOptionPanel() { name = "RAB_ToolOptionsPanel"; atlas = ResourceLoader.GetAtlas("Ingame"); backgroundSprite = "SubcategoriesPanel"; size = new Vector2(204, 180); absolutePosition = new Vector3(RoundAboutBuilder.savedWindowX.value, RoundAboutBuilder.savedWindowY.value); isVisible = false; //DebugUtils.Log("absolutePosition: " + absolutePosition); eventPositionChanged += (c, p) => { if (absolutePosition.x < 0) { absolutePosition = RoundAboutBuilder.defWindowPosition; } Vector2 resolution = GetUIView().GetScreenResolution(); absolutePosition = new Vector2( Mathf.Clamp(absolutePosition.x, 0, resolution.x - width), Mathf.Clamp(absolutePosition.y, 0, resolution.y - height)); RoundAboutBuilder.savedWindowX.value = (int)absolutePosition.x; RoundAboutBuilder.savedWindowY.value = (int)absolutePosition.y; }; UIDragHandle dragHandle = AddUIComponent <UIDragHandle>(); dragHandle.width = width; dragHandle.relativePosition = Vector3.zero; dragHandle.target = parent; P_TmpeSetupPanel = AddUIComponent <TmpeSetupPanel>(); InitPanels(); // From Elektrix's Road Tools UIButton openDescription = AddUIComponent <UIButton>(); openDescription.relativePosition = new Vector3(width - 24f, 8f); openDescription.size = new Vector3(15f, 15f); openDescription.normalFgSprite = "ToolbarIconHelp"; openDescription.name = "RAB_workshopButton"; openDescription.tooltip = "Roundabout Builder [" + RoundAboutBuilder.VERSION + "] by Strad\nOpen in Steam Workshop"; UIUtil.SetupButtonStateSprites(ref openDescription, "OptionBase", true); if (!PlatformService.IsOverlayEnabled()) { openDescription.isVisible = false; openDescription.isEnabled = false; } openDescription.eventClicked += delegate(UIComponent component, UIMouseEventParameter click) { if (PlatformService.IsOverlayEnabled() && RoundAboutBuilder.WORKSHOP_FILE_ID != null) { PlatformService.ActivateGameOverlayToWorkshopItem(RoundAboutBuilder.WORKSHOP_FILE_ID); } openDescription.Unfocus(); }; // -- Elektrix float cummulativeHeight = 8; /* Top section */ m_topSection = AddUIComponent <UIPanel>(); m_topSection.relativePosition = new Vector2(0, 0); m_topSection.SendToBack(); UILabel label = m_topSection.AddUIComponent <UILabel>(); label.textScale = 0.9f; label.text = "Roundabout Builder"; label.relativePosition = new Vector2(8, cummulativeHeight); label.SendToBack(); cummulativeHeight += label.height + 8; m_topSection.height = cummulativeHeight; m_topSection.width = width; dragHandle.height = cummulativeHeight; dropDown = AddUIComponent <UINetInfoDropDown>(); //dropDown.relativePosition = new Vector2(8, cummulativeHeight); dropDown.width = width - 16; //cummulativeHeight += dropDown.height + 8; /* Bottom section */ m_followTerrainSection = AddUIComponent <UIPanel>(); m_followTerrainSection.width = 204f; m_followTerrainSection.clipChildren = true; var chbFollowTerrain = UIUtil.CreateCheckBox(m_followTerrainSection); chbFollowTerrain.name = "RAB_followTerrain"; chbFollowTerrain.label.text = "Level terrain"; chbFollowTerrain.tooltip = "Make the roundabout the same height everywhere"; chbFollowTerrain.isChecked = !SavedFollowTerrain; chbFollowTerrain.relativePosition = new Vector3(8, 0); chbFollowTerrain.eventCheckChanged += (c, state) => { // Let's make it confusing - the variable and the chackbox will have opposite values SavedFollowTerrain.value = !state; }; m_followTerrainSection.height = chbFollowTerrain.height + 8; m_setupTmpeSection = AddUIComponent <UIPanel>(); m_setupTmpeSection.width = 204f; m_setupTmpeSection.clipChildren = true; var setupTmpe = UIUtil.CreateCheckBox(m_setupTmpeSection); setupTmpe.name = "RAB_setupTmpe"; setupTmpe.label.text = "Set up TMPE"; setupTmpe.tooltip = "Apply TMPE policies to the roundabout"; setupTmpe.isChecked = SavedSetupTmpe; setupTmpe.relativePosition = new Vector3(8, 0); setupTmpe.eventCheckChanged += (c, state) => { SavedSetupTmpe.value = state; }; var tmpeButton = UIUtil.CreateButton(m_setupTmpeSection); tmpeButton.text = "..."; tmpeButton.tooltip = "TMPE settings"; tmpeButton.height = setupTmpe.height; tmpeButton.width = 30; tmpeButton.relativePosition = new Vector2(width - tmpeButton.width - 8, 0); tmpeButton.eventClick += (c, p) => { toolOnUI.enabled = false; SwitchWindow(P_TmpeSetupPanel); }; m_setupTmpeSection.height = setupTmpe.height + 8; //cummulativeHeight += keepOpen.height + 8; cummulativeHeight = 0; m_bottomSection = AddUIComponent <UIPanel>(); var keepOpen = UIUtil.CreateCheckBox(m_bottomSection); keepOpen.name = "RAB_keepOpen"; keepOpen.label.text = "Keep open"; keepOpen.tooltip = "Keep the window open after roundabout is built"; keepOpen.isChecked = SavedKeepOpen.value; keepOpen.relativePosition = new Vector3(8, cummulativeHeight); keepOpen.width = 196; // width - padding keepOpen.eventCheckChanged += (c, state) => { SavedKeepOpen.value = state; }; cummulativeHeight += keepOpen.height + 8; // Back button backButton = UIUtil.CreateButton(m_bottomSection); backButton.text = "Back"; backButton.relativePosition = new Vector2(8, cummulativeHeight); backButton.width = width - 16; backButton.eventClick += (c, p) => { if (backButton.isVisible) { if (m_panelOnUI.IsSpecialWindow) { SwitchWindow(m_lastStandardPanel); toolOnUI.enabled = true; } else { toolOnUI.GoToFirstStage(); SwitchTool(RoundaboutTool.Instance); } } }; cummulativeHeight += backButton.height + 8; closeButton = UIUtil.CreateButton(m_bottomSection); closeButton.text = "Close"; closeButton.relativePosition = new Vector2(8, cummulativeHeight); closeButton.eventClick += (c, p) => { enabled = false; if (toolOnUI != null) { toolOnUI.enabled = false; } }; undoButton = UIUtil.CreateButton(m_bottomSection); undoButton.text = "Undo"; undoButton.tooltip = "Remove last built roundabout (CTRL+Z). Warning: Use only right after the roundabout has been built"; undoButton.relativePosition = new Vector2(16 + closeButton.width, cummulativeHeight); undoButton.isEnabled = false; undoButton.eventClick += (c, p) => { ModThreading.UndoAction(); }; cummulativeHeight += closeButton.height + 8; m_bottomSection.height = cummulativeHeight; m_bottomSection.width = width; m_hoveringLabel = AddUIComponent <HoveringLabel>(); m_hoveringLabel.isVisible = false; /* Enable roundabout tool as default */ SwitchTool(RoundaboutTool.Instance); // Is done by modthreading from 1.5.3 on /*try * { * if(RoundAboutBuilder.ShowUIButton) * UIPanelButton.CreateButton(); * } * catch(Exception e) * { * Debug.LogWarning("Failed to create UI button."); * Debug.LogWarning(e); * }*/ enabled = false; }