//p_OffsetPrecent range is from 0.0 - 1.0 for 0 - 100 percent offset public void AddUIElementToScreen(string p_UIElementPrefabName, ScreenAnchor p_ScreenAnchor, Vector2 p_OffsetPercent) { UIElement t_NewElement = Instantiate(AssetManager.m_Instance.GetPrefab(p_UIElementPrefabName)).GetComponent <UIElement>(); Vector2 t_sizeoffset = t_NewElement.m_HalfSize; Vector2 t_finalposition; Vector2 t_Offset = new Vector2(Screen.width * p_OffsetPercent.x, Screen.height * p_OffsetPercent.y); switch (p_ScreenAnchor) { case ScreenAnchor.TOP_LEFT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(0, m_screensize.y) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(t_sizeoffset.x, -t_sizeoffset.y); break; case ScreenAnchor.TOP_CENTER: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x / 2, m_screensize.y) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(0, -t_sizeoffset.y); break; case ScreenAnchor.TOP_RIGHT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x, m_screensize.y) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(-t_sizeoffset.x, -t_sizeoffset.y); break; case ScreenAnchor.CENTER_LEFT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(0, m_screensize.y / 2) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(t_sizeoffset.x, 0); break; case ScreenAnchor.CENTER: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x / 2, m_screensize.y / 2) + t_Offset); t_NewElement.transform.position = t_finalposition; break; case ScreenAnchor.CENTER_RIGHT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x, m_screensize.y / 2) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(-t_sizeoffset.x, 0); break; case ScreenAnchor.LOWER_LEFT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(0, 0) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(t_sizeoffset.x, t_sizeoffset.y); break; case ScreenAnchor.LOWER_CENTER: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x / 2, 0) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(0, t_sizeoffset.y); break; case ScreenAnchor.LOWER_RIGHT: t_finalposition = Camera.main.ScreenToWorldPoint(new Vector2(m_screensize.x, 0) + t_Offset); t_NewElement.transform.position = t_finalposition + new Vector2(-t_sizeoffset.x, t_sizeoffset.y); break; default: break; } t_NewElement.transform.SetParent(GameObject.FindGameObjectWithTag("Canvas").transform); }
public static D2.Axis GetAxis(ScreenAnchor anchor) { switch (anchor) { case ScreenAnchor.UpperLeft: return(new D2.Axis(0, 0)); case ScreenAnchor.UpperMiddle: return(new D2.Axis(GetSystemMetrics(0) / 2, 0)); case ScreenAnchor.UpperRight: return(new D2.Axis(GetSystemMetrics(0), 0)); case ScreenAnchor.CenterLeft: return(new D2.Axis(0, GetSystemMetrics(1) / 2)); case ScreenAnchor.CenterMiddle: return(new D2.Axis(GetSystemMetrics(0) / 2, GetSystemMetrics(1) / 2)); case ScreenAnchor.CenterRight: return(new D2.Axis(GetSystemMetrics(0), GetSystemMetrics(1) / 2)); case ScreenAnchor.BottonLeft: return(new D2.Axis(0, GetSystemMetrics(1))); case ScreenAnchor.BottonMiddle: return(new D2.Axis(GetSystemMetrics(0) / 2, GetSystemMetrics(1))); case ScreenAnchor.BottonRight: return(new D2.Axis(GetSystemMetrics(0), GetSystemMetrics(1))); default: return(new D2.Axis(GetSystemMetrics(0), GetSystemMetrics(1))); } }
public static void DrawWindow(uint player, int startId, ScreenAnchor anchor, int x, int y, int width, int height, float lifeTime = 10.0f) { string top = WindowTopLeft; string middle = WindowMiddleLeft; string bottom = WindowBottomLeft; for (int i = 0; i < width; i++) { top += WindowTopMiddle; middle += WindowMiddleBlank; bottom += WindowBottomMiddle; } top += WindowTopRight; middle += WindowMiddleRight; bottom += WindowBottomRight; Draw(player, top, x, y, anchor, startId++, lifeTime); for (var i = 0; i < height; i++) { Draw(player, middle, x, ++y, anchor, startId++, lifeTime); } Draw(player, bottom, x, ++y, anchor, startId, lifeTime); }
/// <summary> /// Draws the HP, MP, and STM status information on the player's screen. /// </summary> /// <param name="player">The player to draw the component for.</param> private static void DrawStatusComponent(uint player) { var playerId = GetObjectUUID(player); var dbPlayer = DB.Get <Player>(playerId) ?? new Player(); var currentHP = GetCurrentHitPoints(player); var maxHP = GetMaxHitPoints(player); var currentMP = dbPlayer.MP; var maxMP = Stat.GetMaxMP(player, dbPlayer); var currentSTM = dbPlayer.Stamina; var maxSTM = Stat.GetMaxStamina(player, dbPlayer); var backgroundBar = BuildBar(1, 1, 22); var hpBar = BuildBar(currentHP, maxHP, 22); var mpBar = BuildBar(currentMP, maxMP, 22); var stmBar = BuildBar(currentSTM, maxSTM, 22); const int windowX = 1; const int windowY = 5; const int windowWidth = 25; const ScreenAnchor Anchor = ScreenAnchor.BottomRight; // Draw order is backwards. The top-most layer needs to be drawn first. var centerWindowX = Gui.CenterStringInWindow(backgroundBar, windowX, windowWidth); // Draw the text var hpText = "HP:".PadRight(5, ' ') + $"{currentHP.ToString().PadLeft(4, ' ')} / {maxHP.ToString().PadLeft(4, ' ')}"; var mpText = "MP:".PadRight(5, ' ') + $"{currentMP.ToString().PadLeft(4, ' ')} / {maxMP.ToString().PadLeft(4, ' ')}"; var stmText = "STM:".PadRight(5, ' ') + $"{currentSTM.ToString().PadLeft(4, ' ')} / {maxSTM.ToString().PadLeft(4, ' ')}"; PostString(player, hpText, centerWindowX + 8, windowY + 3, Anchor, 0.0f, Gui.ColorWhite, Gui.ColorWhite, _idReservation.StartId + 2, Gui.TextName); PostString(player, mpText, centerWindowX + 8, windowY + 2, Anchor, 0.0f, Gui.ColorWhite, Gui.ColorWhite, _idReservation.StartId + 1, Gui.TextName); PostString(player, stmText, centerWindowX + 8, windowY + 1, Anchor, 0.0f, Gui.ColorWhite, Gui.ColorWhite, _idReservation.StartId, Gui.TextName); // Draw the bars PostString(player, hpBar, centerWindowX + 2, windowY + 3, Anchor, 0.0f, Gui.ColorHealthBar, Gui.ColorHealthBar, _idReservation.StartId + 3, Gui.FontName); PostString(player, mpBar, centerWindowX + 2, windowY + 2, Anchor, 0.0f, Gui.ColorManaBar, Gui.ColorManaBar, _idReservation.StartId + 4, Gui.FontName); PostString(player, stmBar, centerWindowX + 2, windowY + 1, Anchor, 0.0f, Gui.ColorStaminaBar, Gui.ColorStaminaBar, _idReservation.StartId + 5, Gui.FontName); // Draw the backgrounds if (!GetLocalBool(player, "PLAYERSTATUSWINDOW_BACKGROUND_DRAWN")) { PostString(player, backgroundBar, centerWindowX + 2, windowY + 3, Anchor, 0.0f, Gui.ColorBlack, Gui.ColorBlack, _idReservation.StartId + 6, Gui.FontName); PostString(player, backgroundBar, centerWindowX + 2, windowY + 2, Anchor, 0.0f, Gui.ColorBlack, Gui.ColorBlack, _idReservation.StartId + 7, Gui.FontName); PostString(player, backgroundBar, centerWindowX + 2, windowY + 1, Anchor, 0.0f, Gui.ColorBlack, Gui.ColorBlack, _idReservation.StartId + 8, Gui.FontName); Gui.DrawWindow(player, _idReservation.StartId + 9, Anchor, windowX, windowY, windowWidth - 2, 3); } }
//Return a Vector3 placing a UI element at some anchored place onscreen public Vector3 GetAnchorPosition(ScreenAnchor horizontal, ScreenAnchor vertical) { float x; float y; switch (horizontal) { case ScreenAnchor.LEFT: x = 0; break; case ScreenAnchor.CENTER_HORIZONTAL: x = .5f; break; case ScreenAnchor.RIGHT: x = 1f; break; default: throw new Exception("ScreenUtil.GetAnchorPosition illegal horizontal value"); } switch (vertical) { case ScreenAnchor.BOTTOM: y = 0; break; case ScreenAnchor.CENTER_VERTICAL: y = .5f; break; case ScreenAnchor.TOP: y = 1f; break; default: throw new Exception("ScreenUtil.GetAnchorPosition illegal horizontal value"); } Vector3 retv = new Vector3(x, y, gameCamera.transform.localPosition.y); retv = gameCamera.ViewportToWorldPoint(retv); return(retv); }
//Return a Vector3 placing a UI element at some anchored place onscreen public Vector3 GetAnchorPosition(ScreenAnchor horizontal, ScreenAnchor vertical) { float x; float y; switch (horizontal) { case ScreenAnchor.LEFT: x = 0; break; case ScreenAnchor.CENTER_HORIZONTAL: x = .5f; break; case ScreenAnchor.RIGHT: x = 1f; break; default: throw new Exception ("ScreenUtil.GetAnchorPosition illegal horizontal value"); } switch (vertical) { case ScreenAnchor.BOTTOM: y = 0; break; case ScreenAnchor.CENTER_VERTICAL: y = .5f; break; case ScreenAnchor.TOP: y = 1f; break; default: throw new Exception ("ScreenUtil.GetAnchorPosition illegal horizontal value"); } Vector3 retv = new Vector3 (x, y, gameCamera.transform.localPosition.y); retv = gameCamera.ViewportToWorldPoint (retv); return retv; }
public LayoutGroupGrid(Texture2D texture, Rectangle rectangle, ScreenAnchor anchor) : base(texture, rectangle, anchor) { }
public Box(Texture2D texture, Point pos, ScreenAnchor anchor) : base(new Rectangle(pos.X, pos.Y, texture.Width * Transform.SizePower, texture.Height * Transform.SizePower), anchor) { this.texture = texture; }
public Box(Texture2D texture, Rectangle rectangle, ScreenAnchor anchor) : base(rectangle, anchor) { this.texture = texture; }
public MovableHandle(Texture2D texture, Point pos, ScreenAnchor anchor) : base(texture, pos, anchor) { }
public Button(Texture2D texture, Point pos, ScreenAnchor anchor) : base(texture, pos, anchor) { }
public Text(Rectangle rectangle, ScreenAnchor anchor) : base(rectangle, anchor) { }
private static void Draw(uint player, string message, int x, int y, ScreenAnchor anchor, int id, float lifeTime = 10.0f) { PostString(player, message, x, y, anchor, lifeTime, ColorWhite, ColorWhite, id, FontName); }
public DebugTextPositionObj(Rectangle rectangle, ScreenAnchor anchor) : base(rectangle, anchor) { }