2020-06-13 20:36:20 -04:00
|
|
|
package d2gamescreen
|
2019-10-27 19:00:38 -04:00
|
|
|
|
|
|
|
import (
|
2020-07-02 13:55:43 -04:00
|
|
|
"fmt"
|
2019-11-15 09:04:27 -05:00
|
|
|
"os"
|
2020-07-14 00:24:49 -04:00
|
|
|
"strings"
|
2020-06-19 02:19:27 -04:00
|
|
|
"time"
|
2019-11-06 18:25:19 -05:00
|
|
|
|
2020-09-20 17:52:01 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2hero"
|
|
|
|
|
2020-09-12 16:51:30 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
2020-07-22 15:03:03 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2math/d2vector"
|
2020-09-12 16:51:30 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2020-11-18 16:02:49 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2util"
|
2020-09-12 16:51:30 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapengine"
|
2020-09-12 16:51:30 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2mapgen"
|
2020-06-21 18:40:37 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map/d2maprenderer"
|
2020-06-13 20:36:20 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2screen"
|
2019-10-27 19:00:38 -04:00
|
|
|
)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
|
|
|
subtilesPerTile = 5
|
|
|
|
)
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
type regionSpec struct {
|
2019-11-17 00:52:13 -05:00
|
|
|
regionType d2enum.RegionIdType
|
|
|
|
startPresetIndex int
|
|
|
|
endPresetIndex int
|
|
|
|
extra []int
|
|
|
|
}
|
|
|
|
|
2020-07-22 15:03:03 -04:00
|
|
|
func getRegions() []regionSpec {
|
|
|
|
return []regionSpec{
|
|
|
|
// Act I
|
|
|
|
{d2enum.RegionAct1Town, 1, 3, []int{}},
|
|
|
|
{d2enum.RegionAct1Wilderness, 4, 52, []int{
|
|
|
|
108,
|
|
|
|
160, 161, 162, 163, 164,
|
|
|
|
}},
|
|
|
|
{d2enum.RegionAct1Cave, 53, 107, []int{}},
|
|
|
|
{d2enum.RegionAct1Crypt, 109, 159, []int{}},
|
|
|
|
{d2enum.RegionAct1Monestary, 165, 165, []int{}},
|
|
|
|
{d2enum.RegionAct1Courtyard, 166, 166, []int{256}},
|
|
|
|
{d2enum.RegionAct1Barracks, 167, 205, []int{}},
|
|
|
|
{d2enum.RegionAct1Jail, 206, 255, []int{}},
|
|
|
|
{d2enum.RegionAct1Cathedral, 257, 257, []int{}},
|
|
|
|
{d2enum.RegionAct1Catacombs, 258, 299, []int{}},
|
|
|
|
{d2enum.RegionAct1Tristram, 300, 300, []int{}},
|
|
|
|
|
|
|
|
// Act II
|
|
|
|
{d2enum.RegionAct2Town, 301, 301, []int{}},
|
|
|
|
{d2enum.RegionAct2Sewer, 302, 352, []int{}},
|
|
|
|
{d2enum.RegionAct2Harem, 353, 357, []int{}},
|
|
|
|
{d2enum.RegionAct2Basement, 358, 361, []int{}},
|
|
|
|
{d2enum.RegionAct2Desert, 362, 413, []int{}},
|
|
|
|
{d2enum.RegionAct2Tomb, 414, 481, []int{}},
|
|
|
|
{d2enum.RegionAct2Lair, 482, 509, []int{}},
|
|
|
|
{d2enum.RegionAct2Arcane, 510, 528, []int{}},
|
|
|
|
|
|
|
|
// Act III
|
|
|
|
{d2enum.RegionAct3Town, 529, 529, []int{}},
|
|
|
|
{d2enum.RegionAct3Jungle, 530, 604, []int{}},
|
|
|
|
{d2enum.RegionAct3Kurast, 605, 658, []int{
|
|
|
|
748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769,
|
|
|
|
770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791,
|
|
|
|
792, 793, 794, 795, 796,
|
|
|
|
}},
|
|
|
|
{d2enum.RegionAct3Spider, 659, 664, []int{}},
|
|
|
|
{d2enum.RegionAct3Dungeon, 665, 704, []int{}},
|
|
|
|
{d2enum.RegionAct3Sewer, 705, 747, []int{}},
|
|
|
|
|
|
|
|
// Act IV
|
|
|
|
{d2enum.RegionAct4Town, 797, 798, []int{}},
|
|
|
|
{d2enum.RegionAct4Mesa, 799, 835, []int{}},
|
|
|
|
{d2enum.RegionAct4Lava, 836, 862, []int{}},
|
|
|
|
|
|
|
|
// Act V -- broken or wrong order
|
|
|
|
{d2enum.RegonAct5Town, 863, 864, []int{}},
|
|
|
|
{d2enum.RegionAct5Siege, 865, 879, []int{}},
|
|
|
|
{d2enum.RegionAct5Barricade, 880, 1002, []int{}},
|
|
|
|
{d2enum.RegionAct5IceCaves, 1003, 1041, []int{}},
|
|
|
|
{d2enum.RegionAct5Temple, 1042, 1052, []int{}},
|
|
|
|
{d2enum.RegionAct5Baal, 1059, 1090, []int{}},
|
|
|
|
{d2enum.RegionAct5Lava, 1053, 1058, []int{}},
|
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// CreateMapEngineTest creates the Map Engine Test screen and returns a pointer to it
|
2020-07-18 09:54:10 -04:00
|
|
|
func CreateMapEngineTest(currentRegion,
|
|
|
|
levelPreset int,
|
2020-09-12 16:51:30 -04:00
|
|
|
asset *d2asset.AssetManager,
|
2020-07-18 09:54:10 -04:00
|
|
|
term d2interface.Terminal,
|
|
|
|
renderer d2interface.Renderer,
|
|
|
|
inputManager d2interface.InputManager,
|
2020-07-26 15:17:00 -04:00
|
|
|
audioProvider d2interface.AudioProvider,
|
2020-11-18 16:02:49 -05:00
|
|
|
l d2util.LogLevel,
|
2020-08-05 22:31:56 -04:00
|
|
|
screen *d2screen.ScreenManager,
|
2020-09-20 17:52:01 -04:00
|
|
|
) (*MapEngineTest, error) {
|
|
|
|
heroStateFactory, err := d2hero.NewHeroStateFactory(asset)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
mapEngineTest := &MapEngineTest{
|
2020-09-20 17:52:01 -04:00
|
|
|
currentRegion: currentRegion,
|
|
|
|
levelPreset: levelPreset,
|
|
|
|
fileIndex: 0,
|
|
|
|
regionSpec: regionSpec{},
|
|
|
|
filesCount: 0,
|
|
|
|
asset: asset,
|
|
|
|
terminal: term,
|
|
|
|
renderer: renderer,
|
|
|
|
inputManager: inputManager,
|
|
|
|
audioProvider: audioProvider,
|
|
|
|
screen: screen,
|
|
|
|
playerStateFactory: heroStateFactory,
|
2020-11-21 05:33:22 -05:00
|
|
|
logLevel: l,
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-11-18 16:02:49 -05:00
|
|
|
mapEngineTest.playerState = heroStateFactory.CreateTestGameState()
|
|
|
|
|
|
|
|
mapEngineTest.logger = d2util.NewLogger()
|
|
|
|
mapEngineTest.logger.SetLevel(l)
|
|
|
|
mapEngineTest.logger.SetPrefix(logPrefix)
|
|
|
|
|
|
|
|
return mapEngineTest, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MapEngineTest represents the MapEngineTest screen
|
|
|
|
type MapEngineTest struct {
|
|
|
|
asset *d2asset.AssetManager
|
|
|
|
playerStateFactory *d2hero.HeroStateFactory
|
|
|
|
playerState *d2hero.HeroState
|
|
|
|
mapEngine *d2mapengine.MapEngine
|
|
|
|
mapGen *d2mapgen.MapGenerator
|
|
|
|
mapRenderer *d2maprenderer.MapRenderer
|
|
|
|
terminal d2interface.Terminal
|
|
|
|
renderer d2interface.Renderer
|
|
|
|
inputManager d2interface.InputManager
|
|
|
|
audioProvider d2interface.AudioProvider
|
|
|
|
screen *d2screen.ScreenManager
|
|
|
|
|
|
|
|
lastMouseX, lastMouseY int
|
|
|
|
selX, selY int
|
|
|
|
selectedTile *d2mapengine.MapTile
|
|
|
|
|
|
|
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/806
|
|
|
|
currentRegion int
|
|
|
|
levelPreset int
|
|
|
|
fileIndex int
|
|
|
|
regionSpec regionSpec
|
|
|
|
filesCount int
|
2020-09-20 17:52:01 -04:00
|
|
|
|
2020-11-21 05:33:22 -05:00
|
|
|
logger *d2util.Logger
|
|
|
|
logLevel d2util.LogLevel
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
func (met *MapEngineTest) loadRegionByIndex(n, levelPreset, fileIndex int) {
|
2020-11-18 16:02:49 -05:00
|
|
|
met.logger.Info(fmt.Sprintf("Loaded region: Type(%d) LevelPreset(%d) FileIndex(%d)", n, levelPreset, fileIndex))
|
2020-07-22 15:03:03 -04:00
|
|
|
met.mapRenderer.InvalidateImageCache()
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-22 15:03:03 -04:00
|
|
|
for _, spec := range getRegions() {
|
2020-07-06 20:13:55 -04:00
|
|
|
if spec.regionType != d2enum.RegionIdType(n) {
|
|
|
|
continue
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
met.regionSpec = spec
|
|
|
|
inExtra := false
|
|
|
|
|
|
|
|
for _, e := range spec.extra {
|
|
|
|
if e == levelPreset {
|
|
|
|
inExtra = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2019-11-13 14:26:42 -05:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
if !inExtra {
|
|
|
|
if levelPreset < spec.startPresetIndex {
|
|
|
|
levelPreset = spec.startPresetIndex
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-06 20:13:55 -04:00
|
|
|
if levelPreset > spec.endPresetIndex {
|
|
|
|
levelPreset = spec.endPresetIndex
|
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2020-07-06 20:13:55 -04:00
|
|
|
|
|
|
|
met.levelPreset = levelPreset
|
2019-11-17 00:52:13 -05:00
|
|
|
}
|
2019-11-13 14:26:42 -05:00
|
|
|
|
2020-11-21 05:33:22 -05:00
|
|
|
mapGen, _ := d2mapgen.NewMapGenerator(met.asset, met.logLevel, met.mapEngine)
|
2020-09-20 17:52:01 -04:00
|
|
|
met.mapGen = mapGen
|
|
|
|
|
2019-11-13 14:26:42 -05:00
|
|
|
if n == 0 {
|
2020-06-21 23:23:00 -04:00
|
|
|
met.mapEngine.SetSeed(time.Now().UnixNano())
|
2020-09-20 17:52:01 -04:00
|
|
|
met.mapGen.GenerateAct1Overworld()
|
2019-11-17 16:06:02 -05:00
|
|
|
} else {
|
2020-11-21 05:33:22 -05:00
|
|
|
met.mapEngine = d2mapengine.CreateMapEngine(met.logLevel, met.asset) // necessary for map name update
|
2020-06-21 23:23:00 -04:00
|
|
|
met.mapEngine.SetSeed(time.Now().UnixNano())
|
2020-07-23 12:56:50 -04:00
|
|
|
met.mapEngine.GenerateMap(d2enum.RegionIdType(n), levelPreset, fileIndex)
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapRenderer.SetMapEngine(met.mapEngine)
|
2020-07-18 23:37:35 -04:00
|
|
|
position := d2vector.NewPosition(met.mapRenderer.WorldToOrtho(met.mapEngine.GetCenterPosition()))
|
2020-07-26 15:17:00 -04:00
|
|
|
met.mapRenderer.SetCameraPosition(&position)
|
|
|
|
|
2020-09-08 15:58:35 -04:00
|
|
|
musicDef := d2resource.GetMusicDef(met.regionSpec.regionType)
|
2020-07-26 15:17:00 -04:00
|
|
|
|
|
|
|
met.audioProvider.PlayBGM(musicDef.MusicFile)
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnLoad loads the resources for the Map Engine Test screen
|
2020-06-24 18:46:03 -04:00
|
|
|
func (met *MapEngineTest) OnLoad(loading d2screen.LoadingState) {
|
2020-07-13 20:29:17 -04:00
|
|
|
if err := met.inputManager.BindHandler(met); err != nil {
|
2020-11-18 16:02:49 -05:00
|
|
|
met.logger.Error("could not add MapEngineTest as event handler")
|
2020-07-02 13:55:43 -04:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
loading.Progress(twentyPercent)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-11-21 05:33:22 -05:00
|
|
|
met.mapEngine = d2mapengine.CreateMapEngine(met.logLevel, met.asset)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
loading.Progress(fiftyPercent)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-09-12 16:51:30 -04:00
|
|
|
met.mapRenderer = d2maprenderer.CreateMapRenderer(met.asset, met.renderer, met.mapEngine,
|
2020-11-21 05:33:22 -05:00
|
|
|
met.terminal, met.logLevel, 0.0, 0.0)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-07-18 09:54:10 -04:00
|
|
|
loading.Progress(seventyPercent)
|
2020-07-02 13:55:43 -04:00
|
|
|
met.loadRegionByIndex(met.currentRegion, met.levelPreset, met.fileIndex)
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnUnload releases the resources for the Map Engine Test screen
|
2020-02-08 21:02:37 -05:00
|
|
|
func (met *MapEngineTest) OnUnload() error {
|
2020-10-25 10:21:14 -04:00
|
|
|
// https://github.com/OpenDiablo2/OpenDiablo2/issues/792
|
2020-07-13 20:29:17 -04:00
|
|
|
if err := met.inputManager.UnbindHandler(met); err != nil {
|
2020-07-02 13:55:43 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
const (
|
|
|
|
lineSmallOffsetY = 12
|
|
|
|
lineNormalOffsetY = 16
|
|
|
|
lineSmallIndentX = 10
|
|
|
|
lineNormalIndentX = 15
|
|
|
|
lineBigIndentX = 170 // distance between text columns
|
|
|
|
)
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Render renders the Map Engine Test screen
|
2020-10-28 14:17:42 -04:00
|
|
|
func (met *MapEngineTest) Render(screen d2interface.Surface) {
|
2020-06-13 18:32:09 -04:00
|
|
|
met.mapRenderer.Render(screen)
|
2020-01-31 23:18:11 -05:00
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("N - next region, P - previous region")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
screen.PushTranslation(0, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Shift+N - next preset, Shift+P - previous preset")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
screen.PushTranslation(0, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Ctrl+N - next file, Ctrl+P - previous file")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
screen.PushTranslation(0, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Left click selects tile, right click unselects")
|
2020-07-14 00:24:49 -04:00
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
2020-07-14 00:24:49 -04:00
|
|
|
|
2020-10-28 14:17:42 -04:00
|
|
|
met.renderTileInfo(screen)
|
2020-10-26 18:55:13 -04:00
|
|
|
}
|
|
|
|
|
2020-10-28 14:17:42 -04:00
|
|
|
func (met *MapEngineTest) renderTileInfo(screen d2interface.Surface) {
|
2020-07-14 00:24:49 -04:00
|
|
|
if met.selectedTile == nil {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineNormalIndentX, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
2020-07-14 00:24:49 -04:00
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("No tile selected")
|
2020-07-14 00:24:49 -04:00
|
|
|
} else {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineSmallIndentX, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
screen.PushTranslation(0, lineNormalOffsetY) // extra vspace
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Tile %v,%v", met.selX, met.selY)
|
2020-07-14 00:24:49 -04:00
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineNormalIndentX, lineNormalOffsetY)
|
|
|
|
defer screen.Pop()
|
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Walls")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop := 0
|
2020-07-21 08:50:45 -04:00
|
|
|
for _, wall := range met.selectedTile.Components.Walls {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
|
|
|
tmpString := fmt.Sprintf("%#v", wall)
|
|
|
|
stringSlice := strings.Split(tmpString, " ")
|
|
|
|
tmp2 := strings.Split(stringSlice[0], "{")
|
|
|
|
stringSlice[0] = tmp2[1]
|
|
|
|
for _, str := range stringSlice {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf(str)
|
2020-07-14 00:24:49 -04:00
|
|
|
}
|
|
|
|
}
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-07-14 00:24:49 -04:00
|
|
|
screen.PopN(tpop)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineBigIndentX, 0)
|
|
|
|
defer screen.Pop()
|
2020-10-25 10:21:14 -04:00
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Floors")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop = 0
|
2020-07-21 08:50:45 -04:00
|
|
|
for _, floor := range met.selectedTile.Components.Floors {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
|
|
|
tmpString := fmt.Sprintf("%#v", floor)
|
|
|
|
stringSlice := strings.Split(tmpString, " ")
|
|
|
|
tmp2 := strings.Split(stringSlice[0], "{")
|
|
|
|
stringSlice[0] = tmp2[1]
|
|
|
|
for _, str := range stringSlice {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf(str)
|
2020-07-14 00:24:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.PopN(tpop)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineBigIndentX, 0)
|
|
|
|
defer screen.Pop()
|
2020-10-25 10:21:14 -04:00
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Shadows")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
tpop = 0
|
2020-07-21 08:50:45 -04:00
|
|
|
for _, shadow := range met.selectedTile.Components.Shadows {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
|
|
|
tmpString := fmt.Sprintf("%#v", shadow)
|
|
|
|
stringSlice := strings.Split(tmpString, " ")
|
|
|
|
tmp2 := strings.Split(stringSlice[0], "{")
|
|
|
|
stringSlice[0] = tmp2[1]
|
|
|
|
for _, str := range stringSlice {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf(str)
|
2020-07-14 00:24:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.PopN(tpop)
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(lineBigIndentX, 0)
|
|
|
|
defer screen.Pop()
|
2020-10-25 10:21:14 -04:00
|
|
|
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf("Substitutions")
|
2020-10-25 03:42:31 -04:00
|
|
|
|
|
|
|
tpop = 0
|
2020-07-21 08:50:45 -04:00
|
|
|
for _, subst := range met.selectedTile.Components.Substitutions {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
|
|
|
tmpString := fmt.Sprintf("%#v", subst)
|
|
|
|
stringSlice := strings.Split(tmpString, " ")
|
|
|
|
tmp2 := strings.Split(stringSlice[0], "{")
|
|
|
|
stringSlice[0] = tmp2[1]
|
|
|
|
for _, str := range stringSlice {
|
2020-10-25 03:42:31 -04:00
|
|
|
screen.PushTranslation(0, lineSmallOffsetY)
|
2020-07-14 00:24:49 -04:00
|
|
|
tpop++
|
2020-07-17 18:51:44 -04:00
|
|
|
screen.DrawTextf(str)
|
2020-07-14 00:24:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.PopN(tpop)
|
|
|
|
}
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// OnMouseMove is the mouse move handler
|
2020-07-14 00:24:49 -04:00
|
|
|
func (met *MapEngineTest) OnMouseMove(event d2interface.MouseMoveEvent) bool {
|
|
|
|
mx, my := event.X(), event.Y()
|
|
|
|
met.lastMouseX = mx
|
|
|
|
met.lastMouseY = my
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:25:09 -04:00
|
|
|
// OnMouseButtonDown handles mouse button down events
|
2020-07-14 00:24:49 -04:00
|
|
|
func (met *MapEngineTest) OnMouseButtonDown(event d2interface.MouseEvent) bool {
|
|
|
|
if event.Button() == d2enum.MouseButtonLeft {
|
2020-09-12 16:25:09 -04:00
|
|
|
met.handleLeftClick()
|
2020-07-18 23:37:35 -04:00
|
|
|
|
2020-07-14 00:24:49 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if event.Button() == d2enum.MouseButtonRight {
|
|
|
|
met.selectedTile = nil
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:25:09 -04:00
|
|
|
// OnMouseButtonRepeat handles repeated mouse clicks
|
2020-07-18 23:37:35 -04:00
|
|
|
func (met *MapEngineTest) OnMouseButtonRepeat(event d2interface.MouseEvent) bool {
|
|
|
|
if event.Button() == d2enum.MouseButtonLeft {
|
2020-09-12 16:25:09 -04:00
|
|
|
met.handleLeftClick()
|
2020-07-18 23:37:35 -04:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:25:09 -04:00
|
|
|
func (met *MapEngineTest) handleLeftClick() {
|
|
|
|
px, py := met.mapRenderer.ScreenToWorld(met.lastMouseX, met.lastMouseY)
|
|
|
|
met.selX = int(px)
|
|
|
|
met.selY = int(py)
|
|
|
|
met.selectedTile = met.mapEngine.TileAt(int(px), int(py))
|
|
|
|
|
|
|
|
camVect := met.mapRenderer.Camera.GetPosition().Vector
|
|
|
|
|
2020-10-25 03:42:31 -04:00
|
|
|
halfScreenWidth, halfScreenHeight := screenWidth>>1, screenHeight>>1
|
|
|
|
|
|
|
|
x := float64(met.lastMouseX-halfScreenWidth) / subtilesPerTile
|
|
|
|
y := float64(met.lastMouseY-halfScreenHeight) / subtilesPerTile
|
|
|
|
|
2020-09-12 16:25:09 -04:00
|
|
|
targetPosition := d2vector.NewPositionTile(x, y)
|
|
|
|
targetPosition.Add(&camVect)
|
|
|
|
|
|
|
|
met.mapRenderer.SetCameraTarget(&targetPosition)
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// Advance runs the update logic on the Map Engine Test screen
|
2020-02-08 21:02:37 -05:00
|
|
|
func (met *MapEngineTest) Advance(tickTime float64) error {
|
2020-02-01 21:51:49 -05:00
|
|
|
met.mapEngine.Advance(tickTime)
|
2020-06-21 18:40:37 -04:00
|
|
|
met.mapRenderer.Advance(tickTime)
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnKeyRepeat is called to handle repeated key presses
|
2020-07-03 15:09:16 -04:00
|
|
|
func (met *MapEngineTest) OnKeyRepeat(event d2interface.KeyEvent) bool {
|
2020-01-25 23:28:21 -05:00
|
|
|
var moveSpeed float64 = 8
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.KeyMod() == d2enum.KeyModShift {
|
2020-01-25 23:28:21 -05:00
|
|
|
moveSpeed *= 2
|
2019-12-08 22:18:42 -05:00
|
|
|
}
|
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyDown {
|
2020-07-18 23:37:35 -04:00
|
|
|
v := d2vector.NewVector(0, moveSpeed)
|
2020-07-25 09:36:54 -04:00
|
|
|
met.mapRenderer.MoveCameraTargetBy(v)
|
2020-07-18 23:37:35 -04:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-01 14:12:23 -04:00
|
|
|
}
|
2020-01-25 23:28:21 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyUp {
|
2020-07-18 23:37:35 -04:00
|
|
|
v := d2vector.NewVector(0, -moveSpeed)
|
2020-07-25 09:36:54 -04:00
|
|
|
met.mapRenderer.MoveCameraTargetBy(v)
|
2020-07-18 23:37:35 -04:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-01 14:12:23 -04:00
|
|
|
}
|
2019-11-15 09:04:27 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyRight {
|
2020-07-18 23:37:35 -04:00
|
|
|
v := d2vector.NewVector(moveSpeed, 0)
|
2020-07-25 09:36:54 -04:00
|
|
|
met.mapRenderer.MoveCameraTargetBy(v)
|
2020-07-18 23:37:35 -04:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
|
|
|
}
|
2019-12-13 00:33:11 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyLeft {
|
2020-07-18 23:37:35 -04:00
|
|
|
v := d2vector.NewVector(-moveSpeed, 0)
|
2020-07-25 09:36:54 -04:00
|
|
|
met.mapRenderer.MoveCameraTargetBy(v)
|
2020-07-18 23:37:35 -04:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-15 09:04:27 -05:00
|
|
|
}
|
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:55:43 -04:00
|
|
|
// OnKeyDown defines the actions of the Map Engine Test screen when a key is pressed
|
2020-07-03 15:09:16 -04:00
|
|
|
func (met *MapEngineTest) OnKeyDown(event d2interface.KeyEvent) bool {
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyEscape {
|
2019-11-13 14:26:42 -05:00
|
|
|
os.Exit(0)
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-13 14:26:42 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyN {
|
2020-07-03 15:09:16 -04:00
|
|
|
switch event.KeyMod() {
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModControl:
|
2020-06-23 01:05:01 -04:00
|
|
|
met.fileIndex++
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModShift:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.levelPreset = increment(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-07-02 13:55:43 -04:00
|
|
|
default:
|
2020-07-22 15:03:03 -04:00
|
|
|
met.currentRegion = increment(met.currentRegion, 0, len(getRegions()))
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-17 08:09:54 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-07-06 21:26:08 -04:00
|
|
|
if event.Key() == d2enum.KeyP {
|
2020-07-03 15:09:16 -04:00
|
|
|
switch event.KeyMod() {
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModControl:
|
2020-06-23 01:05:01 -04:00
|
|
|
met.fileIndex--
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-07-06 21:26:08 -04:00
|
|
|
case d2enum.KeyModShift:
|
2020-01-25 23:28:21 -05:00
|
|
|
met.levelPreset = decrement(met.levelPreset, met.regionSpec.startPresetIndex, met.regionSpec.endPresetIndex)
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-07-02 13:55:43 -04:00
|
|
|
default:
|
2020-07-22 15:03:03 -04:00
|
|
|
met.currentRegion = decrement(met.currentRegion, 0, len(getRegions()))
|
2020-08-05 22:31:56 -04:00
|
|
|
met.screen.SetNextScreen(met)
|
2020-01-25 23:28:21 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return true
|
2019-11-17 08:09:54 -05:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
2020-01-25 23:28:21 -05:00
|
|
|
return false
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
2019-11-17 00:52:13 -05:00
|
|
|
|
|
|
|
func increment(v, min, max int) int {
|
|
|
|
v++
|
|
|
|
if v > max {
|
|
|
|
return min
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func decrement(v, min, max int) int {
|
|
|
|
v--
|
|
|
|
if v < min {
|
|
|
|
return max
|
|
|
|
}
|
2020-07-02 13:55:43 -04:00
|
|
|
|
2019-11-17 00:52:13 -05:00
|
|
|
return v
|
|
|
|
}
|