private static bool DrawPuriumShieldBar() { int anchorX = Main.screenWidth / 2; Player player = Main.player[Main.myPlayer]; if (player.ghost) { return(true); } Mod mod = Bluemagic.Instance; BluemagicPlayer modPlayer = player.GetModPlayer <BluemagicPlayer>(mod); if (modPlayer.puriumShieldChargeMax <= 0f) { return(true); } const int barSize = 128; const int padding = 4; const int chargeSize = barSize - 2 * padding; const int chargeHeight = 20; DynamicSpriteFont font = Main.fontMouseText; float puriumShieldCharge = Math.Min(modPlayer.puriumShieldCharge, modPlayer.puriumShieldChargeMax); string chargeText = (int)puriumShieldCharge + "/" + (int)modPlayer.puriumShieldChargeMax; string maxText = "Purity Shield Charge: " + (int)modPlayer.puriumShieldChargeMax + "/" + (int)modPlayer.puriumShieldChargeMax; Vector2 maxTextSize = font.MeasureString(maxText); Color textColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Main.spriteBatch.DrawString(font, "Purity Shield Charge:", new Vector2(anchorX + barSize / 2 - maxTextSize.X / 2f, 6f), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, chargeText, new Vector2(anchorX + barSize / 2 + maxTextSize.X / 2f, 6f), textColor, 0f, new Vector2(font.MeasureString(chargeText).X, 0f), 1f, SpriteEffects.None, 0f); float fill = puriumShieldCharge / modPlayer.puriumShieldChargeMax; Main.spriteBatch.Draw(mod.GetTexture("PuriumShieldBar"), new Vector2(anchorX, 32f), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); Main.spriteBatch.Draw(mod.GetTexture("PuriumShieldCharge"), new Vector2(anchorX + padding, 32f + padding), new Rectangle(0, 0, (int)(fill * chargeSize), chargeHeight), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); return(true); }
public override void Load() { // 모드 초기화 instance = this; Directory.CreateDirectory(MKTCore.translatorPath); if (ModContent.GetInstance <Config>().FontChage) { DynamicSpriteFont MKTPFontMouse = GetFont("Fonts/MKT_MouseText"); DynamicSpriteFont MKTPItemStack = GetFont("Fonts/MKT_ItemStack"); DynamicSpriteFont MKTFontDeath = GetFont("Fonts/MKT_DeathText"); Main.fontMouseText = MKTPFontMouse; // 툴팁, 채팅 Main.fontItemStack = MKTPItemStack; // 업적, UI 제목 Main.fontDeathText = MKTFontDeath; // 타이틀 메뉴 //Main.fontCombatText[0] = MKTPFontMouse; //Main.fontCombatText[1] = MKTPFontMouse; } // 설치한 모드 탐색 this.MKTmods = new List <MKTMod>(); foreach (Mod mod in ModLoader.Mods) { if (mod.Name == "ModLoader") { continue; } if (mod.Name == this.Name) { continue; } this.MKTmods.Add(new MKTMod(mod)); } // 클라이언트 번역 if (ModContent.GetInstance <Config>().TerrariaPatcher) { new MKTTerraria(); } }
private static bool DrawDisasterBar() { int anchorX = Main.screenWidth / 2 + 175; Player player = Main.player[Main.myPlayer]; if (player.ghost) { return(true); } Mod mod = AlchemistNPC.Instance; AlchemistNPCPlayer modPlayer = player.GetModPlayer <AlchemistNPCPlayer>(); if (modPlayer.PH == false) { return(true); } const int barSize = 128; const int padding = 4; const int chargeSize = barSize - 2 * padding; const int chargeHeight = 20; DynamicSpriteFont font = Main.fontMouseText; float Gauge = Math.Min(modPlayer.DisasterGauge, 500); string chargeText = Gauge + "/" + 500; string maxText = "Disaster Gauge: " + 500 + "/" + 500; Vector2 maxTextSize = font.MeasureString(maxText); Color textColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Main.spriteBatch.DrawString(font, "Disaster Gauge:", new Vector2(anchorX + barSize / 2 - maxTextSize.X / 2f, 42f), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, chargeText, new Vector2(anchorX + barSize / 2 + maxTextSize.X / 2f, 42f), textColor, 0f, new Vector2(font.MeasureString(chargeText).X, 0f), 1f, SpriteEffects.None, 0f); float fill = Gauge / 500; Main.spriteBatch.Draw(mod.GetTexture("Interface/DisasterBar"), new Vector2(anchorX, 64f), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); Main.spriteBatch.Draw(mod.GetTexture("Interface/DisasterCharge"), new Vector2(anchorX + padding, 64f + padding), new Rectangle(0, 0, (int)(fill * chargeSize), chargeHeight), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); return(true); }
protected override void DrawSelf(SpriteBatch spriteBatch) { CalculatedStyle innerDimensions = GetInnerDimensions(); //Vector2 drawPos = new Vector2(innerDimensions.X + 5f, innerDimensions.Y + 30f); float shopx = innerDimensions.X; float shopy = innerDimensions.Y; Player player = Main.LocalPlayer; AlchemistNPCPlayer modPlayer = player.GetModPlayer <AlchemistNPCPlayer>(); int anchorX = (int)shopx; DynamicSpriteFont font = Main.fontMouseText; string maxText = "9999"; Vector2 maxTextSize = font.MeasureString(maxText); Color textColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT1, new Vector2(shopx + (float)(24) + (float)1, shopy), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT2, new Vector2(shopx + (float)(24) + (float)1, shopy + 60), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT3, new Vector2(shopx + (float)(24) + (float)1, shopy + 120), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT4, new Vector2(shopx + (float)(24) + (float)1, shopy + 180), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT5, new Vector2(shopx + (float)(24) + (float)1, shopy + 240), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); Main.spriteBatch.DrawString(font, "" + modPlayer.RCT6, new Vector2(shopx + (float)(24) + (float)1, shopy + 300), textColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f); }
public static string WrapString(string input, int length, DynamicSpriteFont font, float scale) { string output = ""; string[] words = input.Split(); string line = ""; foreach (string str in words) { if (font.MeasureString(line).X *scale < length) { output += (" " + str); line += (" " + str); } else { output += ("\n" + str); line = (str); } } return(output); }
public override void Load() { // Will show up in client.log under the ExampleMod name Logger.InfoFormat("{0} example logging", Name); // Registers a new hotkey instrumentHotKey = RegisterHotKey("Instrument Key", "D"); // See https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb197781(v=xnagamestudio.41) for special keys // All code below runs only if we're not loading on a server if (!Main.dedServ) { if (FontExists("Fonts/ExampleFont")) { exampleFont = GetFont("Fonts/ExampleFont"); } // Custom UI pianoUI = new PianoUI(); pianoUI.Activate(); pianistUserInterface = new UserInterface(); pianistUserInterface.SetState(pianoUI); } }
protected override void DrawSelf(SpriteBatch spriteBatch) { Texture2D texture = ModContent.GetTexture("MagicStorage/Assets/SearchBar"); CalculatedStyle dim = GetDimensions(); int innerWidth = (int)dim.Width - 2 * padding; int innerHeight = (int)dim.Height - 2 * padding; spriteBatch.Draw(texture, dim.Position(), new Rectangle(0, 0, padding, padding), Color.White); spriteBatch.Draw(texture, new Rectangle((int)dim.X + padding, (int)dim.Y, innerWidth, padding), new Rectangle(padding, 0, 1, padding), Color.White); spriteBatch.Draw(texture, new Vector2(dim.X + padding + innerWidth, dim.Y), new Rectangle(padding + 1, 0, padding, padding), Color.White); spriteBatch.Draw(texture, new Rectangle((int)dim.X, (int)dim.Y + padding, padding, innerHeight), new Rectangle(0, padding, padding, 1), Color.White); spriteBatch.Draw(texture, new Rectangle((int)dim.X + padding, (int)dim.Y + padding, innerWidth, innerHeight), new Rectangle(padding, padding, 1, 1), Color.White); spriteBatch.Draw(texture, new Rectangle((int)dim.X + padding + innerWidth, (int)dim.Y + padding, padding, innerHeight), new Rectangle(padding + 1, padding, padding, 1), Color.White); spriteBatch.Draw(texture, new Vector2(dim.X, dim.Y + padding + innerHeight), new Rectangle(0, padding + 1, padding, padding), Color.White); spriteBatch.Draw(texture, new Rectangle((int)dim.X + padding, (int)dim.Y + padding + innerHeight, innerWidth, padding), new Rectangle(padding, padding + 1, 1, padding), Color.White); spriteBatch.Draw(texture, new Vector2(dim.X + padding + innerWidth, dim.Y + padding + innerHeight), new Rectangle(padding + 1, padding + 1, padding, padding), Color.White); UpdateText(); string drawText = text; if (text.Length == 0) { drawText = focused ? string.Empty : defaultText.Value; } DynamicSpriteFont font = Main.fontMouseText; float scale = innerHeight / font.MeasureString(drawText).Y; Color color = focused ? Color.Black : Color.Black * 0.75f; spriteBatch.DrawString(font, drawText, new Vector2(dim.X + padding, dim.Y + padding), color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); if (focused && cursorTimer < 30) { float drawCursor = font.MeasureString(drawText.Substring(0, cursorPosition)).X *scale; spriteBatch.DrawString(font, "|", new Vector2(dim.X + padding + drawCursor, dim.Y + padding), color, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); } }
public static void DrawBuffButton(int superColor, int numLines) { const string text = "Bless"; DynamicSpriteFont font = Main.fontMouseText; Vector2 scale = new Vector2(0.9f); Vector2 stringSize = ChatManager.GetStringSize(font, text, scale); Vector2 position = new Vector2(180 + Main.screenWidth / 2 + stringSize.X - 20f, 130 + numLines * 30); Color baseColor = new Color(superColor, (int)(superColor / 1.1), superColor / 2, superColor); Vector2 mousePos = new Vector2(Main.mouseX, Main.mouseY); if (mousePos.Between(position, position + stringSize * scale) && !PlayerInput.IgnoreMouseInterface) //Mouse hovers over button { Main.LocalPlayer.mouseInterface = true; Main.LocalPlayer.releaseUseItem = true; scale *= 1.1f; if (!HoveringBuffButton) { Main.PlaySound(SoundID.MenuTick); } HoveringBuffButton = true; if (Main.mouseLeft && Main.mouseLeftRelease) { var options = new List <string> { "You wish for a challenge? I may stop you not, as it benefits us both. I do hope you're prepared!", "I shall consult the gods about their boons - these monsters will become relentless, I hope you are aware.", "You want me to call them what?! Such foul battle language, yet I will deliver the message. The Gods won't be happy about this!", "The boons cause slain foes to drop stronger tokens, yes, but do remember that the foes become stronger, too!", "Do come back alive! I would enjoy hearing tales of your victories. Bring many tokens as well!" }; for (int i = 0; i < 30; i++) { int num = Dust.NewDust(new Vector2(Main.LocalPlayer.Center.X + Main.rand.Next(-100, 100), Main.LocalPlayer.Center.Y + Main.rand.Next(-100, 100)), Main.LocalPlayer.width, Main.LocalPlayer.height, ModContent.DustType <Dusts.BlessingDust>(), 0f, -2f, 0, default, 2f);
//////////////// /// <summary></summary> /// <param name="theme"></param> /// <param name="skipThemeRefreshNow"></param> /// <param name="text"></param> /// <param name="textScale"></param> /// <param name="large"></param> public UIThemedText(UITheme theme, bool skipThemeRefreshNow, string text, float textScale = 1, bool large = false) : base(text, textScale, large) { this.Theme = theme; this.ScaleCopy = textScale; this.LargeCopy = large; DynamicSpriteFont font = large ? Main.fontDeathText : Main.fontMouseText; this.SizeCopy = new Vector2( font.MeasureString(text.ToString()).X, large ? 32f : 16f ) * textScale; if (!skipThemeRefreshNow) { theme.ApplyText(this); } }
protected override void LoadContent() { _s = new SpriteBatch(GraphicsDevice); _font = DynamicSpriteFont.FromTtf(TitleContainer.OpenStream($"{Content.RootDirectory}/SourceCodePro-Medium.ttf"), 30); GuiHelper.Setup(this, _font); Core.Setup(this); _canvas = new Canvas(); _pixel = Content.Load <Texture2D>("Pixel"); _grid = Content.Load <Effect>("Grid"); _grid.Parameters["BackgroundColor"].SetValue(new Color(10, 10, 10).ToVector4()); _grid.Parameters["GridColor"].SetValue(new Color(30, 30, 30).ToVector4()); _grid.Parameters["GridSize"].SetValue(new Vector2(Core.NoteWidth, Core.NoteHeight)); _grid.Parameters["LineSize"].SetValue(new Vector2(Core.LineSize)); // Possible crash if there are no devices? Core.Midi = new Midi(); Core.Menu = new Menu(); }
protected override void Initialize() { Ste.Initialize(this, graphics); Window.AllowUserResizing = true; bullets = new List <Bullet>(); Ste.ChangeResolution(1920, 1080); a = new FlareFxAlt(graphicsDevice, 40, 40, "Test2"); MeteorBullet.flarefx = new FlareFx(graphicsDevice, 40, 40, "Test"); MeteorBullet.flarefxAlt = a as FlareFxAlt; mousePos = new Vector2[15]; vertexBatch = new VertexBatch(graphicsDevice); //var n = new FontStb_Native(Ste.GetAsset("SourceHanSansCN-Regular.ttf"), graphicsDevice); //text = new DynamicTextureTextGDI(graphicsDevice, Environment.CurrentDirectory + Path.DirectorySeparatorChar + "SourceHanSansCN-Regular.ttf", 40, "***ABCD文字绘制测试\nStellaris\n增益免疫汉化组"); dtt = new DynamicSpriteFont(graphicsDevice, Ste.GetAsset("SourceHanSansCN-Regular.ttf"), 80, useNative: false); var font = new FontStb_Native(Ste.GetAsset("Product-Sans-Regular.ttf")); font.ReverseFont = dtt.font; dtt2 = new DynamicSpriteFont(graphicsDevice, font, 80); tex3 = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("trail3.png")); tex = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("zzzz.png")); tex2 = Texture2D.FromStream(graphicsDevice, Ste.GetAsset("trail3.png")); z = new Effect(graphicsDevice, Ste.GetAsset("Blur.cfx").ToByteArray()); base.Initialize(); }
protected override void DrawChildren(SpriteBatch spriteBatch) { base.DrawChildren(spriteBatch); CalculatedStyle space = GetInnerDimensions(); //Main.spriteBatch.Draw(Main.magicPixel, space.ToRectangle(), Color.Yellow * .7f); //Main.spriteBatch.Draw(Main.magicPixel, GetOuterDimensions().ToRectangle(), Color.Red * .7f); DynamicSpriteFont font = Main.fontMouseText; float position = 0f; if (this._scrollbar != null) { position = -this._scrollbar.GetValue(); } //foreach (var drawtext in drawtexts) //{ // if (position + drawtext.Item2 > space.Height) // break; // if (position >= 0) // Utils.DrawBorderString(spriteBatch, drawtext.Item1, new Vector2(space.X, space.Y + position), Color.White, 1f); // position += drawtext.Item2; //} //float offset = 0; TextSnippet[] texts; foreach (var snippetList in drawTextSnippets) { texts = snippetList.ToArray(); float snippetListHeight = ChatManager.GetStringSize(font, texts, Vector2.One).Y; //Main.NewText($"Y: {ChatManager.GetStringSize(font, texts, Vector2.One).X}"); if (position > -snippetListHeight) { //foreach (var snippet in snippetList) //{ int hoveredSnippet = -1; ChatManager.ConvertNormalSnippets(texts); ChatManager.DrawColorCodedStringWithShadow(spriteBatch, font, texts, new Vector2(space.X + 2, space.Y + position /*+ offset*/), 0f, Vector2.Zero, Vector2.One, out hoveredSnippet); //offset += 20; //offset += texts.Max(t => (int)ChatManager.GetStringSize(Main.fontMouseText, texts, Vector2.One).X); if (hoveredSnippet > -1 && IsMouseHovering) { texts[hoveredSnippet].OnHover(); if (Main.mouseLeft && Main.mouseLeftRelease /* && Terraria.GameInput.PlayerInput.Triggers.JustReleased.MouseLeft*/) { texts[hoveredSnippet].OnClick(); } } } position += snippetListHeight; if (position > space.Height) { break; } //} } //if (drawTextSnippets.Count > 0) //{ // //ChatManager.DrawColorCodedStringShadow() // int hoveredSnippet = -1; // ChatManager.DrawColorCodedStringWithShadow(spriteBatch, font, drawTextSnippets[0].ToArray(), new Vector2(space.X, space.Y + position), 0f, Vector2.Zero, Vector2.One, out hoveredSnippet); // if (hoveredSnippet > -1) // { // //array[hoveredSnippet].OnHover(); // } //} }
public override void RecalculateChildren() { base.RecalculateChildren(); if (!heightNeedsRecalculating) { return; } CalculatedStyle space = GetInnerDimensions(); if (space.Width <= 0 || space.Height <= 0) { return; } DynamicSpriteFont font = Main.fontMouseText; drawTextSnippets = WordwrapStringSmart(text, Color.White, font, (int)space.Width - 2, -1); //height = ChatManager.GetStringSize(font, text, Vector2.One, space.Width).Y; //Main.NewText($"h: {height} "); //Main.NewText($"a: {drawTextSnippets[0][0].GetStringLength(font)} "); //// 18* 28 == 504 //// 18 * ? == 588 //float hsum = 0; height = 0; foreach (var snippetList in drawTextSnippets) { var texts = snippetList.ToArray(); height += ChatManager.GetStringSize(font, texts, Vector2.One).Y; //Main.NewText($"calc Y: {ChatManager.GetStringSize(font, texts, Vector2.One).Y}"); } //Main.NewText($"Count: {drawTextSnippets.Count} Height:{height} sum: {hsum}"); //height = hsum; //height = ChatManager.GetStringSize(font, "1", Vector2.One).Y; /* * drawtexts.Clear(); * float position = 0f; * float textHeight = font.MeasureString("A").Y; * string[] lines = text.Split('\n'); * foreach (string line in lines) * { * string drawString = line; * if (drawString.Length == 0) * { * position += textHeight; * } * while (drawString.Length > 0) * { * string remainder = ""; * while (font.MeasureString(drawString).X > space.Width) * { * remainder = drawString[drawString.Length - 1] + remainder; * drawString = drawString.Substring(0, drawString.Length - 1); * } * if (remainder.Length > 0) * { * int index = drawString.LastIndexOf(' '); * if (index >= 0) * { * remainder = drawString.Substring(index + 1) + remainder; * drawString = drawString.Substring(0, index); * } * } * drawtexts.Add(new Tuple<string, float>(drawString, textHeight)); * position += textHeight; * drawString = remainder; * } * } * height = position; */ heightNeedsRecalculating = false; }
// Attempt at fix: problems: long words crash it, spaces seem to be miscounted. public static List <List <TextSnippet> > WordwrapStringSmart(string text, Color c, DynamicSpriteFont font, int maxWidth, int maxLines) { TextSnippet[] array = ChatManager.ParseMessage(text, c).ToArray(); List <List <TextSnippet> > finalList = new List <List <TextSnippet> >(); List <TextSnippet> list2 = new List <TextSnippet>(); for (int i = 0; i < array.Length; i++) { TextSnippet textSnippet = array[i]; string[] array2 = textSnippet.Text.Split(new char[] { '\n' }); for (int j = 0; j < array2.Length - 1; j++) { list2.Add(textSnippet.CopyMorph(array2[j])); finalList.Add(list2); list2 = new List <TextSnippet>(); } list2.Add(textSnippet.CopyMorph(array2[array2.Length - 1])); } finalList.Add(list2); if (maxWidth != -1) { for (int k = 0; k < finalList.Count; k++) { List <TextSnippet> currentLine = finalList[k]; float usedWidth = 0f; for (int l = 0; l < currentLine.Count; l++) { //float stringLength = list3[l].GetStringLength(font); // GetStringLength doesn't match UniqueDraw float stringLength = ChatManager.GetStringSize(font, new TextSnippet[] { currentLine[l] }, Vector2.One).X; //float stringLength2 = ChatManager.GetStringSize(font, " ", Vector2.One).X; //float stringLength3 = ChatManager.GetStringSize(font, "1", Vector2.One).X; if (stringLength + usedWidth > (float)maxWidth) { int num2 = maxWidth - (int)usedWidth; if (usedWidth > 0f) { num2 -= 16; } float toFill = num2; bool filled = false; int successfulIndex = -1; int index = 0; while (index < currentLine[l].Text.Length && !filled) { if (currentLine[l].Text[index] == ' ') { if (ChatManager.GetStringSize(font, currentLine[l].Text.Substring(0, index), Vector2.One).X < toFill) { successfulIndex = index; } else { filled = true; //if (successfulIndex == 0) // successfulIndex = index; } } index++; } if (currentLine[l].Text.Length == 0) { filled = true; } int num4 = successfulIndex; if (successfulIndex == -1) // last item is too big { if (l == 0) // 1st item in list, keep it and move on { //list2 = new List<TextSnippet>{currentLine[l]}; list2 = new List <TextSnippet>(); for (int m = l + 1; m < currentLine.Count; m++) { list2.Add(currentLine[m]); } finalList[k] = finalList[k].Take(/*l + */ 1).ToList <TextSnippet>(); // take 1 finalList.Insert(k + 1, list2); } else // midway through list, keep previous and move this to next { list2 = new List <TextSnippet>(); for (int m = l; m < currentLine.Count; m++) { list2.Add(currentLine[m]); } finalList[k] = finalList[k].Take(l).ToList <TextSnippet>(); // take previous ones finalList.Insert(k + 1, list2); } } else { string newText = currentLine[l].Text.Substring(0, num4); string newText2 = currentLine[l].Text.Substring(num4).TrimStart(); list2 = new List <TextSnippet> { currentLine[l].CopyMorph(newText2) }; for (int m = l + 1; m < currentLine.Count; m++) { list2.Add(currentLine[m]); } currentLine[l] = currentLine[l].CopyMorph(newText); finalList[k] = finalList[k].Take(l + 1).ToList <TextSnippet>(); finalList.Insert(k + 1, list2); } break; } usedWidth += stringLength; } } } if (maxLines != -1) { while (finalList.Count > 10) { finalList.RemoveAt(10); } } return(finalList); }
protected override void DrawSelf(SpriteBatch spriteBatch) { Rectangle hitbox = GetDimensions().ToRectangle(); Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.White); if (focused) { Terraria.GameInput.PlayerInput.WritingText = true; Main.instance.HandleIME(); WriteAll(Main.GetInputText(Text)); if (JustPressed(Keys.Tab)) { if (unfocusOnTab) { Unfocus(); } OnTabPressed?.Invoke(); } if (JustPressed(Keys.Enter)) { if (unfocusOnEnter) { Unfocus(); } OnEnterPressed?.Invoke(); } if (JustPressed(Keys.Up)) { OnUpPressed?.Invoke(); } } CalculatedStyle innerDimensions2 = base.GetInnerDimensions(); Vector2 pos2 = innerDimensions2.Position(); if (IsLarge) { pos2.Y -= 10f * TextScale * TextScale; } else { pos2.Y -= 2f * TextScale; } if (IsLarge) { Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1); this._frameCount++; CalculatedStyle innerDimensions = base.GetInnerDimensions(); Vector2 pos = innerDimensions.Position(); DynamicSpriteFont spriteFont = base.IsLarge ? Main.fontDeathText : Main.fontMouseText; Vector2 vector = new Vector2(spriteFont.MeasureString(base.Text.Substring(0, this._cursor)).X, base.IsLarge ? 32f : 16f) * base.TextScale; if (base.IsLarge) { pos.Y -= 8f * base.TextScale; } else { pos.Y -= 1f * base.TextScale; } if (Text.Length == 0) { pos.X += 5; if (base.IsLarge) { Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1); pos.X -= 5; } if (!focused) { return; } pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f; if ((this._frameCount %= 40) > 20) { return; } if (base.IsLarge) { Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1); }
public static float GetStringHeight(DynamicSpriteFont font, string text, float scale) { return(font.MeasureString(text).Y *scale); }
public override float GetStringLength(DynamicSpriteFont font) { return((float)(32.0 * (double)this.Scale * 0.649999976158142)); }
public override void Load() { // Will show up in client.log under the ExampleMod name Logger.InfoFormat("{0} example logging", Name); // In older tModLoader versions we used: ErrorLogger.Log("blabla"); // Replace that with above // Registers a new hotkey RandomBuffHotKey = RegisterHotKey("Random Buff", "P"); // See https://docs.microsoft.com/en-us/previous-versions/windows/xna/bb197781(v%3dxnagamestudio.41) for special keys // Registers a new custom currency FaceCustomCurrencyId = CustomCurrencyManager.RegisterCurrency(new ExampleCustomCurrency(ModContent.ItemType <Items.Face>(), 999L)); Mundane.AddHacks(); // All code below runs only if we're not loading on a server if (!Main.dedServ) { // Add certain equip textures AddEquipTexture(null, EquipType.Legs, "ExampleRobe_Legs", "ExampleMod/Items/Armor/ExampleRobe_Legs"); AddEquipTexture(new Items.Armor.BlockyHead(), null, EquipType.Head, "BlockyHead", "ExampleMod/Items/Armor/ExampleCostume_Head"); AddEquipTexture(new Items.Armor.BlockyBody(), null, EquipType.Body, "BlockyBody", "ExampleMod/Items/Armor/ExampleCostume_Body", "ExampleMod/Items/Armor/ExampleCostume_Arms"); AddEquipTexture(new Items.Armor.BlockyLegs(), null, EquipType.Legs, "BlockyLeg", "ExampleMod/Items/Armor/ExampleCostume_Legs"); // Register a new music box AddMusicBox(GetSoundSlot(SoundType.Music, "Sounds/Music/MarbleGallery"), ItemType("ExampleMusicBox"), TileType("ExampleMusicBox")); // Change the vanilla loom texture Main.instance.LoadTiles(TileID.Loom); // First load the tile texture Main.tileTexture[TileID.Loom] = GetTexture("Tiles/AnimatedLoom"); // Now we change it //What if....Replace a vanilla item texture and equip texture. //Main.itemTexture[ItemID.CopperHelmet] = GetTexture("Resprite/CopperHelmet_Item"); //Item copperHelmet = new Item(); //copperHelmet.SetDefaults(ItemID.CopperHelmet); //Main.armorHeadLoaded[copperHelmet.headSlot] = true; //Main.armorHeadTexture[copperHelmet.headSlot] = GetTexture("Resprite/CopperHelmet_Head"); // Create new skies and screen filters Filters.Scene["ExampleMod:PuritySpirit"] = new Filter(new PuritySpiritScreenShaderData("FilterMiniTower").UseColor(0.4f, 0.9f, 0.4f).UseOpacity(0.7f), EffectPriority.VeryHigh); SkyManager.Instance["ExampleMod:PuritySpirit"] = new PuritySpiritSky(); Filters.Scene["ExampleMod:MonolithVoid"] = new Filter(new ScreenShaderData("FilterMoonLord"), EffectPriority.Medium); SkyManager.Instance["ExampleMod:MonolithVoid"] = new VoidSky(); GameShaders.Armor.BindShader(ModContent.ItemType <Items.ExampleDye>(), new ArmorShaderData(new Ref <Effect>(GetEffect("Effects/ExampleEffect")), "ExampleDyePass")); GameShaders.Hair.BindShader(ModContent.ItemType <Items.ExampleHairDye>(), new LegacyHairShaderData().UseLegacyMethod((Player player, Color newColor, ref bool lighting) => Color.Green)); GameShaders.Misc["ExampleMod:DeathAnimation"] = new MiscShaderData(new Ref <Effect>(GetEffect("Effects/ExampleEffectDeath")), "DeathAnimation").UseImage("Images/Misc/Perlin"); if (FontExists("Fonts/ExampleFont")) { exampleFont = GetFont("Fonts/ExampleFont"); } // Custom UI ExampleUI = new ExampleUI(); ExampleUI.Activate(); _exampleUserInterface = new UserInterface(); _exampleUserInterface.SetState(ExampleUI); // Custom Resource Bar ExampleResourceBar = new ExampleResourceBar(); _exampleResourceBarUserInterface = new UserInterface(); _exampleResourceBarUserInterface.SetState(ExampleResourceBar); // UserInterface can only show 1 UIState at a time. If you want different "pages" for a UI, switch between UIStates on the same UserInterface instance. // We want both the Coin counter and the Example Person UI to be independent and coexist simultaneously, so we have them each in their own UserInterface. ExamplePersonUserInterface = new UserInterface(); // We will call .SetState later in ExamplePerson.OnChatButtonClicked } // Register custom mod translations, lives left is for Spirit of Purity // See the .lang files in the Localization folder for an easier to manage approach to translations. These few examples are here just to illustrate the concept. ModTranslation text = CreateTranslation("LivesLeft"); text.SetDefault("{0} has {1} lives left!"); AddTranslation(text); text = CreateTranslation("LifeLeft"); text.SetDefault("{0} has 1 life left!"); AddTranslation(text); text = CreateTranslation("NPCTalk"); text.SetDefault("<{0}> {1}"); AddTranslation(text); text = CreateTranslation("Common.LocalizedLabelDynamic"); text.SetDefault($"[i:{ModContent.ItemType<Items.Weapons.SpectreGun>()}] This dynamic label is added in ExampleMod.Load"); AddTranslation(text); // Volcano warning is for the random volcano tremor text = CreateTranslation("VolcanoWarning"); text.SetDefault("Did you hear something....A Volcano! Find Cover!"); AddTranslation(text); }
protected override void DrawSelf(SpriteBatch spriteBatch) { if (focused) { // This might work.....assuming chat isn't open WriteAll(Main.GetInputText(Text)); } CalculatedStyle innerDimensions2 = base.GetInnerDimensions(); Vector2 pos2 = innerDimensions2.Position(); if (IsLarge) { pos2.Y -= 10f * TextScale * TextScale; } else { pos2.Y -= 2f * TextScale; } //pos2.X += (innerDimensions2.Width - TextSize.X) * 0.5f; if (IsLarge) { Utils.DrawBorderStringBig(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, Text, pos2, TextColor, TextScale, 0f, 0f, -1); this._frameCount++; CalculatedStyle innerDimensions = base.GetInnerDimensions(); Vector2 pos = innerDimensions.Position(); DynamicSpriteFont spriteFont = base.IsLarge ? Main.fontDeathText : Main.fontMouseText; Vector2 vector = new Vector2(spriteFont.MeasureString(base.Text.Substring(0, this._cursor)).X, base.IsLarge ? 32f : 16f) * base.TextScale; if (base.IsLarge) { pos.Y -= 8f * base.TextScale; } else { pos.Y -= 1f * base.TextScale; } if (Text.Length == 0) { Vector2 hintTextSize = new Vector2(spriteFont.MeasureString(hintText.ToString()).X, IsLarge ? 32f : 16f) * TextScale; pos.X += 5; //(hintTextSize.X); if (base.IsLarge) { Utils.DrawBorderStringBig(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, hintText, pos, Color.Gray, base.TextScale, 0f, 0f, -1); pos.X -= 5; //pos.X -= (innerDimensions.Width - hintTextSize.X) * 0.5f; } if (!focused) { return; } pos.X += /*(innerDimensions.Width - base.TextSize.X) * 0.5f*/ +vector.X - (base.IsLarge ? 8f : 4f) * base.TextScale + 6f; if ((this._frameCount %= 40) > 20) { return; } if (base.IsLarge) { Utils.DrawBorderStringBig(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1); return; } Utils.DrawBorderString(spriteBatch, "|", pos, base.TextColor, base.TextScale, 0f, 0f, -1); }
public static void Init(string name, int size) { var bytes = Platform.Current.LoadFile(name); font = DynamicSpriteFont.FromTtf(bytes, size, 2048, 2048); }
public static Vector2 DrawColorCodedString(SpriteBatch spriteBatch, DynamicSpriteFont font, string text, Vector2 position, Color baseColor, float rotation, Vector2 origin, Vector2 baseScale, float maxWidth = -1f, bool ignoreColors = false) { var vector2_1 = position; var vector2_2 = vector2_1; var strArray1 = text.Split('\n'); var x = font.MeasureString(" ").X; var color = baseColor; var num1 = 1f; var num2 = 0.0f; foreach (var str1 in strArray1) { var chArray = new char[1] { ':' }; foreach (var str2 in str1.Split(chArray)) { if (str2.StartsWith("sss")) { if (str2.StartsWith("sss1")) { if (!ignoreColors) { color = Color.Red; } } else if (str2.StartsWith("sss2")) { if (!ignoreColors) { color = Color.Blue; } } else if (str2.StartsWith("sssr") && !ignoreColors) { color = Color.White; } } else { var strArray2 = str2.Split(' '); for (var index = 0; index < strArray2.Length; ++index) { if (index != 0) { vector2_1.X += x * baseScale.X * num1; } if ((double)maxWidth > 0.0) { var num3 = font.MeasureString(strArray2[index]).X *baseScale.X *num1; if ((double)vector2_1.X - (double)position.X + (double)num3 > (double)maxWidth) { vector2_1.X = position.X; vector2_1.Y += (float)font.LineSpacing * num2 * baseScale.Y; vector2_2.Y = Math.Max(vector2_2.Y, vector2_1.Y); num2 = 0.0f; } } if ((double)num2 < (double)num1) { num2 = num1; } DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, font, strArray2[index], vector2_1, color, rotation, origin, baseScale * num1, SpriteEffects.None, 0.0f); vector2_1.X += font.MeasureString(strArray2[index]).X *baseScale.X *num1; vector2_2.X = Math.Max(vector2_2.X, vector2_1.X); } } } vector2_1.X = position.X; vector2_1.Y += (float)font.LineSpacing * num2 * baseScale.Y; vector2_2.Y = Math.Max(vector2_2.Y, vector2_1.Y); num2 = 0.0f; } return(vector2_2); }
public SpriteFont NewDynamic(float defaultSize, string fontName, FontStyle style, FontAntiAliasMode antiAliasMode = FontAntiAliasMode.Default, bool useKerning = false, float extraSpacing = 0, float extraLineSpacing = 0, char defaultCharacter = ' ') { var font = new DynamicSpriteFont { Size = defaultSize, FontName = fontName, Style = style, AntiAlias = antiAliasMode, UseKerning = useKerning, ExtraSpacing = extraSpacing, ExtraLineSpacing = extraLineSpacing, DefaultCharacter = defaultCharacter, FontSystem = this }; return font; }
public static Vector2 DrawColorCodedStringWithShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, string text, Vector2 position, Color baseColor, float rotation, Vector2 origin, Vector2 baseScale, float maxWidth = -1f, float spread = 2f) { var array = ChatManager.ParseMessage(text, baseColor).ToArray(); ChatManager.ConvertNormalSnippets(array); ChatManager.DrawColorCodedStringShadow(spriteBatch, font, array, position, Color.Black, rotation, origin, baseScale, maxWidth, spread); int hoveredSnippet; return(ChatManager.DrawColorCodedString(spriteBatch, font, array, position, Color.White, rotation, origin, baseScale, out hoveredSnippet, maxWidth, false)); }
public override float GetStringLength(DynamicSpriteFont font) { return(26f * GlyphTagHandler.GlyphsScale); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { #if MONOGAME || FNA GraphicsDevice.Clear(Color.CornflowerBlue); TimeSpan total = gameTime.TotalGameTime; #elif STRIDE // Clear screen GraphicsContext.CommandList.Clear(GraphicsDevice.Presenter.BackBuffer, Color.CornflowerBlue); GraphicsContext.CommandList.Clear(GraphicsDevice.Presenter.DepthStencilBuffer, DepthStencilClearOptions.DepthBuffer | DepthStencilClearOptions.Stencil); // Set render target GraphicsContext.CommandList.SetRenderTargetAndViewport(GraphicsDevice.Presenter.DepthStencilBuffer, GraphicsDevice.Presenter.BackBuffer); TimeSpan total = gameTime.Total; #endif Vector2 scale = _animatedScaling ? new Vector2(1 + .25f * (float)Math.Sin(total.TotalSeconds * .5f)) : Vector2.One; // TODO: Add your drawing code here #if MONOGAME || FNA _spriteBatch.Begin(); #elif STRIDE _spriteBatch.Begin(GraphicsContext); #endif Vector2 cursor = Vector2.Zero; // Render some text _font = _currentFontSystem.GetFont(18); DrawString("The quick いろは brown\nfox にほへ jumps over\nt🙌h📦e l👏a👏zy dog adfasoqiw yraldh ald halwdha ldjahw dlawe havbx get872rq", ref cursor, Alignment.Left, scale); _font = _currentFontSystem.GetFont(30); DrawString("The quick いろは brown\nfox にほへ jumps over\nt🙌h📦e l👏a👏zy dog", ref cursor, Alignment.Left, Color.Bisque, scale); DrawString("Colored Text", ref cursor, Alignment.Left, ColoredTextColors, scale); // Render some scaled text with alignment using origin. Vector2 columnCursor = cursor; DrawString("Left-Justified", ref columnCursor, Alignment.Left, new Vector2(.75f) * scale); #if !STRIDE var width = GraphicsDevice.Viewport.Width; #else var width = GraphicsDevice.Presenter.BackBuffer.Width; #endif columnCursor = new Vector2(width / 2f, cursor.Y); DrawString("Centered", ref columnCursor, Alignment.Center, new Vector2(1) * scale); columnCursor = new Vector2(width, cursor.Y); DrawString("Right-Justified", ref columnCursor, Alignment.Right, new Vector2(1.5f) * scale); cursor = new Vector2(0, columnCursor.Y); // Render the atlas texture _font = _currentFontSystem.GetFont(26); DrawString("Texture:", ref cursor, Alignment.Left, Vector2.One); var texture = _currentFontSystem.EnumerateTextures().First(); _spriteBatch.Draw(texture, cursor, Color.White); _spriteBatch.End(); base.Draw(gameTime); }
protected override void DrawSelf(SpriteBatch spriteBatch) //Adapted from breath meter code { base.DrawSelf(spriteBatch); Player player = Main.player[Main.myPlayer]; var modPlayer = Main.LocalPlayer.GetModPlayer <ECPlayer>(); if (!(!modPlayer.PsychosisFull() || modPlayer.psychosisDelay2 > 0 || player.HasBuff(BuffType <Buffs.PsychedOut>()) && !player.dead)) { return; } //Thanks to Verveine for the revamped code Vector2 vector = (player.position + new Vector2(player.width * 0.5f, player.gravDir > 0 ? player.height - 10 + player.gfxOffY : 10 + player.gfxOffY)).Floor(); vector = Vector2.Transform(vector - Main.screenPosition, Main.GameViewMatrix.EffectMatrix * Main.GameViewMatrix.ZoomMatrix) / Main.UIScale; this.Left.Set(vector.X, 0f); this.Top.Set(vector.Y, 0f); CalculatedStyle dimensions = GetDimensions(); Point value = new Point((int)dimensions.X, (int)dimensions.Y); float precent = modPlayer.psychosis / modPlayer.TotalPsychosis(); int frameY = 0; if (player.HasBuff(BuffType <Buffs.PsychedOut>())) { //if (player.FindBuffIndex(mod.BuffType("PsychedOut")) <= 15) // frameY = 234; if (modPlayer.playerTic < 5) { frameY = 198; } else { frameY = 216; } } else { if (precent >= 1f) { frameY = 0; } else if (precent >= 0.9f) { frameY = 18; } else if (precent >= 0.8f) { frameY = 36; } else if (precent >= 0.7f) { frameY = 54; } else if (precent >= 0.6f) { frameY = 72; } else if (precent >= 0.5f) { frameY = 90; } else if (precent >= 0.4f) { frameY = 108; } else if (precent >= 0.3f) { frameY = 126; } else if (precent >= 0.2f) { frameY = 144; } else if (precent >= 0.1f) { frameY = 162; } else if (precent >= 0f) { frameY = 180; } else { frameY = 234; } } Main.spriteBatch.Draw(GetTexture("EsperClass/UI/PsychosisMeter"), new Vector2(value.X - 40, value.Y + 20f), new Rectangle(0, frameY, 74, 18), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); DynamicSpriteFont font = Main.fontMouseText; string psychosisText = (int)ECPlayer.ModPlayer(player).psychosis + " / " + ECPlayer.ModPlayer(player).TotalPsychosis(); Vector2 maxTextSize = font.MeasureString(psychosisText); Color textColor = new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor); Main.spriteBatch.DrawString(font, psychosisText, new Vector2(value.X + maxTextSize.X / 2f, value.Y + 40f), textColor, 0f, new Vector2(font.MeasureString(psychosisText).X, 0f), 1f, SpriteEffects.None, 0f); if (ECPlayer.ModPlayer(player).lihzahrdSetBonus) { float precent2 = modPlayer.lihzahrdPower / 30f; if (precent2 <= 0f) { frameY = 0; } else if (precent2 <= 0.1f) { frameY = 18; } else if (precent2 <= 0.2f) { frameY = 36; } else if (precent2 <= 0.3f) { frameY = 54; } else if (precent2 <= 0.4f) { frameY = 72; } else if (precent2 <= 0.5f) { frameY = 90; } else if (precent2 <= 0.6f) { frameY = 108; } else if (precent2 <= 0.7f) { frameY = 126; } else if (precent2 <= 0.8f) { frameY = 144; } else if (precent2 <= 0.9f) { frameY = 162; } else if (precent2 <= 1f) { frameY = 180; } Main.spriteBatch.Draw(GetTexture("EsperClass/UI/PsychosisMeterExtra"), new Vector2(value.X - 40, value.Y + 20f), new Rectangle(0, frameY, 74, 18), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } //spriteBatch.Draw(bubbleTexture, value + new Vector2((float)(26 * (j - 1) + num20) - 125f, 32f + ((float)bubbleTexture.Height - (float)bubbleTexture.Height * num23) / 2f + (float)num19), new Rectangle(0, 0, bubbleTexture.Width, bubbleTexture.Height), new Color(num22, num22, num22, num22), 0f, default(Vector2), num23, SpriteEffects.None, 0f); }
private string WordWrap(DynamicSpriteFont font, string text, float wrapWidth) { if (wrapWidth <= 0) { return(text); } // first step: break words. var words = new List <string>(); var w = ""; for (var i = 0; i <= text.Length; i++) { if (i < text.Length) { var ch = text[i]; w += ch; if (char.IsWhiteSpace(ch)) { words.Add(w); w = ""; } } else { if (!string.IsNullOrEmpty(w)) { words.Add(w); } } } // step 2: Line-wrap. var sb = new StringBuilder(); var lineWidth = 0f; for (var i = 0; i < words.Count; i++) { var word = words[i]; var m = font.MeasureString(word).X; var m2 = font.MeasureString(word.Trim()).X; if (lineWidth + m2 > wrapWidth && lineWidth > 0) // this makes the whole thing a lot less greedy { sb.Append(LineSeparator); lineWidth = 0; } if (m > lineWidth) { var letterWrapped = LetterWrap(font, word, wrapWidth); var lines = letterWrapped.Split(LineSeparator); var last = lines.Last(); m = font.MeasureString(last).X; word = last; sb.Append(letterWrapped); } else { sb.Append(word); } if (word.EndsWith(LineSeparator)) { lineWidth = 0; } else { lineWidth += m; } } return(sb.ToString()); }
public virtual float GetStringLength(DynamicSpriteFont font) { return((float)font.MeasureString(this.Text).X *this.Scale); }
private static void GetDistance( Player localPlayer, DynamicSpriteFont font, Player player, string nameToShow, out Vector2 namePlatePos, out float namePlateDist, out Vector2 measurement) { float uiScale = Main.UIScale; int screenWidth = Main.screenWidth; int screenHeight = Main.screenHeight; Vector2 screenPosition = Main.screenPosition; SpriteViewMatrix gameViewMatrix = Main.GameViewMatrix; namePlatePos = font.MeasureString(nameToShow); float num1 = 0.0f; if (player.chatOverhead.timeLeft > 0) { num1 = -namePlatePos.Y * uiScale; } else if (player.emoteTime > 0) { num1 = -namePlatePos.Y * uiScale; } Vector2 vector2_1 = new Vector2((float)(screenWidth / 2) + screenPosition.X, (float)(screenHeight / 2) + screenPosition.Y); Vector2 position = player.position; Vector2 vector2_2 = position + (position - vector2_1) * (gameViewMatrix.Zoom - Vector2.One); namePlateDist = 0.0f; float num2 = vector2_2.X + (float)(player.width / 2) - vector2_1.X; float num3 = (float)((double)vector2_2.Y - (double)namePlatePos.Y - 2.0) + num1 - vector2_1.Y; float num4 = (float)Math.Sqrt((double)num2 * (double)num2 + (double)num3 * (double)num3); int num5 = screenHeight; if (screenHeight > screenWidth) { num5 = screenWidth; } int num6 = num5 / 2 - 50; if (num6 < 100) { num6 = 100; } if ((double)num4 < (double)num6) { namePlatePos.X = (float)((double)vector2_2.X + (double)(player.width / 2) - (double)namePlatePos.X / 2.0) - screenPosition.X; namePlatePos.Y = (float)((double)vector2_2.Y - (double)namePlatePos.Y - 2.0) + num1 - screenPosition.Y; } else { namePlateDist = num4; float num7 = (float)num6 / num4; namePlatePos.X = (float)((double)(screenWidth / 2) + (double)num2 * (double)num7 - (double)namePlatePos.X / 2.0); namePlatePos.Y = (float)((double)(screenHeight / 2) + (double)num3 * (double)num7 + 40.0 * (double)uiScale); } measurement = font.MeasureString(nameToShow); namePlatePos += measurement / 2f; namePlatePos *= 1f / uiScale; namePlatePos -= measurement / 2f; if ((double)localPlayer.gravDir != -1.0) { return; } namePlatePos.Y = (float)screenHeight - namePlatePos.Y; }
public static Vector2 GetStringSize(DynamicSpriteFont font, string text, float scale) { return(font.MeasureString(text) * scale); }
public void Draw() { int namePlateDistance = Main.teamNamePlateDistance; if (namePlateDistance <= 0) { return; } this._playerOnScreenCache.Clear(); this._playerOffScreenCache.Clear(); SpriteBatch spriteBatch = Main.spriteBatch; PlayerInput.SetZoom_World(); PlayerInput.SetZoom_UI(); int num1 = namePlateDistance * 8; Player[] player1 = Main.player; int player2 = Main.myPlayer; byte mouseTextColor = Main.mouseTextColor; Color[] teamColor = Main.teamColor; Vector2 screenPosition = Main.screenPosition; Player localPlayer = player1[player2]; float num2 = (float)mouseTextColor / (float)byte.MaxValue; if (localPlayer.team == 0) { return; } DynamicSpriteFont font = FontAssets.MouseText.get_Value(); for (int index = 0; index < (int)byte.MaxValue; ++index) { if (index != player2) { Player player3 = player1[index]; if (player3.active && !player3.dead && player3.team == localPlayer.team) { string name = player3.name; Vector2 namePlatePos; float namePlateDist; Vector2 measurement; NewMultiplayerClosePlayersOverlay.GetDistance(localPlayer, font, player3, name, out namePlatePos, out namePlateDist, out measurement); Color color = new Color((int)(byte)((double)teamColor[player3.team].R * (double)num2), (int)(byte)((double)teamColor[player3.team].G * (double)num2), (int)(byte)((double)teamColor[player3.team].B * (double)num2), (int)mouseTextColor); if ((double)namePlateDist > 0.0) { float num3 = player3.Distance(localPlayer.Center); if ((double)num3 <= (double)num1) { float num4 = 20f; float num5 = -27f - (float)(((double)measurement.X - 85.0) / 2.0); string textValue = Language.GetTextValue("GameUI.PlayerDistance", (object)(int)((double)num3 / 16.0 * 2.0)); Vector2 npDistPos = font.MeasureString(textValue); npDistPos.X = namePlatePos.X - num5; npDistPos.Y = (float)((double)namePlatePos.Y + (double)measurement.Y / 2.0 - (double)npDistPos.Y / 2.0) - num4; this._playerOffScreenCache.Add(new NewMultiplayerClosePlayersOverlay.PlayerOffScreenCache(name, namePlatePos, color, npDistPos, textValue, player3, measurement)); } } else { this._playerOnScreenCache.Add(new NewMultiplayerClosePlayersOverlay.PlayerOnScreenCache(name, namePlatePos, color)); } } } } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOnScreenCache.Count; ++index) { this._playerOnScreenCache[index].DrawPlayerName_WhenPlayerIsOnScreen(spriteBatch); } NewMultiplayerClosePlayersOverlay.PlayerOffScreenCache playerOffScreenCache; for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerName(spriteBatch); } for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerDistance(spriteBatch); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawLifeBar(); } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, (BlendState)null, (SamplerState)null, (DepthStencilState)null, (RasterizerState)null, (Effect)null, Main.UIScaleMatrix); for (int index = 0; index < this._playerOffScreenCache.Count; ++index) { playerOffScreenCache = this._playerOffScreenCache[index]; playerOffScreenCache.DrawPlayerHead(); } }