private void DrawCharacter(SpriteBatch batch, string text, int index, Vector2 position, SpriteFont font, RectangleF sourceRect, float drawDepth, bool isNameplate) { DialogueEffectInstance effectInstance = GetCurrentDialogueEffectInstance(text, index, isNameplate); Color outlineColor = new Color(Color.Black, alpha); Color color = new Color(Color.White, alpha); if (effectInstance != null) { if (effectInstance.dialogueEffect.effect != null) { if (effectInstance.dialogueEffect.effect == "shake" || effectInstance.dialogueEffect.effect == "glitch_sml") { position += new Vector2(Utility.rand.NextFloat(-2, 2), Utility.rand.NextFloat(-2, 2)); } if (effectInstance.dialogueEffect.effect == "sine") { int rate = 60; float percent = (float)((sineTimer + (index * 5)) % rate) / (float)rate; float sine = (float)Math.Sin(MathHelper.Pi * 2 * percent) * 4; position.Y += sine; } } if (effectInstance.dialogueEffect.color != null) { string colorRGBA = effectInstance.dialogueEffect.color; string[] rgba = colorRGBA.Replace(" ", "").Split(','); bool hasR = int.TryParse(rgba[0], out int r); bool hasG = int.TryParse(rgba[1], out int g); bool hasB = int.TryParse(rgba[2], out int b); bool hasA = int.TryParse(rgba[3], out int a); if (hasR) { color.R = (byte)r; } if (hasG) { color.G = (byte)g; } if (hasB) { color.B = (byte)b; } if (hasA) { color.A = (byte)a; } } } /*batch.Draw(font.Texture, position + new Vector2(-2, 0), sourceRect.ToRectangle(), outlineColor, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth - 0.01f); * batch.Draw(font.Texture, position + new Vector2(2, 0), sourceRect.ToRectangle(), outlineColor, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth - 0.01f); * batch.Draw(font.Texture, position + new Vector2(0, -2), sourceRect.ToRectangle(), outlineColor, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth - 0.01f); * batch.Draw(font.Texture, position + new Vector2(0, 2), sourceRect.ToRectangle(), outlineColor, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth - 0.01f);*/ batch.Draw(font.Texture, position, sourceRect.ToRectangle(), color, 0, Vector2.Zero, 1, SpriteEffects.None, drawDepth); }
private void UpdateText() { if (letterDelay <= 0) { if (currentSubstringIndex < fullText.Length) { while (letterDelay == 0) { letterDelay = currentDialogueSet.currentDialogue.letterDelay; currentSubstringIndex++; currentText = fullText.Substring(0, currentSubstringIndex); DialogueCharacterAdded?.Invoke(currentText[currentSubstringIndex - 1]); DialogueEffectInstance currentInstance = GetCurrentDialogueEffectInstance(currentText, currentSubstringIndex, false); if (currentInstance != null) { if (currentSubstringIndex == currentInstance.start) { letterDelay += currentInstance.dialogueEffect.preDelay; } if (currentSubstringIndex == currentInstance.end) { letterDelay += currentInstance.dialogueEffect.postDelay; } if (currentInstance.dialogueEffect.appearInstantly && currentSubstringIndex > currentInstance.start && currentSubstringIndex < currentInstance.end) { letterDelay = 0; } } } } else { currentFinished = true; } } else { letterDelay--; } }
private void RecreateDrawString(SpriteBatch batch, Vector2 position, SpriteFont font, string text, float drawDepth, bool isNameplate) { Vector2 offset = Vector2.Zero; bool firstGlyphOfLine = true; var glyphs = font.GetGlyphs(); for (int i = 0; i < text.Length; i++) { char character = text[i]; if (character == '\r') { continue; } if (character == '\n') { offset.X = 0; offset.Y += font.LineSpacing; firstGlyphOfLine = true; continue; } DialogueEffectInstance effectInstance = GetCurrentDialogueEffectInstance(text, i, isNameplate); if (effectInstance != null && effectInstance.dialogueEffect.effect == "glitch_sml") { int times = Utility.rand.Next(-3, 3); if (times > 0) { string characters = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789-=" + "!@#$%^&*()_+" + "{}[]\\|'\";:,<.>/?"; character = characters[Utility.rand.Next(0, characters.Length - 1)]; } } SpriteFont.Glyph currentGlyph = glyphs[character]; if (firstGlyphOfLine) { offset.X = Math.Max(currentGlyph.LeftSideBearing, 0); firstGlyphOfLine = false; } else { offset.X += font.Spacing + currentGlyph.LeftSideBearing; } Vector2 finalPos = offset; finalPos.X += currentGlyph.Cropping.X; finalPos.Y += currentGlyph.Cropping.Y; finalPos += position; RectangleF sourceRect = new RectangleF(); sourceRect.x = currentGlyph.BoundsInTexture.X; sourceRect.y = currentGlyph.BoundsInTexture.Y; sourceRect.width = currentGlyph.BoundsInTexture.Width; sourceRect.height = currentGlyph.BoundsInTexture.Height; DrawCharacter(batch, text, i, finalPos, font, sourceRect, drawDepth, isNameplate); offset.X += currentGlyph.Width + currentGlyph.RightSideBearing; } }