mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-12-26 12:06:24 -05:00
camera offset for ui panels : (#369)
* camera offset for ui panels : added maprenderer viewport to be aligned left or right calling alignement on keyPress in game_controls * check if already aligned
This commit is contained in:
parent
b95335f399
commit
afe4a3a25a
@ -58,3 +58,15 @@ func (m *MapRenderer) ScreenToOrtho(x, y int) (float64, float64) {
|
||||
func (m *MapRenderer) WorldToOrtho(x, y float64) (float64, float64) {
|
||||
return m.viewport.WorldToOrtho(x, y)
|
||||
}
|
||||
|
||||
func (m *MapRenderer) ViewportToLeft() {
|
||||
m.viewport.toLeft()
|
||||
}
|
||||
|
||||
func (m *MapRenderer) ViewportToRight() {
|
||||
m.viewport.toRight()
|
||||
}
|
||||
|
||||
func (m *MapRenderer) ViewportDefault() {
|
||||
m.viewport.resetAlign()
|
||||
}
|
||||
|
@ -11,11 +11,19 @@ type worldTrans struct {
|
||||
y float64
|
||||
}
|
||||
|
||||
const (
|
||||
center = 0
|
||||
left = 1
|
||||
right = 2
|
||||
)
|
||||
|
||||
type Viewport struct {
|
||||
screenRect d2common.Rectangle
|
||||
transStack []worldTrans
|
||||
transCurrent worldTrans
|
||||
camera *Camera
|
||||
defaultScreenRect d2common.Rectangle
|
||||
screenRect d2common.Rectangle
|
||||
transStack []worldTrans
|
||||
transCurrent worldTrans
|
||||
camera *Camera
|
||||
align int
|
||||
}
|
||||
|
||||
func NewViewport(x, y, width, height int) *Viewport {
|
||||
@ -26,6 +34,12 @@ func NewViewport(x, y, width, height int) *Viewport {
|
||||
Width: width,
|
||||
Height: height,
|
||||
},
|
||||
defaultScreenRect: d2common.Rectangle{
|
||||
Left: x,
|
||||
Top: y,
|
||||
Width: width,
|
||||
Height: height,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,3 +144,26 @@ func (v *Viewport) getCameraOffset() (float64, float64) {
|
||||
|
||||
return camX, camY
|
||||
}
|
||||
|
||||
func (v *Viewport) toLeft() {
|
||||
if v.align == left {
|
||||
return
|
||||
}
|
||||
v.screenRect.Width = v.defaultScreenRect.Width / 2
|
||||
}
|
||||
|
||||
func (v *Viewport) toRight() {
|
||||
if v.align == right {
|
||||
return
|
||||
}
|
||||
v.screenRect.Width = v.defaultScreenRect.Width / 2
|
||||
v.screenRect.Left = v.defaultScreenRect.Left + v.defaultScreenRect.Width/2
|
||||
}
|
||||
|
||||
func (v *Viewport) resetAlign() {
|
||||
if v.align == center {
|
||||
return
|
||||
}
|
||||
v.screenRect.Width = v.defaultScreenRect.Width
|
||||
v.screenRect.Left = v.defaultScreenRect.Left
|
||||
}
|
||||
|
@ -55,16 +55,35 @@ func NewGameControls(hero *d2map.Player, mapEngine *d2map.MapEngine, mapRenderer
|
||||
func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
|
||||
if event.Key == d2input.KeyI {
|
||||
g.inventory.Toggle()
|
||||
g.updateLayout()
|
||||
return true
|
||||
}
|
||||
if event.Key == d2input.KeyC {
|
||||
g.heroStats.Toggle()
|
||||
g.updateLayout()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *GameControls) updateLayout() {
|
||||
isRightPanelOpen := false
|
||||
isLeftPanelOpen := false
|
||||
|
||||
// todo : add same logic when adding quest log and skill tree
|
||||
isRightPanelOpen = g.inventory.isOpen || isRightPanelOpen
|
||||
isLeftPanelOpen = g.heroStats.isOpen || isLeftPanelOpen
|
||||
|
||||
if isRightPanelOpen == isLeftPanelOpen {
|
||||
g.mapRenderer.ViewportDefault()
|
||||
} else if isRightPanelOpen == true {
|
||||
g.mapRenderer.ViewportToLeft()
|
||||
} else {
|
||||
g.mapRenderer.ViewportToRight()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameControls) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
||||
px, py := g.mapRenderer.ScreenToWorld(event.X, event.Y)
|
||||
px = float64(int(px*10)) / 10.0
|
||||
|
Loading…
Reference in New Issue
Block a user