Centralized usage of Fonts to fix cache #515 (#556)

The split between d2ui and d2asset Font version caused incorrect caching between the two. After looking at d2interface.Font, I saw the d2asset was the most recent and more tightly and cleanly packaged.

I therefore removed the old d2ui.Font and embedded the d2asset version in the d2ui.Label and d2ui.Button.

Looking at the code of d2ui, it would be logical to completly swap it for their d2gui version. But at least for the moment, the d2ui.Button as more functionality since it embeds a Label (instead of a font), and this label now has multiline horizontal alignement.
This commit is contained in:
Maxime Lavigne (malavv) 2020-07-07 20:16:22 -04:00 committed by GitHub
parent 252e6c6c23
commit 0a78a1adcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 130 additions and 276 deletions

View File

@ -103,7 +103,7 @@ func (f *Font) Clone() d2interface.Font {
}
}
// RenderText draws a string of text in a style described by Font onto the d2interface.Surface
// RenderText prints a text using its configured style on a Surface (multi-lines are left-aligned, use label otherwise)
func (f *Font) RenderText(text string, target d2interface.Surface) error {
f.sheet.SetColorMod(f.color)
f.sheet.SetBlend(false)

View File

@ -19,6 +19,7 @@ const (
buttonStatePressedToggled
)
// Button is a user actionable drawable toggle switch
type Button struct {
widgetBase

View File

@ -1,6 +1,7 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image"
"image/color"
@ -112,7 +113,10 @@ func CreateButton(renderer d2interface.Renderer, buttonType ButtonType, text str
}
buttonLayout := ButtonLayouts[buttonType]
result.buttonLayout = buttonLayout
font := GetFont(buttonLayout.FontPath, d2resource.PaletteUnits)
lbl := CreateLabel(buttonLayout.FontPath, d2resource.PaletteUnits)
lbl.SetText(text)
lbl.Color = color.RGBA{R: 100, G: 100, B: 100, A: 255}
lbl.Alignment = d2gui.HorizontalAlignCenter
animation, _ := d2asset.LoadAnimation(buttonLayout.ResourceName, buttonLayout.PaletteName)
buttonSprite, _ := LoadSprite(animation)
@ -127,33 +131,45 @@ func CreateButton(renderer d2interface.Renderer, buttonType ButtonType, text str
}
result.normalSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
_, fontHeight := font.GetTextMetrics(text)
textY := (result.height / 2) - (fontHeight / 2) + buttonLayout.TextOffset
_, labelHeight := lbl.GetSize()
textY := result.height / 2 - labelHeight / 2
xOffset := result.width / 2
buttonSprite.SetPosition(0, 0)
buttonSprite.SetBlend(true)
buttonSprite.RenderSegmented(result.normalSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame)
font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.normalSurface)
lbl.SetPosition(xOffset, textY)
lbl.Render(result.normalSurface)
if buttonLayout.AllowFrameChange {
if totalButtonTypes > 1 {
result.pressedSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
buttonSprite.RenderSegmented(result.pressedSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+1)
font.Render(-2, textY+2, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.pressedSurface)
lbl.SetPosition(xOffset-2, textY + 2)
lbl.Render(result.pressedSurface)
}
if totalButtonTypes > 2 {
result.toggledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
buttonSprite.RenderSegmented(result.toggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+2)
font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.toggledSurface)
lbl.SetPosition(xOffset, textY)
lbl.Render(result.toggledSurface)
}
if totalButtonTypes > 3 {
result.pressedToggledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
buttonSprite.RenderSegmented(result.pressedToggledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.BaseFrame+3)
font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.pressedToggledSurface)
lbl.SetPosition(xOffset, textY)
lbl.Render(result.pressedToggledSurface)
}
if buttonLayout.DisabledFrame != -1 {
result.disabledSurface, _ = renderer.NewSurface(result.width, result.height, d2enum.FilterNearest)
buttonSprite.RenderSegmented(result.disabledSurface, buttonLayout.XSegments, buttonLayout.YSegments, buttonLayout.DisabledFrame)
font.Render(0, textY, text, color.RGBA{R: 100, G: 100, B: 100, A: 255}, result.disabledSurface)
lbl.SetPosition(xOffset, textY)
lbl.Render(result.disabledSurface)
}
}
return result

View File

