@@ -2,10 +2,11 @@ use crate::client::Features;
2
2
use crate :: client_state:: { ActiveDialog , ShownPlayer , State , StateUpdate , OFFSET , ZOOM } ;
3
3
use crate :: happiness_ui:: start_increase_happiness;
4
4
use crate :: layout_ui:: {
5
- bottom_left_button, bottom_right_button , right_center_button , right_center_label ,
6
- top_center_label, top_left_label,
5
+ bottom_left_button, bottom_left_texture , bottom_right_texture , icon_pos , left_mouse_button ,
6
+ top_center_label, top_center_texture , top_left_label, top_right_texture , ICON_SIZE ,
7
7
} ;
8
- use macroquad:: math:: vec2;
8
+ use crate :: resource_ui:: ResourceType ;
9
+ use macroquad:: math:: { u32, vec2} ;
9
10
use macroquad:: prelude:: * ;
10
11
use macroquad:: ui:: { root_ui, Ui } ;
11
12
use server:: action:: Action ;
@@ -14,12 +15,7 @@ use server::player::Player;
14
15
use server:: playing_actions:: PlayingAction ;
15
16
use server:: resource_pile:: ResourcePile ;
16
17
17
- pub fn show_globals ( game : & Game , player : & ShownPlayer ) -> StateUpdate {
18
- show_top_left ( game) ;
19
- show_top_center ( game, player) ;
20
-
21
- let mut y = -100. ;
22
-
18
+ pub fn player_select ( game : & Game , player : & ShownPlayer , state : & State ) -> StateUpdate {
23
19
let i = game
24
20
. players
25
21
. iter ( )
@@ -28,77 +24,147 @@ pub fn show_globals(game: &Game, player: &ShownPlayer) -> StateUpdate {
28
24
let mut players: Vec < _ > = game. players . iter ( ) . map ( |p| p. index ) . collect ( ) ;
29
25
players. rotate_left ( i) ;
30
26
27
+ let mut y = ( players. len ( ) as f32 * -ICON_SIZE ) / 2. ;
28
+
31
29
for p in players {
32
- let p = game. get_player ( p) ;
33
- let shown = player. index == p. index ;
34
- let prefix = if shown { "* " } else { "" } ;
35
- let name = p. get_name ( ) ;
36
- let x = -200. ;
37
- let label = format ! ( "{prefix}{name}" ) ;
38
- if shown {
39
- right_center_label ( player, vec2 ( x, y) , & label) ;
40
- } else if right_center_button ( player, vec2 ( x, y) , & label) {
41
- return StateUpdate :: SetShownPlayer ( p. index ) ;
30
+ let pl = game. get_player ( p) ;
31
+ let shown = player. index == pl. index ;
32
+ let pos = vec2 ( player. screen_size . x , player. screen_size . y / 2.0 ) + vec2 ( -20. , y) ;
33
+
34
+ let color = player_color ( pl. index ) ;
35
+ set_default_camera ( ) ;
36
+
37
+ let w = if shown { ICON_SIZE + 10. } else { ICON_SIZE } ;
38
+ let x = pos. x - w + ICON_SIZE ;
39
+ draw_rectangle ( x, pos. y , w, ICON_SIZE , color) ;
40
+ draw_rectangle_lines ( x, pos. y , w, ICON_SIZE , 2.0 , BLACK ) ;
41
+ let text = format ! ( "{}" , pl. victory_points( ) ) ;
42
+
43
+ draw_text ( & text, pos. x + 5. , pos. y + 20. , 20.0 , BLACK ) ;
44
+
45
+ let active = game. active_player ( ) ;
46
+ if active == pl. index {
47
+ draw_texture_ex (
48
+ & state. assets . active_player ,
49
+ x - 25. ,
50
+ pos. y + 5. ,
51
+ WHITE ,
52
+ DrawTextureParams {
53
+ dest_size : Some ( vec2 ( 20. , 20. ) ) ,
54
+ ..Default :: default ( )
55
+ } ,
56
+ ) ;
57
+ }
58
+
59
+ set_camera ( & state. camera ) ;
60
+
61
+ if !shown && left_mouse_button ( Rect :: new ( x, pos. y , w, ICON_SIZE ) ) {
62
+ return StateUpdate :: SetShownPlayer ( pl. index ) ;
42
63
}
43
- y += 40. ;
64
+
65
+ y += ICON_SIZE ;
44
66
}
45
67
46
68
StateUpdate :: None
47
69
}
48
70
49
- fn show_top_center ( game : & Game , player : & ShownPlayer ) {
71
+ pub fn resource_label (
72
+ player : & ShownPlayer ,
73
+ state : & State ,
74
+ label : & str ,
75
+ resource_type : ResourceType ,
76
+ p : Vec2 ,
77
+ ) {
78
+ top_icon_with_label (
79
+ player,
80
+ state,
81
+ label,
82
+ & state. assets . resources [ & resource_type] ,
83
+ p,
84
+ ) ;
85
+ }
86
+
87
+ pub fn top_icon_with_label (
88
+ player : & ShownPlayer ,
89
+ state : & State ,
90
+ label : & str ,
91
+ texture : & Texture2D ,
92
+ p : Vec2 ,
93
+ ) {
94
+ top_center_texture ( state, texture, p) ;
95
+ top_center_label ( player, p + vec2 ( -30. - label. len ( ) as f32 * 5. , 40. ) , label) ;
96
+ }
97
+
98
+ pub fn show_top_center ( game : & Game , player : & ShownPlayer , state : & State ) {
50
99
let p = game. get_player ( player. index ) ;
51
100
52
- top_center_label ( player, vec2 ( -400. , 0. ) , & resource_ui ( p, "Fd" , |r| r. food ) ) ;
53
- top_center_label ( player, vec2 ( -320. , 0. ) , & resource_ui ( p, "Wd" , |r| r. wood ) ) ;
54
- top_center_label ( player, vec2 ( -240. , 0. ) , & resource_ui ( p, "Ore" , |r| r. ore ) ) ;
55
- top_center_label ( player, vec2 ( -160. , 0. ) , & resource_ui ( p, "Id" , |r| r. ideas ) ) ;
56
- top_center_label (
101
+ resource_label (
57
102
player,
58
- vec2 ( -80. , 0. ) ,
59
- & resource_ui ( p, "Gld" , |r| r. gold as u32 ) ,
103
+ state,
104
+ & resource_ui ( p, |r| r. food ) ,
105
+ ResourceType :: Food ,
106
+ icon_pos ( -4 , 0 ) ,
60
107
) ;
61
- top_center_label (
108
+ resource_label (
62
109
player,
63
- vec2 ( 0. , 0. ) ,
64
- & resource_ui ( p, "Md" , |r| r. mood_tokens ) ,
110
+ state,
111
+ & resource_ui ( p, |r| r. wood ) ,
112
+ ResourceType :: Wood ,
113
+ icon_pos ( -3 , 0 ) ,
65
114
) ;
66
- top_center_label (
115
+ resource_label (
67
116
player,
68
- vec2 ( 80. , 0. ) ,
69
- & resource_ui ( p, "Cul" , |r| r. culture_tokens ) ,
117
+ state,
118
+ & resource_ui ( p, |r| r. ore ) ,
119
+ ResourceType :: Ore ,
120
+ icon_pos ( -2 , 0 ) ,
70
121
) ;
71
-
72
- top_center_label (
122
+ resource_label (
73
123
player,
74
- vec2 ( 170. , 0. ) ,
75
- & format ! ( "Civ {}" , p. civilization. name) ,
124
+ state,
125
+ & resource_ui ( p, |r| r. ideas ) ,
126
+ ResourceType :: Ideas ,
127
+ icon_pos ( -1 , 0 ) ,
76
128
) ;
77
- top_center_label (
129
+ resource_label (
78
130
player,
79
- vec2 ( 250. , 0. ) ,
80
- & format ! ( "VP {}" , p. victory_points( ) ) ,
131
+ state,
132
+ & resource_ui ( p, |r| r. gold as u32 ) ,
133
+ ResourceType :: Gold ,
134
+ icon_pos ( 0 , 0 ) ,
81
135
) ;
82
- top_center_label (
136
+ resource_label (
83
137
player,
84
- vec2 ( 300. , 0. ) ,
85
- & format ! (
86
- "Ldr {}" ,
87
- if let Some ( l) = & p. active_leader {
88
- & l. name
89
- } else {
90
- "-"
91
- }
92
- ) ,
138
+ state,
139
+ & resource_ui ( p, |r| r. mood_tokens ) ,
140
+ ResourceType :: MoodTokens ,
141
+ icon_pos ( 1 , 0 ) ,
142
+ ) ;
143
+ resource_label (
144
+ player,
145
+ state,
146
+ & resource_ui ( p, |r| r. culture_tokens ) ,
147
+ ResourceType :: CultureTokens ,
148
+ icon_pos ( 2 , 0 ) ,
149
+ ) ;
150
+
151
+ top_icon_with_label (
152
+ player,
153
+ state,
154
+ & format ! ( "{}" , & p. victory_points( ) ) ,
155
+ & state. assets . victory_points ,
156
+ icon_pos ( 3 , 0 ) ,
93
157
) ;
158
+
94
159
show_wonders ( game, player, & mut root_ui ( ) ) ;
95
160
}
96
161
97
- fn show_top_left ( game : & Game ) {
162
+ pub fn show_top_left ( game : & Game , player : & ShownPlayer ) {
98
163
let mut y = 0. ;
99
164
let mut label = |label : String | {
100
- top_left_label ( vec2 ( 0. , y) , & label) ;
101
- y += 30. ;
165
+ let p = vec2 ( 0. , y * 25. ) ;
166
+ y += 1. ;
167
+ top_left_label ( p, & label) ;
102
168
} ;
103
169
104
170
match & game. state {
@@ -110,31 +176,42 @@ fn show_top_left(game: &Game) {
110
176
_ => label ( format ! ( "Round {}" , game. round) ) ,
111
177
}
112
178
113
- let current = game. current_player_index ;
114
- label ( format ! ( "Playing {}" , & game. get_player( current) . get_name( ) ) ) ;
179
+ let p = game. get_player ( player. index ) ;
115
180
116
- match & game. state {
117
- GameState :: StatusPhase ( _) | GameState :: Finished => { }
118
- _ => label ( format ! ( "Actions {}" , game. actions_left) ) ,
119
- }
181
+ label ( p. get_name ( ) ) ;
120
182
121
- match & game. state {
122
- GameState :: Movement { .. } => label ( "Movement" . to_string ( ) ) ,
123
- GameState :: CulturalInfluenceResolution ( _) => {
124
- label ( "Cultural Influence Resolution" . to_string ( ) ) ;
183
+ label ( format ! ( "Civ {}" , p. civilization. name) ) ;
184
+
185
+ label ( format ! (
186
+ "Leader {}" ,
187
+ if let Some ( l) = & p. active_leader {
188
+ & l. name
189
+ } else {
190
+ "-"
125
191
}
126
- GameState :: Combat ( c) => label ( format ! ( "Combat Round {} Phase {:?}" , c. round, c. phase) ) ,
127
- GameState :: PlaceSettler { .. } => label ( "Place Settler" . to_string ( ) ) ,
128
- _ => { }
129
- }
192
+ ) ) ;
130
193
131
- if let Some ( m) = moves_left ( & game. state ) {
132
- label ( format ! ( "Moves left {m}" ) ) ;
133
- }
194
+ if game. current_player_index == p. index {
195
+ label ( "Your turn" . to_string ( ) ) ;
196
+
197
+ match & game. state {
198
+ GameState :: StatusPhase ( _) | GameState :: Finished => { }
199
+ _ => label ( format ! ( "Actions {}" , game. actions_left) ) ,
200
+ }
201
+
202
+ match & game. state {
203
+ GameState :: Movement { .. } => label ( "Movement" . to_string ( ) ) ,
204
+ GameState :: CulturalInfluenceResolution ( _) => {
205
+ label ( "Cultural Influence Resolution" . to_string ( ) ) ;
206
+ }
207
+ GameState :: Combat ( c) => label ( format ! ( "Combat Round {} Phase {:?}" , c. round, c. phase) ) ,
208
+ GameState :: PlaceSettler { .. } => label ( "Place Settler" . to_string ( ) ) ,
209
+ _ => { }
210
+ }
134
211
135
- let active = game. active_player ( ) ;
136
- if active != current {
137
- label ( format ! ( "Active {}" , game . get_player ( active ) . get_name ( ) ) ) ;
212
+ if let Some ( m ) = moves_left ( & game. state ) {
213
+ label ( format ! ( "Moves left {m}" ) ) ;
214
+ }
138
215
}
139
216
}
140
217
@@ -176,54 +253,55 @@ pub fn show_wonders(game: &Game, player: &ShownPlayer, ui: &mut Ui) {
176
253
}
177
254
}
178
255
179
- fn resource_ui ( player : & Player , name : & str , f : impl Fn ( & ResourcePile ) -> u32 ) -> String {
256
+ fn resource_ui ( player : & Player , f : impl Fn ( & ResourcePile ) -> u32 ) -> String {
180
257
let r: & ResourcePile = & player. resources ;
181
258
let l: & ResourcePile = & player. resource_limit ;
182
- format ! ( "{name} { }/{}" , f( r) , f( l) )
259
+ format ! ( "{}/{}" , f( r) , f( l) )
183
260
}
184
261
185
262
pub fn show_global_controls ( game : & Game , state : & mut State , features : & Features ) -> StateUpdate {
186
263
let player = & state. shown_player ( game) ;
187
264
188
- if bottom_left_button ( player, vec2 ( 0. , -50. ) , "+" ) {
265
+ let assets = & state. assets ;
266
+ if bottom_left_texture ( state, & assets. zoom_in , icon_pos ( 1 , -1 ) ) {
189
267
state. zoom *= 1.1 ;
190
268
return StateUpdate :: None ;
191
269
}
192
- if bottom_left_button ( player , vec2 ( 70. , - 50. ) , "-" ) {
270
+ if bottom_left_texture ( state , & assets . zoom_out , icon_pos ( 0 , - 1 ) ) {
193
271
state. zoom /= 1.1 ;
194
272
return StateUpdate :: None ;
195
273
}
196
- if bottom_left_button ( player , vec2 ( 140. , - 50. ) , "0" ) {
274
+ if bottom_left_texture ( state , & assets . reset , icon_pos ( 2 , - 1 ) ) {
197
275
state. zoom = ZOOM ;
198
276
state. offset = OFFSET ;
199
277
return StateUpdate :: None ;
200
278
}
201
- if bottom_left_button ( player , vec2 ( 210. , - 80. ) , "" ) {
202
- state. offset += vec2 ( - 0.1 , 0. ) ;
279
+ if bottom_left_texture ( state , & assets . up , icon_pos ( 4 , - 2 ) ) {
280
+ state. offset += vec2 ( 0. , 0.1 ) ;
203
281
return StateUpdate :: None ;
204
282
}
205
- if bottom_left_button ( player , vec2 ( 310. , - 80. ) , "" ) {
206
- state. offset += vec2 ( 0.1 , 0. ) ;
283
+ if bottom_left_texture ( state , & assets . down , icon_pos ( 4 , - 1 ) ) {
284
+ state. offset += vec2 ( 0. , - 0.1 ) ;
207
285
return StateUpdate :: None ;
208
286
}
209
- if bottom_left_button ( player , vec2 ( 260. , - 110. ) , "" ) {
210
- state. offset += vec2 ( 0. , 0.1 ) ;
287
+ if bottom_left_texture ( state , & assets . left , icon_pos ( 3 , - 1 ) ) {
288
+ state. offset += vec2 ( - 0.1 , 0. ) ;
211
289
return StateUpdate :: None ;
212
290
}
213
- if bottom_left_button ( player , vec2 ( 260. , - 50. ) , "" ) {
214
- state. offset += vec2 ( 0. , - 0.1 ) ;
291
+ if bottom_left_texture ( state , & assets . right , icon_pos ( 5 , - 1 ) ) {
292
+ state. offset += vec2 ( 0.1 , 0. ) ;
215
293
return StateUpdate :: None ;
216
294
}
217
295
218
- if game. can_undo ( ) && bottom_right_button ( player , vec2 ( - 400. , - 50. ) , "Undo" ) {
296
+ if game. can_undo ( ) && bottom_right_texture ( state , & assets . undo , icon_pos ( - 6 , - 1 ) ) {
219
297
return StateUpdate :: Execute ( Action :: Undo ) ;
220
298
}
221
- if game. can_redo ( ) && bottom_right_button ( player , vec2 ( - 300. , - 50. ) , "Redo" ) {
299
+ if game. can_redo ( ) && bottom_right_texture ( state , & assets . redo , icon_pos ( - 5 , - 1 ) ) {
222
300
return StateUpdate :: Execute ( Action :: Redo ) ;
223
301
}
224
302
if player. can_control
225
303
&& matches ! ( game. state, GameState :: Playing )
226
- && bottom_right_button ( player , vec2 ( - 180. , - 50. ) , "End Turn" )
304
+ && bottom_right_texture ( state , & assets . end_turn , icon_pos ( - 4 , - 1 ) )
227
305
{
228
306
let left = game. actions_left ;
229
307
return StateUpdate :: execute_with_warning (
@@ -236,16 +314,17 @@ pub fn show_global_controls(game: &Game, state: &mut State, features: &Features)
236
314
) ;
237
315
}
238
316
239
- if player. can_play_action && bottom_left_button ( player , vec2 ( 0. , -170. ) , "Move" ) {
317
+ if player. can_play_action && bottom_left_texture ( state , & assets . movement , icon_pos ( 0 , -3 ) ) {
240
318
return StateUpdate :: execute ( Action :: Playing ( PlayingAction :: MoveUnits ) ) ;
241
319
}
242
- if player. can_play_action && bottom_left_button ( player , vec2 ( 0. , -140. ) , "Inc. Hap." ) {
320
+ if player. can_play_action && bottom_left_texture ( state , & assets . happy , icon_pos ( 0 , -2 ) ) {
243
321
return start_increase_happiness ( game, player) ;
244
322
}
245
- if bottom_left_button ( player , vec2 ( 0. , - 110. ) , "Advances" ) {
323
+ if top_right_texture ( state , & assets . advances , icon_pos ( - 2 , 0 ) ) {
246
324
return StateUpdate :: OpenDialog ( ActiveDialog :: AdvanceMenu ) ;
247
325
} ;
248
- if bottom_left_button ( player, vec2 ( 0. , -80. ) , "Log" ) {
326
+
327
+ if top_right_texture ( state, & assets. log , icon_pos ( -1 , 0 ) ) {
249
328
return StateUpdate :: OpenDialog ( ActiveDialog :: Log ) ;
250
329
} ;
251
330
let d = state. game_state_dialog ( game, & ActiveDialog :: None ) ;
@@ -257,10 +336,10 @@ pub fn show_global_controls(game: &Game, state: &mut State, features: &Features)
257
336
}
258
337
259
338
if features. import_export {
260
- if bottom_right_button ( player , vec2 ( - 300. , - 100. ) , "Import" ) {
339
+ if bottom_right_texture ( state , & assets . import , icon_pos ( - 2 , - 3 ) ) {
261
340
return StateUpdate :: Import ;
262
341
} ;
263
- if bottom_right_button ( player , vec2 ( - 150. , - 100. ) , "Export" ) {
342
+ if bottom_right_texture ( state , & assets . export , icon_pos ( - 1 , - 3 ) ) {
264
343
return StateUpdate :: Export ;
265
344
} ;
266
345
}
0 commit comments