2020-06-13 20:36:20 -04:00
|
|
|
package d2gamescreen
|
2019-10-26 23:59:27 -04:00
|
|
|
|
|
|
|
import (
|
2019-11-12 23:44:04 -05:00
|
|
|
"math"
|
2019-11-11 23:48:55 -05:00
|
|
|
"os"
|
2020-11-18 03:46:03 -05:00
|
|
|
"strconv"
|
2020-11-26 06:25:47 -05:00
|
|
|
"strings"
|
2020-06-28 19:31:10 -04:00
|
|
|
|
2020-09-20 17:52:01 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
|
|
|
|
2020-07-11 11:24:04 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-02-01 21:06:22 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-11-18 16:02:49 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-02-01 18:55:56 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-06-23 18:12:08 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapentity"
|
2020-06-13 20:36:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
2020-01-31 23:18:11 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2ui"
|
2020-06-23 18:12:08 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client/d2clientconnectiontype"
|
2019-10-26 23:59:27 -04:00
|
|
|
)
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
// CreateCharacterSelect creates the character select screen and returns a pointer to it
|
|
|
|
func CreateCharacterSelect(
|
|
|
|
navigator d2interface.Navigator,
|
|
|
|
asset *d2asset.AssetManager,
|
|
|
|
renderer d2interface.Renderer,
|
|
|
|
inputManager d2interface.InputManager,
|
|
|
|
audioProvider d2interface.AudioProvider,
|
|
|
|
ui *d2ui.UIManager,
|
|
|
|
connectionType d2clientconnectiontype.ClientConnectionType,
|
|
|
|
l d2util.LogLevel,
|
|
|
|
connectionHost string,
|
|
|
|
) (*CharacterSelect, error) {
|
|
|
|
playerStateFactory, err := d2hero.NewHeroStateFactory(asset)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
entityFactory, err := d2mapentity.NewMapEntityFactory(asset)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
characterSelect := &CharacterSelect{
|
|
|
|
selectedCharacter: -1,
|
|
|
|
asset: asset,
|
|
|
|
MapEntityFactory: entityFactory,
|
|
|
|
renderer: renderer,
|
|
|
|
connectionType: connectionType,
|
|
|
|
connectionHost: connectionHost,
|
|
|
|
inputManager: inputManager,
|
|
|
|
audioProvider: audioProvider,
|
|
|
|
navigator: navigator,
|
|
|
|
uiManager: ui,
|
|
|
|
HeroStateFactory: playerStateFactory,
|
|
|
|
}
|
|
|
|
|
2020-11-22 00:36:59 -05:00
|
|
|
characterSelect.Logger = d2util.NewLogger()
|
|
|
|
characterSelect.Logger.SetLevel(l)
|
|
|
|
characterSelect.Logger.SetPrefix(logPrefix)
|
2020-11-18 16:02:49 -05:00
|
|
|
|
|
|
|
return characterSelect, nil
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// CharacterSelect represents the character select screen
|
2019-10-26 23:59:27 -04:00
|
|
|
type CharacterSelect struct {
|
2020-09-12 16:51:30 -04:00
|
|
|
asset *d2asset.AssetManager
|
|
|
|
*d2mapentity.MapEntityFactory
|
2020-09-20 17:52:01 -04:00
|
|
|
*d2hero.HeroStateFactory
|
2020-02-01 18:55:56 -05:00
|
|
|
background *d2ui.Sprite
|
2020-08-06 10:30:23 -04:00
|
|
|
newCharButton *d2ui.Button
|
|
|
|
convertCharButton *d2ui.Button
|
|
|
|
deleteCharButton *d2ui.Button
|
|
|
|
exitButton *d2ui.Button
|
|
|
|
okButton *d2ui.Button
|
|
|
|
deleteCharCancelButton *d2ui.Button
|
|
|
|
deleteCharOkButton *d2ui.Button
|
2020-02-01 18:55:56 -05:00
|
|
|
selectionBox *d2ui.Sprite
|
|
|
|
okCancelBox *d2ui.Sprite
|
2020-08-06 10:30:23 -04:00
|
|
|
d2HeroTitle *d2ui.Label
|
|
|
|
deleteCharConfirmLabel *d2ui.Label
|
|
|
|
charScrollbar *d2ui.Scrollbar
|
|
|
|
characterNameLabel [8]*d2ui.Label
|
|
|
|
characterStatsLabel [8]*d2ui.Label
|
|
|
|
characterExpLabel [8]*d2ui.Label
|
2020-06-21 18:40:37 -04:00
|
|
|
characterImage [8]*d2mapentity.Player
|
2020-09-20 17:52:01 -04:00
|
|
|
gameStates []*d2hero.HeroState
|
2019-11-11 23:48:55 -05:00
|
|
|
selectedCharacter int
|
2020-09-25 21:53:56 -04:00
|
|
|
tickTimer float64
|
|
|
|
storedTickTimer float64
|
2019-11-11 23:48:55 -05:00
|
|
|
showDeleteConfirmation bool
|
2020-11-13 07:40:44 -05:00
|
|
|
loaded bool
|
2020-06-18 14:11:04 -04:00
|
|
|
connectionType d2clientconnectiontype.ClientConnectionType
|
|
|
|
connectionHost string
|
2020-07-14 13:11:23 -04:00
|
|
|
|
2020-08-06 10:30:23 -04:00
|
|
|
uiManager *d2ui.UIManager
|
2020-07-14 13:11:23 -04:00
|
|
|
inputManager d2interface.InputManager
|
|
|
|
audioProvider d2interface.AudioProvider
|
|
|
|
renderer d2interface.Renderer
|
2020-10-07 21:20:05 -04:00
|
|
|
navigator d2interface.Navigator
|
2020-11-22 00:36:59 -05:00
|
|
|
|
|
|
|
*d2util.Logger
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
const (
|
|
|
|
tenPercent = 0.1 * iota
|
|
|
|
twentyPercent
|
|
|
|
thirtyPercent
|
|
|
|
fourtyPercent
|
|
|
|
fiftyPercent
|
|
|
|
sixtyPercent
|
|
|
|
seventyPercent
|
|
|
|
eightyPercent
|
|
|
|
ninetyPercent
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
rootLabelOffsetX = 115
|
|
|
|
rootLabelOffsetY = 100
|
|
|
|
labelHeight = 15
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
selectionBoxNumColumns = 2
|
|
|
|
selectionBoxNumRows = 4
|
|
|
|
selectionBoxWidth = 272
|
|
|
|
selectionBoxHeight = 92
|
|
|
|
selectionBoxOffsetX = 37
|
|
|
|
selectionBoxOffsetY = 86
|
|
|
|
selectionBoxImageOffsetX = 40
|
|
|
|
selectionBoxImageOffsetY = 50
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
blackHalfOpacity = 0x0000007f
|
|
|
|
lightBrown = 0xbca88cff
|
|
|
|
lightGreen = 0x18ff00ff
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
screenWidth = 800
|
|
|
|
screenHeight = 600
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
newCharBtnX, newCharBtnY = 33, 468
|
|
|
|
convertCharBtnX, convertCharBtnY = 233, 468
|
|
|
|
deleteCharBtnX, deleteCharBtnY = 433, 468
|
|
|
|
deleteCancelX, deleteCancelY = 282, 308
|
|
|
|
deleteOkX, deleteOkY = 422, 308
|
|
|
|
exitBtnX, exitBtnY = 33, 537
|
|
|
|
okBtnX, okBtnY = 625, 537
|
|
|
|
)
|
|
|
|
|
2020-09-25 21:53:56 -04:00
|
|
|
const (
|
|
|
|
doubleClickTime = 1.25
|
|
|
|
)
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnLoad loads the resources for the Character Select screen
|
2020-06-24 18:46:03 -04:00
|
|
|
func (v *CharacterSelect) OnLoad(loading d2screen.LoadingState) {
|
2020-06-28 19:31:10 -04:00
|
|
|
v.audioProvider.PlayBGM(d2resource.BGMTitle)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
err := v.inputManager.BindHandler(v)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
v.Error("failed to add Character Select screen as event handler")
|
2020-07-02 13:55:43 -04:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
loading.Progress(tenPercent)
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-10-26 07:39:10 -04:00
|
|
|
v.loadBackground()
|
|
|
|
v.createButtons(loading)
|
|
|
|
v.loadHeroTitle()
|
|
|
|
|
|
|
|
loading.Progress(thirtyPercent)
|
|
|
|
|
|
|
|
v.loadDeleteCharConfirm()
|
|
|
|
v.loadSelectionBox()
|
|
|
|
v.loadOkCancelBox()
|
|
|
|
v.loadCharScrollbar()
|
|
|
|
|
|
|
|
loading.Progress(fiftyPercent)
|
|
|
|
|
|
|
|
for i := 0; i < 8; i++ {
|
|
|
|
offsetX, offsetY := rootLabelOffsetX, rootLabelOffsetY+((i/2)*95)
|
|
|
|
|
|
|
|
if i&1 > 0 {
|
|
|
|
offsetX = 385
|
|
|
|
}
|
|
|
|
|
|
|
|
v.characterNameLabel[i] = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
|
|
|
|
v.characterNameLabel[i].SetPosition(offsetX, offsetY)
|
2020-12-14 05:25:37 -05:00
|
|
|
v.characterNameLabel[i].Color[0] = d2util.Color(lightBrown)
|
2020-10-26 07:39:10 -04:00
|
|
|
|
|
|
|
offsetY += labelHeight
|
|
|
|
|
|
|
|
v.characterStatsLabel[i] = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
|
|
|
|
v.characterStatsLabel[i].SetPosition(offsetX, offsetY)
|
|
|
|
|
|
|
|
offsetY += labelHeight
|
|
|
|
|
|
|
|
v.characterExpLabel[i] = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteStatic)
|
|
|
|
v.characterExpLabel[i].SetPosition(offsetX, offsetY)
|
2020-12-14 05:25:37 -05:00
|
|
|
v.characterExpLabel[i].Color[0] = d2util.Color(lightGreen)
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
v.refreshGameStates()
|
2020-11-13 07:40:44 -05:00
|
|
|
v.loaded = true
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) loadBackground() {
|
|
|
|
var err error
|
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
bgX, bgY := 0, 0
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
v.background, err = v.uiManager.NewSprite(d2resource.CharacterSelectionBackground, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
v.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
v.background.SetPosition(bgX, bgY)
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-10-26 07:39:10 -04:00
|
|
|
func (v *CharacterSelect) loadHeroTitle() {
|
2020-07-18 09:54:10 -04:00
|
|
|
heroTitleX, heroTitleY := 320, 23
|
2020-08-06 10:30:23 -04:00
|
|
|
v.d2HeroTitle = v.uiManager.NewLabel(d2resource.Font42, d2resource.PaletteUnits)
|
2020-07-18 09:54:10 -04:00
|
|
|
v.d2HeroTitle.SetPosition(heroTitleX, heroTitleY)
|
2020-11-13 15:03:30 -05:00
|
|
|
v.d2HeroTitle.Alignment = d2ui.HorizontalAlignCenter
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-10-26 07:39:10 -04:00
|
|
|
func (v *CharacterSelect) loadDeleteCharConfirm() {
|
2020-08-06 10:30:23 -04:00
|
|
|
v.deleteCharConfirmLabel = v.uiManager.NewLabel(d2resource.Font16, d2resource.PaletteUnits)
|
2020-12-12 04:39:26 -05:00
|
|
|
lines := strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateLabel(d2enum.DelCharConfLabel), 29), "\n")
|
2020-07-07 20:16:22 -04:00
|
|
|
v.deleteCharConfirmLabel.SetText(lines)
|
2020-11-13 15:03:30 -05:00
|
|
|
v.deleteCharConfirmLabel.Alignment = d2ui.HorizontalAlignCenter
|
2020-07-18 09:54:10 -04:00
|
|
|
deleteConfirmX, deleteConfirmY := 400, 185
|
|
|
|
v.deleteCharConfirmLabel.SetPosition(deleteConfirmX, deleteConfirmY)
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) loadSelectionBox() {
|
|
|
|
var err error
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
v.selectionBox, err = v.uiManager.NewSprite(d2resource.CharacterSelectionSelectBox, d2resource.PaletteSky)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
v.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
selBoxX, selBoxY := 37, 86
|
|
|
|
v.selectionBox.SetPosition(selBoxX, selBoxY)
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) loadOkCancelBox() {
|
|
|
|
var err error
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
v.okCancelBox, err = v.uiManager.NewSprite(d2resource.PopUpOkCancel, d2resource.PaletteFechar)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
v.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
okCancelX, okCancelY := 270, 175
|
|
|
|
v.okCancelBox.SetPosition(okCancelX, okCancelY)
|
2020-10-26 07:39:10 -04:00
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
2020-10-26 07:39:10 -04:00
|
|
|
func (v *CharacterSelect) loadCharScrollbar() {
|
2020-07-18 09:54:10 -04:00
|
|
|
scrollBarX, scrollBarY, scrollBarHeight := 586, 87, 369
|
2020-08-06 10:30:23 -04:00
|
|
|
v.charScrollbar = v.uiManager.NewScrollbar(scrollBarX, scrollBarY, scrollBarHeight)
|
2020-02-08 21:02:37 -05:00
|
|
|
v.charScrollbar.OnActivated(func() { v.onScrollUpdate() })
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
func (v *CharacterSelect) createButtons(loading d2screen.LoadingState) {
|
2020-11-26 06:25:47 -05:00
|
|
|
v.newCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall, strings.Join(
|
|
|
|
d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#831"), 13), "\n"))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.newCharButton.SetPosition(newCharBtnX, newCharBtnY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.newCharButton.OnActivated(func() { v.onNewCharButtonClicked() })
|
|
|
|
|
2020-11-24 11:50:31 -05:00
|
|
|
v.convertCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall,
|
2020-11-26 06:25:47 -05:00
|
|
|
strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#825"), 13), "\n"))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.convertCharButton.SetPosition(convertCharBtnX, convertCharBtnY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.convertCharButton.SetEnabled(false)
|
|
|
|
|
2020-11-24 11:50:31 -05:00
|
|
|
v.deleteCharButton = v.uiManager.NewButton(d2ui.ButtonTypeTall,
|
2020-11-26 06:25:47 -05:00
|
|
|
strings.Join(d2util.SplitIntoLinesWithMaxWidth(v.asset.TranslateString("#832"), 13), "\n"))
|
2020-07-02 13:55:43 -04:00
|
|
|
v.deleteCharButton.OnActivated(func() { v.onDeleteCharButtonClicked() })
|
2020-07-18 09:54:10 -04:00
|
|
|
v.deleteCharButton.SetPosition(deleteCharBtnX, deleteCharBtnY)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-12-12 04:39:26 -05:00
|
|
|
v.exitButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateLabel(d2enum.ExitLabel))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.exitButton.SetPosition(exitBtnX, exitBtnY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.exitButton.OnActivated(func() { v.onExitButtonClicked() })
|
2020-07-18 09:54:10 -04:00
|
|
|
|
|
|
|
loading.Progress(twentyPercent)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-12-12 04:39:26 -05:00
|
|
|
v.deleteCharCancelButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, v.asset.TranslateLabel(d2enum.NoLabel))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.deleteCharCancelButton.SetPosition(deleteCancelX, deleteCancelY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.deleteCharCancelButton.SetVisible(false)
|
|
|
|
v.deleteCharCancelButton.OnActivated(func() { v.onDeleteCharacterCancelClicked() })
|
|
|
|
|
2020-12-12 04:39:26 -05:00
|
|
|
v.deleteCharOkButton = v.uiManager.NewButton(d2ui.ButtonTypeOkCancel, v.asset.TranslateLabel(d2enum.YesLabel))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.deleteCharOkButton.SetPosition(deleteOkX, deleteOkY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.deleteCharOkButton.SetVisible(false)
|
|
|
|
v.deleteCharOkButton.OnActivated(func() { v.onDeleteCharacterConfirmClicked() })
|
|
|
|
|
2020-12-12 04:39:26 -05:00
|
|
|
v.okButton = v.uiManager.NewButton(d2ui.ButtonTypeMedium, v.asset.TranslateLabel(d2enum.OKLabel))
|
2020-07-18 09:54:10 -04:00
|
|
|
v.okButton.SetPosition(okBtnX, okBtnY)
|
2020-07-02 13:55:43 -04:00
|
|
|
v.okButton.OnActivated(func() { v.onOkButtonClicked() })
|
|
|
|
}
|
|
|
|
|
2019-11-12 23:44:04 -05:00
|
|
|
func (v *CharacterSelect) onScrollUpdate() {
|
|
|
|
v.moveSelectionBox()
|
|
|
|
v.updateCharacterBoxes()
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
func (v *CharacterSelect) updateCharacterBoxes() {
|
2020-11-24 04:47:11 -05:00
|
|
|
expText := v.asset.TranslateString("#803")
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
for i := 0; i < 8; i++ {
|
2019-11-12 23:44:04 -05:00
|
|
|
idx := i + (v.charScrollbar.GetCurrentOffset() * 2)
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
if idx >= len(v.gameStates) {
|
|
|
|
v.characterNameLabel[i].SetText("")
|
|
|
|
v.characterStatsLabel[i].SetText("")
|
|
|
|
v.characterExpLabel[i].SetText("")
|
|
|
|
v.characterImage[i] = nil
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
continue
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-08-02 21:26:07 -04:00
|
|
|
heroName := v.gameStates[idx].HeroName
|
2020-11-24 05:50:58 -05:00
|
|
|
heroInfo := v.asset.TranslateString("level") + " " + strconv.FormatInt(int64(v.gameStates[idx].Stats.Level), 10) +
|
2020-11-25 06:37:16 -05:00
|
|
|
" " + v.asset.TranslateString(v.gameStates[idx].HeroType.String())
|
2020-08-02 21:26:07 -04:00
|
|
|
|
|
|
|
v.characterNameLabel[i].SetText(d2ui.ColorTokenize(heroName, d2ui.ColorTokenGold))
|
|
|
|
v.characterStatsLabel[i].SetText(d2ui.ColorTokenize(heroInfo, d2ui.ColorTokenWhite))
|
|
|
|
v.characterExpLabel[i].SetText(d2ui.ColorTokenize(expText, d2ui.ColorTokenGreen))
|
2020-07-17 22:11:16 -04:00
|
|
|
|
|
|
|
heroType := v.gameStates[idx].HeroType
|
2020-09-20 17:52:01 -04:00
|
|
|
equipment := v.DefaultHeroItems[heroType]
|
2020-07-17 22:11:16 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/791
|
2020-09-12 16:51:30 -04:00
|
|
|
v.characterImage[i] = v.NewPlayer("", "", 0, 0, 0,
|
2020-06-26 17:12:19 -04:00
|
|
|
v.gameStates[idx].HeroType,
|
2020-07-17 22:11:16 -04:00
|
|
|
v.gameStates[idx].Stats,
|
2020-09-20 11:55:44 -04:00
|
|
|
v.gameStates[idx].Skills,
|
2020-07-17 22:11:16 -04:00
|
|
|
&equipment,
|
2020-10-31 14:30:08 -04:00
|
|
|
v.gameStates[idx].LeftSkill,
|
|
|
|
v.gameStates[idx].RightSkill,
|
2020-11-22 17:53:33 -05:00
|
|
|
v.gameStates[idx].Gold,
|
2019-11-14 22:20:01 -05:00
|
|
|
)
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 02:58:37 -04:00
|
|
|
func (v *CharacterSelect) onNewCharButtonClicked() {
|
2020-07-14 13:11:23 -04:00
|
|
|
v.navigator.ToSelectHero(v.connectionType, v.connectionHost)
|
2019-10-27 02:58:37 -04:00
|
|
|
}
|
|
|
|
|
2019-10-26 23:59:27 -04:00
|
|
|
func (v *CharacterSelect) onExitButtonClicked() {
|
2020-07-14 13:11:23 -04:00
|
|
|
v.navigator.ToMainMenu()
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Render renders the Character Select screen
|
2020-10-28 14:17:42 -04:00
|
|
|
func (v *CharacterSelect) Render(screen d2interface.Surface) {
|
2020-11-11 08:55:59 -05:00
|
|
|
v.background.RenderSegmented(screen, 4, 3, 0)
|
2020-11-11 09:01:36 -05:00
|
|
|
v.d2HeroTitle.Render(screen)
|
|
|
|
|
2019-11-12 23:44:04 -05:00
|
|
|
actualSelectionIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-12 23:44:04 -05:00
|
|
|
if v.selectedCharacter > -1 && actualSelectionIndex >= 0 && actualSelectionIndex < 8 {
|
2020-11-11 08:55:59 -05:00
|
|
|
v.selectionBox.RenderSegmented(screen, 2, 1, 0)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
for i := 0; i < 8; i++ {
|
2019-11-12 23:44:04 -05:00
|
|
|
idx := i + (v.charScrollbar.GetCurrentOffset() * 2)
|
2019-11-11 23:48:55 -05:00
|
|
|
if idx >= len(v.gameStates) {
|
|
|
|
continue
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-11-11 09:01:36 -05:00
|
|
|
v.characterNameLabel[i].Render(screen)
|
|
|
|
v.characterStatsLabel[i].Render(screen)
|
|
|
|
v.characterExpLabel[i].Render(screen)
|
2020-07-18 09:54:10 -04:00
|
|
|
|
2020-11-06 06:38:20 -05:00
|
|
|
x, y := v.characterNameLabel[i].GetPosition()
|
|
|
|
charImgX := x - selectionBoxImageOffsetX
|
|
|
|
charImgY := y + selectionBoxImageOffsetY
|
2020-07-18 09:54:10 -04:00
|
|
|
screen.PushTranslation(charImgX, charImgY)
|
2019-12-28 16:46:08 -05:00
|
|
|
v.characterImage[i].Render(screen)
|
|
|
|
screen.Pop()
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
if v.showDeleteConfirmation {
|
2020-12-14 05:25:37 -05:00
|
|
|
screen.DrawRect(screenWidth, screenHeight, d2util.Color(blackHalfOpacity))
|
2020-11-11 08:55:59 -05:00
|
|
|
v.okCancelBox.RenderSegmented(screen, 2, 1, 0)
|
2020-11-11 09:01:36 -05:00
|
|
|
v.deleteCharConfirmLabel.Render(screen)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) moveSelectionBox() {
|
2019-11-12 23:44:04 -05:00
|
|
|
if v.selectedCharacter == -1 {
|
|
|
|
v.d2HeroTitle.SetText("")
|
|
|
|
return
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
bw := 272
|
|
|
|
bh := 92
|
2019-11-12 23:44:04 -05:00
|
|
|
selectedIndex := v.selectedCharacter - (v.charScrollbar.GetCurrentOffset() * 2)
|
2020-07-18 09:54:10 -04:00
|
|
|
|
|
|
|
selBoxX := selectionBoxOffsetX + ((selectedIndex & 1) * bw)
|
|
|
|
selBoxY := selectionBoxOffsetY + (bh * (selectedIndex / 2))
|
|
|
|
v.selectionBox.SetPosition(selBoxX, selBoxY)
|
2019-11-11 23:48:55 -05:00
|
|
|
v.d2HeroTitle.SetText(v.gameStates[v.selectedCharacter].HeroName)
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnMouseButtonDown is called when a mouse button is clicked
|
2020-07-03 15:09:16 -04:00
|
|
|
func (v *CharacterSelect) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
2020-11-13 07:40:44 -05:00
|
|
|
if !v.loaded {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
if v.showDeleteConfirmation {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Button() != d2enum.MouseButtonLeft {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
mx, my := event.X(), event.Y()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
bw := selectionBoxWidth
|
|
|
|
bh := selectionBoxHeight
|
|
|
|
localMouseX := mx - selectionBoxOffsetX
|
|
|
|
localMouseY := my - selectionBoxOffsetY
|
|
|
|
|
|
|
|
// if Mouse is within character selection bounds.
|
|
|
|
if localMouseX > 0 && localMouseX < bw*2 && localMouseY >= 0 && localMouseY < bh*4 {
|
|
|
|
adjustY := localMouseY / bh
|
|
|
|
// sets current verticle index for selected character in left column.
|
|
|
|
selectedIndex := adjustY * selectionBoxNumColumns
|
|
|
|
|
|
|
|
// if selected character in left column should be in right column, add 1.
|
|
|
|
if localMouseX > bw {
|
|
|
|
selectedIndex++
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure selection takes the scrollbar into account to make proper selection.
|
|
|
|
if (v.charScrollbar.GetCurrentOffset()*2)+selectedIndex < len(v.gameStates) {
|
|
|
|
selectedIndex = (v.charScrollbar.GetCurrentOffset() * 2) + selectedIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the selection box didn't move, check if it was a double click, otherwise set selectedCharacter to
|
|
|
|
// selectedIndex and move selection box over both.
|
|
|
|
if v.selectedCharacter == selectedIndex {
|
|
|
|
// We clicked twice within character selection box within v.doubleClickTime seconds.
|
|
|
|
if (v.tickTimer - v.storedTickTimer) < doubleClickTime {
|
|
|
|
v.onOkButtonClicked()
|
|
|
|
}
|
|
|
|
} else if selectedIndex < len(v.gameStates) {
|
|
|
|
v.selectedCharacter = selectedIndex
|
|
|
|
v.moveSelectionBox()
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
2020-10-25 10:21:14 -04:00
|
|
|
// Keep track of when we last clicked so we can determine if we double clicked a character.
|
|
|
|
v.storedTickTimer = v.tickTimer
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-10-25 10:21:14 -04:00
|
|
|
return true
|
2020-06-23 18:12:08 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Advance runs the update logic on the Character Select screen
|
2020-06-23 18:12:08 -04:00
|
|
|
func (v *CharacterSelect) Advance(tickTime float64) error {
|
2019-12-26 11:14:26 -05:00
|
|
|
for _, hero := range v.characterImage {
|
|
|
|
if hero != nil {
|
2020-09-25 21:53:56 -04:00
|
|
|
v.tickTimer += tickTime
|
2020-06-24 13:49:13 -04:00
|
|
|
hero.Advance(tickTime)
|
2019-12-26 11:14:26 -05:00
|
|
|
}
|
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
return nil
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) onDeleteCharButtonClicked() {
|
|
|
|
v.toggleDeleteCharacterDialog(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) onDeleteCharacterConfirmClicked() {
|
2020-09-23 13:30:54 -04:00
|
|
|
err := os.Remove(v.gameStates[v.selectedCharacter].FilePath)
|
|
|
|
if err != nil {
|
2020-11-22 00:36:59 -05:00
|
|
|
v.Error(err.Error())
|
2020-09-23 13:30:54 -04:00
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2019-11-12 23:44:04 -05:00
|
|
|
v.charScrollbar.SetCurrentOffset(0)
|
2019-11-11 23:48:55 -05:00
|
|
|
v.refreshGameStates()
|
|
|
|
v.toggleDeleteCharacterDialog(false)
|
2019-11-12 23:44:04 -05:00
|
|
|
v.deleteCharButton.SetEnabled(len(v.gameStates) > 0)
|
|
|
|
v.okButton.SetEnabled(len(v.gameStates) > 0)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) onDeleteCharacterCancelClicked() {
|
|
|
|
v.toggleDeleteCharacterDialog(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) toggleDeleteCharacterDialog(showDialog bool) {
|
|
|
|
v.showDeleteConfirmation = showDialog
|
|
|
|
v.okButton.SetEnabled(!showDialog)
|
|
|
|
v.deleteCharButton.SetEnabled(!showDialog)
|
|
|
|
v.exitButton.SetEnabled(!showDialog)
|
|
|
|
v.newCharButton.SetEnabled(!showDialog)
|
|
|
|
v.deleteCharOkButton.SetVisible(showDialog)
|
|
|
|
v.deleteCharCancelButton.SetVisible(showDialog)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *CharacterSelect) refreshGameStates() {
|
2020-09-20 17:52:01 -04:00
|
|
|
gameStates, err := v.HeroStateFactory.GetAllHeroStates()
|
|
|
|
if err == nil {
|
|
|
|
v.gameStates = gameStates
|
|
|
|
}
|
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
v.updateCharacterBoxes()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
if len(v.gameStates) > 0 {
|
|
|
|
v.selectedCharacter = 0
|
2020-07-18 09:54:10 -04:00
|
|
|
numStates := selectionBoxNumColumns * selectionBoxNumRows
|
|
|
|
byHalf := 2.0
|
|
|
|
|
2019-11-11 23:48:55 -05:00
|
|
|
v.d2HeroTitle.SetText(v.gameStates[0].HeroName)
|
2020-07-18 09:54:10 -04:00
|
|
|
v.charScrollbar.SetMaxOffset(int(math.Ceil(float64(len(v.gameStates)-numStates) / byHalf)))
|
2019-11-11 23:48:55 -05:00
|
|
|
} else {
|
|
|
|
v.selectedCharacter = -1
|
2019-11-12 23:44:04 -05:00
|
|
|
v.charScrollbar.SetMaxOffset(0)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
v.moveSelectionBox()
|
2019-10-26 23:59:27 -04:00
|
|
|
}
|
2019-11-13 00:31:52 -05:00
|
|
|
|
|
|
|
func (v *CharacterSelect) onOkButtonClicked() {
|
2020-07-14 13:11:23 -04:00
|
|
|
v.navigator.ToCreateGame(v.gameStates[v.selectedCharacter].FilePath, v.connectionType, v.connectionHost)
|
2019-11-13 00:31:52 -05:00
|
|
|
}
|
2020-09-25 23:14:32 -04:00
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// OnUnload candles cleanup when this screen is closed
|
2020-09-25 23:14:32 -04:00
|
|
|
func (v *CharacterSelect) OnUnload() error {
|
2020-10-25 10:21:14 -04:00
|
|
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/792
|
|
|
|
if err := v.inputManager.UnbindHandler(v); err != nil {
|
2020-09-25 23:14:32 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-13 07:40:44 -05:00
|
|
|
v.loaded = false
|
|
|
|
|
2020-09-25 23:14:32 -04:00
|
|
|
return nil
|
|
|
|
}
|