|
| 1 | +use itertools::Itertools; |
| 2 | +use macroquad::hash; |
| 3 | +use macroquad::math::{bool, vec2}; |
1 | 4 | use std::cmp::min;
|
2 | 5 | use std::collections::HashMap;
|
3 | 6 |
|
4 |
| -use macroquad::math::bool; |
5 |
| - |
6 | 7 | use server::action::Action;
|
7 |
| -use server::content::advances::get_all; |
| 8 | +use server::advance::{Advance, Bonus}; |
| 9 | +use server::content::advances; |
8 | 10 | use server::game::Game;
|
9 | 11 | use server::game::GameState;
|
| 12 | +use server::player::Player; |
10 | 13 | use server::playing_actions::PlayingAction;
|
11 | 14 | use server::resource_pile::AdvancePaymentOptions;
|
12 | 15 | use server::status_phase::{StatusPhaseAction, StatusPhaseState};
|
13 | 16 |
|
14 | 17 | use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
15 |
| -use crate::dialog_ui::dialog; |
| 18 | +use crate::dialog_ui::full_dialog; |
16 | 19 | use crate::payment_ui::{payment_dialog, HasPayment, Payment, ResourcePayment};
|
17 | 20 | use crate::resource_ui::{new_resource_map, ResourceType};
|
18 | 21 | use crate::select_ui::HasCountSelectableObject;
|
@@ -77,56 +80,110 @@ impl HasPayment for AdvancePayment {
|
77 | 80 | }
|
78 | 81 |
|
79 | 82 | pub fn show_advance_menu(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
80 |
| - show_generic_advance_menu("Advances", game, player, true, |name| { |
| 83 | + show_generic_advance_menu("Advances", game, player, |name| { |
81 | 84 | StateUpdate::SetDialog(ActiveDialog::AdvancePayment(AdvancePayment::new(
|
82 | 85 | game,
|
83 | 86 | player.index,
|
84 |
| - &name, |
| 87 | + name, |
85 | 88 | )))
|
86 | 89 | })
|
87 | 90 | }
|
88 | 91 |
|
89 | 92 | pub fn show_free_advance_menu(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
90 |
| - show_generic_advance_menu("Select a free advance", game, player, false, |name| { |
91 |
| - StateUpdate::status_phase(StatusPhaseAction::FreeAdvance(name)) |
| 93 | + show_generic_advance_menu("Select a free advance", game, player, |name| { |
| 94 | + StateUpdate::status_phase(StatusPhaseAction::FreeAdvance(name.to_string())) |
92 | 95 | })
|
93 | 96 | }
|
94 | 97 |
|
95 | 98 | pub fn show_generic_advance_menu(
|
96 | 99 | title: &str,
|
97 | 100 | game: &Game,
|
98 | 101 | player: &ShownPlayer,
|
99 |
| - close_button: bool, |
100 |
| - new_update: impl Fn(String) -> StateUpdate, |
| 102 | + new_update: impl Fn(&str) -> StateUpdate, |
101 | 103 | ) -> StateUpdate {
|
102 |
| - dialog(title, close_button, |ui| { |
| 104 | + full_dialog(title, |ui| { |
103 | 105 | let p = player.get(game);
|
104 |
| - for a in get_all() { |
105 |
| - let name = a.name; |
106 |
| - if player.can_play_action { |
107 |
| - if p.has_advance(&name) { |
108 |
| - ui.label(None, &name); |
109 |
| - } else { |
110 |
| - let can = if matches!( |
111 |
| - game.state, |
112 |
| - GameState::StatusPhase(StatusPhaseState::FreeAdvance) |
113 |
| - ) { |
114 |
| - p.can_advance_free(&name) |
| 106 | + let mut update = StateUpdate::None; |
| 107 | + let mut current_group = None; |
| 108 | + for (_a, list) in &advances::get_all().iter().chunk_by(|a| { |
| 109 | + if a.required.is_none() { |
| 110 | + current_group = Some(&a.name); |
| 111 | + &a.name |
| 112 | + } else { |
| 113 | + current_group.unwrap() |
| 114 | + } |
| 115 | + }) { |
| 116 | + let advances = list.collect::<Vec<_>>(); |
| 117 | + ui.group(hash!(&advances[0].name), vec2(1500., 90.), |ui| { |
| 118 | + for a in advances { |
| 119 | + let name = &a.name; |
| 120 | + let can_advance = if player.can_play_action { |
| 121 | + p.can_advance(name) |
| 122 | + } else if player.can_control |
| 123 | + && matches!( |
| 124 | + game.state, |
| 125 | + GameState::StatusPhase(StatusPhaseState::FreeAdvance) |
| 126 | + ) |
| 127 | + { |
| 128 | + p.can_advance_free(name) |
| 129 | + } else { |
| 130 | + false |
| 131 | + }; |
| 132 | + |
| 133 | + let desc = description(p, a); |
| 134 | + if p.has_advance(name) { |
| 135 | + ui.label(None, &desc); |
| 136 | + } else if can_advance { |
| 137 | + if ui.button(None, desc) { |
| 138 | + update = new_update(name); |
| 139 | + } |
115 | 140 | } else {
|
116 |
| - player.can_control && p.can_advance(&name) |
| 141 | + ui.label(None, &desc); |
117 | 142 | };
|
118 |
| - if can && ui.button(None, name.clone()) { |
119 |
| - return new_update(name); |
120 |
| - } |
121 | 143 | }
|
122 |
| - } else if p.has_advance(&name) { |
123 |
| - ui.label(None, &name); |
124 |
| - } |
| 144 | + }); |
125 | 145 | }
|
126 |
| - StateUpdate::None |
| 146 | + update |
127 | 147 | })
|
128 | 148 | }
|
129 | 149 |
|
| 150 | +fn description(p: &Player, a: &Advance) -> String { |
| 151 | + let name = &a.name; |
| 152 | + let desc = &a.description; |
| 153 | + |
| 154 | + let mut parts = vec![]; |
| 155 | + parts.push(if p.has_advance(name) { |
| 156 | + format!("+ {name}") |
| 157 | + } else { |
| 158 | + format!(" {name}") |
| 159 | + }); |
| 160 | + parts.push(desc.clone()); |
| 161 | + parts.push(format!("Cost: {}", p.advance_cost(name))); |
| 162 | + if let Some(r) = &a.required { |
| 163 | + parts.push(format!("Required: {r}")); |
| 164 | + } |
| 165 | + if let Some(c) = &a.contradicting { |
| 166 | + parts.push(format!("Contradicts: {c}")); |
| 167 | + } |
| 168 | + if let Some(b) = &a.bonus { |
| 169 | + parts.push(format!( |
| 170 | + "Bonus: {}", |
| 171 | + match b { |
| 172 | + Bonus::MoodToken => "Mood Token", |
| 173 | + Bonus::CultureToken => "Culture Token", |
| 174 | + } |
| 175 | + )); |
| 176 | + } |
| 177 | + if let Some(g) = &a.government { |
| 178 | + parts.push(format!("Government: {g}")); |
| 179 | + } |
| 180 | + if let Some(u) = &a.unlocked_building { |
| 181 | + parts.push(format!("Unlocks: {u}")); |
| 182 | + } |
| 183 | + |
| 184 | + parts.join(", ") |
| 185 | +} |
| 186 | + |
130 | 187 | pub fn pay_advance_dialog(ap: &AdvancePayment, player: &ShownPlayer) -> StateUpdate {
|
131 | 188 | payment_dialog(
|
132 | 189 | player,
|
|
0 commit comments