Skip to content

Commit 0ed8de2

Browse files
authored
Tech (#153)
1 parent aa554b4 commit 0ed8de2

Some content is hidden

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

43 files changed

+2261
-310
lines changed

client/src/action_buttons.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::layout_ui::{bottom_left_texture, icon_pos};
55
use crate::move_ui::MoveIntent;
66
use crate::render_context::RenderContext;
77
use server::action::Action;
8-
use server::content::advances::get_advance_by_name;
8+
use server::content::advances::get_advance;
99
use server::content::custom_actions::{CustomAction, CustomActionType};
1010
use server::game::GameState;
1111
use server::playing_actions::{PlayingAction, PlayingActionType};
@@ -81,9 +81,9 @@ fn global_move(rc: &RenderContext) -> StateUpdate {
8181
fn custom_action_tooltip(custom_action_type: &CustomActionType) -> String {
8282
match custom_action_type {
8383
CustomActionType::ConstructWonder => "Construct a wonder".to_string(),
84-
CustomActionType::AbsolutePower => get_advance_by_name("Absolute Power").description,
85-
CustomActionType::VotingIncreaseHappiness => get_advance_by_name("Voting").description,
86-
CustomActionType::FreeEconomyCollect => get_advance_by_name("Free Economy").description,
84+
CustomActionType::AbsolutePower => get_advance("Absolute Power").description,
85+
CustomActionType::VotingIncreaseHappiness => get_advance("Voting").description,
86+
CustomActionType::FreeEconomyCollect => get_advance("Free Economy").description,
8787
}
8888
}
8989

client/src/city_ui.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,18 @@ fn collect_resources_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option
181181
"Collect resources",
182182
&[("Free Economy", CustomActionType::FreeEconomyCollect)],
183183
|custom| {
184+
let (collections, modifiers) = possible_resource_collections(
185+
rc.game,
186+
city.position,
187+
city.player_index,
188+
&HashMap::new(),
189+
);
184190
ActiveDialog::CollectResources(CollectResources::new(
185191
city.player_index,
186192
city.position,
187-
possible_resource_collections(
188-
rc.game,
189-
city.position,
190-
city.player_index,
191-
&HashMap::new(),
192-
),
193+
collections,
193194
custom,
195+
modifiers,
194196
))
195197
},
196198
)

client/src/client.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::client_state::{
1313
use crate::collect_ui::collect_dialog;
1414
use crate::construct_ui::pay_construction_dialog;
1515
use crate::dialog_ui::{cancel_button, ok_button, OkTooltip};
16+
use crate::event_ui::custom_phase_event_origin;
1617
use crate::happiness_ui::{increase_happiness_click, increase_happiness_menu};
1718
use crate::hex_ui::pixel_to_coordinate;
1819
use crate::layout_ui::{bottom_centered_text, icon_pos, top_right_texture};
@@ -55,13 +56,13 @@ fn render(rc: &RenderContext, features: &Features) -> StateUpdate {
5556
if show_map {
5657
updates.add(rc.with_camera(CameraMode::World, draw_map));
5758
}
58-
if !state.active_dialog.is_full_modal() {
59+
if !state.active_dialog.is_modal() {
5960
show_top_left(rc);
6061
}
6162
if show_map {
6263
show_top_center(rc);
6364
}
64-
if !state.active_dialog.is_full_modal() {
65+
if !state.active_dialog.is_modal() {
6566
updates.add(player_select(rc));
6667
updates.add(show_global_controls(rc, features));
6768
}
@@ -169,7 +170,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
169170
custom_actions_ui::payment_reward_dialog(rc, p)
170171
}
171172
ActiveDialog::CustomPhaseAdvanceRewardRequest(r) => {
172-
custom_actions_ui::advance_reward_dialog(rc, r, ActiveDialog::event_origin(rc).name())
173+
custom_actions_ui::advance_reward_dialog(rc, r, custom_phase_event_origin(rc).name())
173174
}
174175
}
175176
}

client/src/client_state.rs

+15-39
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ use crate::client::{Features, GameSyncRequest};
33
use crate::collect_ui::CollectResources;
44
use crate::combat_ui::RemoveCasualtiesSelection;
55
use crate::construct_ui::ConstructionPayment;
6+
use crate::event_ui::{custom_phase_event_origin, event_help, pay_help};
67
use crate::happiness_ui::IncreaseHappinessConfig;
78
use crate::layout_ui::FONT_SIZE;
8-
use crate::log_ui::{add_advance_help, advance_help};
99
use crate::map_ui::ExploreResolutionConfig;
1010
use crate::move_ui::{MoveDestination, MoveIntent, MovePayment, MoveSelection};
1111
use crate::payment_ui::Payment;
1212
use crate::recruit_unit_ui::{RecruitAmount, RecruitSelection};
1313
use crate::render_context::RenderContext;
1414
use crate::status_phase_ui::ChooseAdditionalAdvances;
1515
use macroquad::prelude::*;
16-
use server::ability_initializer::EventOrigin;
1716
use server::action::Action;
1817
use server::city::{City, MoodState};
1918
use server::combat::{active_attackers, active_defenders, CombatPhase};
20-
use server::content::advances::{NAVIGATION, ROADS};
2119
use server::content::custom_phase_actions::{CustomPhaseAdvanceRewardRequest, CustomPhaseRequest};
2220
use server::game::{CulturalInfluenceResolution, CurrentMove, Game, GameState};
2321
use server::position::Position;
@@ -113,34 +111,34 @@ impl ActiveDialog {
113111
"Click on a city to increase happiness".to_string(),
114112
]
115113
}
116-
ActiveDialog::AdvancePayment(_)
117-
| ActiveDialog::ConstructionPayment(_)
118-
| ActiveDialog::MovePayment(_) => {
119-
vec!["Pay resources".to_string()]
120-
}
121-
ActiveDialog::CollectResources(collect) => collect.help_text(rc.game),
114+
ActiveDialog::AdvancePayment(p) => pay_help(rc, p),
115+
ActiveDialog::ConstructionPayment(p) => pay_help(rc, &p.payment),
116+
ActiveDialog::MovePayment(p) => pay_help(rc, &p.payment),
117+
ActiveDialog::CollectResources(collect) => collect.help_text(rc),
122118
ActiveDialog::RecruitUnitSelection(_) => vec!["Click on a unit to recruit".to_string()],
123119
ActiveDialog::ReplaceUnits(_) => vec!["Click on a unit to replace".to_string()],
124120
ActiveDialog::MoveUnits(m) => {
125121
if m.start.is_some() {
126122
let mut result = vec![];
127-
if m.destinations.is_empty() {
123+
let destinations = &m.destinations.list;
124+
if destinations.is_empty() {
128125
result.push("No unit on this tile can move".to_string());
129126
}
130-
if m.destinations
127+
if destinations
131128
.iter()
132129
.any(|d| matches!(d, MoveDestination::Tile(_)))
133130
{
134131
result.push("Click on a highlighted tile to move units".to_string());
135132
};
136-
if m.destinations
133+
if destinations
137134
.iter()
138135
.any(|d| matches!(d, MoveDestination::Carrier(_)))
139136
{
140137
result.push("Click on a carrier to embark units".to_string());
141138
};
142-
add_advance_help(rc, &mut result, NAVIGATION);
143-
add_advance_help(rc, &mut result, ROADS);
139+
m.destinations.modifiers.iter().for_each(|m| {
140+
result.extend(event_help(rc, m, true));
141+
});
144142
result
145143
} else {
146144
vec!["Click on a unit to move".to_string()]
@@ -189,29 +187,12 @@ impl ActiveDialog {
189187
ActiveDialog::WaitingForUpdate => vec!["Waiting for server update".to_string()],
190188
ActiveDialog::CustomPhaseResourceRewardRequest(_)
191189
| 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
190+
| ActiveDialog::CustomPhasePaymentRequest(_) => {
191+
event_help(rc, &custom_phase_event_origin(rc), true)
192+
}
201193
}
202194
}
203195

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-
215196
#[must_use]
216197
pub fn show_for_other_player(&self) -> bool {
217198
matches!(self, ActiveDialog::Log | ActiveDialog::DetermineFirstPlayer) || self.is_advance()
@@ -222,11 +203,6 @@ impl ActiveDialog {
222203
matches!(self, ActiveDialog::Log) || self.is_advance()
223204
}
224205

225-
#[must_use]
226-
pub fn is_full_modal(&self) -> bool {
227-
self.is_modal()
228-
}
229-
230206
#[must_use]
231207
pub fn is_advance(&self) -> bool {
232208
matches!(

client/src/collect_ui.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::client_state::{ActiveDialog, StateUpdate};
55
use crate::dialog_ui::{
66
cancel_button, ok_button, BaseOrCustomAction, BaseOrCustomDialog, OkTooltip,
77
};
8+
use crate::event_ui::event_help;
89
use crate::hex_ui;
910
use crate::hex_ui::Point;
1011
use crate::layout_ui::{draw_scaled_icon, is_in_circle, left_mouse_button_pressed};
@@ -17,6 +18,7 @@ use macroquad::shapes::draw_circle;
1718
use server::action::Action;
1819
use server::collect::{get_total_collection, possible_resource_collections};
1920
use server::content::custom_actions::CustomAction;
21+
use server::events::EventOrigin;
2022
use server::game::Game;
2123
use server::playing_actions::{Collect, PlayingAction};
2224
use server::position::Position;
@@ -30,6 +32,7 @@ pub struct CollectResources {
3032
possible_collections: HashMap<Position, HashSet<ResourcePile>>,
3133
collections: Vec<(Position, ResourcePile)>,
3234
custom: BaseOrCustomDialog,
35+
pub modifiers: Vec<EventOrigin>,
3336
}
3437

3538
impl CollectResources {
@@ -38,13 +41,15 @@ impl CollectResources {
3841
city_position: Position,
3942
possible_collections: HashMap<Position, HashSet<ResourcePile>>,
4043
custom: BaseOrCustomDialog,
44+
modifiers: Vec<EventOrigin>,
4145
) -> CollectResources {
4246
CollectResources {
4347
player_index,
4448
city_position,
4549
collections: vec![],
4650
possible_collections,
4751
custom,
52+
modifiers,
4853
}
4954
}
5055

@@ -55,13 +60,18 @@ impl CollectResources {
5560
.map(|(_, r)| r)
5661
}
5762

58-
pub fn help_text(&self, game: &Game) -> Vec<String> {
59-
let extra = self.extra_resources(game);
60-
vec![
63+
pub fn help_text(&self, rc: &RenderContext) -> Vec<String> {
64+
let extra = self.extra_resources(rc.game);
65+
let mut r = vec![
6166
self.custom.title.clone(),
6267
"Click on a tile to collect resources".to_string(),
6368
format!("{extra} left"),
64-
]
69+
];
70+
for o in self.modifiers.clone() {
71+
let vec1 = event_help(rc, &o, true);
72+
r.extend(vec1);
73+
}
74+
r
6575
}
6676

6777
pub fn extra_resources(&self, game: &Game) -> i8 {
@@ -134,8 +144,9 @@ fn click_collect_option(
134144
}
135145

136146
let used = new.collections.clone().into_iter().collect();
137-
new.possible_collections =
138-
possible_resource_collections(rc.game, col.city_position, col.player_index, &used);
147+
let (c, m) = possible_resource_collections(rc.game, col.city_position, col.player_index, &used);
148+
new.possible_collections = c;
149+
new.modifiers = m;
139150

140151
StateUpdate::OpenDialog(ActiveDialog::CollectResources(new))
141152
}

client/src/dialog_ui.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct BaseOrCustomDialog {
2828
pub fn show_pending_update(update: &PendingUpdate, rc: &RenderContext) -> StateUpdate {
2929
let state = &rc.state;
3030
let t = if update.warning.is_empty() {
31-
if state.active_dialog.is_full_modal() {
31+
if state.active_dialog.is_modal() {
3232
&update.info.join(", ")
3333
} else {
3434
"Are you sure?"

client/src/event_ui.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use crate::log_ui::break_text;
2+
use crate::payment_ui::Payment;
3+
use crate::render_context::RenderContext;
4+
use server::content::advances::get_advance;
5+
use server::content::wonders::get_wonder;
6+
use server::events::EventOrigin;
7+
8+
#[must_use]
9+
pub fn event_help(rc: &RenderContext, origin: &EventOrigin, do_break: bool) -> Vec<String> {
10+
let h = match origin {
11+
EventOrigin::Advance(a) => get_advance(a).description,
12+
EventOrigin::Wonder(w) => get_wonder(w).description,
13+
EventOrigin::Leader(l) => {
14+
let l = rc.shown_player.get_leader(l).unwrap();
15+
// todo: leader should have a 2 event sources
16+
format!(
17+
"{}, {}",
18+
l.first_ability_description, l.second_ability_description
19+
)
20+
}
21+
EventOrigin::SpecialAdvance(s) => {
22+
let s = rc
23+
.shown_player
24+
.civilization
25+
.special_advances
26+
.iter()
27+
.find(|sa| &sa.name == s)
28+
.unwrap();
29+
s.description.clone()
30+
}
31+
};
32+
let h = format!("{}: {}", origin.name(), h);
33+
if do_break {
34+
let mut result = vec![];
35+
break_text(&h, 30, &mut result);
36+
result
37+
} else {
38+
vec![h]
39+
}
40+
}
41+
42+
#[must_use]
43+
pub fn custom_phase_event_origin(rc: &RenderContext) -> EventOrigin {
44+
rc.game
45+
.custom_phase_state
46+
.current
47+
.as_ref()
48+
.unwrap()
49+
.origin
50+
.clone()
51+
}
52+
53+
pub fn pay_help(rc: &RenderContext, p: &Payment) -> Vec<String> {
54+
let mut result = vec!["Pay resources".to_string()];
55+
for o in p.cost.modifiers.clone() {
56+
result.extend(event_help(rc, &o, true));
57+
}
58+
result
59+
}

client/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod combat_ui;
2020
mod construct_ui;
2121
mod custom_actions_ui;
2222
mod dialog_ui;
23+
mod event_ui;
2324
mod happiness_ui;
2425
mod hex_ui;
2526
mod influence_ui;

client/src/log_ui.rs

-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::client_state::StateUpdate;
22
use crate::render_context::RenderContext;
33
use macroquad::math::vec2;
4-
use server::content::advances::get_advance_by_name;
54

65
pub fn show_log(rc: &RenderContext) -> StateUpdate {
76
let state = rc.state;
@@ -39,19 +38,3 @@ pub fn break_text(label: &str, len: usize, result: &mut Vec<String>) {
3938
result.push(label.to_string());
4039
});
4140
}
42-
43-
pub fn advance_help(rc: &RenderContext, advance: &str) -> Vec<String> {
44-
let mut result = vec![];
45-
add_advance_help(rc, &mut result, advance);
46-
result
47-
}
48-
49-
pub fn add_advance_help(rc: &RenderContext, result: &mut Vec<String>, advance: &str) {
50-
if rc.shown_player.has_advance(advance) {
51-
break_text(
52-
&format!("{}: {}", advance, get_advance_by_name(advance).description),
53-
30,
54-
result,
55-
);
56-
}
57-
}

client/src/map_ui.rs

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn overlay_color(rc: &RenderContext, pos: Position) -> Color {
145145
alpha_overlay(0.5)
146146
} else if s
147147
.destinations
148+
.list
148149
.iter()
149150
.any(|d| matches!(d, MoveDestination::Tile((p, _)) if *p == pos))
150151
{

0 commit comments

Comments
 (0)