Skip to content

Commit 42338f2

Browse files
authored
Payment model (#134)
1 parent 72bb424 commit 42338f2

File tree

87 files changed

+2890
-1212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2890
-1212
lines changed

client/src/advance_ui.rs

+9-34
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::client_state::{ActiveDialog, StateUpdate};
22
use crate::layout_ui::{left_mouse_button_pressed_in_rect, top_centered_text};
33
use crate::log_ui::break_text;
4-
use crate::payment_ui::{payment_model_dialog, PaymentModelEntry};
4+
use crate::payment_ui::{new_payment, payment_model_dialog, Payment};
55
use crate::player_ui::player_color;
66
use crate::render_context::RenderContext;
77
use crate::tooltip::show_tooltip_for_rect;
@@ -13,9 +13,7 @@ use macroquad::prelude::{
1313
use server::action::Action;
1414
use server::advance::{Advance, Bonus};
1515
use server::content::advances;
16-
use server::game::Game;
1716
use server::game::GameState;
18-
use server::payment::PaymentModel;
1917
use server::player::Player;
2018
use server::playing_actions::PlayingAction;
2119
use server::status_phase::StatusPhaseAction;
@@ -30,22 +28,9 @@ pub enum AdvanceState {
3028
Unavailable,
3129
}
3230

33-
#[derive(Clone)]
34-
pub struct AdvancePayment {
35-
pub name: String,
36-
model: PaymentModel,
37-
}
38-
39-
impl AdvancePayment {
40-
fn new(game: &Game, player_index: usize, name: &str) -> AdvancePayment {
41-
let model = game
42-
.get_player(player_index)
43-
.get_advance_payment_options(name);
44-
AdvancePayment {
45-
name: name.to_string(),
46-
model,
47-
}
48-
}
31+
fn new_advance_payment(rc: &RenderContext, name: &str) -> Payment {
32+
let p = rc.shown_player;
33+
new_payment(&p.advance_cost(name), &p.resources, name, false)
4934
}
5035

5136
pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
@@ -64,9 +49,8 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
6449
}
6550
},
6651
|a| {
67-
StateUpdate::OpenDialog(ActiveDialog::AdvancePayment(AdvancePayment::new(
68-
game,
69-
rc.shown_player.index,
52+
StateUpdate::OpenDialog(ActiveDialog::AdvancePayment(new_advance_payment(
53+
rc,
7054
a.name.as_str(),
7155
)))
7256
},
@@ -222,25 +206,16 @@ fn description(p: &Player, a: &Advance) -> Vec<String> {
222206
parts
223207
}
224208

225-
pub fn pay_advance_dialog(ap: &AdvancePayment, rc: &RenderContext) -> StateUpdate {
209+
pub fn pay_advance_dialog(ap: &Payment, rc: &RenderContext) -> StateUpdate {
226210
let update = show_paid_advance_menu(rc);
227211
if !matches!(update, StateUpdate::None) {
228212
// select a different advance
229213
return update;
230214
};
231215
payment_model_dialog(
232216
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-
},
217+
&[ap.clone()],
218+
|p| ActiveDialog::AdvancePayment(p[0].clone()),
244219
true,
245220
|pile| {
246221
StateUpdate::Execute(Action::Playing(PlayingAction::Advance {

client/src/client_state.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use server::game::{CulturalInfluenceResolution, CurrentMove, Game, GameState};
88
use server::position::Position;
99
use server::status_phase::{StatusPhaseAction, StatusPhaseState};
1010

11-
use crate::advance_ui::AdvancePayment;
1211
use crate::assets::Assets;
1312
use crate::city_ui::building_name;
1413
use crate::client::{Features, GameSyncRequest};
@@ -20,6 +19,7 @@ use crate::layout_ui::FONT_SIZE;
2019
use crate::log_ui::advance_help;
2120
use crate::map_ui::ExploreResolutionConfig;
2221
use crate::move_ui::{MoveDestination, MoveIntent, MoveSelection};
22+
use crate::payment_ui::Payment;
2323
use crate::recruit_unit_ui::{RecruitAmount, RecruitSelection};
2424
use crate::render_context::RenderContext;
2525
use crate::status_phase_ui::ChooseAdditionalAdvances;
@@ -34,7 +34,7 @@ pub enum ActiveDialog {
3434
// playing actions
3535
IncreaseHappiness(IncreaseHappinessConfig),
3636
AdvanceMenu,
37-
AdvancePayment(AdvancePayment),
37+
AdvancePayment(Payment),
3838
ConstructionPayment(ConstructionPayment),
3939
CollectResources(CollectResources),
4040
RecruitUnitSelection(RecruitAmount),
@@ -106,11 +106,8 @@ impl ActiveDialog {
106106
"Click on a city to increase happiness".to_string(),
107107
]
108108
}
109-
ActiveDialog::AdvancePayment(a) => {
110-
vec![format!("Click on resources to pay for {}", a.name)]
111-
}
112-
ActiveDialog::ConstructionPayment(c) => {
113-
vec![format!("Click on resources to pay for {}", c.name)]
109+
ActiveDialog::AdvancePayment(_) | ActiveDialog::ConstructionPayment(_) => {
110+
vec!["Pay resources".to_string()]
114111
}
115112
ActiveDialog::CollectResources(collect) => collect.help_text(rc.game),
116113
ActiveDialog::RecruitUnitSelection(_) => vec!["Click on a unit to recruit".to_string()],

client/src/combat_ui.rs

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::client_state::{ActiveDialog, StateUpdate};
22
use crate::dialog_ui::{cancel_button_with_tooltip, ok_button, OkTooltip};
3-
use crate::payment_ui::{payment_model_dialog, PaymentModelEntry};
3+
use crate::payment_ui::{new_payment, payment_model_dialog, Payment};
44
use crate::render_context::RenderContext;
55
use crate::select_ui::ConfirmSelection;
66
use crate::unit_ui;
@@ -10,7 +10,6 @@ use server::content::custom_phase_actions::{
1010
CustomPhaseAction, SiegecraftPayment, SIEGECRAFT_EXTRA_DIE, SIEGECRAFT_IGNORE_HIT,
1111
};
1212
use server::game::Game;
13-
use server::payment::get_single_resource_payment_model;
1413
use server::position::Position;
1514
use server::unit::Unit;
1615

@@ -100,44 +99,46 @@ pub fn play_action_card_dialog(rc: &RenderContext) -> StateUpdate {
10099

101100
#[derive(Clone)]
102101
pub struct SiegecraftPaymentModel {
103-
extra_die: PaymentModelEntry,
104-
ignore_hit: PaymentModelEntry,
102+
extra_die: Payment,
103+
ignore_hit: Payment,
105104
}
106105

107106
impl SiegecraftPaymentModel {
108107
pub fn new(game: &Game) -> SiegecraftPaymentModel {
109108
let available = game.get_player(game.active_player()).resources.clone();
110109
SiegecraftPaymentModel {
111-
extra_die: PaymentModelEntry {
112-
name: "Cancel fortress extra die in first round of combat".to_string(),
113-
model: get_single_resource_payment_model(&available, &SIEGECRAFT_EXTRA_DIE),
114-
optional: true,
115-
},
116-
ignore_hit: PaymentModelEntry {
117-
name: "Cancel fortress ignore hit in first round of combat".to_string(),
118-
model: get_single_resource_payment_model(&available, &SIEGECRAFT_IGNORE_HIT),
119-
optional: true,
120-
},
110+
extra_die: new_payment(
111+
&SIEGECRAFT_EXTRA_DIE,
112+
&available,
113+
"Cancel fortress extra die in first round of combat",
114+
true,
115+
),
116+
ignore_hit: new_payment(
117+
&SIEGECRAFT_IGNORE_HIT,
118+
&available,
119+
"Cancel fortress ignore hit in first round of combat",
120+
true,
121+
),
121122
}
122123
}
123124
}
124125

125126
pub fn pay_siegecraft_dialog(p: &SiegecraftPaymentModel, rc: &RenderContext) -> StateUpdate {
126127
payment_model_dialog(
127128
rc,
128-
&vec![p.extra_die.clone(), p.ignore_hit.clone()],
129+
&[p.extra_die.clone(), p.ignore_hit.clone()],
129130
|p| {
130131
ActiveDialog::SiegecraftPayment(SiegecraftPaymentModel {
131132
extra_die: p[0].clone(),
132133
ignore_hit: p[1].clone(),
133134
})
134135
},
135136
false,
136-
|_| {
137+
|p| {
137138
StateUpdate::Execute(Action::CustomPhase(
138139
CustomPhaseAction::SiegecraftPaymentAction(SiegecraftPayment {
139-
extra_die: p.extra_die.model.default().clone(),
140-
ignore_hit: p.ignore_hit.model.default().clone(),
140+
extra_die: p[0].clone(),
141+
ignore_hit: p[1].clone(),
141142
}),
142143
))
143144
},

0 commit comments

Comments
 (0)