private void DrawSubstringNotLeftAligned() { TextAnchor originalAlignment = GuiStyle.alignment; GuiStyle.alignment = GetLeftAlignedVersion(GuiStyle.alignment); float lineHeight = GuiStyle.CalcSize(new GUIContent(text)).y; float y = rect.y; int start = 0; int charsLeft = substringLength; while (charsLeft > 0) { string line = GetNextLine(text, start); string subLine = line.Substring(0, Mathf.Min(line.Length, charsLeft)); start += line.Length; charsLeft -= line.Length; float lineWidth = GuiStyle.CalcSize(new GUIContent(line.Trim())).x; float x = IsCenterAligned(originalAlignment) ? Mathf.Ceil(rect.x + (0.5f * rect.width) - (0.5f * lineWidth)) + 0.5f : rect.x + rect.width - lineWidth; UnityGUITools.DrawText(new Rect(x, y, rect.width, lineHeight), GetRichTextClosedText(subLine.Trim()), GuiStyle, textStyle, textStyleColor); y += GuiStyle.lineHeight; } GuiStyle.alignment = originalAlignment; }
private void ShowStyleEditor() { ImGui.BeginWindow("Style Editor"); //If guiStyle has changed, show button to revert changes if (!guiStyle.Equals(StyleRef)) { ImGui.SameLine(); if (ImGui.Button("Revert Style")) { guiStyle = StyleRef; //Style imguiStyle = ImGui.GetStyle(); //guiStyle.ApplyStyle(ref imguiStyle); } } if (ImGui.CollapsingHeader("Rendering", "renderingOptions", true, true)) { ImGui.Checkbox("AntiAliased Lines", ref guiStyle.AntiAliasedLines); ImGui.Checkbox("AntiAliased Shapes", ref guiStyle.AntiAliasedShapes); //ImGui.SliderFloat("Curve Tessellation Tolerence", ref guiStyle.CurveTessellationTolerance, 0, 10, guiStyle.CurveTessellationTolerance.ToString(), 1); ImGui.SliderFloat("Global Alpha", ref guiStyle.Alpha, 0.2f, 1, Math.Round(guiStyle.Alpha, 2).ToString(), 1); } if (ImGui.CollapsingHeader("Settings", "settings", true, true)) { Int2 winPadding = new Int2(); ImGui.SliderInt2("Window Padding", ref winPadding, 0, 20, "Test"); } Style imguiStyle = ImGui.GetStyle(); guiStyle.ApplyStyle(ref imguiStyle); ImGui.EndWindow(); }
public TextBox(Vector2 position, Vector2 size, string text, GuiStyle style) { this.position = position; this.size = size; this.text = text; this.style = style; }
private void SelectFrame(IGuiFrame friendListing) { GuiPath selectEverything = new GuiPath("**/*"); foreach (Button button in selectEverything.SelectElements <Button>((IGuiContainer)friendListing.Parent)) { button.Disable(); } IGuiStyle buttonStyle = new GuiStyle(mGuiManager.GetDefaultStyle(typeof(Button)), "ButtonStyle"); IGuiStyle frameStyle = new GuiStyle(friendListing.Style, "FrameStyle"); foreach (IGuiStyle style in mFirstTimeLevelGui.AllStyles) { if (style.Name == "SecondaryButtonStyle") { buttonStyle = new GuiStyle(style, "ButtonStyle"); } else if (style.Name == "SelectedFrameStyle") { frameStyle = new GuiStyle(style, "FrameStyle"); } } foreach (Button button in selectEverything.SelectElements <Button>(friendListing)) { button.Style = buttonStyle; button.Enable(); } friendListing.Style = frameStyle; }
//Source https://gist.github.com/dougbinks/8089b4bbaccaaf6fa204236978d165a9#file-imguiutils-h-L9-L93 private void SetUpImguiStyle() { Style imguiStyle = ImGui.GetStyle(); guiStyle = new GuiStyle(); guiStyle.ReadFromFile(new Uri(_baseDirectory + "/Resources/Styles/Default.json")); guiStyle.ApplyStyle(ref imguiStyle); }
internal override void Draw(Canvas canvas, GuiStyle style) { var x = this.GlobalX; var y = this.GlobalY; var w = this.W; var h = this.H; DrawFrame(canvas, x, y, w, h, style); base.Draw(canvas, style); }
public IGuiStyle GetThumbStyle(ItemId clothingId) { IGuiStyle result; ClothingItem prototype; if (mItemIdsToClothingItems.TryGetValue(clothingId, out prototype)) { FashionGameGui gui = GameFacade.Instance.RetrieveMediator <FashionGameGui>(); result = new GuiStyle(gui.GetNamedStyle(prototype.StyleName), "ThumbnailStyle"); result.InternalMargins = result.InternalMargins * 0.5f; } else { throw new Exception("Unexpected clothing of itemId (" + clothingId + ")"); } return(result); }
public void SpawnFloatingWindow(Vector3 startingWorldPoint, uint value, string message, Color color) { IGuiStyle labelStyle = new GuiStyle(Manager.GetDefaultStyle(typeof(Label)), "FloatingText"); labelStyle.DefaultTextAnchor = GuiAnchor.BottomRight; labelStyle.Normal.TextColor = color; labelStyle.DefaultFont = (Font)Resources.Load("Fonts/HelveticaNeueCondensedBold"); IGuiFrame mainFrame = new GuiFrame("MainFrame", new MainFrameSizePosition()); Label scoreLabel = new Label("ScoreLabel", new ExpandText(), labelStyle, message + "\n+" + value.ToString()); scoreLabel.DropShadowEnabled = true; mainFrame.AddChildWidget(scoreLabel, new HorizontalAutoLayout()); // TODO: Hard coded values Window floatingWindow = new Window ( "ScoreFloatingWindow", new FixedSize(96.0f, 64.0f), Manager, mainFrame, Manager.GetDefaultStyle(typeof(GuiElement)) // invisible window ); Camera cam = GameFacade.Instance.RetrieveMediator <FashionCameraMediator>().Camera; // TODO: Hard coded values Manager.SetTopLevelPosition ( floatingWindow, new FloatFromPosition ( mScheduler, cam, startingWorldPoint, 75.0f, 1.5f, delegate() { floatingWindow.Close(); } ) ); }
private int GetGuiStyleValue(GuiStyle guiStyle) { switch (guiStyle) { case GuiStyle.Frame: return(ScanOverlay.GuiStyleDefault); case GuiStyle.Laser: return(ScanOverlay.GuiStyleLaser); case GuiStyle.None: return(ScanOverlay.GuiStyleNone); case GuiStyle.MatrixScan: return(ScanOverlay.GuiStyleMatrixScan); default: return(ScanOverlay.GuiStyleLocationsOnly); } }
private string GetNextLine(string text, int start) { string remainder = text.Substring(start); int lastSpace = 0; if (GuiStyle.CalcSize(new GUIContent(remainder.Trim())).x > rect.width) { int length = 1; while (start + length < text.Length) { string candidate = text.Substring(start, length + 1); if (text[start + length] == ' ') { lastSpace = length; } float width = GuiStyle.CalcSize(new GUIContent(candidate.Trim())).x; if (width < rect.width) { length++; } else { int maxLength = remainder.Length; if (lastSpace > 0) { return(text.Substring(start, Mathf.Max(1, Mathf.Min(lastSpace, maxLength)))); } else { return(text.Substring(start, Mathf.Max(1, Mathf.Min(length - 1, maxLength)))); } } } } return(remainder); }
/// <summary> /// Starts a walk down the runway /// </summary> public void SetActive(FashionModelNeeds needs, FashionLevel level) { if (needs == null) { throw new ArgumentNullException("needs"); } mNeeds = needs; if (level == null) { throw new ArgumentNullException("level"); } mLevel = level; mNametag.MainGui.Showing = true; mDesiredClothing.Clear(); if (mDesiredClothingFrame != null) { mDesiredClothingFrame.ClearChildWidgets(); } mDesiredStations.Clear(); mStateMachine = new FashionModelStateMachine(this, mLevel); UnityGameObject.transform.position = mLevel.Start.First; mActiveWalkCycle = mCatWalk; mActiveWalkCycleSpeed = mCatWalkSpeed; mCompletionBonusTime = 5.0f; mReady = false; mHandleBonusTask = mScheduler.StartCoroutine(HandleBonus()); IGuiManager manager = GameFacade.Instance.RetrieveMediator <RuntimeGuiManager>(); mDesiredClothingFrame = new GuiFrame("MainFrame", new MainFrameSizePosition()); IGuiStyle windowStyle = new GuiStyle(manager.GetDefaultStyle(typeof(Window)), "ModelNeedsWindow"); windowStyle.Normal.Background = null; windowStyle.Hover.Background = null; // TODO: Hard coded values float windowHeight = 192.0f; mDesiredClothingWindow = new Window ( "ModelClothingPanel", new FixedSize(128.0f, windowHeight), manager, mDesiredClothingFrame, windowStyle ); // TODO: Hard coded values mFollowWorldSpaceObject = new FollowWorldSpaceObject ( GameFacade.Instance.RetrieveMediator <FashionCameraMediator>().Camera, this.DisplayObject.transform, GuiAnchor.CenterLeft, new Vector2(0.0f, windowHeight * 0.4f), new Vector3(0.125f, APPROX_AVATAR_HEIGHT * 1.3f, 0.25f) ); manager.SetTopLevelPosition ( mDesiredClothingWindow, mFollowWorldSpaceObject ); ClothingMediator clothingMediator = GameFacade.Instance.RetrieveMediator <ClothingMediator>(); // Setup Clothes GUI foreach (ItemId clothing in mNeeds.Clothing) { Image desiredClothingImage = new Image("DesiredClothingLabel", clothingMediator.GetThumbStyle(clothing), clothingMediator.GetThumbnail(clothing)); mDesiredClothing.Add(clothing, desiredClothingImage); mDesiredClothingFrame.AddChildWidget(desiredClothingImage, new HorizontalAutoLayout()); } // Setup Station GUI foreach (ModelStation station in mNeeds.Stations) { Image desiredStationImage = new Image("DesiredStationImage", station.Image); mDesiredStations.Add(station, desiredStationImage); mDesiredClothingFrame.AddChildWidget(desiredStationImage, new HorizontalAutoLayout()); mCompletionBonusTime += station.WaitTime + mWalkToStationTimeBonus; } this.DisplayObject.SetActiveRecursively(true); Shader fashionModelShader = Shader.Find("Avatar/Fashion Model"); if (fashionModelShader == null) { throw new Exception("Cannot find 'Avatar/Fashion Model' shader"); } mModelMaterials.Clear(); foreach (Component component in UnityGameObject.GetComponentsInChildren(typeof(Renderer))) { Renderer renderer = (Renderer)component; foreach (Material mat in renderer.materials) { mat.shader = fashionModelShader; mModelMaterials.Add(mat); } } mNeeds.AddOnCompleteAction(ModelComplete); }
public RuntimeConsole(IGuiManager guiManager) : base(guiManager, mGuiPath) { if (guiManager == null) { throw new ArgumentNullException("guiManager"); } mManager = guiManager; mConsoleWindow = this.MainGui; mConsoleWindow.Showing = false; IInputManager inputManager = GameFacade.Instance.RetrieveMediator <InputManagerMediator>(); if (inputManager == null) { throw new Exception("Cannot construct a RuntimeConsole without having an InputManagerMediator registered in the GameFacade"); } inputManager.RegisterForButtonUp(KeyCode.BackQuote, delegate() { mConsoleWindow.Showing = !mConsoleWindow.Showing; }); mLogFrame = mConsoleWindow.SelectSingleElement <IGuiFrame>("MainFrame/DebugLogFrame"); mMainFrameWidth = mLogFrame.Size.x; Button closeButton = mConsoleWindow.SelectSingleElement <Button>("HeaderFrame/CloseButton"); if (closeButton == null) { throw new Exception("Cannot find the button expected to be at 'HeaderFrame/CloseButton'"); } closeButton.AddOnPressedAction(delegate() { mConsoleWindow.Showing = false; }); IGuiStyle defaultLabelStyle = new GuiStyle(mManager.GetDefaultStyle(typeof(Label)), "ConsoleLabel"); defaultLabelStyle.WordWrap = true; //defaultLabelStyle.DefaultFont = (Font)Resources.Load("Fonts/CourierBold"); IGuiStyle errorStyle = new GuiStyle(defaultLabelStyle, "ConsoleErrorLabel"); defaultLabelStyle.Normal.TextColor = Color.white; errorStyle.Normal.TextColor = Color.Lerp(Color.black, Color.red, 0.35f); mLogLevelStyles.Add(LogLevel.Error, errorStyle); mLogLevelStyles.Add(LogLevel.Info, defaultLabelStyle); mCommandEntryBox = mConsoleWindow.SelectSingleElement <Textbox>("**/CommandEntryBox"); inputManager.RegisterForButtonDown(KeyCode.Return, delegate() { if (this.MainGui.Showing) { List <string> lineParsed = new List <string>(mCommandEntryBox.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); Action <ICollection <string> > command; if (lineParsed.Count > 0 && mCommands.TryGetValue(lineParsed[0], out command)) { lineParsed.RemoveAt(0); command(lineParsed); } } }); }