aboutsummaryrefslogtreecommitdiff
path: root/go/client/startMenu.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/client/startMenu.go')
-rw-r--r--go/client/startMenu.go132
1 files changed, 70 insertions, 62 deletions
diff --git a/go/client/startMenu.go b/go/client/startMenu.go
index 8f149f8b..29a4a18c 100644
--- a/go/client/startMenu.go
+++ b/go/client/startMenu.go
@@ -1,11 +1,8 @@
package main
import (
- "image/color"
"log"
- "github.com/hajimehoshi/ebiten/v2"
- "github.com/hajimehoshi/ebiten/v2/inpututil"
// "muhq.space/muhqs-game/go/game"
"muhq.space/muhqs-game/go/ui"
)
@@ -13,17 +10,22 @@ import (
const (
START_BUTTON_WIDTH = 150
START_BUTTON_HEIGHT = 50
+
+ DECK_LIST_WIDTH = 300
+ DECK_LIST_HEIGHT = 500
)
type StartMenu struct {
+ ui.Collection
app *app
width, height int
+ deckInput *ui.TextInput
+
playerName string
startDeck string
remote string
mapPath string
- widgets []ui.Widget
}
func NewStartMenu(app *app) *StartMenu {
@@ -33,18 +35,55 @@ func NewStartMenu(app *app) *StartMenu {
}
func (m *StartMenu) build() {
- playerLabel := ui.NewFixedTextBox(
+ deckInput := ui.NewTextInput(
+ (m.width-DECK_LIST_WIDTH)/2,
+ (m.height-DECK_LIST_HEIGHT)/2,
+ DECK_LIST_WIDTH,
+ DECK_LIST_HEIGHT,
+ "deck",
+ )
+ deckInput.Bg(ui.Gray)
+
+ if m.startDeck != "" {
+ deckInput.AddInput([]rune(m.startDeck))
+ }
+
+ m.deckInput = deckInput
+ m.AddWidget(deckInput)
+
+ m.AddWidget(ui.NewFixedTextBox(
+ (m.width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH,
+ deckInput.Y-START_BUTTON_HEIGHT,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "map:",
+ ).Centering(true))
+
+ mapInput := ui.NewTextInput(
+ (m.width-START_BUTTON_WIDTH)/2,
+ deckInput.Y-START_BUTTON_HEIGHT,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "map",
+ )
+
+ if m.mapPath != "" {
+ mapInput.AddInput([]rune(m.mapPath))
+ }
+
+ m.AddWidget(mapInput)
+
+ m.AddWidget(ui.NewFixedTextBox(
(m.width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH,
- (m.height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT,
+ mapInput.Y-START_BUTTON_HEIGHT,
START_BUTTON_WIDTH,
START_BUTTON_HEIGHT,
"name:",
- ).Centering(true).Bg(color.Black)
- m.widgets = append(m.widgets, playerLabel)
+ ).Centering(true))
playerInput := ui.NewTextInput(
(m.width-START_BUTTON_WIDTH)/2,
- (m.height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT,
+ mapInput.Y-START_BUTTON_HEIGHT,
START_BUTTON_WIDTH,
START_BUTTON_HEIGHT,
"player name",
@@ -54,77 +93,46 @@ func (m *StartMenu) build() {
playerInput.AddInput([]rune(m.playerName))
}
- m.widgets = append(m.widgets, playerInput)
+ m.AddWidget(playerInput)
- m.widgets = append(m.widgets, ui.NewSimpleButton(
- (m.width-START_BUTTON_WIDTH)/2,
- (m.height-START_BUTTON_HEIGHT)/2,
+ m.AddWidget(ui.NewSimpleButton(
+ (m.width-START_BUTTON_WIDTH)/2+START_BUTTON_WIDTH/2,
+ deckInput.Y+deckInput.Height,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "Sealed",
+ func(*ui.SimpleButton) {
+ sealed := NewSealed(m.width, m.height, m.app)
+ m.app.pushActivity(sealed)
+ }))
+
+ m.AddWidget(ui.NewSimpleButton(
+ (m.width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH/2,
+ deckInput.Y+deckInput.Height,
START_BUTTON_WIDTH,
START_BUTTON_HEIGHT,
"Start",
func(*ui.SimpleButton) {
m.playerName = playerInput.Text()
- m.app.active = m.next()
+ m.mapPath = mapInput.Text()
+ m.startDeck = deckInput.Text()
+ m.startGame()
}))
}
func (m *StartMenu) Update() error {
- if m.widgets == nil {
+ if m.Widgets() == nil {
m.build()
}
- x, y := ebiten.CursorPosition()
-
- var activeWidget ui.Widget
- for _, w := range m.widgets {
- if !w.Contains(x, y) {
- continue
- }
- activeWidget = w
- break
- }
-
- if activeWidget == nil {
- return nil
- }
-
- scrollX, scrollY := ebiten.Wheel()
- if scrollX != 0 || scrollY != 0 {
- if scrollable, ok := activeWidget.(ui.Scrollable); ok {
- scrollable.Scroll(int(scrollX), int(scrollY))
- }
- }
-
- if textInput, ok := activeWidget.(*ui.TextInput); ok {
- // var input []rune
- // ebiten.AppendInputChars(input)
- input := ebiten.InputChars()
- if len(input) > 0 {
- textInput.AddInput(input)
- }
- textInput.HandleKey()
- }
-
- if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
- if btn, ok := activeWidget.(ui.Button); ok {
- btn.Click(x, y)
- }
- }
-
- return nil
-}
-
-func (m *StartMenu) Draw(screen *ebiten.Image) {
- for _, w := range m.widgets {
- w.Draw(screen)
- }
+ return m.Collection.Update()
}
func (m *StartMenu) Layout(width, height int) (int, int) {
return m.width, m.height
}
-func (m *StartMenu) next() ebiten.Game {
+func (m *StartMenu) startGame() {
if m.remote != "" {
log.Fatal("Remote games are currently not implemented")
}
@@ -138,5 +146,5 @@ func (m *StartMenu) next() ebiten.Game {
g.gameState.Players[idx].Color = color
}
- return g.Start()
+ m.app.pushActivity(g.Start())
}