1
1
use crate :: client_state:: { ActiveDialog , StateUpdate } ;
2
- use crate :: dialog_ui:: OkTooltip ;
3
- use crate :: layout_ui:: { bottom_center_text, left_mouse_button_pressed_in_rect, top_centered_text} ;
2
+ use crate :: layout_ui:: { left_mouse_button_pressed_in_rect, top_centered_text} ;
4
3
use crate :: log_ui:: break_text;
5
- use crate :: payment_ui:: { payment_dialog , HasPayment , Payment , ResourcePayment } ;
4
+ use crate :: payment_ui:: { payment_model_dialog , PaymentModelEntry } ;
6
5
use crate :: player_ui:: player_color;
7
6
use crate :: render_context:: RenderContext ;
8
- use crate :: resource_ui:: new_resource_map;
9
- use crate :: select_ui:: HasCountSelectableObject ;
10
7
use crate :: tooltip:: show_tooltip_for_rect;
11
8
use macroquad:: color:: Color ;
12
9
use macroquad:: math:: vec2;
@@ -21,9 +18,7 @@ use server::game::GameState;
21
18
use server:: payment:: PaymentModel ;
22
19
use server:: player:: Player ;
23
20
use server:: playing_actions:: PlayingAction ;
24
- use server:: resource:: ResourceType ;
25
21
use server:: status_phase:: StatusPhaseAction ;
26
- use std:: cmp:: min;
27
22
use std:: ops:: Rem ;
28
23
29
24
const COLUMNS : usize = 6 ;
@@ -39,7 +34,6 @@ pub enum AdvanceState {
39
34
pub struct AdvancePayment {
40
35
pub name : String ,
41
36
model : PaymentModel ,
42
- payment : Payment ,
43
37
}
44
38
45
39
impl AdvancePayment {
@@ -49,44 +43,9 @@ impl AdvancePayment {
49
43
. get_advance_payment_options ( name) ;
50
44
AdvancePayment {
51
45
name : name. to_string ( ) ,
52
- payment : AdvancePayment :: new_payment ( model. clone ( ) ) ,
53
46
model,
54
47
}
55
48
}
56
-
57
- pub fn new_payment ( model : PaymentModel ) -> Payment {
58
- let PaymentModel :: Sum ( a) = model;
59
- let left = a. left ;
60
-
61
- let mut resources: Vec < ResourcePayment > = new_resource_map ( & a. default )
62
- . into_iter ( )
63
- . map ( |e| ResourcePayment :: new ( e. 0 , e. 1 , 0 , min ( a. cost , e. 1 + left. amount ( e. 0 ) ) ) )
64
- . collect ( ) ;
65
- resources. sort_by_key ( |r| r. resource ) ;
66
-
67
- Payment { resources }
68
- }
69
-
70
- pub fn valid ( & self ) -> OkTooltip {
71
- let pile = self . payment . to_resource_pile ( ) ;
72
- let valid = self . model . is_valid ( & pile) ;
73
-
74
- if valid {
75
- OkTooltip :: Valid ( format ! ( "Pay {} to research {}" , pile, self . name) )
76
- } else {
77
- OkTooltip :: Invalid ( format ! (
78
- "You don't have {} to research {}" ,
79
- self . model. default ( ) ,
80
- self . name
81
- ) )
82
- }
83
- }
84
- }
85
-
86
- impl HasPayment for AdvancePayment {
87
- fn payment ( & self ) -> & Payment {
88
- & self . payment
89
- }
90
49
}
91
50
92
51
pub fn show_paid_advance_menu ( rc : & RenderContext ) -> StateUpdate {
@@ -269,28 +228,25 @@ pub fn pay_advance_dialog(ap: &AdvancePayment, rc: &RenderContext) -> StateUpdat
269
228
// select a different advance
270
229
return update;
271
230
} ;
272
- bottom_center_text ( rc, & ap. name , vec2 ( -200. , -50. ) ) ;
273
- payment_dialog (
274
- ap,
275
- AdvancePayment :: valid,
276
- || {
231
+ payment_model_dialog (
232
+ rc,
233
+ & [ PaymentModelEntry {
234
+ name : ap. name . clone ( ) ,
235
+ model : ap. model . clone ( ) ,
236
+ optional : false ,
237
+ } ] ,
238
+ |p| {
239
+ ActiveDialog :: AdvancePayment ( AdvancePayment {
240
+ name : ap. name . clone ( ) ,
241
+ model : p[ 0 ] . model . clone ( ) ,
242
+ } )
243
+ } ,
244
+ true ,
245
+ |pile| {
277
246
StateUpdate :: Execute ( Action :: Playing ( PlayingAction :: Advance {
278
247
advance : ap. name . to_string ( ) ,
279
- payment : ap . payment . to_resource_pile ( ) ,
248
+ payment : pile [ 0 ] . clone ( ) ,
280
249
} ) )
281
250
} ,
282
- |ap, r| ap. payment . get ( r) . selectable . max > 0 ,
283
- |ap, r| add ( ap, r, 1 ) ,
284
- |ap, r| add ( ap, r, -1 ) ,
285
- rc,
286
251
)
287
252
}
288
-
289
- fn add ( ap : & AdvancePayment , r : ResourceType , i : i32 ) -> StateUpdate {
290
- let mut new = ap. clone ( ) ;
291
- let p = new. payment . get_mut ( r) ;
292
-
293
- let c = p. counter_mut ( ) ;
294
- c. current = ( c. current as i32 + i) as u32 ;
295
- StateUpdate :: OpenDialog ( ActiveDialog :: AdvancePayment ( new) )
296
- }
0 commit comments