2020-08-25 09:10:26 -04:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-11-18 16:02:49 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-08-25 09:10:26 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
2020-11-16 04:41:01 -05:00
|
|
|
miniPanelX = 325
|
|
|
|
miniPanelY = 526
|
|
|
|
|
|
|
|
panelOffsetLeft = 130
|
|
|
|
panelOffsetRight = 130
|
2020-10-25 03:42:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
containerOffsetX = -75
|
2020-11-16 04:41:01 -05:00
|
|
|
containerOffsetY = -49
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
buttonOffsetX = -72
|
2020-11-16 04:41:01 -05:00
|
|
|
buttonOffsetY = -52
|
2020-10-25 03:42:31 -04:00
|
|
|
)
|
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
type miniPanelContent struct {
|
|
|
|
buttonType d2ui.ButtonType
|
|
|
|
onActivate func()
|
|
|
|
tooltip string
|
|
|
|
}
|
|
|
|
|
|
|
|
type miniPanelActions struct {
|
|
|
|
characterToggle func()
|
|
|
|
inventoryToggle func()
|
|
|
|
skilltreeToggle func()
|
|
|
|
partyToggle func()
|
|
|
|
automapToggle func()
|
|
|
|
messageToggle func()
|
|
|
|
questToggle func()
|
|
|
|
menuToggle func()
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
func newMiniPanel(asset *d2asset.AssetManager,
|
|
|
|
uiManager *d2ui.UIManager,
|
|
|
|
l d2util.LogLevel,
|
|
|
|
isSinglePlayer bool) *miniPanel {
|
|
|
|
mp := &miniPanel{
|
|
|
|
ui: uiManager,
|
|
|
|
asset: asset,
|
|
|
|
isOpen: false,
|
|
|
|
isSinglePlayer: isSinglePlayer,
|
|
|
|
}
|
|
|
|
|
|
|
|
mp.logger = d2util.NewLogger()
|
|
|
|
mp.logger.SetLevel(l)
|
|
|
|
mp.logger.SetPrefix(logPrefix)
|
|
|
|
|
|
|
|
return mp
|
|
|
|
}
|
|
|
|
|
2020-08-25 09:10:26 -04:00
|
|
|
type miniPanel struct {
|
2020-11-16 04:41:01 -05:00
|
|
|
ui *d2ui.UIManager
|
2020-09-12 16:51:30 -04:00
|
|
|
asset *d2asset.AssetManager
|
2020-08-25 09:10:26 -04:00
|
|
|
container *d2ui.Sprite
|
2020-11-16 04:41:01 -05:00
|
|
|
sprite *d2ui.Sprite
|
2020-08-25 09:10:26 -04:00
|
|
|
isOpen bool
|
|
|
|
isSinglePlayer bool
|
2020-11-16 04:41:01 -05:00
|
|
|
movedLeft bool
|
|
|
|
movedRight bool
|
|
|
|
panelGroup *d2ui.WidgetGroup
|
|
|
|
tooltipGroup *d2ui.WidgetGroup
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
logger *d2util.Logger
|
2020-11-16 04:41:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) load(actions *miniPanelActions) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
m.sprite, err = m.ui.NewSprite(d2resource.MinipanelButton, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
m.logger.Error(err.Error())
|
2020-11-16 04:41:01 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
m.createWidgets(actions)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) createWidgets(actions *miniPanelActions) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
m.panelGroup = m.ui.NewWidgetGroup(d2ui.RenderPriorityMinipanel)
|
|
|
|
m.panelGroup.SetPosition(miniPanelX, miniPanelY)
|
|
|
|
|
|
|
|
m.tooltipGroup = m.ui.NewWidgetGroup(d2ui.RenderPriorityForeground)
|
|
|
|
|
2020-08-25 09:10:26 -04:00
|
|
|
miniPanelContainerPath := d2resource.Minipanel
|
2020-11-16 04:41:01 -05:00
|
|
|
if m.isSinglePlayer {
|
2020-08-25 09:10:26 -04:00
|
|
|
miniPanelContainerPath = d2resource.MinipanelSmall
|
|
|
|
}
|
2020-09-12 16:25:09 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
m.container, err = m.ui.NewSprite(miniPanelContainerPath, d2resource.PaletteSky)
|
2020-09-23 13:30:54 -04:00
|
|
|
if err != nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
m.logger.Error(err.Error())
|
2020-11-16 04:41:01 -05:00
|
|
|
return
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
if err = m.container.SetCurrentFrame(0); err != nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
m.logger.Error(err.Error())
|
2020-11-16 04:41:01 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// nolint:golint,gomnd // divide by 2 does not need a magic number
|
|
|
|
x, y := screenWidth/2+containerOffsetX, screenHeight+containerOffsetY
|
|
|
|
m.container.SetPosition(x, y)
|
|
|
|
m.panelGroup.AddWidget(m.container)
|
|
|
|
|
|
|
|
buttonWidth, buttonHeight, err := m.sprite.GetFrameSize(0)
|
2020-09-23 13:30:54 -04:00
|
|
|
if err != nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
m.logger.Error(err.Error())
|
2020-11-16 04:41:01 -05:00
|
|
|
return
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
buttonWidth++
|
|
|
|
|
|
|
|
// nolint:golint,gomnd // divide by 2 does not need a magic number
|
|
|
|
x, y = screenWidth/2+buttonOffsetX, screenHeight+buttonOffsetY-buttonHeight
|
|
|
|
buttonsFirst := []miniPanelContent{
|
|
|
|
{d2ui.ButtonTypeMinipanelCharacter,
|
|
|
|
actions.characterToggle,
|
|
|
|
m.asset.TranslateString("minipanelchar"),
|
|
|
|
},
|
|
|
|
{d2ui.ButtonTypeMinipanelInventory,
|
|
|
|
actions.inventoryToggle,
|
|
|
|
m.asset.TranslateString("minipanelinv"),
|
|
|
|
},
|
|
|
|
{d2ui.ButtonTypeMinipanelSkill,
|
|
|
|
actions.skilltreeToggle,
|
|
|
|
m.asset.TranslateString("minipaneltree"),
|
|
|
|
},
|
2020-10-25 03:42:31 -04:00
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
for i := range buttonsFirst {
|
|
|
|
btn := m.createButton(buttonsFirst[i], x+(i*buttonWidth), y, buttonHeight)
|
|
|
|
m.panelGroup.AddWidget(btn)
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
idxOffset := len(buttonsFirst)
|
|
|
|
|
|
|
|
if !m.isSinglePlayer {
|
|
|
|
partyContent := miniPanelContent{d2ui.ButtonTypeMinipanelParty,
|
|
|
|
actions.partyToggle,
|
|
|
|
m.asset.TranslateString("minipanelparty"),
|
|
|
|
}
|
|
|
|
btn := m.createButton(partyContent, x+(3*buttonWidth), y, buttonHeight)
|
|
|
|
m.panelGroup.AddWidget(btn)
|
|
|
|
idxOffset++
|
2020-09-12 16:51:30 -04:00
|
|
|
}
|
2020-11-16 04:41:01 -05:00
|
|
|
|
|
|
|
buttonsLast := []miniPanelContent{
|
|
|
|
{d2ui.ButtonTypeMinipanelAutomap,
|
|
|
|
actions.automapToggle,
|
|
|
|
m.asset.TranslateString("minipanelautomap"),
|
|
|
|
},
|
|
|
|
{d2ui.ButtonTypeMinipanelMessage,
|
|
|
|
actions.messageToggle,
|
|
|
|
m.asset.TranslateString("minipanelmessage"),
|
|
|
|
},
|
|
|
|
{d2ui.ButtonTypeMinipanelQuest,
|
|
|
|
actions.questToggle,
|
|
|
|
m.asset.TranslateString("minipanelquest"),
|
|
|
|
},
|
|
|
|
{d2ui.ButtonTypeMinipanelMen,
|
|
|
|
actions.menuToggle,
|
|
|
|
m.asset.TranslateString("minipanelmenubtn"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range buttonsLast {
|
|
|
|
idx := i + idxOffset
|
|
|
|
btn := m.createButton(buttonsLast[i], x+(idx*buttonWidth), y, buttonHeight)
|
|
|
|
m.panelGroup.AddWidget(btn)
|
|
|
|
}
|
|
|
|
|
|
|
|
m.panelGroup.SetVisible(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) createButton(content miniPanelContent, x, y, buttonHeight int) *d2ui.Button {
|
|
|
|
// Tooltip
|
|
|
|
tt := m.ui.NewTooltip(d2resource.Font16, d2resource.PaletteSky, d2ui.TooltipXCenter, d2ui.TooltipYTop)
|
|
|
|
tt.SetPosition(x, y-buttonHeight)
|
|
|
|
tt.SetText(content.tooltip)
|
|
|
|
tt.SetVisible(false)
|
|
|
|
m.tooltipGroup.AddWidget(tt)
|
|
|
|
|
|
|
|
// Button
|
|
|
|
btn := m.ui.NewButton(content.buttonType, "")
|
|
|
|
btn.SetPosition(x, y)
|
|
|
|
btn.OnActivated(content.onActivate)
|
|
|
|
btn.SetTooltip(tt)
|
|
|
|
|
|
|
|
return btn
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) IsOpen() bool {
|
|
|
|
return m.isOpen
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) Toggle() {
|
2020-11-16 04:41:01 -05:00
|
|
|
if m.isOpen {
|
|
|
|
m.Close()
|
|
|
|
} else {
|
|
|
|
m.Open()
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) Open() {
|
2020-11-16 04:41:01 -05:00
|
|
|
m.panelGroup.SetVisible(true)
|
2020-08-25 09:10:26 -04:00
|
|
|
m.isOpen = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *miniPanel) Close() {
|
2020-11-16 04:41:01 -05:00
|
|
|
m.panelGroup.SetVisible(false)
|
2020-08-25 09:10:26 -04:00
|
|
|
m.isOpen = false
|
|
|
|
}
|
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) IsInRect(px, py int) bool {
|
|
|
|
return m.panelGroup.Contains(px, py)
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) moveRight() {
|
|
|
|
m.panelGroup.OffsetPosition(panelOffsetRight, 0)
|
|
|
|
m.tooltipGroup.OffsetPosition(panelOffsetRight, 0)
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) undoMoveRight() {
|
|
|
|
m.panelGroup.OffsetPosition(-panelOffsetRight, 0)
|
|
|
|
m.tooltipGroup.OffsetPosition(-panelOffsetRight, 0)
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) moveLeft() {
|
|
|
|
m.panelGroup.OffsetPosition(-panelOffsetLeft, 0)
|
|
|
|
m.tooltipGroup.OffsetPosition(-panelOffsetLeft, 0)
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) undoMoveLeft() {
|
|
|
|
m.panelGroup.OffsetPosition(panelOffsetLeft, 0)
|
|
|
|
m.tooltipGroup.OffsetPosition(panelOffsetLeft, 0)
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) SetMovedLeft(moveLeft bool) {
|
|
|
|
if m.movedLeft == moveLeft {
|
|
|
|
return
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
if m.movedRight {
|
|
|
|
if moveLeft {
|
|
|
|
m.undoMoveRight()
|
|
|
|
m.panelGroup.SetVisible(false)
|
|
|
|
} else {
|
|
|
|
m.moveRight()
|
|
|
|
m.panelGroup.SetVisible(true)
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
2020-11-16 04:41:01 -05:00
|
|
|
} else {
|
|
|
|
if moveLeft {
|
|
|
|
m.moveLeft()
|
|
|
|
} else {
|
|
|
|
m.undoMoveLeft()
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
2020-11-16 04:41:01 -05:00
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
m.movedLeft = moveLeft
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
func (m *miniPanel) SetMovedRight(moveRight bool) {
|
|
|
|
if m.movedRight == moveRight {
|
|
|
|
return
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
if m.movedLeft {
|
|
|
|
if moveRight {
|
|
|
|
m.undoMoveLeft()
|
|
|
|
m.panelGroup.SetVisible(false)
|
|
|
|
} else {
|
|
|
|
m.moveLeft()
|
|
|
|
m.panelGroup.SetVisible(true)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if moveRight {
|
|
|
|
m.moveRight()
|
|
|
|
} else {
|
|
|
|
m.undoMoveRight()
|
|
|
|
}
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|
|
|
|
|
2020-11-16 04:41:01 -05:00
|
|
|
m.movedRight = moveRight
|
2020-08-25 09:10:26 -04:00
|
|
|
}
|