@ -1,145 +0,0 @@
package d2ui
import (
"encoding/binary"
"image/color"
"strings"
"unicode"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
)
var fontCache = map[string]*Font{}
// FontSize represents the size of a character in a font
type FontSize struct {
Width uint8
Height uint8
}
// Font represents a font
type Font struct {
fontSprite *Sprite
fontTable map[uint16]uint16
metrics map[uint16]FontSize
}
// GetFont creates or loads an existing font
func GetFont(fontPath string, palettePath string) *Font {
cacheItem, exists := fontCache[fontPath+"_"+palettePath]
if exists {
return cacheItem
}
newFont := CreateFont(fontPath, palettePath)
fontCache[fontPath+"_"+palettePath] = newFont
return newFont
}
// CreateFont creates an instance of a MPQ Font
func CreateFont(font string, palettePath string) *Font {
result := &Font{
fontTable: make(map[uint16]uint16),
metrics: make(map[uint16]FontSize),
}
// bug: performance issue when using CJK fonts, because ten thousand frames will be rendered PER font
animation, _ := d2asset.LoadAnimation(font+".dc6", palettePath)
result.fontSprite, _ = LoadSprite(animation)
woo := "Woo!\x01"
fontData, err := d2asset.LoadFile(font + ".tbl")
if err != nil {
panic(err)
}
if string(fontData[0:5]) != woo {
panic("No woo :(")
}
containsCjk := false
for i := 12; i < len(fontData); i += 14 {
// font mappings, map unicode code points to array indics
unicodeCode := binary.LittleEndian.Uint16(fontData[i : i+2])
fontIndex := binary.LittleEndian.Uint16(fontData[i+8 : i+10])
result.fontTable[unicodeCode] = fontIndex
if unicodeCode < unicode.MaxLatin1 {
result.metrics[unicodeCode] = FontSize{
Width: fontData[i+3],
Height: fontData[i+4],
}
} else if !containsCjk {
// CJK characters are all in the same size
result.metrics[unicode.MaxLatin1] = FontSize{
Width: fontData[i+3],
Height: fontData[i+4],
}
containsCjk = true
}
}
return result
}
// GetTextMetrics returns the size of the specified text
func (v *Font) GetTextMetrics(text string) (width, height int) {
width = 0
curWidth := 0
height = 0
_, maxCharHeight := v.fontSprite.GetFrameBounds()
for _, ch := range text {
if ch == '\n' {
width = d2common.MaxInt(width, curWidth)
curWidth = 0
height += maxCharHeight + 6
continue
}
curWidth += v.getCharWidth(ch)
}
width = d2common.MaxInt(width, curWidth)
height += maxCharHeight
return
}
// Render draws the font on the target surface
func (v *Font) Render(x, y int, text string, color color.Color, target d2interface.Surface) {
v.fontSprite.SetColorMod(color)
v.fontSprite.SetBlend(false)
maxCharHeight := uint32(0)
for _, m := range v.metrics {
maxCharHeight = d2common.Max(maxCharHeight, uint32(m.Height))
}
targetWidth, _ := target.GetSize()
lines := strings.Split(text, "\n")
for lineIdx, line := range lines {
lineWidth, _ := v.GetTextMetrics(line)
xPos := x + ((targetWidth / 2) - lineWidth/2)
for _, ch := range line {
width := v.getCharWidth(ch)
index := v.fontTable[uint16(ch)]
v.fontSprite.SetCurrentFrame(int(index))
_, height := v.fontSprite.GetCurrentFrameSize()
v.fontSprite.SetPosition(xPos, y+height)
v.fontSprite.Render(target)
xPos += width
}
if lineIdx >= len(lines)-1 {
break
}
xPos = x
y += int(maxCharHeight + 6)
}
}
func (v *Font) getCharWidth(char rune) (width int) {
if char < unicode.MaxLatin1 {
return int(v.metrics[uint16(char)].Width)
}
return int(v.metrics[unicode.MaxLatin1].Width)
}

View File

