Skip to content

Commit aa554b4

Browse files
authored
more tech (#152)
1 parent 47fc609 commit aa554b4

File tree

126 files changed

+6391
-8767
lines changed

Some content is hidden

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

126 files changed

+6391
-8767
lines changed

client/src/advance_ui.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ pub fn show_advance_menu(
8989
let state = rc.state;
9090

9191
for pass in 0..2 {
92-
for (i, (group_name, advances)) in advances::get_groups().iter().enumerate() {
92+
for (i, group) in advances::get_groups().iter().enumerate() {
9393
let pos =
9494
vec2(i.rem(COLUMNS) as f32 * 140., (i / COLUMNS) as f32 * 180.) + vec2(20., 70.);
9595
if pass == 0 {
9696
state.draw_text(
97-
group_name,
98-
pos.x + (140. - state.measure_text(group_name).width) / 2.,
97+
&group.name,
98+
pos.x + (140. - state.measure_text(&group.name).width) / 2.,
9999
pos.y - 15.,
100100
);
101101
}
102102

103-
for (i, a) in advances.iter().enumerate() {
103+
for (i, a) in group.advances.iter().enumerate() {
104104
let pos = pos + vec2(0., i as f32 * 35.);
105105
let name = &a.name;
106106
let advance_state = advance_state(a, p);

client/src/client.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
165165
ActiveDialog::CustomPhasePaymentRequest(c) => {
166166
custom_actions_ui::custom_phase_payment_dialog(rc, c)
167167
}
168-
ActiveDialog::CustomPhaseRewardRequest(p) => custom_actions_ui::reward_dialog(rc, p),
168+
ActiveDialog::CustomPhaseResourceRewardRequest(p) => {
169+
custom_actions_ui::payment_reward_dialog(rc, p)
170+
}
171+
ActiveDialog::CustomPhaseAdvanceRewardRequest(r) => {
172+
custom_actions_ui::advance_reward_dialog(rc, r, ActiveDialog::event_origin(rc).name())
173+
}
169174
}
170175
}
171176

client/src/client_state.rs

+35-14
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use server::action::Action;
1818
use server::city::{City, MoodState};
1919
use server::combat::{active_attackers, active_defenders, CombatPhase};
2020
use server::content::advances::{NAVIGATION, ROADS};
21-
use server::content::custom_phase_actions::CustomPhaseRequest;
21+
use server::content::custom_phase_actions::{CustomPhaseAdvanceRewardRequest, CustomPhaseRequest};
2222
use server::game::{CulturalInfluenceResolution, CurrentMove, Game, GameState};
2323
use server::position::Position;
2424
use server::status_phase::{StatusPhaseAction, StatusPhaseState};
@@ -59,7 +59,8 @@ pub enum ActiveDialog {
5959
Retreat,
6060
RemoveCasualties(RemoveCasualtiesSelection),
6161

62-
CustomPhaseRewardRequest(Payment),
62+
CustomPhaseResourceRewardRequest(Payment),
63+
CustomPhaseAdvanceRewardRequest(CustomPhaseAdvanceRewardRequest),
6364
CustomPhasePaymentRequest(Vec<Payment>),
6465
}
6566

@@ -93,7 +94,8 @@ impl ActiveDialog {
9394
ActiveDialog::PlaceSettler => "place settler",
9495
ActiveDialog::Retreat => "retreat",
9596
ActiveDialog::RemoveCasualties(_) => "remove casualties",
96-
ActiveDialog::CustomPhaseRewardRequest(_) => "trade route selection",
97+
ActiveDialog::CustomPhaseResourceRewardRequest(_) => "trade route selection",
98+
ActiveDialog::CustomPhaseAdvanceRewardRequest(_) => "advance selection",
9799
ActiveDialog::CustomPhasePaymentRequest(_) => "custom phase payment request",
98100
}
99101
}
@@ -185,18 +187,31 @@ impl ActiveDialog {
185187
}
186188
)],
187189
ActiveDialog::WaitingForUpdate => vec!["Waiting for server update".to_string()],
188-
ActiveDialog::CustomPhaseRewardRequest(_) => {
189-
vec!["Select trade route reward".to_string()]
190-
}
191-
ActiveDialog::CustomPhasePaymentRequest(_r) => {
192-
match &rc.game.custom_phase_state.current.as_ref().unwrap().origin {
193-
EventOrigin::Advance(a) => advance_help(rc, a),
194-
_ => vec![], // TODO
195-
}
196-
}
190+
ActiveDialog::CustomPhaseResourceRewardRequest(_)
191+
| ActiveDialog::CustomPhaseAdvanceRewardRequest(_)
192+
| ActiveDialog::CustomPhasePaymentRequest(_) => Self::event_help(rc),
193+
}
194+
}
195+
196+
#[must_use]
197+
pub fn event_help(rc: &RenderContext) -> Vec<String> {
198+
match &Self::event_origin(rc) {
199+
EventOrigin::Advance(a) => advance_help(rc, a),
200+
_ => vec![], // TODO
197201
}
198202
}
199203

