aboutsummaryrefslogtreecommitdiff
path: root/go/client
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-14 16:05:06 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 15:50:09 +0200
commit379c17fe2244dc8fe8365cdbf3d62e21951c8121 (patch)
tree32a1741be38f3745c1edea86a4adf9116cc7c93f /go/client
parent1ac413e1d0ddc39a41374ff9b3375e6de3e1af1c (diff)
downloadmuhqs-game-379c17fe2244dc8fe8365cdbf3d62e21951c8121.tar.gz
muhqs-game-379c17fe2244dc8fe8365cdbf3d62e21951c8121.zip
add sealed activity to select a starting deck
Diffstat (limited to 'go/client')
-rw-r--r--go/client/game.go6
-rw-r--r--go/client/main.go16
-rw-r--r--go/client/sealed.go106
-rw-r--r--go/client/startMenu.go132
4 files changed, 192 insertions, 68 deletions
diff --git a/go/client/game.go b/go/client/game.go
index 91e7e365..76b04fa7 100644
--- a/go/client/game.go
+++ b/go/client/game.go
@@ -503,8 +503,10 @@ func (g *Game) Update() error {
scrollX, scrollY := ebiten.Wheel()
if scrollX != 0 || scrollY != 0 {
- if scrollable, ok := obj.(ui.Scrollable); ok {
- scrollable.Scroll(int(scrollX), int(scrollY))
+ for _, w := range g.widgets {
+ if scrollable, ok := w.(ui.Scrollable); ok && w.Contains(x, y) {
+ scrollable.Scroll(int(scrollX), int(scrollY))
+ }
}
}
diff --git a/go/client/main.go b/go/client/main.go
index 632bcc13..2b7496ad 100644
--- a/go/client/main.go
+++ b/go/client/main.go
@@ -28,15 +28,23 @@ type app struct {
windowWidth int
windowHeight int
- active ebiten.Game
+ activities []ebiten.Game
+}
+
+func (a *app) pushActivity(activity ebiten.Game) {
+ a.activities = append(a.activities, activity)
+}
+
+func (a *app) popActivity() {
+ a.activities = a.activities[:len(a.activities)-1]
}
func (a *app) Update() error {
- return a.active.Update()
+ return a.activities[len(a.activities)-1].Update()
}
func (a *app) Draw(screen *ebiten.Image) {
- a.active.Draw(screen)
+ a.activities[len(a.activities)-1].Draw(screen)
}
func (a *app) Layout(outsideWidth, outsideHeight int) (int, int) {
@@ -84,7 +92,7 @@ func main() {
1 nautics/galley`
}
- app.active = startMenu
+ app.pushActivity(startMenu)
if err := ebiten.RunGame(app); err != nil {
log.Fatal(err)
}
diff --git a/go/client/sealed.go b/go/client/sealed.go
new file mode 100644
index 00000000..6096a1d5
--- /dev/null
+++ b/go/client/sealed.go
@@ -0,0 +1,106 @@
+package main
+
+import (
+ "strings"
+
+ "muhq.space/muhqs-game/go/game"
+ "muhq.space/muhqs-game/go/ui"
+)
+
+const (
+ SIDEBARD_WIDTH = 200
+)
+
+type Sealed struct {
+ ui.Collection
+ app *app
+ width, height int
+
+ pool game.PileOfCards
+ deck game.PileOfCards
+}
+
+func NewSealed(width, height int, app *app) *Sealed {
+ s := &Sealed{app: app, width: width, height: height}
+
+ s.AddWidget(ui.NewFixedTextBox(
+ (s.width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH,
+ (s.height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "sets:",
+ ).Centering(true))
+
+ setInput := ui.NewTextInput(
+ (s.width-START_BUTTON_WIDTH)/2,
+ (s.height-START_BUTTON_HEIGHT)/2-START_BUTTON_HEIGHT,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "set list",
+ )
+ s.AddWidget(setInput)
+
+ s.AddWidget(ui.NewSimpleButton(
+ (s.width-START_BUTTON_WIDTH)/2,
+ (s.height-START_BUTTON_HEIGHT)/2,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "Start",
+ func(*ui.SimpleButton) {
+ s.startSealed(setInput.Text())
+ }))
+
+ return s
+}
+
+func (s *Sealed) Layout(width, height int) (int, int) {
+ return s.width, s.height
+}
+
+func (s *Sealed) startSealed(_sets string) {
+ s.pool = game.NewPileOfCards()
+ s.deck = game.NewPileOfCards()
+
+ s.Clear()
+
+ sets := strings.Split(_sets, ",")
+ for _, setName := range sets {
+ set := game.SetNames[setName]
+ setDeck := game.NewDeckFromCardPaths(set.CardPaths())
+ setDeck.MoveInto(s.pool)
+ }
+
+ deckList := ui.NewPocList(s.width-SIDEBARD_WIDTH/2, s.height-START_BUTTON_HEIGHT-20, s.deck)
+ deckList.Bg(ui.Gray)
+ s.AddWidget(deckList)
+
+ grid := ui.NewCardGrid(0, 0, s.width-SIDEBARD_WIDTH, s.height, 0.5, s.pool).Columns(3)
+ selectCard := func(x, y int) {
+ _card := grid.FindObjectAt(x, y)
+ if _card == nil {
+ return
+ }
+
+ card := _card.(*game.Card)
+ s.pool.MoveCard(card, s.deck)
+ grid.ForceRedraw()
+ deckList.ForceRedraw()
+ }
+ s.AddWidget(ui.NewClickWrapper(grid, selectCard))
+
+ s.AddWidget(ui.NewSimpleButton(
+ s.width-SIDEBARD_WIDTH/2-START_BUTTON_WIDTH/2,
+ s.height-START_BUTTON_HEIGHT,
+ START_BUTTON_WIDTH,
+ START_BUTTON_HEIGHT,
+ "Done",
+ func(*ui.SimpleButton) {
+ s.done()
+ }))
+}
+
+func (s *Sealed) done() {
+ startMenu := s.app.activities[len(s.app.activities)-2].(*StartMenu)
+ startMenu.deckInput.SetInput(s.deck.ToList())
+ s.app.popActivity()
+}
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())
}