@ -1,71 +1,57 @@
package d2ui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image/color"
"log"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
// LabelAlignment represents a label's alignment
type LabelAlignment uint8
const (
// LabelAlignLeft represents a left-aligned label
LabelAlignLeft LabelAlignment = 0
// LabelAlignCenter represents a center-aligned label
LabelAlignCenter LabelAlignment = 1
// LabelAlignRight represents a right-aligned label
LabelAlignRight LabelAlignment = 2
)
// Label represents a user interface label
type Label struct {
text string
renderer d2interface.Renderer
X int
Y int
Width int
Height int
Alignment LabelAlignment
font *Font
imageData map[string]d2interface.Surface
Alignment d2gui.HorizontalAlign
font d2interface.Font
Color color.Color
}
// CreateLabel creates a new instance of a UI label
func CreateLabel(renderer d2interface.Renderer, fontPath, palettePath string) Label {
func CreateLabel(fontPath, palettePath string) Label {
font, _ := d2asset.LoadFont(fontPath+".tbl", fontPath+".dc6", palettePath)
result := Label{
renderer: renderer,
Alignment: LabelAlignLeft,
Alignment: d2gui.HorizontalAlignLeft,
Color: color.White,
font: GetFont(fontPath, palettePath),
imageData: make(map[string]d2interface.Surface),
font: font,
}
return result
}
// Render draws the label on the screen
// Render draws the label on the screen, respliting the lines to allow for other alignments
func (v *Label) Render(target d2interface.Surface) {
if len(v.text) == 0 {
return
}
v.cacheImage()
v.font.SetColor(v.Color)
target.PushTranslation(v.X, v.Y)
x, y := v.X, v.Y
if v.Alignment == LabelAlignCenter {
x, y = v.X-v.Width/2, v.Y
} else if v.Alignment == LabelAlignRight {
x, y = v.X-v.Width, v.Y
lines := strings.Split(v.text, "\n")
yOffset := 0
for _, line := range lines {
lw, lh := v.GetTextMetrics(line)
target.PushTranslation(v.getAlignOffset(lw), yOffset)
_ = v.font.RenderText(line, target)
yOffset += lh
target.Pop()
}
target.PushFilter(d2enum.FilterNearest)
target.PushCompositeMode(d2enum.CompositeModeSourceAtop)
target.PushTranslation(x, y)
defer target.PopN(3)
_ = target.Render(v.imageData[v.text])
target.Pop()
}
// SetPosition moves the label to the specified location
@ -74,34 +60,31 @@ func (v *Label) SetPosition(x, y int) {
v.Y = y
}
// GetSize returns the size of the label
func (v *Label) GetSize() (width, height int) {
return v.font.GetTextMetrics(v.text)
}
// GetTextMetrics returns the width and height of the enclosing rectangle in Pixels.
func (v *Label) GetTextMetrics(text string) (width, height int) {
return v.font.GetTextMetrics(text)
}
func (v *Label) cacheImage() {
if v.imageData[v.text] != nil {
return
}
width, height := v.font.GetTextMetrics(v.text)
v.Width = width
v.Height = height
v.imageData[v.text], _ = v.renderer.NewSurface(width, height, d2enum.FilterNearest)
surface, _ := v.renderer.CreateSurface(v.imageData[v.text])
v.font.Render(0, 0, v.text, v.Color, surface)
}
// SetText sets the label's text
func (v *Label) SetText(newText string) {
if v.text == newText {
return
}
v.text = newText
}
// Size returns the size of the label
func (v Label) GetSize() (width, height int) {
v.cacheImage()
width = v.Width
height = v.Height
return
func (v *Label) getAlignOffset(textWidth int) int {
switch v.Alignment {
case d2gui.HorizontalAlignLeft:
return 0
case d2gui.HorizontalAlignCenter:
return -textWidth / 2
case d2gui.HorizontalAlignRight:
return -textWidth
default:
log.Fatal("Invalid Alignment")
return 0
}
}

View File

@ -33,8 +33,8 @@ func CreateTextbox(renderer d2interface.Renderer) TextBox {
tb := TextBox{
filter: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
bgSprite: bgSprite,
textLabel: CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteUnits),
lineBar: CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteUnits),
textLabel: CreateLabel(d2resource.FontFormal11, d2resource.PaletteUnits),
lineBar: CreateLabel(d2resource.FontFormal11, d2resource.PaletteUnits),
enabled: true,
visible: true,
}
@ -137,10 +137,11 @@ func (v *TextBox) GetSize() (width, height int) {
}
func (v *TextBox) SetPosition(x, y int) {
lw, _ := v.textLabel.GetSize()
v.x = x
v.y = y
v.textLabel.SetPosition(v.x+6, v.y+3)
v.lineBar.SetPosition(v.x+6+v.textLabel.Width, v.y+3)
v.lineBar.SetPosition(v.x+6+lw, v.y+3)
v.bgSprite.SetPosition(v.x, v.y+26)
}

View File

@ -3,16 +3,14 @@ package d2gamescreen
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image/color"
"math"
"os"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
"github.com/OpenDiablo2/OpenDiablo2/d2common"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2inventory"
@ -86,19 +84,16 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
v.createButtons(loading)
v.d2HeroTitle = d2ui.CreateLabel(v.renderer, d2resource.Font42, d2resource.PaletteUnits)
v.d2HeroTitle = d2ui.CreateLabel(d2resource.Font42, d2resource.PaletteUnits)
v.d2HeroTitle.SetPosition(320, 23)
v.d2HeroTitle.Alignment = d2ui.LabelAlignCenter
v.d2HeroTitle.Alignment = d2gui.HorizontalAlignCenter
loading.Progress(0.3)
v.deleteCharConfirmLabel = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
lines := d2common.SplitIntoLinesWithMaxWidth(
"Are you sure that you want to delete this character? Take note: this will delete all versions of this Character.",
29,
)
v.deleteCharConfirmLabel.SetText(strings.Join(lines, "\n"))
v.deleteCharConfirmLabel.Alignment = d2ui.LabelAlignCenter
v.deleteCharConfirmLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
lines := "Are you sure that you want\nto delete this character?\nTake note: this will delete all\nversions of this Character."
v.deleteCharConfirmLabel.SetText(lines)
v.deleteCharConfirmLabel.Alignment = d2gui.HorizontalAlignCenter
v.deleteCharConfirmLabel.SetPosition(400, 185)
animation, _ = d2asset.LoadAnimation(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
@ -120,12 +115,12 @@ func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
xOffset = 385
}
v.characterNameLabel[i] = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.characterNameLabel[i] = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.characterNameLabel[i].Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
v.characterNameLabel[i].SetPosition(xOffset, 100+((i/2)*95))
v.characterStatsLabel[i] = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.characterStatsLabel[i] = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.characterStatsLabel[i].SetPosition(xOffset, 115+((i/2)*95))
v.characterExpLabel[i] = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteStatic)
v.characterExpLabel[i] = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteStatic)
v.characterExpLabel[i].Color = color.RGBA{R: 24, G: 255, A: 255}
v.characterExpLabel[i].SetPosition(xOffset, 130+((i/2)*95))
}
@ -136,7 +131,7 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) {
v.newCharButton = d2ui.CreateButton(
v.renderer,
d2ui.ButtonTypeTall,
d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("CREATE NEW CHARACTER", 15)),
"CREATE NEW\nCHARACTER",
)
v.newCharButton.SetPosition(33, 468)
v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() })
@ -145,7 +140,7 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) {
v.convertCharButton = d2ui.CreateButton(
v.renderer,
d2ui.ButtonTypeTall,
d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("CONVERT TO EXPANSION", 15)),
"CONVERT TO\nEXPANSION",
)
v.convertCharButton.SetPosition(233, 468)
v.convertCharButton.SetEnabled(false)
@ -154,7 +149,7 @@ func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) {
v.deleteCharButton = d2ui.CreateButton(
v.renderer,
d2ui.ButtonTypeTall,
d2common.CombineStrings(d2common.SplitIntoLinesWithMaxWidth("DELETE CHARACTER", 15)),
"DELETE\nCHARACTER",
)
v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() })
v.deleteCharButton.SetPosition(433, 468)

