From 8186ecd55a0f41058ff72b0d203f5eb4d0431179 Mon Sep 17 00:00:00 2001 From: "M. Sz" Date: Mon, 14 Dec 2020 18:29:54 +0100 Subject: [PATCH] help overlay text --- d2core/d2ui/label.go | 5 +++ d2game/d2player/game_controls.go | 1 + d2game/d2player/help_overlay.go | 64 +++++++++++++++++--------------- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/d2core/d2ui/label.go b/d2core/d2ui/label.go index 1004a21c..9c5c53dd 100644 --- a/d2core/d2ui/label.go +++ b/d2core/d2ui/label.go @@ -108,6 +108,11 @@ func (v *Label) SetText(newText string) { v.text = v.processColorTokens(newText) } +// GetText returns label text +func (v *Label) GetText() string { + return v.text +} + // SetBackgroundColor sets the background highlight color func (v *Label) SetBackgroundColor(c color.Color) { v.backgroundColor = c diff --git a/d2game/d2player/game_controls.go b/d2game/d2player/game_controls.go index c17f5281..2335cc52 100644 --- a/d2game/d2player/game_controls.go +++ b/d2game/d2player/game_controls.go @@ -659,6 +659,7 @@ func (g *GameControls) onCloseQuestLog() { func (g *GameControls) toggleHelpOverlay() { if !g.inventory.IsOpen() && !g.skilltree.IsOpen() && !g.heroStatsPanel.IsOpen() && !g.questLog.IsOpen() { + g.HelpOverlay.updateKeyMap(g.keyMap) g.hud.miniPanel.openDisabled() g.HelpOverlay.Toggle() g.updateLayout() diff --git a/d2game/d2player/help_overlay.go b/d2game/d2player/help_overlay.go index 54ab30b6..f9106bf2 100644 --- a/d2game/d2player/help_overlay.go +++ b/d2game/d2player/help_overlay.go @@ -155,6 +155,8 @@ const ( beltDotY = 568 ) +const bullets = 8 + // NewHelpOverlay creates a new HelpOverlay instance func NewHelpOverlay( asset *d2asset.AssetManager, @@ -182,6 +184,7 @@ type HelpOverlay struct { frames []*d2ui.Sprite text []*d2ui.Label lines []line + bullets [bullets]*d2ui.Label uiManager *d2ui.UIManager closeButton *d2ui.Button keyMap *KeyMap @@ -332,7 +335,7 @@ func (h *HelpOverlay) setupTitleAndButton() { h.text = append(h.text, newLabel) } -func (h *HelpOverlay) setupBulletedList() { +func (h *HelpOverlay) updateBulletText() { // Bullets // the hotkeys displayed here should be pulled from a mapping of input events to game events // https://github.com/OpenDiablo2/OpenDiablo2/issues/793 @@ -378,17 +381,35 @@ func (h *HelpOverlay) setupBulletedList() { )}, } - for idx := range callouts { + for i := 0; i < bullets; i++ { + h.bullets[i].SetText(callouts[i].text) + } +} + +func (h *HelpOverlay) setupBulletedList() { + for idx := 0; idx < bullets; idx++ { listItemOffsetY := idx * listItemVerticalOffset - h.createBullet(callout{ - LabelText: callouts[idx].text, - LabelX: listRootX, - LabelY: listRootY + listItemOffsetY, - DotX: listBulletX, - DotY: listBulletRootY + listItemOffsetY, - }) + label := h.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteSky) + label.SetPosition(listRootX, listRootY+listItemOffsetY) + h.bullets[idx] = label + h.panelGroup.AddWidget(h.bullets[idx]) + + newDot, err := h.uiManager.NewSprite(d2resource.HelpYellowBullet, d2resource.PaletteSky) + if err != nil { + h.Error(err.Error()) + } + + err = newDot.SetCurrentFrame(0) + if err != nil { + h.Error(err.Error()) + } + + newDot.SetPosition(listBulletX, listBulletRootY+listItemOffsetY+bulletOffsetY) + + h.frames = append(h.frames, newDot) } + h.updateBulletText() } // nolint:funlen // can't reduce @@ -553,26 +574,6 @@ type callout struct { DotY int } -func (h *HelpOverlay) createBullet(c callout) { - newLabel := h.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteSky) - newLabel.SetText(c.LabelText) - newLabel.SetPosition(c.LabelX, c.LabelY) - h.text = append(h.text, newLabel) - - newDot, err := h.uiManager.NewSprite(d2resource.HelpYellowBullet, d2resource.PaletteSky) - if err != nil { - h.Error(err.Error()) - } - - err = newDot.SetCurrentFrame(0) - if err != nil { - h.Error(err.Error()) - } - - newDot.SetPosition(c.DotX, c.DotY+bulletOffsetY) - h.frames = append(h.frames, newDot) -} - func (h *HelpOverlay) createLabel(c callout) { newLabel := h.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteSky) newLabel.SetText(c.LabelText) @@ -631,3 +632,8 @@ func (h *HelpOverlay) Render(target d2interface.Surface) { target.Pop() } } + +func (h *HelpOverlay) updateKeyMap(km *KeyMap) { + h.keyMap = km + h.updateBulletText() +}