protected override void Initialize() { Content.RootDirectory = "Content"; // Create all the services we need. UltimaServices.Register <SpriteBatch3D>(new SpriteBatch3D(this)); UltimaServices.Register <SpriteBatchUI>(new SpriteBatchUI(this)); Network = UltimaServices.Register <INetworkClient>(new NetworkClient()); Input = UltimaServices.Register <InputManager>(new InputManager(Window.Handle)); UserInterface = UltimaServices.Register <UserInterfaceService>(new UserInterfaceService()); // Make sure we have a UO installation before loading IO. if (!FileManager.IsUODataPresent) { return; } // Initialize and load data AnimData.Initialize(); Animations.Initialize(GraphicsDevice); ArtData.Initialize(GraphicsDevice); ASCIIText.Initialize(GraphicsDevice); TextUni.Initialize(GraphicsDevice); GumpData.Initialize(GraphicsDevice); HuesXNA.Initialize(GraphicsDevice); TexmapData.Initialize(GraphicsDevice); StringData.LoadStringList("enu"); SkillsData.Initialize(); GraphicsDevice.Textures[1] = HuesXNA.HueTexture0; GraphicsDevice.Textures[2] = HuesXNA.HueTexture1; EngineVars.EngineRunning = true; EngineVars.InWorld = false; ActiveModel = new LoginModel(); }
// pass bool = false to get the width of the line to be drawn without actually drawing anything. Useful for aligning text. unsafe void writeTexture_Line(List <AAtom> atoms, uint *rPtr, ref int x, int y, int linewidth, int maxHeight, ref int lineheight, bool draw) { for (int i = 0; i < atoms.Count; i++) { AFont font = TextUni.GetFont((int)atoms[i].Font); if (lineheight < font.Height) { lineheight = font.Height; } if (draw) { if (atoms[i] is CharacterAtom) { CharacterAtom atom = (CharacterAtom)atoms[i]; ACharacter character = font.GetCharacter(atom.Character); // HREF links should be colored white, because we will hue them at runtime. uint color = atom.IsHREF ? 0xFFFFFFFF : Utility.UintFromColor(atom.Color); character.WriteToBuffer(rPtr, x, y, linewidth, maxHeight, font.Baseline, atom.Style_IsBold, atom.Style_IsItalic, atom.Style_IsUnderlined, atom.Style_IsOutlined, color, 0xFF000008); } else if (atoms[i] is ImageAtom) { ImageAtom atom = (ImageAtom)atoms[i]; if (lineheight < atom.Height) { lineheight = atom.Height; } Images.AddImage(new Rectangle(x, y + (lineheight - atom.Height) / 2, atom.Width, atom.Height), atom.Texture, GumpData.GetGumpXNA(atom.ValueOver), GumpData.GetGumpXNA(atom.ValueDown)); atom.AssociatedImage = Images[Images.Count - 1]; } } x += atoms[i].Width; } }
void getTextDimensions(Reader reader, int maxwidth, int maxheight, out int width, out int height, out int ascender) { width = 0; height = 0; ascender = 0; int lineheight = 0; int widestline = 0; int descenderheight = 0; int linecount = 0; List <AAtom> word = new List <AAtom>(); int additionalwidth = 0; // for italic + outlined characters, which need a little more room for their slant/outline. int word_width = 0; for (int i = 0; i < reader.Length; ++i) { word_width += reader.Atoms[i].Width; additionalwidth -= reader.Atoms[i].Width; if (additionalwidth < 0) { additionalwidth = 0; } if (lineheight < reader.Atoms[i].Height) { lineheight = reader.Atoms[i].Height; } if (reader.Atoms[i].IsThisAtomALineBreak) { if (width + additionalwidth > widestline) { widestline = width + additionalwidth; } height += lineheight; linecount += 1; descenderheight = 0; lineheight = 0; width = 0; } else { word.Add(reader.Atoms[i]); // we may need to add additional width for special style characters. if (reader.Atoms[i] is CharacterAtom) { CharacterAtom atom = (CharacterAtom)reader.Atoms[i]; AFont font = TextUni.GetFont((int)atom.Font); ACharacter ch = font.GetCharacter(atom.Character); // italic characters need a little extra width if they are at the end of the line. if (atom.Style_IsItalic) { additionalwidth = font.Height / 2; } if (atom.Style_IsOutlined) { additionalwidth += 2; } if (ch.YOffset + ch.Height - lineheight > descenderheight) { descenderheight = ch.YOffset + ch.Height - lineheight; } if (ch.YOffset < 0 && linecount == 0 && ascender > ch.YOffset) { ascender = ch.YOffset; } } if (reader.Atoms[i].Alignment != Alignments.Left) { widestline = maxwidth; } if (i == reader.Length - 1 || reader.Atoms[i + 1].CanBreakAtThisAtom) { // Now make sure this line can fit the word. if (width + word_width + additionalwidth <= maxwidth) { // it can fit! width += word_width + additionalwidth; word_width = 0; word.Clear(); // if this word is followed by a space, does it fit? If not, drop it entirely and insert \n after the word. if (!(i == reader.Length - 1) && reader.Atoms[i + 1].IsThisAtomABreakingSpace) { int charwidth = reader.Atoms[i + 1].Width; if (width + charwidth <= maxwidth) { // we can fit an extra space here. width += charwidth; i++; } else { // can't fit an extra space on the end of the line. replace the space with a \n. ((CharacterAtom)reader.Atoms[i + 1]).Character = '\n'; } } } else { // this word cannot fit in the current line. if ((width > 0) && (i - word.Count >= 0)) { // if this is the last word in a line. Replace the last space character with a line break // and back up to the beginning of this word. if (reader.Atoms[i - word.Count].IsThisAtomABreakingSpace) { ((CharacterAtom)reader.Atoms[i - word.Count]).Character = '\n'; i = i - word.Count - 1; } else { reader.Atoms.Insert(i - word.Count, new CharacterAtom('\n')); i = i - word.Count; } word.Clear(); word_width = 0; } else { // this is the only word on the line and we will need to split it. // first back up until we've reached the reduced the size of the word // so that it fits on one line, and split it there. int iWordWidth = word_width; for (int j = word.Count - 1; j >= 1; j--) { int iDashWidth = TextUni.GetFont((int)word[j].Font).GetCharacter('-').Width; if (iWordWidth + iDashWidth <= maxwidth) { reader.Atoms.Insert(i - (word.Count - j) + 1, new CharacterAtom('\n')); reader.Atoms.Insert(i - (word.Count - j) + 1, new CharacterAtom('-')); break; } iWordWidth -= word[j].Width; } i -= word.Count + 2; if (i < 0) { i = -1; } word.Clear(); width = 0; word_width = 0; } } } } } width += additionalwidth; height += lineheight + descenderheight; linecount += 1; if (widestline > width) { width = widestline; } }
public override void Update(double totalMS, double frameMS) { if (m_TextEntry == null) { m_TextEntry = new TextEntry(this, 0, 1, m_UserInterface.Height - TextUni.GetFont(0).Height, 400, TextUni.GetFont(0).Height, 0, 0, 64, string.Empty); m_TextEntry.LegacyCarat = true; AddControl(new CheckerTrans(this, 0, 0, m_UserInterface.Height - 20, m_UserInterface.Width, 20)); AddControl(m_TextEntry); } int y = m_TextEntry.Y - 48; for (int i = 0; i < m_TextEntries.Count; i++) { m_TextEntries[i].Update(totalMS, frameMS); if (m_TextEntries[i].IsExpired) { m_TextEntries[i].Dispose(); m_TextEntries.RemoveAt(i); i--; } } // Ctrl-Q = Cycle backwards through the things you have said today // Ctrl-W = Cycle forwards through the things you have said today if (m_Input.HandleKeyboardEvent(KeyboardEventType.Down, WinKeys.Q, false, false, true) && m_MessageHistoryIndex > -1) { if (m_MessageHistoryIndex > 0) { m_MessageHistoryIndex -= 1; } m_TextEntry.Text = m_MessageHistory[m_MessageHistoryIndex]; } else if (m_Input.HandleKeyboardEvent(KeyboardEventType.Down, WinKeys.W, false, false, true)) { if (m_MessageHistoryIndex < m_MessageHistory.Count - 1) { m_MessageHistoryIndex += 1; m_TextEntry.Text = m_MessageHistory[m_MessageHistoryIndex]; } else { m_TextEntry.Text = string.Empty; } } base.Update(totalMS, frameMS); }
public SpanAtom() { m_height = TextUni.GetFont((int)Font).Height; }