package main import ( "strings" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/inpututil" "muhq.space/muhqs-game/go/game" "muhq.space/muhqs-game/go/ui" ) const ( SIDEBARD_WIDTH = 200 ) type Sealed struct { ui.Collection app *app pool game.PileOfCards deck game.PileOfCards } func NewSealed(width, height int, app *app) *Sealed { s := &Sealed{ app: app, Collection: ui.Collection{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) Update() error { if err := s.Collection.Update(); err != nil { return err } if inpututil.IsKeyJustPressed(ebiten.KeyEscape) { s.app.popActivity() } return nil } 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.NewDeck() for _, c := range game.NewDeckFromCardPaths(set.CardPaths()).Cards() { if c.IsBuyable() { setDeck.AddCard(c) } } 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() }