OpenDiablo2 / OpenDiablo2

An open source re-implementation of Diablo 2

Home Page:https://opendiablo2.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Refactor the way panels are opened/closed

gravestench opened this issue · comments

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()
}

hi, Is this issue available? I would like to work on this @gravestench

Okay, assigned to you.

Thanks, I will get started on this.

Status?

I don't think @krishnaindani has even forked the od2 repo, they are no longer assigned.

Sorry, I got stucked with something else.

commented

@gravestench I'm working on it now