Refactor the way panels are opened/closed
gravestench opened this issue · comments
gravestench commented
We should refactor the way we handle opened UI panels. The code for this is in d2game/d2player/game_controls.go
. In particular, look towards GameControls.onEscKey
.
I am thinking that we should implement a stack in GameControls
for managing the panels.
It could be used like this:
type panel interface {
IsOpen() bool
Close()
}
type panelContainer interface {
HasOpenPanels() bool
ClosePanels()
}
func (g *GameControls) onEscKey() {
// special case for opening the escape menu when panel stack is empty
if len(g.panelStack) == 0 {
g.escapeMenu.Open()
g.panelStack = append(g.panelStack, g.escapeMenu)
g.updateLayout()
return
}
// generic case, pop the last thing off the, close it, and then update
lastIdx := len(g.panelStack)-1
last := g.panelStack[lastIdx]
if p, isPanel := last.(panel); isPanel {
p.Close()
}
if p, isPanelContainer := last.(panelContainer); isPanelContainer && {
p.ClosePanels()
}
g.panelStack = append(g.panelStack[:lastIdx], g.panelStack[lastIdx+1:]...)
g.updateLayout()
}
Krishna Indani commented
hi, Is this issue available? I would like to work on this @gravestench
gravestench commented
Okay, assigned to you.
Krishna Indani commented
Thanks, I will get started on this.
gravestench commented
Status?
gravestench commented
I don't think @krishnaindani has even forked the od2 repo, they are no longer assigned.
Krishna Indani commented
Sorry, I got stucked with something else.
M.Sz. commented
@gravestench I'm working on it now