View File

@ -256,7 +256,7 @@ func (v *Credits) getNewFontLabel(isHeading bool) *d2ui.Label {
newLabelItem := &labelItem{
Available: false,
IsHeading: isHeading,
Label: d2ui.CreateLabel(v.renderer, d2resource.FontFormal10, d2resource.PaletteSky),
Label: d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteSky),
}
if isHeading {

View File

@ -4,6 +4,7 @@ package d2gamescreen
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image/color"
"log"
"os"
@ -133,47 +134,46 @@ func (v *MainMenu) loadBackgroundSprites() {
}
func (v *MainMenu) createLabels(loading d2screen.LoadingState) {
v.versionLabel = d2ui.CreateLabel(v.renderer, d2resource.FontFormal12, d2resource.PaletteStatic)
v.versionLabel.Alignment = d2ui.LabelAlignRight
v.versionLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
v.versionLabel.Alignment = d2gui.HorizontalAlignRight
v.versionLabel.SetText("OpenDiablo2 - " + d2common.BuildInfo.Branch)
v.versionLabel.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
v.versionLabel.SetPosition(795, -10)
v.commitLabel = d2ui.CreateLabel(v.renderer, d2resource.FontFormal10, d2resource.PaletteStatic)
v.commitLabel.Alignment = d2ui.LabelAlignLeft
v.commitLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
v.commitLabel.Alignment = d2gui.HorizontalAlignLeft
v.commitLabel.SetText(d2common.BuildInfo.Commit)
v.commitLabel.Color = color.RGBA{R: 255, G: 255, B: 255, A: 255}
v.commitLabel.SetPosition(2, 2)
v.copyrightLabel = d2ui.CreateLabel(v.renderer, d2resource.FontFormal12, d2resource.PaletteStatic)
v.copyrightLabel.Alignment = d2ui.LabelAlignCenter
v.copyrightLabel = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
v.copyrightLabel.Alignment = d2gui.HorizontalAlignCenter
v.copyrightLabel.SetText("Diablo 2 is © Copyright 2000-2016 Blizzard Entertainment")
v.copyrightLabel.Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
v.copyrightLabel.SetPosition(400, 500)
loading.Progress(0.3)
v.copyrightLabel2 = d2ui.CreateLabel(v.renderer, d2resource.FontFormal12, d2resource.PaletteStatic)
v.copyrightLabel2.Alignment = d2ui.LabelAlignCenter
v.copyrightLabel2 = d2ui.CreateLabel(d2resource.FontFormal12, d2resource.PaletteStatic)
v.copyrightLabel2.Alignment =d2gui.HorizontalAlignCenter
v.copyrightLabel2.SetText("All Rights Reserved.")
v.copyrightLabel2.Color = color.RGBA{R: 188, G: 168, B: 140, A: 255}
v.copyrightLabel2.SetPosition(400, 525)
v.openDiabloLabel = d2ui.CreateLabel(v.renderer, d2resource.FontFormal10, d2resource.PaletteStatic)
v.openDiabloLabel.Alignment = d2ui.LabelAlignCenter
v.openDiabloLabel = d2ui.CreateLabel(d2resource.FontFormal10, d2resource.PaletteStatic)
v.openDiabloLabel.Alignment = d2gui.HorizontalAlignCenter
v.openDiabloLabel.SetText("OpenDiablo2 is neither developed by, nor endorsed by Blizzard or its parent company Activision")
v.openDiabloLabel.Color = color.RGBA{R: 255, G: 255, B: 140, A: 255}
v.openDiabloLabel.SetPosition(400, 580)
loading.Progress(0.5)
v.tcpIPOptionsLabel = d2ui.CreateLabel(v.renderer, d2resource.Font42, d2resource.PaletteUnits)
v.tcpIPOptionsLabel = d2ui.CreateLabel(d2resource.Font42, d2resource.PaletteUnits)
v.tcpIPOptionsLabel.SetPosition(400, 23)
v.tcpIPOptionsLabel.Alignment = d2ui.LabelAlignCenter
v.tcpIPOptionsLabel.Alignment = d2gui.HorizontalAlignCenter
v.tcpIPOptionsLabel.SetText("TCP/IP Options")
v.tcpJoinGameLabel = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.tcpJoinGameLabel.Alignment = d2ui.LabelAlignCenter
v.tcpJoinGameLabel.SetText(d2common.CombineStrings(
d2common.SplitIntoLinesWithMaxWidth("Enter Host IP Address to Join Game", 23)))
v.tcpJoinGameLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.tcpJoinGameLabel.Alignment = d2gui.HorizontalAlignCenter
v.tcpJoinGameLabel.SetText("Enter Host IP Address\nto Join Game")
v.tcpJoinGameLabel.Color = color.RGBA{R: 216, G: 196, B: 128, A: 255}
v.tcpJoinGameLabel.SetPosition(400, 190)

View File

@ -2,6 +2,7 @@ package d2gamescreen
import (
"fmt"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image"
"image/color"
@ -254,42 +255,42 @@ func (v *SelectHeroClass) OnLoad(loading d2screen.LoadingState) {
}
func (v *SelectHeroClass) createLabels() {
v.headingLabel = d2ui.CreateLabel(v.renderer, d2resource.Font30, d2resource.PaletteUnits)
v.headingLabel = d2ui.CreateLabel(d2resource.Font30, d2resource.PaletteUnits)
fontWidth, _ := v.headingLabel.GetSize()
v.headingLabel.SetPosition(400-fontWidth/2, 17)
v.headingLabel.SetText("Select Hero Class")
v.headingLabel.Alignment = d2ui.LabelAlignCenter
v.headingLabel.Alignment = d2gui.HorizontalAlignCenter
v.heroClassLabel = d2ui.CreateLabel(v.renderer, d2resource.Font30, d2resource.PaletteUnits)
v.heroClassLabel.Alignment = d2ui.LabelAlignCenter
v.heroClassLabel = d2ui.CreateLabel(d2resource.Font30, d2resource.PaletteUnits)
v.heroClassLabel.Alignment = d2gui.HorizontalAlignCenter
v.heroClassLabel.SetPosition(400, 65)
v.heroDesc1Label = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc1Label.Alignment = d2ui.LabelAlignCenter
v.heroDesc1Label = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc1Label.Alignment = d2gui.HorizontalAlignCenter
v.heroDesc1Label.SetPosition(400, 100)
v.heroDesc2Label = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc2Label.Alignment = d2ui.LabelAlignCenter
v.heroDesc2Label = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc2Label.Alignment = d2gui.HorizontalAlignCenter
v.heroDesc2Label.SetPosition(400, 115)
v.heroDesc3Label = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc3Label.Alignment = d2ui.LabelAlignCenter
v.heroDesc3Label = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.heroDesc3Label.Alignment = d2gui.HorizontalAlignCenter
v.heroDesc3Label.SetPosition(400, 130)
v.heroNameLabel = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.heroNameLabel.Alignment = d2ui.LabelAlignLeft
v.heroNameLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.heroNameLabel.Alignment = d2gui.HorizontalAlignLeft
v.heroNameLabel.Color = color.RGBA{R: 216, G: 196, B: 128, A: 255}
v.heroNameLabel.SetText("Character Name")
v.heroNameLabel.SetPosition(321, 475)
v.expansionCharLabel = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.expansionCharLabel.Alignment = d2ui.LabelAlignLeft
v.expansionCharLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.expansionCharLabel.Alignment = d2gui.HorizontalAlignLeft
v.expansionCharLabel.Color = color.RGBA{R: 216, G: 196, B: 128, A: 255}
v.expansionCharLabel.SetText("EXPANSION CHARACTER")
v.expansionCharLabel.SetPosition(339, 526)
v.hardcoreCharLabel = d2ui.CreateLabel(v.renderer, d2resource.Font16, d2resource.PaletteUnits)
v.hardcoreCharLabel.Alignment = d2ui.LabelAlignLeft
v.hardcoreCharLabel = d2ui.CreateLabel(d2resource.Font16, d2resource.PaletteUnits)
v.hardcoreCharLabel.Alignment = d2gui.HorizontalAlignLeft
v.hardcoreCharLabel.Color = color.RGBA{R: 216, G: 196, B: 128, A: 255}
v.hardcoreCharLabel.SetText("Hardcore")
v.hardcoreCharLabel.SetPosition(339, 548)

View File

@ -1,6 +1,7 @@
package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"image"
"image/color"
"log"
@ -86,12 +87,12 @@ func NewGameControls(renderer d2interface.Renderer, hero *d2mapentity.Player, ma
missileID = id
})
zoneLabel := d2ui.CreateLabel(renderer, d2resource.Font30, d2resource.PaletteUnits)
zoneLabel := d2ui.CreateLabel(d2resource.Font30, d2resource.PaletteUnits)
zoneLabel.Color = color.RGBA{R: 255, G: 88, B: 82, A: 255}
zoneLabel.Alignment = d2ui.LabelAlignCenter
zoneLabel.Alignment = d2gui.HorizontalAlignCenter
nameLabel := d2ui.CreateLabel(renderer, d2resource.FontFormal11, d2resource.PaletteStatic)
nameLabel.Alignment = d2ui.LabelAlignCenter
nameLabel := d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic)
nameLabel.Alignment = d2gui.HorizontalAlignCenter
nameLabel.SetText("")
nameLabel.Color = color.White

View File

@ -1,6 +1,7 @@
package d2player
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2gui"
"strconv"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
@ -276,9 +277,9 @@ func (s *HeroStatsPanel) createStatValueLabel(stat int, x int, y int) d2ui.Label
}
func (s *HeroStatsPanel) createTextLabel(element PanelText) d2ui.Label {
label := d2ui.CreateLabel(s.renderer, element.Font, d2resource.PaletteStatic)
label := d2ui.CreateLabel(element.Font, d2resource.PaletteStatic)
if element.AlignCenter {
label.Alignment = d2ui.LabelAlignCenter
label.Alignment = d2gui.HorizontalAlignCenter
}
label.SetText(element.Text)