2019-12-16 11:04:39 -05:00
|
|
|
package d2player
|
|
|
|
|
|
|
|
import (
|
2020-06-22 15:55:32 -04:00
|
|
|
"image/color"
|
2020-06-23 12:28:05 -04:00
|
|
|
"log"
|
2020-06-25 00:39:09 -04:00
|
|
|
"math"
|
2020-06-22 15:55:32 -04:00
|
|
|
"time"
|
|
|
|
|
2020-06-30 09:58:53 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
|
2020-02-23 03:23:18 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-06-28 21:40:52 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-01-26 00:39:13 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer"
|
2020-02-01 20:39:28 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2019-12-16 11:04:39 -05:00
|
|
|
)
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
type Panel interface {
|
|
|
|
IsOpen() bool
|
|
|
|
Toggle()
|
|
|
|
Open()
|
|
|
|
Close()
|
|
|
|
}
|
|
|
|
|
2020-02-22 20:44:30 -05:00
|
|
|
// ID of missile to create when user right clicks.
|
|
|
|
var missileID = 59
|
2020-06-25 14:56:49 -04:00
|
|
|
var expBarWidth = 120.0
|
|
|
|
var staminaBarWidth = 102.0
|
|
|
|
var globeHeight = 80
|
|
|
|
var globeWidth = 80
|
2020-02-22 20:44:30 -05:00
|
|
|
|
2020-06-25 19:18:37 -04:00
|
|
|
var leftMenuRect = d2common.Rectangle{Left: 0, Top: 0, Width: 400, Height: 600}
|
|
|
|
var rightMenuRect = d2common.Rectangle{Left: 400, Top: 0, Width: 400, Height: 600}
|
|
|
|
var bottomMenuRect = d2common.Rectangle{Left: 0, Top: 550, Width: 800, Height: 50}
|
|
|
|
|
2019-12-16 11:04:39 -05:00
|
|
|
type GameControls struct {
|
2020-06-25 14:56:49 -04:00
|
|
|
hero *d2mapentity.Player
|
|
|
|
mapEngine *d2mapengine.MapEngine
|
|
|
|
mapRenderer *d2maprenderer.MapRenderer
|
|
|
|
inventory *Inventory
|
|
|
|
heroStatsPanel *HeroStatsPanel
|
|
|
|
inputListener InputCallbackListener
|
|
|
|
FreeCam bool
|
|
|
|
lastMouseX int
|
|
|
|
lastMouseY int
|
|
|
|
lastHealthPercent float64
|
|
|
|
lastManaPercent float64
|
2019-12-16 11:04:39 -05:00
|
|
|
|
|
|
|
// UI
|
2020-06-25 14:56:49 -04:00
|
|
|
globeSprite *d2ui.Sprite
|
|
|
|
hpManaStatusSprite *d2ui.Sprite
|
2020-06-29 00:41:58 -04:00
|
|
|
hpStatusBar d2interface.Surface
|
|
|
|
manaStatusBar d2interface.Surface
|
2020-06-25 14:56:49 -04:00
|
|
|
mainPanel *d2ui.Sprite
|
|
|
|
menuButton *d2ui.Sprite
|
|
|
|
skillIcon *d2ui.Sprite
|
|
|
|
zoneChangeText *d2ui.Label
|
|
|
|
nameLabel *d2ui.Label
|
|
|
|
runButton d2ui.Button
|
|
|
|
isZoneTextShown bool
|
|
|
|
actionableRegions []ActionableRegion
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
|
|
|
|
2020-06-23 12:28:05 -04:00
|
|
|
type ActionableType int
|
2020-06-24 13:49:13 -04:00
|
|
|
type ActionableRegion struct {
|
|
|
|
ActionableTypeId ActionableType
|
|
|
|
Rect d2common.Rectangle
|
|
|
|
}
|
2020-06-23 12:28:05 -04:00
|
|
|
|
|
|
|
const (
|
|
|
|
// Since they require special handling, not considering (1) globes, (2) content of the mini panel, (3) belt
|
|
|
|
leftSkill = ActionableType(iota)
|
|
|
|
leftSelec = ActionableType(iota)
|
|
|
|
xp = ActionableType(iota)
|
|
|
|
walkRun = ActionableType(iota)
|
|
|
|
stamina = ActionableType(iota)
|
|
|
|
miniPanel = ActionableType(iota)
|
|
|
|
rightSelec = ActionableType(iota)
|
|
|
|
rightSkill = ActionableType(iota)
|
|
|
|
)
|
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
func NewGameControls(hero *d2mapentity.Player, mapEngine *d2mapengine.MapEngine, mapRenderer *d2maprenderer.MapRenderer, inputListener InputCallbackListener, term d2interface.Terminal) *GameControls {
|
|
|
|
term.BindAction("setmissile", "set missile id to summon on right click", func(id int) {
|
2020-02-22 20:44:30 -05:00
|
|
|
missileID = id
|
|
|
|
})
|
|
|
|
|
2020-06-25 14:56:49 -04:00
|
|
|
zoneLabel := d2ui.CreateLabel(d2resource.Font30, d2resource.PaletteUnits)
|
|
|
|
zoneLabel.Color = color.RGBA{R: 255, G: 88, B: 82, A: 255}
|
|
|
|
zoneLabel.Alignment = d2ui.LabelAlignCenter
|
2020-06-22 15:55:32 -04:00
|
|
|
|
2020-06-25 00:39:09 -04:00
|
|
|
nameLabel := d2ui.CreateLabel(d2resource.FontFormal11, d2resource.PaletteStatic)
|
|
|
|
nameLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
nameLabel.SetText("")
|
|
|
|
nameLabel.Color = color.White
|
|
|
|
|
2020-06-21 20:46:00 -04:00
|
|
|
gc := &GameControls{
|
2020-06-22 15:55:32 -04:00
|
|
|
hero: hero,
|
|
|
|
mapEngine: mapEngine,
|
|
|
|
inputListener: inputListener,
|
|
|
|
mapRenderer: mapRenderer,
|
|
|
|
inventory: NewInventory(),
|
2020-06-25 14:56:49 -04:00
|
|
|
heroStatsPanel: NewHeroStatsPanel(hero.Name(), hero.Class, hero.Stats),
|
2020-06-25 00:39:09 -04:00
|
|
|
nameLabel: &nameLabel,
|
2020-06-25 14:56:49 -04:00
|
|
|
zoneChangeText: &zoneLabel,
|
2020-06-24 13:49:13 -04:00
|
|
|
actionableRegions: []ActionableRegion{
|
|
|
|
{leftSkill, d2common.Rectangle{Left: 115, Top: 550, Width: 50, Height: 50}},
|
|
|
|
{leftSelec, d2common.Rectangle{Left: 206, Top: 563, Width: 30, Height: 30}},
|
|
|
|
{xp, d2common.Rectangle{Left: 253, Top: 560, Width: 125, Height: 5}},
|
|
|
|
{walkRun, d2common.Rectangle{Left: 255, Top: 573, Width: 17, Height: 20}},
|
|
|
|
{stamina, d2common.Rectangle{Left: 273, Top: 573, Width: 105, Height: 20}},
|
|
|
|
{miniPanel, d2common.Rectangle{Left: 393, Top: 563, Width: 12, Height: 23}},
|
|
|
|
{rightSelec, d2common.Rectangle{Left: 562, Top: 563, Width: 30, Height: 30}},
|
|
|
|
{rightSkill, d2common.Rectangle{Left: 634, Top: 550, Width: 50, Height: 50}},
|
2020-06-23 12:28:05 -04:00
|
|
|
},
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
2020-06-21 20:46:00 -04:00
|
|
|
|
2020-06-28 21:40:52 -04:00
|
|
|
term.BindAction("freecam", "toggle free camera movement", func() {
|
2020-06-21 20:46:00 -04:00
|
|
|
gc.FreeCam = !gc.FreeCam
|
|
|
|
})
|
|
|
|
|
|
|
|
return gc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) OnKeyRepeat(event d2input.KeyEvent) bool {
|
|
|
|
if g.FreeCam {
|
|
|
|
var moveSpeed float64 = 8
|
|
|
|
if event.KeyMod == d2input.KeyModShift {
|
|
|
|
moveSpeed *= 2
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Key == d2input.KeyDown {
|
|
|
|
g.mapRenderer.MoveCameraBy(0, moveSpeed)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Key == d2input.KeyUp {
|
|
|
|
g.mapRenderer.MoveCameraBy(0, -moveSpeed)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Key == d2input.KeyRight {
|
|
|
|
g.mapRenderer.MoveCameraBy(moveSpeed, 0)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Key == d2input.KeyLeft {
|
|
|
|
g.mapRenderer.MoveCameraBy(-moveSpeed, 0)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
func (g *GameControls) OnKeyDown(event d2input.KeyEvent) bool {
|
2020-06-21 18:44:33 -04:00
|
|
|
switch event.Key {
|
|
|
|
case d2input.KeyEscape:
|
2020-06-25 14:56:49 -04:00
|
|
|
if g.inventory.IsOpen() || g.heroStatsPanel.IsOpen() {
|
2020-06-21 18:44:33 -04:00
|
|
|
g.inventory.Close()
|
2020-06-25 14:56:49 -04:00
|
|
|
g.heroStatsPanel.Close()
|
2020-06-22 09:23:56 -04:00
|
|
|
g.updateLayout()
|
2020-06-21 18:44:33 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case d2input.KeyI:
|
2020-01-25 23:28:21 -05:00
|
|
|
g.inventory.Toggle()
|
2020-06-22 09:23:56 -04:00
|
|
|
g.updateLayout()
|
2020-06-21 18:44:33 -04:00
|
|
|
case d2input.KeyC:
|
2020-06-25 14:56:49 -04:00
|
|
|
g.heroStatsPanel.Toggle()
|
2020-06-22 09:23:56 -04:00
|
|
|
g.updateLayout()
|
2020-06-22 15:55:32 -04:00
|
|
|
case d2input.KeyR:
|
2020-06-24 15:23:38 -04:00
|
|
|
g.onToggleRunButton()
|
2020-06-21 18:44:33 -04:00
|
|
|
default:
|
|
|
|
return false
|
2020-02-08 10:51:11 -05:00
|
|
|
}
|
2020-06-22 15:55:32 -04:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var lastLeftBtnActionTime float64 = 0
|
|
|
|
var lastRightBtnActionTime float64 = 0
|
|
|
|
var mouseBtnActionsTreshhold = 0.25
|
|
|
|
|
|
|
|
func (g *GameControls) OnMouseButtonRepeat(event d2input.MouseEvent) bool {
|
|
|
|
px, py := g.mapRenderer.ScreenToWorld(event.X, event.Y)
|
|
|
|
px = float64(int(px*10)) / 10.0
|
|
|
|
py = float64(int(py*10)) / 10.0
|
|
|
|
|
|
|
|
now := d2common.Now()
|
2020-06-25 19:18:37 -04:00
|
|
|
if event.Button == d2input.MouseButtonLeft && now-lastLeftBtnActionTime >= mouseBtnActionsTreshhold && !g.isInActiveMenusRect(event.X, event.Y) {
|
2020-06-22 15:55:32 -04:00
|
|
|
lastLeftBtnActionTime = now
|
|
|
|
g.inputListener.OnPlayerMove(px, py)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-06-25 19:18:37 -04:00
|
|
|
if event.Button == d2input.MouseButtonRight && now-lastRightBtnActionTime >= mouseBtnActionsTreshhold && !g.isInActiveMenusRect(event.X, event.Y) {
|
2020-06-22 15:55:32 -04:00
|
|
|
lastRightBtnActionTime = now
|
2020-06-26 20:03:00 -04:00
|
|
|
g.inputListener.OnPlayerCast(missileID, px, py)
|
2020-06-22 15:55:32 -04:00
|
|
|
return true
|
|
|
|
}
|
2019-12-16 11:04:39 -05:00
|
|
|
|
2020-06-21 18:44:33 -04:00
|
|
|
return true
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-12-16 11:04:39 -05:00
|
|
|
|
2020-06-21 16:06:52 -04:00
|
|
|
func (g *GameControls) OnMouseMove(event d2input.MouseMoveEvent) bool {
|
2020-06-25 00:39:09 -04:00
|
|
|
mx, my := event.X, event.Y
|
|
|
|
g.lastMouseX = mx
|
|
|
|
g.lastMouseY = my
|
|
|
|
|
2020-06-23 12:28:05 -04:00
|
|
|
for i := range g.actionableRegions {
|
|
|
|
// Mouse over a game control element
|
|
|
|
if g.actionableRegions[i].Rect.IsInRect(mx, my) {
|
|
|
|
g.onHoverActionable(g.actionableRegions[i].ActionableTypeId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 16:06:52 -04:00
|
|
|
return false
|
2020-06-21 15:26:07 -04:00
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
func (g *GameControls) OnMouseButtonDown(event d2input.MouseEvent) bool {
|
2020-06-23 12:28:05 -04:00
|
|
|
mx, my := event.X, event.Y
|
|
|
|
for i := range g.actionableRegions {
|
|
|
|
// If click is on a game control element
|
|
|
|
if g.actionableRegions[i].Rect.IsInRect(mx, my) {
|
|
|
|
g.onClickActionable(g.actionableRegions[i].ActionableTypeId)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
px, py := g.mapRenderer.ScreenToWorld(mx, my)
|
2020-02-22 20:44:30 -05:00
|
|
|
px = float64(int(px*10)) / 10.0
|
|
|
|
py = float64(int(py*10)) / 10.0
|
|
|
|
|
2020-06-25 19:18:37 -04:00
|
|
|
if event.Button == d2input.MouseButtonLeft && !g.isInActiveMenusRect(mx, my) {
|
2020-06-22 15:55:32 -04:00
|
|
|
lastLeftBtnActionTime = d2common.Now()
|
2020-06-18 14:11:04 -04:00
|
|
|
g.inputListener.OnPlayerMove(px, py)
|
2020-02-22 20:44:30 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-06-25 19:18:37 -04:00
|
|
|
if event.Button == d2input.MouseButtonRight && !g.isInActiveMenusRect(mx, my) {
|
2020-06-22 15:55:32 -04:00
|
|
|
lastRightBtnActionTime = d2common.Now()
|
2020-06-26 20:03:00 -04:00
|
|
|
g.inputListener.OnPlayerCast(missileID, px, py)
|
|
|
|
return true
|
2019-12-28 23:32:53 -05:00
|
|
|
}
|
2020-02-22 20:44:30 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return false
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) Load() {
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ := d2asset.LoadAnimation(d2resource.GameGlobeOverlap, d2resource.PaletteSky)
|
|
|
|
g.globeSprite, _ = d2ui.LoadSprite(animation)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-06-25 14:56:49 -04:00
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.HealthManaIndicator, d2resource.PaletteSky)
|
|
|
|
g.hpManaStatusSprite, _ = d2ui.LoadSprite(animation)
|
|
|
|
|
2020-06-29 00:41:58 -04:00
|
|
|
g.hpStatusBar, _ = d2render.NewSurface(globeWidth, globeHeight, d2interface.FilterNearest)
|
2020-06-25 14:56:49 -04:00
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.GamePanels, d2resource.PaletteSky)
|
|
|
|
g.mainPanel, _ = d2ui.LoadSprite(animation)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.MenuButton, d2resource.PaletteSky)
|
|
|
|
g.menuButton, _ = d2ui.LoadSprite(animation)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-02-01 18:55:56 -05:00
|
|
|
animation, _ = d2asset.LoadAnimation(d2resource.GenericSkills, d2resource.PaletteSky)
|
|
|
|
g.skillIcon, _ = d2ui.LoadSprite(animation)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-06-24 15:23:38 -04:00
|
|
|
g.loadUIButtons()
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.inventory.Load()
|
2020-06-25 14:56:49 -04:00
|
|
|
g.heroStatsPanel.Load()
|
2020-06-21 16:06:52 -04:00
|
|
|
}
|
|
|
|
|
2020-06-24 15:23:38 -04:00
|
|
|
func (g *GameControls) loadUIButtons() {
|
|
|
|
// Run button
|
|
|
|
g.runButton = d2ui.CreateButton(d2ui.ButtonTypeRun, "")
|
|
|
|
g.runButton.SetPosition(255, 570)
|
|
|
|
g.runButton.OnActivated(func() { g.onToggleRunButton() })
|
|
|
|
if g.hero.IsRunToggled() {
|
|
|
|
g.runButton.Toggle()
|
|
|
|
}
|
|
|
|
d2ui.AddWidget(&g.runButton)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) onToggleRunButton() {
|
|
|
|
g.runButton.Toggle()
|
|
|
|
g.hero.ToggleRunWalk()
|
|
|
|
// TODO: change the running menu icon
|
|
|
|
g.hero.SetIsRunning(g.hero.IsRunToggled())
|
|
|
|
}
|
|
|
|
|
2020-06-21 16:06:52 -04:00
|
|
|
// ScreenAdvanceHandler
|
|
|
|
func (g *GameControls) Advance(elapsed float64) error {
|
|
|
|
return nil
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
|
|
|
|
2020-06-22 09:23:56 -04:00
|
|
|
func (g *GameControls) updateLayout() {
|
2020-06-25 19:18:37 -04:00
|
|
|
isRightPanelOpen := g.isLeftPanelOpen()
|
|
|
|
isLeftPanelOpen := g.isRightPanelOpen()
|
2020-06-22 09:23:56 -04:00
|
|
|
|
|
|
|
if isRightPanelOpen == isLeftPanelOpen {
|
|
|
|
g.mapRenderer.ViewportDefault()
|
2020-06-25 19:18:37 -04:00
|
|
|
} else if isRightPanelOpen {
|
2020-06-22 09:23:56 -04:00
|
|
|
g.mapRenderer.ViewportToLeft()
|
|
|
|
} else {
|
|
|
|
g.mapRenderer.ViewportToRight()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 19:18:37 -04:00
|
|
|
func (g *GameControls) isLeftPanelOpen() bool {
|
|
|
|
// TODO: add quest log panel
|
|
|
|
return g.heroStatsPanel.IsOpen()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) isRightPanelOpen() bool {
|
|
|
|
// TODO: add skills tree panel
|
|
|
|
return g.inventory.IsOpen()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) isInActiveMenusRect(px int, py int) bool {
|
|
|
|
if bottomMenuRect.IsInRect(px, py) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.isLeftPanelOpen() && leftMenuRect.IsInRect(px, py) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if g.isRightPanelOpen() && rightMenuRect.IsInRect(px, py) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:04:39 -05:00
|
|
|
// TODO: consider caching the panels to single image that is reused.
|
2020-06-29 00:41:58 -04:00
|
|
|
func (g *GameControls) Render(target d2interface.Surface) {
|
2020-06-25 00:39:09 -04:00
|
|
|
for entityIdx := range *g.mapEngine.Entities() {
|
|
|
|
entity := (*g.mapEngine.Entities())[entityIdx]
|
2020-06-27 18:58:41 -04:00
|
|
|
if !entity.Selectable() {
|
2020-06-25 00:39:09 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
entScreenXf, entScreenYf := g.mapRenderer.WorldToScreenF(entity.GetPositionF())
|
|
|
|
entScreenX := int(math.Floor(entScreenXf))
|
|
|
|
entScreenY := int(math.Floor(entScreenYf))
|
|
|
|
|
2020-06-25 10:16:17 -04:00
|
|
|
if ((entScreenX - 20) <= g.lastMouseX) && ((entScreenX + 20) >= g.lastMouseX) &&
|
|
|
|
((entScreenY - 80) <= g.lastMouseY) && (entScreenY >= g.lastMouseY) {
|
2020-06-25 00:39:09 -04:00
|
|
|
g.nameLabel.SetText(entity.Name())
|
2020-06-25 10:16:17 -04:00
|
|
|
g.nameLabel.SetPosition(entScreenX, entScreenY-100)
|
2020-06-25 00:39:09 -04:00
|
|
|
g.nameLabel.Render(target)
|
2020-06-27 18:58:41 -04:00
|
|
|
entity.Highlight()
|
2020-06-25 00:39:09 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:53 -05:00
|
|
|
g.inventory.Render(target)
|
2020-06-25 14:56:49 -04:00
|
|
|
g.heroStatsPanel.Render(target)
|
2019-12-28 23:32:53 -05:00
|
|
|
|
2019-12-28 16:46:08 -05:00
|
|
|
width, height := target.GetSize()
|
2020-02-01 21:51:49 -05:00
|
|
|
offset := 0
|
2019-12-16 11:04:39 -05:00
|
|
|
|
|
|
|
// Left globe holder
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(0)
|
|
|
|
w, _ := g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
|
|
|
|
// Left globe
|
2019-12-21 20:53:18 -05:00
|
|
|
g.globeSprite.SetCurrentFrame(0)
|
2019-12-28 23:32:53 -05:00
|
|
|
g.globeSprite.SetPosition(offset+28, height-5)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.globeSprite.Render(target)
|
2020-06-25 14:56:49 -04:00
|
|
|
|
|
|
|
// Health status bar
|
|
|
|
healthPercent := float64(g.hero.Stats.Health) / float64(g.hero.Stats.MaxHealth)
|
|
|
|
hpBarHeight := int(healthPercent * float64(globeHeight))
|
|
|
|
if g.lastHealthPercent != healthPercent {
|
2020-06-29 00:41:58 -04:00
|
|
|
g.hpStatusBar, _ = d2render.NewSurface(globeWidth, hpBarHeight, d2interface.FilterNearest)
|
2020-06-25 14:56:49 -04:00
|
|
|
g.hpManaStatusSprite.SetCurrentFrame(0)
|
|
|
|
g.hpStatusBar.PushTranslation(0, hpBarHeight)
|
|
|
|
|
|
|
|
g.hpManaStatusSprite.Render(g.hpStatusBar)
|
|
|
|
g.hpStatusBar.Pop()
|
|
|
|
g.lastHealthPercent = healthPercent
|
|
|
|
}
|
|
|
|
|
|
|
|
target.PushTranslation(30, 508+(globeHeight-hpBarHeight))
|
|
|
|
target.Render(g.hpStatusBar)
|
|
|
|
target.Pop()
|
|
|
|
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Left skill
|
2019-12-21 20:53:18 -05:00
|
|
|
g.skillIcon.SetCurrentFrame(2)
|
|
|
|
w, _ = g.skillIcon.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.skillIcon.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.skillIcon.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Left skill selector
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(1)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Stamina
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(2)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
2020-06-25 14:56:49 -04:00
|
|
|
// Stamina status bar
|
|
|
|
target.PushTranslation(273, 572)
|
2020-06-30 09:58:53 -04:00
|
|
|
target.PushCompositeMode(d2enum.CompositeModeLighter)
|
2020-06-25 14:56:49 -04:00
|
|
|
staminaPercent := float64(g.hero.Stats.Stamina) / float64(g.hero.Stats.MaxStamina)
|
|
|
|
target.DrawRect(int(staminaPercent*staminaBarWidth), 19, color.RGBA{R: 175, G: 136, B: 72, A: 200})
|
|
|
|
target.PopN(2)
|
|
|
|
|
|
|
|
// Experience status bar
|
|
|
|
target.PushTranslation(256, 561)
|
|
|
|
expPercent := float64(g.hero.Stats.Experience) / float64(g.hero.Stats.NextLevelExp)
|
|
|
|
target.DrawRect(int(expPercent*expBarWidth), 2, color.RGBA{R: 255, G: 255, B: 255, A: 255})
|
|
|
|
target.Pop()
|
|
|
|
|
2019-12-16 11:04:39 -05:00
|
|
|
// Center menu button
|
2019-12-21 20:53:18 -05:00
|
|
|
g.menuButton.SetCurrentFrame(0)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
|
|
|
g.menuButton.SetPosition((width/2)-8, height-16)
|
|
|
|
g.menuButton.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
|
|
|
|
// Potions
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(3)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Right skill selector
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(4)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Right skill
|
2020-06-25 14:56:49 -04:00
|
|
|
g.skillIcon.SetCurrentFrame(2)
|
2019-12-21 20:53:18 -05:00
|
|
|
w, _ = g.skillIcon.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.skillIcon.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.skillIcon.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
offset += w
|
|
|
|
|
|
|
|
// Right globe holder
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.SetCurrentFrame(5)
|
|
|
|
w, _ = g.mainPanel.GetCurrentFrameSize()
|
2019-12-28 23:32:53 -05:00
|
|
|
g.mainPanel.SetPosition(offset, height)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.mainPanel.Render(target)
|
2019-12-16 11:04:39 -05:00
|
|
|
|
|
|
|
// Right globe
|
2019-12-21 20:53:18 -05:00
|
|
|
g.globeSprite.SetCurrentFrame(1)
|
2019-12-28 23:32:53 -05:00
|
|
|
g.globeSprite.SetPosition(offset+8, height-8)
|
2019-12-21 20:53:18 -05:00
|
|
|
g.globeSprite.Render(target)
|
2020-06-25 14:56:49 -04:00
|
|
|
g.globeSprite.Render(target)
|
|
|
|
|
|
|
|
// Mana status bar
|
|
|
|
manaPercent := float64(g.hero.Stats.Mana) / float64(g.hero.Stats.MaxMana)
|
|
|
|
manaBarHeight := int(manaPercent * float64(globeHeight))
|
|
|
|
if manaPercent != g.lastManaPercent {
|
2020-06-29 00:41:58 -04:00
|
|
|
g.manaStatusBar, _ = d2render.NewSurface(globeWidth, manaBarHeight, d2interface.FilterNearest)
|
2020-06-25 14:56:49 -04:00
|
|
|
g.hpManaStatusSprite.SetCurrentFrame(1)
|
|
|
|
|
|
|
|
g.manaStatusBar.PushTranslation(0, manaBarHeight)
|
|
|
|
g.hpManaStatusSprite.Render(g.manaStatusBar)
|
|
|
|
g.manaStatusBar.Pop()
|
|
|
|
|
|
|
|
g.lastManaPercent = manaPercent
|
|
|
|
}
|
|
|
|
target.PushTranslation(offset+8, 508+(globeHeight-manaBarHeight))
|
|
|
|
target.Render(g.manaStatusBar)
|
|
|
|
target.Pop()
|
2019-12-16 11:04:39 -05:00
|
|
|
|
2020-06-22 15:55:32 -04:00
|
|
|
if g.isZoneTextShown {
|
|
|
|
g.zoneChangeText.SetPosition(width/2, height/4)
|
|
|
|
g.zoneChangeText.Render(target)
|
|
|
|
}
|
2020-06-25 14:56:49 -04:00
|
|
|
|
2020-06-22 15:55:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) SetZoneChangeText(text string) {
|
|
|
|
g.zoneChangeText.SetText(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) ShowZoneChangeText() {
|
|
|
|
g.isZoneTextShown = true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GameControls) HideZoneChangeTextAfter(delay float64) {
|
|
|
|
time.AfterFunc(time.Duration(delay)*time.Second, func() {
|
|
|
|
g.isZoneTextShown = false
|
|
|
|
})
|
2019-12-16 11:04:39 -05:00
|
|
|
}
|
2020-06-21 16:06:52 -04:00
|
|
|
|
2020-06-23 12:28:05 -04:00
|
|
|
// Handles what to do when an actionable is hovered
|
|
|
|
func (g *GameControls) onHoverActionable(item ActionableType) {
|
|
|
|
switch item {
|
|
|
|
case leftSkill:
|
|
|
|
return
|
|
|
|
case leftSelec:
|
|
|
|
return
|
|
|
|
case xp:
|
|
|
|
return
|
|
|
|
case walkRun:
|
|
|
|
return
|
|
|
|
case stamina:
|
|
|
|
return
|
|
|
|
case miniPanel:
|
|
|
|
return
|
|
|
|
case rightSelec:
|
|
|
|
return
|
|
|
|
case rightSkill:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
log.Printf("Unrecognized ActionableType(%d) being hovered\n", item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handles what to do when an actionable is clicked
|
|
|
|
func (g *GameControls) onClickActionable(item ActionableType) {
|
|
|
|
switch item {
|
2020-06-24 13:49:13 -04:00
|
|
|
case leftSkill:
|
|
|
|
log.Println("Left Skill Action Pressed")
|
|
|
|
case leftSelec:
|
|
|
|
log.Println("Left Skill Selector Action Pressed")
|
|
|
|
case xp:
|
|
|
|
log.Println("XP Action Pressed")
|
|
|
|
case walkRun:
|
|
|
|
log.Println("Walk/Run Action Pressed")
|
|
|
|
case stamina:
|
|
|
|
log.Println("Stamina Action Pressed")
|
|
|
|
case miniPanel:
|
|
|
|
log.Println("Mini Panel Action Pressed")
|
|
|
|
case rightSelec:
|
|
|
|
log.Println("Right Skill Selector Action Pressed")
|
|
|
|
case rightSkill:
|
|
|
|
log.Println("Right Skill Action Pressed")
|
2020-06-23 12:28:05 -04:00
|
|
|
default:
|
|
|
|
log.Printf("Unrecognized ActionableType(%d) being clicked\n", item)
|
|
|
|
}
|
|
|
|
}
|