mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-31 14:37:32 -05:00
game-controls refactor
This commit is contained in:
parent
0f658d5dec
commit
8700d63f67
@ -28,7 +28,6 @@ const (
|
||||
// Panel represents the panel at the bottom of the game screen
|
||||
type Panel interface {
|
||||
IsOpen() bool
|
||||
Toggle()
|
||||
Open()
|
||||
Close()
|
||||
}
|
||||
@ -275,7 +274,7 @@ func NewGameControls(
|
||||
hoverLabel.SetBackgroundColor(d2util.Color(blackAlpha50percent))
|
||||
|
||||
gc.heroStatsPanel.SetOnCloseCb(gc.onCloseHeroStatsPanel)
|
||||
gc.questLog.SetOnCloseCb(gc.onCloseQuestLog)
|
||||
gc.questLog.SetOnCloseCb(gc.onCloseHeroQuestLog)
|
||||
gc.inventory.SetOnCloseCb(gc.onCloseInventory)
|
||||
gc.skilltree.SetOnCloseCb(gc.onCloseSkilltree)
|
||||
|
||||
@ -392,11 +391,7 @@ func (g *GameControls) OnKeyDown(event d2interface.KeyEvent) bool {
|
||||
|
||||
switch gameEvent {
|
||||
case d2enum.ClearScreen:
|
||||
g.inventory.Close()
|
||||
g.skilltree.Close()
|
||||
g.heroStatsPanel.Close()
|
||||
g.questLog.Close()
|
||||
g.HelpOverlay.Close()
|
||||
g.clearScreen()
|
||||
g.updateLayout()
|
||||
case d2enum.ToggleInventoryPanel:
|
||||
g.toggleInventoryPanel()
|
||||
@ -440,47 +435,8 @@ func (g *GameControls) OnKeyUp(event d2interface.KeyEvent) bool {
|
||||
func (g *GameControls) onEscKey() {
|
||||
escHandled := false
|
||||
|
||||
if g.hud.skillSelectMenu.IsOpen() {
|
||||
g.hud.skillSelectMenu.ClosePanels()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
|
||||
if g.inventory.IsOpen() {
|
||||
if g.inventory.moveGoldPanel.IsOpen() {
|
||||
g.inventory.moveGoldPanel.Close()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
g.inventory.Close()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
|
||||
if g.skilltree.IsOpen() {
|
||||
g.skilltree.Close()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
|
||||
if g.heroStatsPanel.IsOpen() {
|
||||
g.heroStatsPanel.Close()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
|
||||
if g.questLog.IsOpen() {
|
||||
g.questLog.Close()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
|
||||
if g.HelpOverlay.IsOpen() {
|
||||
g.HelpOverlay.Close()
|
||||
|
||||
escHandled = true
|
||||
}
|
||||
escHandled = g.hasOpenPanels() || g.HelpOverlay.IsOpen() || g.hud.skillSelectMenu.IsOpen()
|
||||
g.clearScreen()
|
||||
|
||||
switch escHandled {
|
||||
case true:
|
||||
@ -632,63 +588,88 @@ func (g *GameControls) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleHeroStatsPanel() {
|
||||
func (g *GameControls) clearLeftScreenSide() {
|
||||
g.heroStatsPanel.Close()
|
||||
g.questLog.Close()
|
||||
g.hud.skillSelectMenu.ClosePanels()
|
||||
g.hud.miniPanel.SetMovedRight(false)
|
||||
g.updateLayout()
|
||||
}
|
||||
|
||||
func (g *GameControls) clearRightScreenSide() {
|
||||
g.inventory.Close()
|
||||
g.skilltree.Close()
|
||||
g.hud.skillSelectMenu.ClosePanels()
|
||||
g.hud.miniPanel.SetMovedLeft(false)
|
||||
g.updateLayout()
|
||||
}
|
||||
|
||||
func (g *GameControls) hasOpenPanels() bool {
|
||||
return g.isRightPanelOpen() || g.isLeftPanelOpen() || g.hud.skillSelectMenu.IsOpen()
|
||||
}
|
||||
|
||||
func (g *GameControls) clearScreen() {
|
||||
g.clearRightScreenSide()
|
||||
g.clearLeftScreenSide()
|
||||
g.hud.skillSelectMenu.ClosePanels()
|
||||
g.HelpOverlay.Close()
|
||||
}
|
||||
|
||||
func (g *GameControls) openLeftPanel(panel Panel) {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.hud.skillSelectMenu.LeftPanel.Close()
|
||||
g.hud.skillSelectMenu.RightPanel.Close()
|
||||
g.questLog.Close()
|
||||
g.heroStatsPanel.Toggle()
|
||||
g.hud.miniPanel.SetMovedRight(g.heroStatsPanel.IsOpen())
|
||||
g.updateLayout()
|
||||
isOpen := panel.IsOpen()
|
||||
fmt.Println(isOpen)
|
||||
g.clearLeftScreenSide()
|
||||
if !isOpen {
|
||||
panel.Open()
|
||||
g.hud.miniPanel.SetMovedRight(true)
|
||||
g.updateLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) openRightPanel(panel Panel) {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
isOpen := panel.IsOpen()
|
||||
fmt.Println(isOpen)
|
||||
g.clearRightScreenSide()
|
||||
if !isOpen {
|
||||
panel.Open()
|
||||
g.hud.miniPanel.SetMovedLeft(true)
|
||||
g.updateLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleHeroStatsPanel() {
|
||||
g.openLeftPanel(g.heroStatsPanel)
|
||||
}
|
||||
|
||||
func (g *GameControls) onCloseHeroStatsPanel() {
|
||||
g.hud.miniPanel.SetMovedRight(g.heroStatsPanel.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleLeftSkillPanel() {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.inventory.Close()
|
||||
g.skilltree.Close()
|
||||
g.questLog.Close()
|
||||
g.heroStatsPanel.Close()
|
||||
g.clearScreen()
|
||||
g.hud.skillSelectMenu.ToggleLeftPanel()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleRightSkillPanel() {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.inventory.Close()
|
||||
g.skilltree.Close()
|
||||
g.questLog.Close()
|
||||
g.heroStatsPanel.Close()
|
||||
g.clearScreen()
|
||||
g.hud.skillSelectMenu.ToggleRightPanel()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleQuestLog() {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.heroStatsPanel.Close()
|
||||
g.hud.skillSelectMenu.LeftPanel.Close()
|
||||
g.hud.skillSelectMenu.RightPanel.Close()
|
||||
g.questLog.Toggle()
|
||||
g.hud.miniPanel.SetMovedRight(g.questLog.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) onCloseQuestLog() {
|
||||
g.hud.miniPanel.SetMovedRight(g.questLog.IsOpen())
|
||||
g.updateLayout()
|
||||
g.openLeftPanel(g.questLog)
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleHelpOverlay() {
|
||||
if !g.inventory.IsOpen() && !g.skilltree.IsOpen() && !g.heroStatsPanel.IsOpen() && !g.questLog.IsOpen() {
|
||||
if !g.isRightPanelOpen() || g.isLeftPanelOpen() {
|
||||
g.HelpOverlay.updateKeyMap(g.keyMap)
|
||||
g.hud.skillSelectMenu.LeftPanel.Close()
|
||||
g.hud.skillSelectMenu.RightPanel.Close()
|
||||
g.hud.skillSelectMenu.ClosePanels()
|
||||
g.hud.miniPanel.openDisabled()
|
||||
g.HelpOverlay.Toggle()
|
||||
g.updateLayout()
|
||||
@ -696,42 +677,21 @@ func (g *GameControls) toggleHelpOverlay() {
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleInventoryPanel() {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.hud.skillSelectMenu.LeftPanel.Close()
|
||||
g.hud.skillSelectMenu.RightPanel.Close()
|
||||
g.skilltree.Close()
|
||||
g.inventory.Toggle()
|
||||
g.hud.miniPanel.SetMovedLeft(g.inventory.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
g.openRightPanel(g.inventory)
|
||||
}
|
||||
|
||||
func (g *GameControls) onCloseInventory() {
|
||||
g.hud.miniPanel.SetMovedLeft(g.inventory.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
|
||||
func (g *GameControls) toggleSkilltreePanel() {
|
||||
if !g.HelpOverlay.IsOpen() {
|
||||
g.inventory.Close()
|
||||
g.hud.skillSelectMenu.LeftPanel.Close()
|
||||
g.hud.skillSelectMenu.RightPanel.Close()
|
||||
g.skilltree.Toggle()
|
||||
g.hud.miniPanel.SetMovedLeft(g.skilltree.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
g.openRightPanel(g.skilltree)
|
||||
}
|
||||
|
||||
func (g *GameControls) onCloseSkilltree() {
|
||||
g.hud.miniPanel.SetMovedLeft(g.skilltree.IsOpen())
|
||||
g.updateLayout()
|
||||
}
|
||||
|
||||
func (g *GameControls) openEscMenu() {
|
||||
g.inventory.Close()
|
||||
g.skilltree.Close()
|
||||
g.heroStatsPanel.Close()
|
||||
g.questLog.Close()
|
||||
g.clearScreen()
|
||||
g.hud.miniPanel.closeDisabled()
|
||||
g.escapeMenu.open()
|
||||
g.updateLayout()
|
||||
@ -792,7 +752,6 @@ func (g *GameControls) updateLayout() {
|
||||
}
|
||||
|
||||
func (g *GameControls) isLeftPanelOpen() bool {
|
||||
// https://github.com/OpenDiablo2/OpenDiablo2/issues/801
|
||||
return g.heroStatsPanel.IsOpen() || g.questLog.IsOpen() || g.inventory.moveGoldPanel.IsOpen()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user