From c6d3997e6f9092703a703d686c3ab4cad5e472f2 Mon Sep 17 00:00:00 2001 From: "anton.gurov" Date: Tue, 12 Nov 2019 12:48:36 +0300 Subject: [PATCH] dev menu --- cmd/game/main.go | 11 +++- engine/gamemap/level.go | 5 ++ engine/gamemap/mapgens/default.go | 14 ++--- engine/gamemap/prefab.go | 5 +- engine/screens/devmenu.go | 95 +++++++++++++++++++++++++++++++ engine/screens/game.go | 4 ++ 6 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 engine/screens/devmenu.go diff --git a/cmd/game/main.go b/cmd/game/main.go index dd278c1..9a2605c 100644 --- a/cmd/game/main.go +++ b/cmd/game/main.go @@ -148,8 +148,17 @@ func main() { }).MakeList(), ) + screenMgr.AddScreen("devmenu", screens.NewDevmenuScreen( + mw, + screenMgr, + &State, + types.NewCenteredRect(mw.Rect, 70, 25), + true, + ).SetBgColor("#ef305c70"). + SetFgColor("white"), + ) - screenMgr.SetScreenByName("title") + screenMgr.SetScreenByName("title") //fixme //player := &mob.Player{ diff --git a/engine/gamemap/level.go b/engine/gamemap/level.go index 1e06b5b..9f2c997 100644 --- a/engine/gamemap/level.go +++ b/engine/gamemap/level.go @@ -82,3 +82,8 @@ func (l *Level) SetAllInvisible() { } } +func (l *Level) SetAllVisible() { + for idx, _ := range l.Tiles { + l.Tiles[idx].Visible = true + } +} diff --git a/engine/gamemap/mapgens/default.go b/engine/gamemap/mapgens/default.go index 0f548b5..ec466db 100644 --- a/engine/gamemap/mapgens/default.go +++ b/engine/gamemap/mapgens/default.go @@ -43,8 +43,8 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap rng := util.NewRNG() //load prefabs - //pfLoader := gamemap.NewPrefabLoader(ctx) - //pfRooms := pfLoader.PrefabRoomsList() + pfLoader := gamemap.NewPrefabLoader(ctx) + pfRooms := pfLoader.PrefabRoomsList() //fill with walls @@ -61,17 +61,17 @@ func DefaultGen(ctx util.ClientCtx,l *gamemap.Level) (*gamemap.Level, []*gamemap var fillage types.RectFill fillage = fges[rng.GetWeightedEntity(map[int]int{1: 10, 2: 1})] var newRoom *gamemap.Room - //if rng.Range(0, 5) > 3 { + if rng.Range(0, 5) == 1 { + //prefab + newRoom = &pfRooms[0] + } else { newRoom = gamemap.NewRandomRectRoom( rng, rng.Range(minRoomSize, maxRoomSize), rng.Range(minRoomSize, maxRoomSize), fillage, ) - //} else { - // prefab - // newRoom = &pfRooms[0] - //} + } where := types.Coords{ rng.Range(1, l.W -2 - newRoom.W), rng.Range(1, l.H - 2 - newRoom.H), diff --git a/engine/gamemap/prefab.go b/engine/gamemap/prefab.go index 456be2a..59c2491 100644 --- a/engine/gamemap/prefab.go +++ b/engine/gamemap/prefab.go @@ -81,7 +81,7 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room { Geometry: make([]func()*Tile, rawPrefab.Size.X*rawPrefab.Size.Y), Mobs: make([]mob.Mob, rawPrefab.Size.X*rawPrefab.Size.Y), Items: make([]items.Carried, rawPrefab.Size.X*rawPrefab.Size.Y), - Connectors: make([]types.Coords, rawPrefab.Size.X*rawPrefab.Size.Y), + Connectors: make([]types.Coords, 0), } //make geometry var f func() *Tile @@ -94,6 +94,9 @@ func (pfbl PrefabLoader) PrefabRoomsList() []Room { for i:=0; i < room.W; i++ { ok := false shortName := currentTileLegend[string(str[i])] + if shortName == "" { + continue + } if shortName == "any" { continue } diff --git a/engine/screens/devmenu.go b/engine/screens/devmenu.go new file mode 100644 index 0000000..46642ad --- /dev/null +++ b/engine/screens/devmenu.go @@ -0,0 +1,95 @@ +package screens + +import ( + "fmt" + "lab.zaar.be/thefish/alchemyst-go/engine/gamestate" + "lab.zaar.be/thefish/alchemyst-go/engine/types" + "lab.zaar.be/thefish/alchemyst-go/ui/mainwindow" +) + +type DevmenuScreen struct { + mw *mainwindow.MainWindow + scm *types.ScreenManager + state *gamestate.GameState + + *types.Rect + + renderParent bool + + bgColor string + fgColor string +} + +func NewDevmenuScreen(mw *mainwindow.MainWindow, scm *types.ScreenManager, state *gamestate.GameState, rect *types.Rect, renderParent bool) *DevmenuScreen { + return &DevmenuScreen{ + mw: mw, + scm: scm, + state: state, + + Rect: rect, + renderParent: renderParent, + } +} + +func (devm *DevmenuScreen) SetBgColor(color string) *DevmenuScreen { + devm.bgColor = color + return devm +} + +func (devm *DevmenuScreen) SetFgColor(color string) *DevmenuScreen { + devm.fgColor = color + return devm +} + +func (devm *DevmenuScreen) UseEcs() bool { return false } +func (devm *DevmenuScreen) Enter() { + +} +func (devm *DevmenuScreen) HandleInput(input string) { + switch input { + case "i": + level := devm.state.Level + for idx, _ := range level.Tiles { + level.Tiles[idx].Visible = false + level.Tiles[idx].Explored = false + } + break + case "v": + level := devm.state.Level + for idx, _ := range level.Tiles { + level.Tiles[idx].Visible = true + level.Tiles[idx].Explored = true + } + fmt.Printf("making everything visible!") + break + case "Escape": + fallthrough + case "Space": + devm.scm.SetScreen(devm.scm.PreviousScreen) + break + } +} +func (devm *DevmenuScreen) Exit() { + if devm.renderParent { + devm.scm.PreviousScreen.Render() + } + menuLayer := devm.mw.GetLayer("menu") + menuLayer.ClearRect(devm.Rect) + bgLayer := devm.mw.GetLayer("menubg") + bgLayer.ClearRect(devm.Rect) + +} +func (devm *DevmenuScreen) Render() { + menuLayer := devm.mw.GetLayer("menu") + menuLayer.ClearRect(devm.Rect) + bgLayer := devm.mw.GetLayer("menubg") + bgLayer.ClearRect(devm.Rect) + bgLayer.WithColor(devm.bgColor).NewWindow(devm.Rect).NoBorder() + + menuLayer.WithColor(devm.fgColor).PrintInside( + devm.Rect, + "v - all visible\ni - all invisible", + 1, + ) + +} \ No newline at end of file diff --git a/engine/screens/game.go b/engine/screens/game.go index 81fb057..38953a2 100644 --- a/engine/screens/game.go +++ b/engine/screens/game.go @@ -65,6 +65,10 @@ func (ts *GameScreen) HandleInput(input string) { case "Shift+/": ts.scm.SetScreenByName("help") break + case "Shift+z": + ts.scm.SetScreenByName("devmenu") + break + case "i": ts.scm.SetScreenByName("inventory") break