2020-11-01 22:43:23 -05:00
|
|
|
package d2player
|
2020-09-09 08:21:27 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"image/color"
|
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2020-09-09 08:21:27 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-11-18 16:02:49 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-09-09 08:21:27 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
|
|
|
)
|
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
/*
|
|
|
|
the 800x600 help screen dc6 file frames look like this
|
|
|
|
the position we set for frames is the lower-left corner x,y
|
|
|
|
+----+------------------+-------------------+------------+----+
|
|
|
|
| 1 | 3 | 4 | 5 | 6 |
|
|
|
|
| |------------------+-------------------| | |
|
|
|
|
| | | | |
|
|
|
|
| | | | |
|
|
|
|
+----+ +------------+----+
|
|
|
|
| 2 | | 7 |
|
|
|
|
| | | |
|
|
|
|
| | | |
|
|
|
|
+----+ +----+
|
|
|
|
*/
|
|
|
|
const (
|
|
|
|
// if you add up frame widths 1,3,4,5,6 you get (65+255+255+245+20) = 840
|
|
|
|
magicHelpBorderOffsetX = -40
|
|
|
|
)
|
|
|
|
|
2020-09-09 08:21:27 -04:00
|
|
|
const (
|
2020-10-23 09:00:51 -04:00
|
|
|
frameTopLeft = iota
|
|
|
|
frameBottomLeft
|
|
|
|
frameTopMiddleLeft
|
|
|
|
frameTopMiddleRight
|
|
|
|
frameTopRightNoCorner
|
|
|
|
frameTopRight
|
|
|
|
frameBottomRight
|
2020-09-09 08:21:27 -04:00
|
|
|
)
|
|
|
|
|
2020-10-22 10:02:32 -04:00
|
|
|
const (
|
|
|
|
inHalf = 2 // when we divide by 2
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// all in pixels
|
|
|
|
windowWidth = 800
|
|
|
|
|
|
|
|
bulletOffsetY = 14
|
2020-10-23 09:00:51 -04:00
|
|
|
lineOffset = 5
|
2020-10-22 10:02:32 -04:00
|
|
|
|
|
|
|
// the title of the panel
|
2020-10-23 09:00:51 -04:00
|
|
|
titleLabelOffsetX = -37
|
2020-10-22 10:02:32 -04:00
|
|
|
|
|
|
|
// for the bulleted list near the top of the screen
|
|
|
|
listRootX = 100
|
|
|
|
listRootY = 59
|
|
|
|
listBulletOffsetY = 10
|
|
|
|
listBulletOffsetX = 12
|
|
|
|
listItemVerticalOffset = 20
|
|
|
|
listBulletRootY = listRootY - listBulletOffsetY + listItemVerticalOffset
|
|
|
|
listBulletX = listRootX - listBulletOffsetX
|
|
|
|
|
|
|
|
// the close button for the help panel
|
2020-10-23 09:00:51 -04:00
|
|
|
closeButtonX = 685
|
|
|
|
closeButtonY = 25
|
2020-11-22 00:38:09 -05:00
|
|
|
closeButtonLabelX = 702
|
2020-10-23 09:00:51 -04:00
|
|
|
closeButtonLabelY = 60
|
2020-10-22 10:02:32 -04:00
|
|
|
|
|
|
|
// the rest of these are for text with a line and dot, towards the bottom of the screen
|
|
|
|
newStatsLabelX = 222
|
|
|
|
newStatsLabelY = 355
|
|
|
|
newStatsDotX = 217
|
|
|
|
newStatsDotY = 574
|
|
|
|
|
|
|
|
newSkillLabelX = 578
|
|
|
|
newSkillLabelY = 355
|
|
|
|
newSkillDotX = 573
|
|
|
|
newSkillDotY = 574
|
|
|
|
|
|
|
|
leftMouseLabelX = 135
|
|
|
|
leftMouseLabelY = 382
|
|
|
|
|
|
|
|
leftButtonSkillLabelX = 135
|
|
|
|
leftButtonSkillLabelY = 397
|
|
|
|
|
|
|
|
leftSkillClickToChangeLabelX = 135
|
|
|
|
leftSkillClickToChangeLabelY = 412
|
|
|
|
leftSkillClickToChangeDotX = 130
|
|
|
|
leftSkillClickToChangeDotY = 565
|
|
|
|
|
|
|
|
rightMouseLabelX = 675
|
|
|
|
rightMouseLabelY = 381
|
|
|
|
|
|
|
|
rightButtonSkillLabelX = 675
|
|
|
|
rightButtonSkillLabelY = 396
|
|
|
|
|
|
|
|
rightSkillClickToChangeLabelX = 675
|
|
|
|
rightSkillClickToChangeLabelY = 411
|
|
|
|
rightSkillClickToChangeDotX = 670
|
|
|
|
rightSkillClickToChangeDotY = 562
|
|
|
|
|
|
|
|
miniPanelLabelX = 450
|
|
|
|
miniPanelLabelY = 371
|
|
|
|
|
|
|
|
characterLabelX = 450
|
|
|
|
characterLabelY = 386
|
|
|
|
|
|
|
|
inventoryLabelX = 450
|
|
|
|
inventoryLabelY = 401
|
|
|
|
|
|
|
|
otherScreensLabelX = 450
|
|
|
|
otherScreensLabelY = 417
|
|
|
|
otherScreensDotX = 445
|
|
|
|
otherScreensDotY = 539
|
|
|
|
|
|
|
|
lifeOrbLabelX = 65
|
|
|
|
lifeOrbLabelY = 451
|
|
|
|
lifeOrbDotX = 60
|
|
|
|
lifeOrbDotY = 538
|
|
|
|
|
|
|
|
staminaBarLabelX = 315
|
|
|
|
staminaBarLabelY = 450
|
|
|
|
staminaBarDotX = 310
|
|
|
|
staminaBarDotY = 583
|
|
|
|
|
|
|
|
manaOrbLabelX = 745
|
|
|
|
manaOrbLabelY = 451
|
|
|
|
manaOrbDotX = 740
|
|
|
|
manaOrbDotY = 538
|
|
|
|
|
|
|
|
runWalkButtonLabelX = 264
|
|
|
|
runWalkButtonLabelY = 480
|
|
|
|
|
|
|
|
toggleLabelX = 264
|
|
|
|
toggleLabelY = 495
|
|
|
|
toggleDotX = 259
|
|
|
|
toggleDotY = 583
|
|
|
|
|
|
|
|
experienceLabelX = 370
|
|
|
|
experienceLabelY = 476
|
|
|
|
|
|
|
|
barLabelX = 370
|
|
|
|
barLabelY = 493
|
|
|
|
barDotX = 365
|
|
|
|
barDotY = 565
|
|
|
|
|
|
|
|
beltLabelX = 535
|
|
|
|
beltLabelY = 490
|
|
|
|
beltDotX = 530
|
|
|
|
beltDotY = 568
|
|
|
|
)
|
|
|
|
|
2020-12-14 12:29:54 -05:00
|
|
|
const bullets = 8
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// NewHelpOverlay creates a new HelpOverlay instance
|
2020-09-18 16:10:52 -04:00
|
|
|
func NewHelpOverlay(
|
|
|
|
asset *d2asset.AssetManager,
|
|
|
|
ui *d2ui.UIManager,
|
2020-11-18 16:02:49 -05:00
|
|
|
l d2util.LogLevel,
|
2020-11-01 22:43:23 -05:00
|
|
|
keyMap *KeyMap,
|
|
|
|
) *HelpOverlay {
|
|
|
|
h := &HelpOverlay{
|
2020-11-21 05:35:32 -05:00
|
|
|
asset: asset,
|
|
|
|
uiManager: ui,
|
|
|
|
keyMap: keyMap,
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Logger = d2util.NewLogger()
|
|
|
|
h.Logger.SetLevel(l)
|
|
|
|
h.Logger.SetPrefix(logPrefix)
|
2020-11-18 16:02:49 -05:00
|
|
|
|
2020-09-09 08:21:27 -04:00
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
// HelpOverlay represents the in-game overlay that toggles visibility when the h key is pressed
|
|
|
|
type HelpOverlay struct {
|
2020-11-21 05:35:32 -05:00
|
|
|
asset *d2asset.AssetManager
|
|
|
|
isOpen bool
|
|
|
|
frames []*d2ui.Sprite
|
|
|
|
text []*d2ui.Label
|
|
|
|
lines []line
|
2020-12-14 12:29:54 -05:00
|
|
|
bullets [bullets]*d2ui.Label
|
2020-11-21 05:35:32 -05:00
|
|
|
uiManager *d2ui.UIManager
|
|
|
|
closeButton *d2ui.Button
|
|
|
|
keyMap *KeyMap
|
|
|
|
onCloseCb func()
|
|
|
|
panelGroup *d2ui.WidgetGroup
|
|
|
|
backgroundWidget *d2ui.CustomWidget
|
2020-11-18 16:02:49 -05:00
|
|
|
|
2020-11-22 00:36:59 -05:00
|
|
|
*d2util.Logger
|
2020-11-18 16:02:49 -05:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// Toggle the visibility state of the overlay
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) Toggle() {
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Info("Help overlay toggled")
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-09-09 08:21:27 -04:00
|
|
|
if h.isOpen {
|
2020-11-01 22:43:23 -05:00
|
|
|
h.Close()
|
2020-09-09 08:21:27 -04:00
|
|
|
} else {
|
|
|
|
h.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
// Close will hide the help overlay
|
|
|
|
func (h *HelpOverlay) Close() {
|
2020-09-09 08:21:27 -04:00
|
|
|
h.isOpen = false
|
2020-11-21 05:35:32 -05:00
|
|
|
h.panelGroup.SetVisible(false)
|
|
|
|
h.onCloseCb()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetOnCloseCb sets the callback run when Close() is called
|
|
|
|
func (h *HelpOverlay) SetOnCloseCb(cb func()) {
|
|
|
|
h.onCloseCb = cb
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) open() {
|
2020-09-09 08:21:27 -04:00
|
|
|
h.isOpen = true
|
2020-11-21 05:35:32 -05:00
|
|
|
h.panelGroup.SetVisible(true)
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// IsOpen returns whether or not the overlay is visible/open
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) IsOpen() bool {
|
2020-09-15 23:37:08 -04:00
|
|
|
return h.isOpen
|
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// IsInRect checks if the given point is within the overlay layout rectangle
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) IsInRect(px, py int) bool {
|
2020-11-21 05:35:32 -05:00
|
|
|
return h.panelGroup.Contains(px, py)
|
2020-09-15 23:37:08 -04:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// Load the overlay graphical assets
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) Load() {
|
2020-11-21 05:35:32 -05:00
|
|
|
h.panelGroup = h.uiManager.NewWidgetGroup(d2ui.RenderPriorityHelpPanel)
|
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
h.setupOverlayFrame()
|
|
|
|
h.setupTitleAndButton()
|
|
|
|
h.setupBulletedList()
|
|
|
|
h.setupLabelsWithLines()
|
2020-11-21 05:35:32 -05:00
|
|
|
|
|
|
|
h.backgroundWidget = h.uiManager.NewCustomWidgetCached(h.Render, screenWidth, screenHeight)
|
|
|
|
h.panelGroup.AddWidget(h.backgroundWidget)
|
|
|
|
h.panelGroup.SetVisible(false)
|
2020-10-26 18:55:13 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) setupOverlayFrame() {
|
2020-10-23 09:00:51 -04:00
|
|
|
frames := []int{
|
|
|
|
frameTopLeft,
|
|
|
|
frameBottomLeft,
|
|
|
|
frameTopMiddleLeft,
|
|
|
|
frameTopMiddleRight,
|
|
|
|
frameTopRightNoCorner,
|
|
|
|
frameTopRight,
|
|
|
|
frameBottomRight,
|
|
|
|
}
|
|
|
|
|
|
|
|
left, top := 0, 0
|
|
|
|
firstFrameWidth := 0
|
|
|
|
prevY := 0
|
|
|
|
prevWidth := 0
|
|
|
|
currentX, currentY := left, top
|
|
|
|
|
|
|
|
for _, frameIndex := range frames {
|
2020-09-23 13:30:54 -04:00
|
|
|
f, err := h.uiManager.NewSprite(d2resource.HelpBorder, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = f.SetCurrentFrame(frameIndex)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-23 09:00:51 -04:00
|
|
|
frameWidth, frameHeight := f.GetCurrentFrameSize()
|
2020-09-09 08:21:27 -04:00
|
|
|
|
|
|
|
switch frameIndex {
|
2020-10-23 09:00:51 -04:00
|
|
|
case frameTopLeft:
|
|
|
|
currentY += frameHeight
|
|
|
|
firstFrameWidth = frameWidth
|
|
|
|
case frameBottomLeft:
|
|
|
|
currentY += frameHeight
|
|
|
|
case frameTopMiddleLeft:
|
|
|
|
currentX = firstFrameWidth
|
|
|
|
currentY = top + frameHeight
|
|
|
|
case frameTopMiddleRight:
|
|
|
|
currentY = top + frameHeight
|
|
|
|
currentX += prevWidth
|
|
|
|
currentX += magicHelpBorderOffsetX
|
|
|
|
case frameTopRightNoCorner:
|
|
|
|
currentY = top + frameHeight
|
|
|
|
currentX += prevWidth
|
|
|
|
case frameTopRight:
|
|
|
|
currentY = top + frameHeight
|
|
|
|
currentX += prevWidth
|
|
|
|
case frameBottomRight:
|
|
|
|
currentY = prevY + frameHeight
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
2020-10-23 09:00:51 -04:00
|
|
|
prevY = currentY
|
|
|
|
prevWidth = frameWidth
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-23 09:00:51 -04:00
|
|
|
f.SetPosition(currentX, currentY)
|
2020-09-09 08:21:27 -04:00
|
|
|
|
|
|
|
h.frames = append(h.frames, f)
|
|
|
|
}
|
2020-10-26 18:55:13 -04:00
|
|
|
}
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) setupTitleAndButton() {
|
2020-09-09 08:21:27 -04:00
|
|
|
// Title
|
2020-11-03 14:10:11 -05:00
|
|
|
text := h.asset.TranslateString("Strhelp1") // "Diablo II Help"
|
2020-09-09 08:21:27 -04:00
|
|
|
newLabel := h.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
|
|
|
|
newLabel.SetText(text)
|
2020-10-22 10:02:32 -04:00
|
|
|
|
|
|
|
titleLabelWidth, _ := newLabel.GetSize()
|
|
|
|
|
|
|
|
newLabel.SetPosition((windowWidth/inHalf)-(titleLabelWidth/inHalf)+titleLabelOffsetX, 0)
|
2020-09-09 08:21:27 -04:00
|
|
|
h.text = append(h.text, newLabel)
|
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
// Button
|
2020-09-20 02:54:24 -04:00
|
|
|
h.closeButton = h.uiManager.NewButton(d2ui.ButtonTypeSquareClose, "")
|
2020-10-22 10:02:32 -04:00
|
|
|
h.closeButton.SetPosition(closeButtonX, closeButtonY)
|
2020-09-15 23:37:08 -04:00
|
|
|
h.closeButton.SetVisible(false)
|
2020-11-01 22:43:23 -05:00
|
|
|
h.closeButton.OnActivated(func() { h.Close() })
|
2020-11-21 05:35:32 -05:00
|
|
|
h.closeButton.SetRenderPriority(d2ui.RenderPriorityForeground)
|
|
|
|
h.panelGroup.AddWidget(h.closeButton)
|
2020-09-09 08:21:27 -04:00
|
|
|
|
|
|
|
newLabel = h.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteSky)
|
2020-11-03 14:10:11 -05:00
|
|
|
newLabel.SetText(h.asset.TranslateString("strClose")) // "Close"
|
2020-10-23 09:00:51 -04:00
|
|
|
newLabel.SetPosition(closeButtonLabelX, closeButtonLabelY)
|
2020-11-22 00:38:09 -05:00
|
|
|
newLabel.Alignment = d2ui.HorizontalAlignCenter
|
2020-09-09 08:21:27 -04:00
|
|
|
h.text = append(h.text, newLabel)
|
2020-10-26 18:55:13 -04:00
|
|
|
}
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-12-14 12:29:54 -05:00
|
|
|
func (h *HelpOverlay) updateBulletText() {
|
2020-09-09 08:21:27 -04:00
|
|
|
// Bullets
|
2020-10-22 10:02:32 -04:00
|
|
|
callouts := []struct{ text string }{
|
2020-10-25 10:21:14 -04:00
|
|
|
// "Ctrl" should be hotkey // "Hold Down <%s> to Run"
|
2020-11-01 22:43:23 -05:00
|
|
|
{text: fmt.Sprintf(
|
2020-11-03 14:10:11 -05:00
|
|
|
h.asset.TranslateString("StrHelp2"),
|
2020-11-13 15:03:30 -05:00
|
|
|
h.keyMap.KeyToString(h.keyMap.GetKeysForGameEvent(d2enum.HoldRun).Primary),
|
2020-11-01 22:43:23 -05:00
|
|
|
)},
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
// "Alt" should be hotkey // "Hold down <%s> to highlight items on the ground"
|
2020-11-01 22:43:23 -05:00
|
|
|
{text: fmt.Sprintf(
|
2020-11-03 14:10:11 -05:00
|
|
|
h.asset.TranslateString("StrHelp3"),
|
2020-11-13 15:03:30 -05:00
|
|
|
h.keyMap.KeyToString(h.keyMap.GetKeysForGameEvent(d2enum.HoldShowGroundItems).Primary),
|
2020-11-01 22:43:23 -05:00
|
|
|
)},
|
2020-10-23 09:00:51 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
// "Shift" should be hotkey // "Hold down <%s> to attack while standing still"
|
2020-11-01 22:43:23 -05:00
|
|
|
{text: fmt.Sprintf(
|
2020-11-03 14:10:11 -05:00
|
|
|
h.asset.TranslateString("StrHelp4"),
|
2020-11-13 15:03:30 -05:00
|
|
|
h.keyMap.KeyToString(h.keyMap.GetKeysForGameEvent(d2enum.HoldStandStill).Primary),
|
2020-11-01 22:43:23 -05:00
|
|
|
)},
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
// "Tab" should be hotkey // "Hit <%s> to toggle the automap on and off"
|
2020-11-01 22:43:23 -05:00
|
|
|
{text: fmt.Sprintf(
|
2020-11-03 14:10:11 -05:00
|
|
|
h.asset.TranslateString("StrHelp5"),
|
2020-11-13 15:03:30 -05:00
|
|
|
h.keyMap.KeyToString(h.keyMap.GetKeysForGameEvent(d2enum.ToggleAutomap).Primary),
|
2020-11-01 22:43:23 -05:00
|
|
|
)},
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-22 10:02:32 -04:00
|
|
|
// "Hit <Esc> to bring up the Game Menu"
|
2020-11-03 14:10:11 -05:00
|
|
|
{text: h.asset.TranslateString("StrHelp6")},
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-10-22 10:02:32 -04:00
|
|
|
// "Hit <Enter> to go into chat mode"
|
2020-11-03 14:10:11 -05:00
|
|
|
{text: h.asset.TranslateString("StrHelp7")},
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-22 10:02:32 -04:00
|
|
|
// "Hit F1-F8 to set your Left or Right Mouse Buttton Skills."
|
2020-11-03 14:10:11 -05:00
|
|
|
{text: h.asset.TranslateString("StrHelp8")},
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
// "H" should be hotkey,
|
2020-11-01 22:43:23 -05:00
|
|
|
{text: fmt.Sprintf(
|
2020-11-03 14:10:11 -05:00
|
|
|
h.asset.TranslateString("StrHelp8a"),
|
2020-11-13 15:03:30 -05:00
|
|
|
h.keyMap.KeyToString(h.keyMap.GetKeysForGameEvent(d2enum.ToggleHelpScreen).Primary),
|
2020-11-01 22:43:23 -05:00
|
|
|
)},
|
2020-10-22 10:02:32 -04:00
|
|
|
}
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-12-14 12:29:54 -05:00
|
|
|
for i := 0; i < bullets; i++ {
|
|
|
|
h.bullets[i].SetText(callouts[i].text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *HelpOverlay) setupBulletedList() {
|
|
|
|
for idx := 0; idx < bullets; idx++ {
|
2020-10-22 10:02:32 -04:00
|
|
|
listItemOffsetY := idx * listItemVerticalOffset
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-12-14 12:29:54 -05:00
|
|
|
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)
|
2020-10-22 10:02:32 -04:00
|
|
|
}
|
2020-12-14 12:29:54 -05:00
|
|
|
h.updateBulletText()
|
2020-10-26 18:55:13 -04:00
|
|
|
}
|
2020-09-09 08:21:27 -04:00
|
|
|
|
2020-10-26 18:55:13 -04:00
|
|
|
// nolint:funlen // can't reduce
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) setupLabelsWithLines() {
|
2020-09-09 08:21:27 -04:00
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("strlvlup"), // "New Stats"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: newStatsLabelX,
|
|
|
|
LabelY: newStatsLabelY,
|
|
|
|
DotX: newStatsDotX,
|
|
|
|
DotY: newStatsDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("strnewskl"), // "New Skill"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: newSkillLabelX,
|
|
|
|
LabelY: newSkillLabelY,
|
|
|
|
DotX: newSkillDotX,
|
|
|
|
DotY: newSkillDotY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
2020-12-14 12:32:56 -05:00
|
|
|
// Some of the help fonts require multiple lines.
|
2020-09-26 11:14:34 -04:00
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp10"), // "Left Mouse-"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: leftMouseLabelX,
|
|
|
|
LabelY: leftMouseLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp11"), // "Button Skill"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: leftButtonSkillLabelX,
|
|
|
|
LabelY: leftButtonSkillLabelY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp12"), // "(Click to Change)"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: leftSkillClickToChangeLabelX,
|
|
|
|
LabelY: leftSkillClickToChangeLabelY,
|
|
|
|
DotX: leftSkillClickToChangeDotX,
|
|
|
|
DotY: leftSkillClickToChangeDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
2020-09-26 11:14:34 -04:00
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp13"), // "Right Mouse"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: rightMouseLabelX,
|
|
|
|
LabelY: rightMouseLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp11"), // "Button Skill"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: rightButtonSkillLabelX,
|
|
|
|
LabelY: rightButtonSkillLabelY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp12"), // "(Click to Change)"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: rightSkillClickToChangeLabelX,
|
|
|
|
LabelY: rightSkillClickToChangeLabelY,
|
|
|
|
DotX: rightSkillClickToChangeDotX,
|
|
|
|
DotY: rightSkillClickToChangeDotY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp17"), // "Mini-Panel"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: miniPanelLabelX,
|
|
|
|
LabelY: miniPanelLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp18"), // "(Opens Character,"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: characterLabelX,
|
|
|
|
LabelY: characterLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp19"), // "inventory, and"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: inventoryLabelX,
|
|
|
|
LabelY: inventoryLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp20"), // "other screens)"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: otherScreensLabelX,
|
|
|
|
LabelY: otherScreensLabelY,
|
|
|
|
DotX: otherScreensDotX,
|
|
|
|
DotY: otherScreensDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp9"), // "Life Orb"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: lifeOrbLabelX,
|
|
|
|
LabelY: lifeOrbLabelY,
|
|
|
|
DotX: lifeOrbDotX,
|
|
|
|
DotY: lifeOrbDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp15"), // "Stamina Bar"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: staminaBarLabelX,
|
|
|
|
LabelY: staminaBarLabelY,
|
|
|
|
DotX: staminaBarDotX,
|
|
|
|
DotY: staminaBarDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp22"), // "Mana Orb"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: manaOrbLabelX,
|
|
|
|
LabelY: manaOrbLabelY,
|
|
|
|
DotX: manaOrbDotX,
|
|
|
|
DotY: manaOrbDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
2020-09-26 11:14:34 -04:00
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp14"), // "Run/Walk"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: runWalkButtonLabelX,
|
|
|
|
LabelY: runWalkButtonLabelY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp14a"), // "Toggle"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: toggleLabelX,
|
|
|
|
LabelY: toggleLabelY,
|
|
|
|
DotX: toggleDotX,
|
|
|
|
DotY: toggleDotY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createLabel(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp16"), // "Experience"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: experienceLabelX,
|
|
|
|
LabelY: experienceLabelY,
|
2020-09-26 11:14:34 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp16a"), // "Bar"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: barLabelX,
|
|
|
|
LabelY: barLabelY,
|
|
|
|
DotX: barDotX,
|
|
|
|
DotY: barDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
h.createCallout(callout{
|
2020-11-03 14:10:11 -05:00
|
|
|
LabelText: h.asset.TranslateString("StrHelp21"), // "Belt"
|
2020-10-22 10:02:32 -04:00
|
|
|
LabelX: beltLabelX,
|
|
|
|
LabelY: beltLabelY,
|
|
|
|
DotX: beltDotX,
|
|
|
|
DotY: beltDotY,
|
2020-09-09 08:21:27 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type line struct {
|
|
|
|
StartX int
|
|
|
|
StartY int
|
|
|
|
MoveX int
|
|
|
|
MoveY int
|
|
|
|
Color color.Color
|
|
|
|
}
|
|
|
|
|
|
|
|
type callout struct {
|
|
|
|
LabelText string
|
|
|
|
LabelX int
|
|
|
|
LabelY int
|
|
|
|
DotX int
|
|
|
|
DotY int
|
|
|
|
}
|
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) createLabel(c callout) {
|
2020-09-26 11:14:34 -04:00
|
|
|
newLabel := h.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteSky)
|
|
|
|
newLabel.SetText(c.LabelText)
|
|
|
|
newLabel.SetPosition(c.LabelX, c.LabelY)
|
|
|
|
h.text = append(h.text, newLabel)
|
2020-11-13 15:03:30 -05:00
|
|
|
newLabel.Alignment = d2ui.HorizontalAlignCenter
|
2020-09-26 11:14:34 -04:00
|
|
|
}
|
|
|
|
|
2020-11-01 22:43:23 -05:00
|
|
|
func (h *HelpOverlay) createCallout(c callout) {
|
2020-09-26 11:14:34 -04:00
|
|
|
newLabel := h.uiManager.NewLabel(d2resource.FontFormal12, d2resource.PaletteSky)
|
2020-09-15 23:37:08 -04:00
|
|
|
newLabel.Color[0] = color.White
|
2020-09-09 08:21:27 -04:00
|
|
|
newLabel.SetText(c.LabelText)
|
|
|
|
newLabel.SetPosition(c.LabelX, c.LabelY)
|
2020-11-13 15:03:30 -05:00
|
|
|
newLabel.Alignment = d2ui.HorizontalAlignCenter
|
2020-09-09 08:21:27 -04:00
|
|
|
ww, hh := newLabel.GetTextMetrics(c.LabelText)
|
|
|
|
h.text = append(h.text, newLabel)
|
|
|
|
_ = ww
|
|
|
|
|
|
|
|
l := line{
|
|
|
|
StartX: c.LabelX,
|
2020-10-23 09:00:51 -04:00
|
|
|
StartY: c.LabelY + hh + lineOffset,
|
2020-09-09 08:21:27 -04:00
|
|
|
MoveX: 0,
|
2020-10-23 09:00:51 -04:00
|
|
|
MoveY: c.DotY - c.LabelY - hh - lineOffset,
|
2020-09-09 08:21:27 -04:00
|
|
|
Color: color.White,
|
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-09-09 08:21:27 -04:00
|
|
|
h.lines = append(h.lines, l)
|
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
newDot, err := h.uiManager.NewSprite(d2resource.HelpWhiteBullet, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = newDot.SetCurrentFrame(0)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
h.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
|
|
|
|
2020-09-09 08:21:27 -04:00
|
|
|
newDot.SetPosition(c.DotX, c.DotY)
|
|
|
|
h.frames = append(h.frames, newDot)
|
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// Render the overlay to the given surface
|
2020-11-21 05:35:32 -05:00
|
|
|
func (h *HelpOverlay) Render(target d2interface.Surface) {
|
2020-09-09 08:21:27 -04:00
|
|
|
for _, f := range h.frames {
|
2020-11-11 09:05:04 -05:00
|
|
|
f.Render(target)
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range h.text {
|
2020-11-11 09:01:36 -05:00
|
|
|
t.Render(target)
|
2020-09-09 08:21:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, l := range h.lines {
|
|
|
|
target.PushTranslation(l.StartX, l.StartY)
|
|
|
|
target.DrawLine(l.MoveX, l.MoveY, l.Color)
|
|
|
|
target.Pop()
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 12:29:54 -05:00
|
|
|
|
|
|
|
func (h *HelpOverlay) updateKeyMap(km *KeyMap) {
|
|
|
|
h.keyMap = km
|
|
|
|
h.updateBulletText()
|
|
|
|
}
|