public TextLabel(DaggerfallFont font = null) { if (font != null) { Font = font; } }
public StatsRollout() : base() { // Add stat labels font = DaggerfallUI.DefaultFont; Vector2 pos = new Vector2(19, 33); for (int i = 0; i < DaggerfallStats.Count; i++) { statLabels[i] = DaggerfallUI.AddTextLabel(font, pos, string.Empty, this); statLabels[i].ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; pos.y += 22f; } // Add stat select buttons pos = new Vector2(7, 20); Vector2 size = new Vector2(36, 20); for (int i = 0; i < DaggerfallStats.Count; i++) { Button button = DaggerfallUI.AddButton(pos, size, this); button.Tag = i; button.OnMouseClick += StatButton_OnMouseClick; pos.y += 22; } // Add up/down spinner spinner = new UpDownSpinner(); this.Components.Add(spinner); spinner.OnUpButtonClicked += Spinner_OnUpButtonClicked; spinner.OnDownButtonClicked += Spinner_OnDownButtonClicked; SelectStat(0); UpdateStatLabels(); }
public TextBox() { font = DaggerfallUI.DefaultFont; Components.Add(textCursor); MaxSize = CalculateMaximumSize(); this.Size = CalculateCurrentSize(); }
/// <summary> /// Adds a single text item. /// Each subsequent text item will be appended to the previous text item position. /// Call NewLine() to start a new line. /// </summary> /// <param name="text">Text for this label.</param> /// <param name="font">Font for this label.</param> /// <param name="color">Text color for this label.</param> /// <returns>TextLabel.</returns> public TextLabel AddTextLabel(string text, DaggerfallFont font, Color color) { TextLabel textLabel = new TextLabel(); textLabel.AutoSize = AutoSizeModes.None; textLabel.MinTextureDim = minTextureDimTextLabel; textLabel.Font = font; textLabel.Position = new Vector2(cursorX, cursorY); textLabel.WrapText = wrapText; textLabel.WrapWords = wrapWords; textLabel.TextScale = TextScale; // Use max width if it has been specified if (maxTextWidth > 0) { textLabel.MaxWidth = maxTextWidth; } textLabel.Text = text; textLabel.Parent = this; textLabel.TextColor = color; textLabel.ShadowColor = ShadowColor; textLabel.ShadowPosition = ShadowPosition; if (textAlignment != HorizontalAlignment.None) { textLabel.HorizontalAlignment = textAlignment; } labels.Add(textLabel); lastLabel = textLabel; cursorX += textLabel.TextWidth; return(textLabel); }
DaggerfallFont GetFont() { if (font == null) { font = DaggerfallUI.DefaultFont; } return(font); }
public TextBox(DaggerfallFont font = null) { if (font == null) this.font = DaggerfallUI.DefaultFont; else this.font = font; Components.Add(textCursor); MaxSize = CalculateMaximumSize(); this.Size = CalculateCurrentSize(); }
public TextBox(DaggerfallFont font = null) { if (font == null) { this.font = DaggerfallUI.DefaultFont; } else { this.font = font; } Components.Add(textCursor); MaxSize = CalculateMaximumSize(); this.Size = CalculateCurrentSize(); }
TextGroup CreateEmptyTextGroup(DaggerfallFont font = null) { if (font == null) { font = DaggerfallUI.DefaultFont; } return(new TextGroup() { text = string.Empty, font = font, alignment = HorizontalAlignment.None, color = DaggerfallUI.DaggerfallDefaultTextColor, }); }
public void AddItem(string text, out ListItem itemOut, int position = -1, object tag = null) { if (font == null) { font = DaggerfallUI.DefaultFont; } TextLabel textLabel = new TextLabel(); if (UseRestrictedRenderArea) { textLabel.RectRestrictedRenderArea = RectRestrictedRenderArea; textLabel.RestrictedRenderAreaCoordinateType = RestrictedRenderAreaCoordinateType; textLabel.RestrictedRenderAreaCustomParent = RestrictedRenderAreaCustomParent; } if (horizontalScrollMode == HorizontalScrollModes.CharWise) { textLabel.MaxWidth = (int)Size.x; } else if (horizontalScrollMode == HorizontalScrollModes.PixelWise) { textLabel.MaxWidth = -1; } textLabel.AutoSize = AutoSizeModes.None; textLabel.HorizontalAlignment = rowAlignment; textLabel.Font = font; textLabel.MaxCharacters = maxCharacters; textLabel.Text = text; textLabel.TextScale = textScale; textLabel.Parent = this; textLabel.WrapText = wrapTextItems; textLabel.WrapWords = wrapWords; itemOut = new ListItem(textLabel); itemOut.textColor = textColor; itemOut.selectedTextColor = selectedTextColor; itemOut.shadowColor = shadowColor; itemOut.selectedShadowColor = selectedShadowColor; itemOut.tag = tag; if (position < 0) { listItems.Add(itemOut); } else { listItems.Insert(position, itemOut); } }
public virtual void RefreshLayout() { // Use default UI font if none set if (font == null) { font = DaggerfallUI.DefaultFont; } if (!wrapText) { CreateNewLabelLayoutSingleLine(); } else { CreateNewLabelLayoutWrapped(); } }
public TextBox(DaggerfallFont font = null) { if (font == null) { this.font = DaggerfallUI.DefaultFont; } else { this.font = font; } Components.Add(textCursor); MaxSize = CalculateMaximumSize(); if (!fixedSize) { this.Size = CalculateCurrentSize(); } previousSDFState = this.font.IsSDFCapable; }
public bool ReformatBook(string filename) { if (string.IsNullOrEmpty(filename)) { return(false); } // Try to open book BookFile book = new BookFile(); if (!BookReplacement.TryImportBook(filename, book) && !book.OpenBook(DaggerfallUnity.Instance.Arena2Path, filename)) { return(false); } // Clear existing Clear(); // Combine all tokens from all pages // The classic concept of pages becomes List <TextFile.Token> allPageTokens = new List <TextFile.Token>(); for (int page = 0; page < book.PageCount; page++) { TextFile.Token[] tokens = book.GetPageTokens(page); foreach (TextFile.Token token in tokens) { allPageTokens.Add(token); } } // Read all tokens and merge into text groups DaggerfallFont prevFont = DaggerfallUI.DefaultFont; TextFile.Token prevToken = new TextFile.Token(TextFile.Formatting.Nothing); TextGroup workingGroup = CreateEmptyTextGroup(prevFont); foreach (TextFile.Token token in allPageTokens) { switch (token.formatting) { // Set font on current group case TextFile.Formatting.FontPrefix: workingGroup.font = prevFont = DaggerfallUI.Instance.GetFont(token.x); break; // Text is added to working group case TextFile.Formatting.Text: workingGroup.text += token.text; break; // Newline becomes a space unless previous token was also newline // This will be treated as a paragraph break case TextFile.Formatting.NewLine: if (prevToken.formatting == TextFile.Formatting.NewLine) { StoreGroup(workingGroup); StoreLineBreakGroup(); workingGroup = CreateEmptyTextGroup(prevFont); } else { workingGroup.text += space; } break; // Set left justify on current group case TextFile.Formatting.JustifyLeft: workingGroup.alignment = HorizontalAlignment.None; break; // Set centre justify on current group case TextFile.Formatting.JustifyCenter: workingGroup.alignment = HorizontalAlignment.Center; break; } prevToken = token; } return(true); }
public DaggerfallFont GetFont(int index) { // Set path string path = string.Empty; if (dfUnity.IsPathValidated) path = dfUnity.Arena2Path; // Try to load font from either Daggerfall path or Resources switch (index) { case 1: if (daggerfallFonts[0] == null) daggerfallFonts[0] = new DaggerfallFont(path, DaggerfallFont.FontName.FONT0000); daggerfallFonts[0].FilterMode = globalFilterMode; return daggerfallFonts[0]; case 2: if (daggerfallFonts[1] == null) daggerfallFonts[1] = new DaggerfallFont(path, DaggerfallFont.FontName.FONT0001); daggerfallFonts[1].FilterMode = globalFilterMode; return daggerfallFonts[1]; case 3: if (daggerfallFonts[2] == null) daggerfallFonts[2] = new DaggerfallFont(path, DaggerfallFont.FontName.FONT0002); daggerfallFonts[2].FilterMode = globalFilterMode; return daggerfallFonts[2]; case 4: default: if (daggerfallFonts[3] == null) daggerfallFonts[3] = new DaggerfallFont(path, DaggerfallFont.FontName.FONT0003); daggerfallFonts[3].FilterMode = globalFilterMode; return daggerfallFonts[3]; case 5: if (daggerfallFonts[4] == null) daggerfallFonts[4] = new DaggerfallFont(path, DaggerfallFont.FontName.FONT0004); daggerfallFonts[4].FilterMode = globalFilterMode; return daggerfallFonts[4]; } }
public StatsRollout(bool onCharacterSheet = false) : base() { if (onCharacterSheet) { characterSheetPositioning = true; } // Add stat labels font = DaggerfallUI.DefaultFont; Vector2 pos; if (!onCharacterSheet) { pos = new Vector2(19, 33); } else { pos = new Vector2(150, 17); } for (int i = 0; i < DaggerfallStats.Count; i++) { statLabels[i] = DaggerfallUI.AddTextLabel(font, pos, string.Empty, this); statLabels[i].ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; if (!onCharacterSheet) { pos.y += 22f; } else { pos.y += 24f; } } // Add stat select buttons if (!onCharacterSheet) { pos = new Vector2(7, 20); } else { pos = new Vector2(141, 6); } Vector2 size; if (!onCharacterSheet) { size = new Vector2(36, 20); } else { size = new Vector2(28, 20); } for (int i = 0; i < DaggerfallStats.Count; i++) { Button button = DaggerfallUI.AddButton(pos, size, this); button.Tag = i; button.OnMouseClick += StatButton_OnMouseClick; if (!onCharacterSheet) { pos.y += 22f; } else { pos.y += 24f; } } // Add up/down spinner spinner = new UpDownSpinner(); this.Components.Add(spinner); spinner.OnUpButtonClicked += Spinner_OnUpButtonClicked; spinner.OnDownButtonClicked += Spinner_OnDownButtonClicked; SelectStat(0); UpdateStatLabels(); }
public TextLabel(DaggerfallFont font = null) { if (font != null) Font = font; }
public StatsRollout(bool onCharacterSheet = false, bool freeEdit = false) : base() { if (onCharacterSheet) { characterSheetPositioning = true; } if (freeEdit) { this.freeEdit = true; modifiedStatTextColor = DaggerfallUI.DaggerfallDefaultTextColor; } // Add stat panels and labels font = DaggerfallUI.DefaultFont; Vector2 panelPos, panelSize; if (!onCharacterSheet) { panelPos = new Vector2(8, 33); panelSize = new Vector2(34, 6); } else { panelPos = new Vector2(141, 17); panelSize = new Vector2(28, 6); } for (int i = 0; i < DaggerfallStats.Count; i++) { statPanels[i] = DaggerfallUI.AddPanel(new Rect(panelPos.x, panelPos.y, panelSize.x, panelSize.y), this); statLabels[i] = DaggerfallUI.AddTextLabel(font, Vector2.zero, string.Empty, statPanels[i]); statLabels[i].HorizontalAlignment = HorizontalAlignment.Center; statLabels[i].ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; if (!onCharacterSheet) { panelPos.y += 22f; } else { panelPos.y += 24f; } } // Add stat select buttons Vector2 pos; if (!onCharacterSheet) { pos = new Vector2(7, 20); } else { pos = new Vector2(141, 6); } Vector2 size; if (!onCharacterSheet) { size = new Vector2(36, 20); } else { size = new Vector2(28, 20); } for (int i = 0; i < DaggerfallStats.Count; i++) { Button button = DaggerfallUI.AddButton(pos, size, this); button.Tag = i; button.OnMouseClick += StatButton_OnMouseClick; if (!onCharacterSheet) { pos.y += 22f; } else { pos.y += 24f; } } // Add up/down spinner spinner = new UpDownSpinner(); this.Components.Add(spinner); spinner.OnUpButtonClicked += Spinner_OnUpButtonClicked; spinner.OnDownButtonClicked += Spinner_OnDownButtonClicked; SelectStat(0); UpdateStatLabels(); }
void ChangeFont(int index) { currentFont = DaggerfallUI.Instance.GetFont(index); }
public ToolTip() { font = DaggerfallUI.DefaultFont; BackgroundColor = DaggerfallUI.DaggerfallUnityDefaultToolTipBackgroundColor; SetMargins(Margins.All, defaultMarginSize); }
public SkillsRollout() : base() { font = DaggerfallUI.DefaultFont; SetupControls(); }
void CreateNewLabelLayoutWrapped() { // Use default UI font if none set if (font == null) { font = DaggerfallUI.DefaultFont; } // // Stage 1 - Encode glyphs and calculate final dimensions // // Start a new layout labelLayout = new LabelLayoutData(); List <GlyphLayoutData> glyphLayout = new List <GlyphLayoutData>(); // Set a local maxWidth that compensates for textScale int maxWidth = (int)(this.maxWidth / textScale); // First pass encodes ASCII and calculates final dimensions int width = 0; int greatestWidthFound = 0; int lastEndOfRowByte = 0; asciiBytes = Encoding.ASCII.GetBytes(text); List <byte[]> rows = new List <byte[]>(); List <int> rowWidth = new List <int>(); for (int i = 0; i < asciiBytes.Length; i++) { // Invalid ASCII bytes are cast to a space character if (!font.HasGlyph(asciiBytes[i])) { asciiBytes[i] = DaggerfallFont.SpaceCode; } // Calculate total width DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); // If maxWidth is set, don't allow the label texture to exceed it if ((maxWidth <= 0) || ((width + glyph.width + font.GlyphSpacing) <= maxWidth)) { width += glyph.width + font.GlyphSpacing; } else { int rowLength; if (wrapWords) { int j; for (j = i; j >= lastEndOfRowByte; j--) { glyph = font.GetGlyph(asciiBytes[j]); if (j < i) // glyph i has not been added to width { width -= glyph.width + font.GlyphSpacing; if (width <= maxWidth && asciiBytes[j] == DaggerfallFont.SpaceCode) { break; } } } if (j > lastEndOfRowByte) // space found in row at position that is not exceeding maxWidth for all summed glyph's widths before this position { i = j; // set new processing position (j is the space position, i will be increased on next loop iteration to point to next chat after the space char) rowLength = j - lastEndOfRowByte; // set length from row start to position before space } else { rowLength = i - lastEndOfRowByte; } // compute width of text-wrapped line width = 0; for (int k = lastEndOfRowByte; k < j; k++) { if (k < j - 1 || (k == j - 1 && asciiBytes[k] != DaggerfallFont.SpaceCode)) // all expect last character if it is a space { glyph = font.GetGlyph(asciiBytes[k]); width += glyph.width + font.GlyphSpacing; } } } else { rowLength = i - lastEndOfRowByte; } // The row of glyphs exceeded maxWidth. Add it to the list of rows and start // counting width again with the remainder of the ASCII bytes. List <byte> content = new List <byte>(asciiBytes).GetRange(lastEndOfRowByte, rowLength); if (content[content.Count - 1] == DaggerfallFont.SpaceCode) { content.RemoveAt(content.Count - 1); } byte[] trimmed = content.ToArray(); rows.Add(trimmed); rowWidth.Add(width); // update greatest width found so far if (greatestWidthFound < width) { greatestWidthFound = width; } // reset width for next line width = 0; lastEndOfRowByte = i + 1; // position after space for next line, note: i will be increased on next loop iteration anyway - so no need to increase i } } if (lastEndOfRowByte > 0) { asciiBytes = new List <byte>(asciiBytes).GetRange(lastEndOfRowByte, asciiBytes.Length - lastEndOfRowByte).ToArray(); } // also get width of last line width = 0; for (int i = 0; i < asciiBytes.Length; i++) { DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); width += glyph.width + font.GlyphSpacing; } // update greatest width found so far if (width <= maxWidth && greatestWidthFound < width) // width should always be <= maxWidth here { greatestWidthFound = width; } rows.Add(asciiBytes); rowWidth.Add(width); // Create virtual layout area totalWidth = maxWidth; totalHeight = (int)(rows.Count * font.GlyphHeight); numTextLines = rows.Count; // // Stage 2 - Add glyphs to layout // // Second pass adds glyphs to label texture float xpos = 0; float ypos = totalHeight - font.GlyphHeight; //foreach (byte[] row in rows) for (int r = 0; r < rows.Count; r++) { byte[] row = rows[r]; float alignmentOffset; switch (horizontalTextAlignment) { default: case HorizontalTextAlignmentSetting.None: case HorizontalTextAlignmentSetting.Left: case HorizontalTextAlignmentSetting.Justify: alignmentOffset = 0.0f; break; case HorizontalTextAlignmentSetting.Center: alignmentOffset = (totalWidth - rowWidth[r]) * 0.5f; break; case HorizontalTextAlignmentSetting.Right: alignmentOffset = totalWidth - rowWidth[r]; break; } int numSpaces = 0; // needed to compute extra offset between words for HorizontalTextAlignmentSetting.Justify int extraSpaceToDistribute = 0; // needed to compute extra offset between words for HorizontalTextAlignmentSetting.Justify if (horizontalTextAlignment == HorizontalTextAlignmentSetting.Justify) { for (int i = 0; i < row.Length; i++) { if (row[i] == DaggerfallFont.SpaceCode) { numSpaces++; } } extraSpaceToDistribute = maxWidth - rowWidth[r]; } xpos = (int)alignmentOffset; for (int i = 0; i < row.Length; i++) { DaggerfallFont.GlyphInfo glyph = font.GetGlyph(row[i]); if (xpos + glyph.width > totalWidth) { break; } if (row[i] == DaggerfallFont.SpaceCode) { if (numSpaces > 1) { int currentPortionExtraSpaceToDistribute = (int)Mathf.Round((float)extraSpaceToDistribute / (float)numSpaces); xpos += currentPortionExtraSpaceToDistribute; extraSpaceToDistribute -= currentPortionExtraSpaceToDistribute; numSpaces--; } else if (numSpaces == 1) { xpos += extraSpaceToDistribute; } } GlyphLayoutData glyphPos = new GlyphLayoutData() { x = xpos, y = totalHeight - font.GlyphHeight - ypos, glyphRawAscii = row[i], glyphWidth = glyph.width, }; glyphLayout.Add(glyphPos); xpos += glyph.width + font.GlyphSpacing; } ypos -= font.GlyphHeight; } labelLayout.glyphLayout = glyphLayout.ToArray(); this.Size = new Vector2(totalWidth * textScale, totalHeight * textScale); }
void CreateLabelTextureSingleLine() { if (font == null) { font = DaggerfallUI.DefaultFont; } // set a local maxWidth that compensates for textScale int maxWidth = (int)(this.maxWidth / textScale); // First pass encodes ASCII and calculates final dimensions int width = 0; asciiBytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("ISO-8859-1"), Encoding.Default.GetBytes(text)); for (int i = startCharacterIndex; i < asciiBytes.Length; i++) { // Invalid ASCII bytes are cast to a space character if (!font.HasGlyph(asciiBytes[i])) { asciiBytes[i] = DaggerfallFont.SpaceASCII; } // Calculate total width DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); width += glyph.width + font.GlyphSpacing; } if (maxWidth > 0 && width > maxWidth) { width = maxWidth; } // Destroy old texture if (singleLineLabelTexture) { UnityEngine.Object.Destroy(singleLineLabelTexture); } // Create target label texture totalWidth = width; totalHeight = (int)(font.GlyphHeight); numTextLines = 1; singleLineLabelTexture = CreateLabelTexture(totalWidth, totalHeight); if (singleLineLabelTexture == null) { throw new Exception("TextLabel failed to create single line labelTexture."); } float alignmentOffset; switch (horizontalTextAlignment) { default: case HorizontalTextAlignmentSetting.None: case HorizontalTextAlignmentSetting.Left: case HorizontalTextAlignmentSetting.Justify: alignmentOffset = 0.0f; break; case HorizontalTextAlignmentSetting.Center: alignmentOffset = (totalWidth - width) * 0.5f; break; case HorizontalTextAlignmentSetting.Right: alignmentOffset = totalWidth - width; break; } // Second pass adds glyphs to label texture int xpos = (int)alignmentOffset; for (int i = startCharacterIndex; i < asciiBytes.Length; i++) { DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); if (xpos + glyph.width >= totalWidth) { break; } singleLineLabelTexture.SetPixels32(xpos, 0, glyph.width, totalHeight, glyph.colors); xpos += glyph.width + font.GlyphSpacing; } singleLineLabelTexture.Apply(false, makeTextureNoLongerReadable); singleLineLabelTexture.filterMode = font.FilterMode; this.Size = new Vector2(totalWidth * textScale, totalHeight * textScale); }
public DaggerfallFont GetFont(int index) { // Do nothing if DaggerfallUnity path not valid if (!DaggerfallUnity.Instance.IsPathValidated) return null; switch (index) { case 1: if (daggerfallFonts[0] == null) daggerfallFonts[0] = new DaggerfallFont(dfUnity.Arena2Path, DaggerfallFont.FontName.FONT0000); daggerfallFonts[0].FilterMode = globalFilterMode; return daggerfallFonts[0]; case 2: if (daggerfallFonts[1] == null) daggerfallFonts[1] = new DaggerfallFont(dfUnity.Arena2Path, DaggerfallFont.FontName.FONT0001); daggerfallFonts[1].FilterMode = globalFilterMode; return daggerfallFonts[1]; case 3: if (daggerfallFonts[2] == null) daggerfallFonts[2] = new DaggerfallFont(dfUnity.Arena2Path, DaggerfallFont.FontName.FONT0002); daggerfallFonts[2].FilterMode = globalFilterMode; return daggerfallFonts[2]; case 4: default: if (daggerfallFonts[3] == null) daggerfallFonts[3] = new DaggerfallFont(dfUnity.Arena2Path, DaggerfallFont.FontName.FONT0003); daggerfallFonts[3].FilterMode = globalFilterMode; return daggerfallFonts[3]; case 5: if (daggerfallFonts[4] == null) daggerfallFonts[4] = new DaggerfallFont(dfUnity.Arena2Path, DaggerfallFont.FontName.FONT0004); daggerfallFonts[4].FilterMode = globalFilterMode; return daggerfallFonts[4]; } }
protected override void Setup() { if (IsSetup) return; // Load native texture nativeTexture = DaggerfallUI.GetTextureFromImg(nativeImgName); if (!nativeTexture) throw new Exception("CreateCharAddBonusStats: Could not load native texture."); // Setup native panel background NativePanel.BackgroundTexture = nativeTexture; // Add stats rollout statsRollout = new StatsRollout(); statsRollout.Position = new Vector2(0, 0); statsRollout.OnStatChanged += StatsRollout_OnStatChanged; NativePanel.Components.Add(statsRollout); // Add secondary stat labels font = DaggerfallUI.DefaultFont; damageModifierLabel = DaggerfallUI.AddTextLabel(font, new Vector2(83, 22), string.Empty, NativePanel); maxEncumbranceLabel = DaggerfallUI.AddTextLabel(font, new Vector2(103, 32), string.Empty, NativePanel); spellPointsLabel = DaggerfallUI.AddTextLabel(font, new Vector2(112, 49), string.Empty, NativePanel); magicResistLabel = DaggerfallUI.AddTextLabel(font, new Vector2(121, 71), string.Empty, NativePanel); toHitModifierLabel = DaggerfallUI.AddTextLabel(font, new Vector2(97, 93), string.Empty, NativePanel); hitPointsModifierLabel = DaggerfallUI.AddTextLabel(font, new Vector2(101, 110), string.Empty, NativePanel); healingRateModifierLabel = DaggerfallUI.AddTextLabel(font, new Vector2(122, 120), string.Empty, NativePanel); // Fix secondary stat shadow colors to match game damageModifierLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; maxEncumbranceLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; spellPointsLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; magicResistLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; toHitModifierLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; hitPointsModifierLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; healingRateModifierLabel.ShadowColor = DaggerfallUI.DaggerfallAlternateShadowColor1; // Add "Reroll" button Button rerollButton = DaggerfallUI.AddButton(new Rect(263, 147, 39, 22), NativePanel); rerollButton.OnMouseClick += RerollButton_OnMouseClick; // Add "Save Roll" button Button saveRoll = DaggerfallUI.AddButton(new Rect(162, 162, 71, 9), NativePanel); saveRoll.OnMouseClick += SaveRoll_OnMouseClick; // Add "Load Roll" button Button loadRoll = DaggerfallUI.AddButton(new Rect(162, 171, 71, 9), NativePanel); loadRoll.OnMouseClick += LoadRoll_OnMouseClick; // Add "OK" button Button okButton = DaggerfallUI.AddButton(new Rect(263, 172, 39, 22), NativePanel); okButton.OnMouseClick += OkButton_OnMouseClick; IsSetup = true; }
void CreateNewLabelLayoutSingleLine() { // // Stage 1 - Encode glyphs and calculate final dimensions // // Use default UI font if none set if (font == null) { font = DaggerfallUI.DefaultFont; } // Start a new layout labelLayout = new LabelLayoutData(); List <GlyphLayoutData> glyphLayout = new List <GlyphLayoutData>(); // Set a local maxWidth that compensates for textScale int maxWidth = (int)(this.maxWidth / textScale); // First pass encodes ASCII and calculates final dimensions int width = 0; asciiBytes = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("ISO-8859-1"), Encoding.Default.GetBytes(text)); for (int i = startCharacterIndex; i < asciiBytes.Length; i++) { // Invalid ASCII bytes are cast to a space character if (!font.HasGlyph(asciiBytes[i])) { asciiBytes[i] = DaggerfallFont.SpaceCode; } // Calculate total width DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); width += glyph.width + font.GlyphSpacing; } // Trim width if (maxWidth > 0 && width > maxWidth) { width = maxWidth; } // Create virtual layout area totalWidth = width; totalHeight = (int)(font.GlyphHeight); numTextLines = 1; labelLayout.width = totalWidth; labelLayout.height = totalHeight; // // Stage 2 - Add glyphs to layout // // Determine horizontal alignment offset float alignmentOffset; switch (horizontalTextAlignment) { default: case HorizontalTextAlignmentSetting.None: case HorizontalTextAlignmentSetting.Left: case HorizontalTextAlignmentSetting.Justify: alignmentOffset = 0.0f; break; case HorizontalTextAlignmentSetting.Center: alignmentOffset = (totalWidth - width) * 0.5f; break; case HorizontalTextAlignmentSetting.Right: alignmentOffset = totalWidth - width; break; } // Second pass adds glyphs to layout int xpos = (int)alignmentOffset; for (int i = startCharacterIndex; i < asciiBytes.Length; i++) { DaggerfallFont.GlyphInfo glyph = font.GetGlyph(asciiBytes[i]); if (xpos + glyph.width >= totalWidth) { break; } GlyphLayoutData glyphPos = new GlyphLayoutData() { x = xpos, y = 0, glyphRawAscii = asciiBytes[i], glyphWidth = glyph.width, }; glyphLayout.Add(glyphPos); xpos += glyph.width + font.GlyphSpacing; } labelLayout.glyphLayout = glyphLayout.ToArray(); this.Size = new Vector2(totalWidth * textScale, totalHeight * textScale); }