204+
#[must_use]
205+
pub fn event_origin(rc: &RenderContext) -> EventOrigin {
206+
rc.game
207+
.custom_phase_state
208+
.current
209+
.as_ref()
210+
.unwrap()
211+
.origin
212+
.clone()
213+
}
214+
200215
#[must_use]
201216
pub fn show_for_other_player(&self) -> bool {
202217
matches!(self, ActiveDialog::Log | ActiveDialog::DetermineFirstPlayer) || self.is_advance()
@@ -221,6 +236,7 @@ impl ActiveDialog {
221236
| ActiveDialog::AdvancePayment(_)
222237
| ActiveDialog::ChangeGovernmentType
223238
| ActiveDialog::ChooseAdditionalAdvances(_)
239+
| ActiveDialog::CustomPhaseAdvanceRewardRequest(_)
224240
)
225241
}
226242
}
@@ -525,8 +541,13 @@ impl State {
525541
})
526542
.collect(),
527543
),
528-
CustomPhaseRequest::Reward(r) => {
529-
ActiveDialog::CustomPhaseRewardRequest(Payment::new_gain(&r.reward, &r.name))
544+
CustomPhaseRequest::ResourceReward(r) => {
545+
ActiveDialog::CustomPhaseResourceRewardRequest(Payment::new_gain(
546+
&r.reward, &r.name,
547+
))
548+
}
549+
CustomPhaseRequest::AdvanceReward(r) => {
550+
ActiveDialog::CustomPhaseAdvanceRewardRequest(r.clone())
530551
}
531552
};
532553
}

client/src/construct_ui.rs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) ->
5151
city_piece: *b,
5252
payment,
5353
port_position: *pos,
54-
temple_bonus: None,
5554
})),
5655
vec![],
5756
city,

client/src/custom_actions_ui.rs

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1+
use crate::advance_ui::{show_advance_menu, AdvanceState};
12
use crate::client_state::{ActiveDialog, StateUpdate};
23
use crate::payment_ui::{multi_payment_dialog, payment_dialog, Payment};
34
use crate::render_context::RenderContext;
45
use server::action::Action;
5-
use server::content::custom_phase_actions::CustomPhaseEventAction;
6+
use server::content::custom_phase_actions::{
7+
CustomPhaseAdvanceRewardRequest, CustomPhaseEventAction,
8+
};
69

7-
pub fn reward_dialog(rc: &RenderContext, payment: &Payment) -> StateUpdate {
10+
pub fn payment_reward_dialog(rc: &RenderContext, payment: &Payment) -> StateUpdate {
811
payment_dialog(
912
rc,
1013
payment,
1114
false,
12-
|p| ActiveDialog::CustomPhaseRewardRequest(p.clone()),
15+
|p| ActiveDialog::CustomPhaseResourceRewardRequest(p.clone()),
1316
|p| {
14-
StateUpdate::Execute(Action::CustomPhaseEvent(CustomPhaseEventAction::Reward(
15-
p.clone(),
16-
)))
17+
StateUpdate::Execute(Action::CustomPhaseEvent(
18+
CustomPhaseEventAction::ResourceReward(p.clone()),
19+
))
1720
},
1821
)
1922
}
@@ -31,3 +34,27 @@ pub fn custom_phase_payment_dialog(rc: &RenderContext, payments: &[Payment]) ->
3134
},
3235
)
3336
}
37+
38+
pub fn advance_reward_dialog(
39+
rc: &RenderContext,
40+
r: &CustomPhaseAdvanceRewardRequest,
41+
name: &str,
42+
) -> StateUpdate {
43+
let possible = &r.choices;
44+
show_advance_menu(
45+
rc,
46+
&format!("Select advance for {name}"),
47+
|a, _| {
48+
if possible.contains(&a.name) {
49+
AdvanceState::Available
50+
} else {
51+
AdvanceState::Unavailable
52+
}
53+
},
54+
|a| {
55+
StateUpdate::Execute(Action::CustomPhaseEvent(
56+
CustomPhaseEventAction::AdvanceReward(a.name.clone()),
57+
))
58+
},
59+
)
60+
}

client/src/local_client/bin/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ pub fn setup_local_game() -> Game {
240240
.pieces
241241
.market = Some(1);
242242

243-
game.advance("Voting", player_index1);
244-
game.advance("Free Economy", player_index1);
245-
game.advance("Storage", player_index1);
243+
game.advance("Voting", player_index1, ResourcePile::empty());
244+
game.advance("Free Economy", player_index1, ResourcePile::empty());
245+
game.advance("Storage", player_index1, ResourcePile::empty());
246246
game.players[player_index1].gain_resources(ResourcePile::food(5));
247247

248248
game

client/src/payment_ui.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn ok_tooltip(payments: &[Payment], mut available: ResourcePile) -> OkTooltip {
196196
let name = &payment.name;
197197
let tooltip = if payment.optional && pile.is_empty() {
198198
OkTooltip::Valid(format!("Pay nothing for {name}"))
199-
} else if available.has_at_least(&pile, 1) && cost.is_valid_payment(&pile) {
199+
} else if available.has_at_least(&pile) && cost.is_valid_payment(&pile) {
200200
// make sure that we can afford all the payments
201201
available -= payment.to_resource_pile();
202202
OkTooltip::Valid(format!("Pay {pile} for {name}"))

0 commit comments

Comments
 (0)