aboutsummaryrefslogtreecommitdiff
path: root/go/client/startMenu.go
blob: 54c47196e82f0483867c7a7155d4c4efb64ab02c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package main

import (
	"log"

	"muhq.space/muhqs-game/go/activities"
	"muhq.space/muhqs-game/go/game"
	"muhq.space/muhqs-game/go/ui"
)

const (
	START_BUTTON_WIDTH  = 175
	START_BUTTON_HEIGHT = 50

	DECK_LIST_WIDTH  = 350
	DECK_LIST_HEIGHT = 500
)

type startMenu struct {
	ui.Collection
	app *app

	deckInput *ui.TextInput

	draft  *activities.Draft
	sealed *activities.Sealed

	playerName string
	startDeck  string
	remote     string
	mapPath    string
}

func NewStartMenu(app *app) *startMenu {
	m := &startMenu{app: app}

	return m
}

func (m *startMenu) build() {
	deckInput := ui.NewTextInput(
		(m.Width-DECK_LIST_WIDTH)/2,
		(m.Height-DECK_LIST_HEIGHT)/2,
		DECK_LIST_WIDTH,
		DECK_LIST_HEIGHT,
		"deck",
		true,
	)
	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",
		false,
	)

	if m.mapPath != "" {
		mapInput.AddInput([]rune(m.mapPath))
	}

	m.AddWidget(mapInput)

	m.AddWidget(ui.NewFixedTextBox(
		(m.Width-START_BUTTON_WIDTH)/2-START_BUTTON_WIDTH,
		mapInput.Y-START_BUTTON_HEIGHT,
		START_BUTTON_WIDTH,
		START_BUTTON_HEIGHT,
		"name:",
	).Centering(true))

	playerInput := ui.NewTextInput(
		(m.Width-START_BUTTON_WIDTH)/2,
		mapInput.Y-START_BUTTON_HEIGHT,
		START_BUTTON_WIDTH,
		START_BUTTON_HEIGHT,
		"player name",
		false,
	)

	if m.playerName != "" {
		playerInput.AddInput([]rune(m.playerName))
	}

	m.AddWidget(playerInput)

	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 := activities.NewSealed(m.Width, m.Height)
			activities.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,
		"Draft",
		func(*ui.SimpleButton) {
			m.draft = activities.NewLocalDraft(m.Width, m.Height, playerInput.Text())
			activities.PushActivity(m.draft)
		}))

	m.AddWidget(ui.NewSimpleButton(
		(m.Width-START_BUTTON_WIDTH)/2,
		deckInput.Y+deckInput.Height+START_BUTTON_HEIGHT+20,
		START_BUTTON_WIDTH,
		START_BUTTON_HEIGHT,
		"Start",
		func(*ui.SimpleButton) {
			m.playerName = playerInput.Text()
			m.mapPath = mapInput.Text()
			m.startDeck = deckInput.Text()
			m.startGame()
		}))
	m.AddWidget(ui.NewSimpleButton(
		(m.Width-START_BUTTON_WIDTH)/2,
		deckInput.Y+deckInput.Height+2*START_BUTTON_HEIGHT+40,
		START_BUTTON_WIDTH,
		START_BUTTON_HEIGHT,
		"Challenges",
		func(*ui.SimpleButton) {
			activities.PushActivity(newChallengesMenu(m.app, playerInput.Text()))
		}))
}

func (m *startMenu) Update() error {
	if m.Widgets() == nil {
		m.build()
	}

	// Get the drafted deck
	if m.draft != nil {
		m.deckInput.SetInput(m.draft.GetDeckList())
		m.draft = nil
	}

	// Get the sealed deck
	if m.sealed != nil {
		m.deckInput.SetInput(m.sealed.Deck.ToList())
		m.sealed = nil
	}

	if err := ui.Update(); err != nil {
		return err
	}

	return m.Collection.Update()
}

func (m *startMenu) Layout(width, height int) (int, int) {
	return m.Width, m.Height
}

func (m *startMenu) startGame() {
	var state game.State
	if m.remote != "" {
		log.Fatal("Remote games are currently not implemented")
	} else {
		state = game.NewLocalState()
	}

	g := newGame(m.app, state).loadMap(m.mapPath).addActivePlayer(m.playerName, m.startDeck)

	if m.mapPath == "the-kraken" {
		g.gameState.AddNewAiPlayer("kraken")
	}

	activities.PushActivity(g.Start())
}