1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-10 09:50:42 +00:00

added background color to labels (#671)

This commit is contained in:
lord 2020-08-02 21:48:17 -07:00 committed by GitHub
parent 50a070d7b0
commit 8560956f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -61,12 +61,13 @@ func ColorTokenize(s string, t ColorToken) string {
// Label represents a user interface label
type Label struct {
text string
X int
Y int
Alignment d2gui.HorizontalAlign
font d2interface.Font
Color map[int]color.Color
text string
X int
Y int
Alignment d2gui.HorizontalAlign
font d2interface.Font
Color map[int]color.Color
backgroundColor color.Color
}
// CreateLabel creates a new instance of a UI label
@ -99,13 +100,17 @@ func (v *Label) Render(target d2interface.Surface) {
for idx := range characters {
character := string(characters[idx])
charWidth, _ := v.GetTextMetrics(character)
charWidth, charHeight := v.GetTextMetrics(character)
if v.Color[idx] != nil {
lastColor = v.Color[idx]
v.font.SetColor(lastColor)
}
if v.backgroundColor != nil {
target.DrawRect(charWidth, charHeight, v.backgroundColor)
}
_ = v.font.RenderText(character, target)
target.PushTranslation(charWidth, 0)
@ -142,6 +147,11 @@ func (v *Label) SetText(newText string) {
v.text = v.processColorTokens(newText)
}
// SetBackgroundColor sets the background highlight color
func (v *Label) SetBackgroundColor(c color.RGBA) {
v.backgroundColor = c
}
func (v *Label) processColorTokens(str string) string {
tokenMatch := regexp.MustCompile(colorTokenMatch)
tokenStrMatch := regexp.MustCompile(colorStrMatch)

View File

@ -124,6 +124,9 @@ func NewGameControls(renderer d2interface.Renderer, hero *d2mapentity.Player, ma
inventoryRecord := d2datadict.Inventory[inventoryRecordKey]
hoverLabel := &nameLabel
hoverLabel.SetBackgroundColor(color.RGBA{0,0,0, uint8(128)})
gc := &GameControls{
renderer: renderer,
hero: hero,
@ -133,7 +136,7 @@ func NewGameControls(renderer d2interface.Renderer, hero *d2mapentity.Player, ma
inventory: NewInventory(inventoryRecord),
heroStatsPanel: NewHeroStatsPanel(renderer, hero.Name(), hero.Class, hero.Stats),
missileID: missileID,
nameLabel: &nameLabel,
nameLabel: hoverLabel,
zoneChangeText: &zoneLabel,
actionableRegions: []ActionableRegion{
{leftSkill, d2common.Rectangle{Left: 115, Top: 550, Width: 50, Height: 50}},
@ -438,10 +441,12 @@ func (g *GameControls) Render(target d2interface.Surface) error {
if within {
xOff, yOff := int(entOffset.X()), int(entOffset.Y())
g.nameLabel.SetText(entity.Label())
xLabel, yLabel := entScreenX-xOff, entScreenY-yOff-entityHeight-hoverLabelOuterPad
g.nameLabel.SetPosition(xLabel, yLabel)
g.nameLabel.Render(target)
entity.Highlight()