info page, bug fixes (#284)
This commit is contained in:
parent
f0dd415d56
commit
03177ac679
82 changed files with 2315 additions and 1281 deletions
BIN
client/assets/info-svgrepo-com.png
Normal file
BIN
client/assets/info-svgrepo-com.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 7.9 KiB |
1
client/clippy.toml
Normal file
1
client/clippy.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
too-many-arguments-threshold = 10
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::city_ui::{IconAction, IconActionVec};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::BaseOrCustomDialog;
|
||||
use crate::event_ui::event_help;
|
||||
use crate::happiness_ui::open_increase_happiness_dialog;
|
||||
|
|
@ -16,7 +16,7 @@ use server::happiness::available_happiness_actions;
|
|||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::resource::ResourceType;
|
||||
|
||||
pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn action_buttons(rc: &RenderContext) -> RenderResult {
|
||||
let assets = rc.assets();
|
||||
let game = rc.game;
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
|||
&["Research advances".to_string()],
|
||||
)
|
||||
{
|
||||
return StateUpdate::OpenDialog(ActiveDialog::AdvanceMenu);
|
||||
return StateUpdate::open_dialog(ActiveDialog::AdvanceMenu);
|
||||
}
|
||||
|
||||
let influence = available_influence_actions(game, rc.shown_player.index);
|
||||
|
|
@ -87,10 +87,10 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
|||
return (icon.action)();
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn custom_action_buttons<'a>(
|
||||
pub(crate) fn custom_action_buttons<'a>(
|
||||
rc: &'a RenderContext,
|
||||
city: Option<&'a City>,
|
||||
) -> IconActionVec<'a> {
|
||||
|
|
@ -109,7 +109,7 @@ pub fn custom_action_buttons<'a>(
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn global_move(rc: &RenderContext) -> StateUpdate {
|
||||
fn global_move(rc: &RenderContext) -> RenderResult {
|
||||
let pos = rc.state.focused_tile;
|
||||
StateUpdate::move_units(
|
||||
rc,
|
||||
|
|
@ -126,7 +126,7 @@ fn generic_custom_action(
|
|||
rc: &RenderContext,
|
||||
c: &CustomActionInfo,
|
||||
city: Option<&City>,
|
||||
) -> Option<StateUpdate> {
|
||||
) -> Option<RenderResult> {
|
||||
let custom_action_type = c.action;
|
||||
|
||||
if let Some(city) = city {
|
||||
|
|
@ -143,12 +143,12 @@ fn generic_custom_action(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn base_or_custom_action(
|
||||
pub(crate) fn base_or_custom_action(
|
||||
rc: &RenderContext,
|
||||
action_types: &[PlayingActionType],
|
||||
title: &str,
|
||||
execute: impl Fn(BaseOrCustomDialog) -> ActiveDialog,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
StateUpdate::dialog_chooser(
|
||||
&format!("Choose action: {title}"),
|
||||
action_types
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
use crate::city_ui::add_building_description;
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::layout_ui::{left_mouse_button_pressed_in_rect, top_centered_text};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::layout_ui::{button_pressed, top_centered_text};
|
||||
use crate::log_ui::break_text;
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip::{add_tooltip_description, show_tooltip_for_rect};
|
||||
use crate::unit_ui::add_unit_description;
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::Color;
|
||||
use macroquad::math::vec2;
|
||||
use macroquad::prelude::{
|
||||
BLACK, BLUE, GRAY, GREEN, Rect, WHITE, YELLOW, draw_rectangle, draw_rectangle_lines,
|
||||
};
|
||||
use macroquad::prelude::{BLACK, BLUE, GRAY, GREEN, Rect, WHITE, YELLOW};
|
||||
use server::action::Action;
|
||||
use server::advance::{Advance, AdvanceAction, AdvanceInfo, Bonus, find_special_advance};
|
||||
use server::game::GameState;
|
||||
|
|
@ -21,7 +19,7 @@ use std::ops::Rem;
|
|||
|
||||
const COLUMNS: usize = 6;
|
||||
|
||||
pub enum AdvanceState {
|
||||
pub(crate) enum AdvanceState {
|
||||
Owned,
|
||||
Removable,
|
||||
Available,
|
||||
|
|
@ -39,7 +37,7 @@ fn new_advance_payment(rc: &RenderContext, a: &AdvanceInfo) -> Payment<Advance>
|
|||
)
|
||||
}
|
||||
|
||||
pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn show_paid_advance_menu(rc: &RenderContext) -> RenderResult {
|
||||
let game = rc.game;
|
||||
show_advance_menu(
|
||||
rc,
|
||||
|
|
@ -56,87 +54,67 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
|
|||
AdvanceState::Unavailable
|
||||
}
|
||||
},
|
||||
|a| StateUpdate::OpenDialog(ActiveDialog::AdvancePayment(new_advance_payment(rc, a))),
|
||||
|a| StateUpdate::open_dialog(ActiveDialog::AdvancePayment(new_advance_payment(rc, a))),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn show_advance_menu(
|
||||
pub(crate) fn show_advance_menu(
|
||||
rc: &RenderContext,
|
||||
title: &str,
|
||||
advance_state: impl Fn(&AdvanceInfo, &Player) -> AdvanceState,
|
||||
new_update: impl Fn(&AdvanceInfo) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
new_update: impl Fn(&AdvanceInfo) -> RenderResult,
|
||||
) -> RenderResult {
|
||||
top_centered_text(rc, title, vec2(0., 10.));
|
||||
let p = rc.shown_player;
|
||||
let state = rc.state;
|
||||
|
||||
for pass in 0..2 {
|
||||
for (i, group) in rc.game.cache.get_advance_groups().iter().enumerate() {
|
||||
let pos =
|
||||
vec2(i.rem(COLUMNS) as f32 * 140., (i / COLUMNS) as f32 * 180.) + vec2(20., 70.);
|
||||
if pass == 0 {
|
||||
state.draw_text(
|
||||
&group.name,
|
||||
pos.x + (140. - state.measure_text(&group.name).width) / 2.,
|
||||
pos.y - 15.,
|
||||
);
|
||||
for (i, group) in rc.game.cache.get_advance_groups().iter().enumerate() {
|
||||
let pos = vec2(i.rem(COLUMNS) as f32 * 140., (i / COLUMNS) as f32 * 180.) + vec2(20., 70.);
|
||||
rc.draw_text(
|
||||
&group.name,
|
||||
pos.x + (140. - state.measure_text(&group.name).width) / 2.,
|
||||
pos.y - 15.,
|
||||
);
|
||||
|
||||
for (i, a) in group.advances.iter().enumerate() {
|
||||
let pos = pos + vec2(0., i as f32 * 35.);
|
||||
let name = &a.name;
|
||||
let advance_state = advance_state(a, p);
|
||||
|
||||
let rect = Rect::new(pos.x, pos.y, 135., 30.);
|
||||
rc.draw_rectangle_with_text(rect, fill_color(rc, p, &advance_state), name);
|
||||
|
||||
if find_special_advance(a.advance, rc.game, rc.shown_player.index).is_some() {
|
||||
rc.draw_rectangle_lines(rect, 12., GREEN);
|
||||
}
|
||||
|
||||
for (i, a) in group.advances.iter().enumerate() {
|
||||
let pos = pos + vec2(0., i as f32 * 35.);
|
||||
let name = &a.name;
|
||||
let advance_state = advance_state(a, p);
|
||||
|
||||
let rect = Rect::new(pos.x, pos.y, 135., 30.);
|
||||
if pass == 0 {
|
||||
draw_rectangle(
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.w,
|
||||
rect.h,
|
||||
fill_color(rc, p, &advance_state),
|
||||
);
|
||||
state.draw_text(name, pos.x + 10., pos.y + 22.);
|
||||
|
||||
if find_special_advance(a.advance, rc.game, rc.shown_player.index).is_some() {
|
||||
draw_rectangle_lines(rect.x, rect.y, rect.w, rect.h, 12., GREEN);
|
||||
rc.draw_rectangle_lines(
|
||||
rect,
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::AdvancePayment(p) => {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
}
|
||||
}
|
||||
|
||||
draw_rectangle_lines(
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.w,
|
||||
rect.h,
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::AdvancePayment(p) => {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
}
|
||||
}
|
||||
_ => 4.,
|
||||
},
|
||||
border_color(a),
|
||||
);
|
||||
} else {
|
||||
// tooltip should be shown on top of everything
|
||||
show_tooltip_for_rect(rc, &description(rc, a), rect, 50.);
|
||||
|
||||
if rc.can_control_shown_player()
|
||||
&& matches!(
|
||||
advance_state,
|
||||
AdvanceState::Available | AdvanceState::Removable
|
||||
)
|
||||
&& left_mouse_button_pressed_in_rect(rect, rc)
|
||||
{
|
||||
return new_update(a);
|
||||
}
|
||||
}
|
||||
_ => 4.,
|
||||
},
|
||||
border_color(a),
|
||||
);
|
||||
// tooltip should be shown on top of everything
|
||||
if button_pressed(rect, rc, &description(rc, a), 50.)
|
||||
&& rc.can_control_shown_player()
|
||||
&& matches!(
|
||||
advance_state,
|
||||
AdvanceState::Available | AdvanceState::Removable
|
||||
)
|
||||
{
|
||||
return new_update(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn fill_color(rc: &RenderContext, p: &Player, advance_state: &AdvanceState) -> Color {
|
||||
|
|
@ -161,7 +139,7 @@ fn border_color(a: &AdvanceInfo) -> Color {
|
|||
fn description(rc: &RenderContext, a: &AdvanceInfo) -> Vec<String> {
|
||||
let mut parts: Vec<String> = vec![];
|
||||
parts.push(a.name.clone());
|
||||
add_tooltip_description(&mut parts, &a.description);
|
||||
break_text(&mut parts, &a.description);
|
||||
parts.push(format!(
|
||||
"Cost: {}",
|
||||
rc.shown_player
|
||||
|
|
@ -203,18 +181,14 @@ fn description(rc: &RenderContext, a: &AdvanceInfo) -> Vec<String> {
|
|||
if let Some(a) = find_special_advance(a.advance, rc.game, rc.shown_player.index) {
|
||||
let s = a.info(rc.game);
|
||||
parts.push(format!("Special advance: {}", s.name));
|
||||
add_tooltip_description(&mut parts, &s.description);
|
||||
break_text(&mut parts, &s.description);
|
||||
}
|
||||
|
||||
parts
|
||||
}
|
||||
|
||||
pub fn pay_advance_dialog(ap: &Payment<Advance>, rc: &RenderContext) -> StateUpdate {
|
||||
let update = show_paid_advance_menu(rc);
|
||||
if !matches!(update, StateUpdate::None) {
|
||||
// select a different advance
|
||||
return update;
|
||||
}
|
||||
pub(crate) fn pay_advance_dialog(ap: &Payment<Advance>, rc: &RenderContext) -> RenderResult {
|
||||
show_paid_advance_menu(rc)?; // select a different advance
|
||||
payment_dialog(rc, ap, true, ActiveDialog::AdvancePayment, |payment| {
|
||||
StateUpdate::execute_with_warning(
|
||||
Action::Playing(PlayingAction::Advance(AdvanceAction::new(
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ use server::unit::UnitType;
|
|||
use server::wonder::Wonder;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct CivAssets {
|
||||
pub(crate) struct CivAssets {
|
||||
pub units: HashMap<UnitType, Texture2D>,
|
||||
}
|
||||
|
||||
pub struct Assets {
|
||||
pub(crate) struct Assets {
|
||||
pub terrain: HashMap<Terrain, Texture2D>,
|
||||
pub exhausted: Texture2D,
|
||||
pub font: Font,
|
||||
|
|
@ -33,13 +33,13 @@ pub struct Assets {
|
|||
|
||||
// UI
|
||||
pub redo: Texture2D,
|
||||
pub reset: Texture2D,
|
||||
pub undo: Texture2D,
|
||||
pub plus: Texture2D,
|
||||
pub minus: Texture2D,
|
||||
pub ok_blocked: Texture2D,
|
||||
pub ok: Texture2D,
|
||||
pub cancel: Texture2D,
|
||||
pub info: Texture2D,
|
||||
|
||||
pub victory_points: Texture2D,
|
||||
pub event_counter: Texture2D,
|
||||
|
|
@ -85,13 +85,13 @@ impl Assets {
|
|||
|
||||
// UI
|
||||
redo: load_png(include_bytes!("../assets/redo-svgrepo-com.png")),
|
||||
reset: load_png(include_bytes!("../assets/reset-svgrepo-com.png")),
|
||||
undo: load_png(include_bytes!("../assets/undo-svgrepo-com.png")),
|
||||
plus: load_png(include_bytes!("../assets/plus-circle-svgrepo-com.png")),
|
||||
minus: load_png(include_bytes!("../assets/minus-circle-svgrepo-com.png")),
|
||||
ok: load_png(include_bytes!("../assets/ok-circle-svgrepo-com.png")),
|
||||
ok_blocked: load_png(include_bytes!("../assets/in-progress-svgrepo-com.png")),
|
||||
cancel: load_png(include_bytes!("../assets/cancel-svgrepo-com.png")),
|
||||
info: load_png(include_bytes!("../assets/info-svgrepo-com.png")),
|
||||
|
||||
victory_points: load_png(include_bytes!("../assets/trophy-cup-svgrepo-com.png")),
|
||||
event_counter: load_png(include_bytes!(
|
||||
|
|
@ -416,7 +416,7 @@ impl Assets {
|
|||
CivAssets { units }
|
||||
}
|
||||
|
||||
pub fn unit(&self, mut unit_type: UnitType, player: &Player) -> &Texture2D {
|
||||
pub(crate) fn unit(&self, mut unit_type: UnitType, player: &Player) -> &Texture2D {
|
||||
if unit_type.is_leader() {
|
||||
unit_type = unit::LEADER_UNIT;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,33 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::custom_phase_ui;
|
||||
use crate::custom_phase_ui::MultiSelection;
|
||||
use crate::dialog_ui::ok_button;
|
||||
use crate::layout_ui::{bottom_centered_text, left_mouse_button_pressed_in_rect};
|
||||
use crate::layout_ui::{bottom_centered_text, button_pressed, rect_from};
|
||||
use crate::log_ui::break_text;
|
||||
use crate::player_ui::get_combat;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::select_ui::HighlightType;
|
||||
use crate::tooltip::show_tooltip_for_rect;
|
||||
use custom_phase_ui::multi_select_tooltip;
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::BLACK;
|
||||
use macroquad::math::{Rect, Vec2, vec2};
|
||||
use macroquad::prelude::{BEIGE, Color, GREEN, RED, YELLOW, draw_rectangle, draw_rectangle_lines};
|
||||
use macroquad::prelude::{BEIGE, Color, GREEN, RED, YELLOW};
|
||||
use server::action::Action;
|
||||
use server::card::{HandCard, HandCardType, hand_cards, validate_card_selection};
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::events::check_event_origin;
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::wonder::Wonder;
|
||||
use server::wonder::{Wonder, WonderInfo};
|
||||
|
||||
pub struct HandCardObject {
|
||||
pub(crate) struct HandCardObject {
|
||||
id: HandCard,
|
||||
name: String,
|
||||
description: Vec<String>,
|
||||
pub description: Vec<String>,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
impl HandCardObject {
|
||||
pub fn new(id: HandCard, color: Color, name: &str, description: Vec<String>) -> Self {
|
||||
pub(crate) fn new(id: HandCard, color: Color, name: &str, description: Vec<String>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
name: name.chars().take(17).collect(),
|
||||
|
|
@ -42,7 +41,7 @@ const ACTION_CARD_COLOR: Color = RED;
|
|||
const OBJECTIVE_CARD_COLOR: Color = BEIGE;
|
||||
const WONDER_CARD_COLOR: Color = YELLOW;
|
||||
|
||||
struct SelectionInfo {
|
||||
pub(crate) struct SelectionInfo {
|
||||
selection: MultiSelection<HandCard>,
|
||||
show_names: Vec<(u8, String)>,
|
||||
}
|
||||
|
|
@ -56,7 +55,7 @@ impl SelectionInfo {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn show_cards(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn show_cards(rc: &RenderContext) -> RenderResult {
|
||||
let p = rc.shown_player;
|
||||
let cards = hand_cards(p, &HandCardType::get_all());
|
||||
let size = vec2(180., 30.);
|
||||
|
|
@ -81,13 +80,9 @@ pub(crate) fn show_cards(rc: &RenderContext) -> StateUpdate {
|
|||
})
|
||||
.collect_vec();
|
||||
|
||||
if let Some(value) = draw_cards(rc, &cards, selection.as_ref(), size, -85.) {
|
||||
return value;
|
||||
}
|
||||
if let Some(value) = draw_cards(rc, &swap_cards, selection.as_ref(), size, -310.) {
|
||||
return value;
|
||||
}
|
||||
StateUpdate::None
|
||||
draw_cards(rc, &cards, selection.as_ref(), size, -85.)?;
|
||||
draw_cards(rc, &swap_cards, selection.as_ref(), size, -310.)?;
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn draw_cards(
|
||||
|
|
@ -96,62 +91,41 @@ fn draw_cards(
|
|||
selection: Option<&SelectionInfo>,
|
||||
size: Vec2,
|
||||
x_offset: f32,
|
||||
) -> Option<StateUpdate> {
|
||||
) -> RenderResult {
|
||||
let screen = rc.state.screen_size;
|
||||
for pass in 0..2 {
|
||||
let mut y = (cards.len() as f32 * -size.y) / 2.;
|
||||
for card in cards {
|
||||
if let Some(value) = draw_card(
|
||||
rc,
|
||||
size,
|
||||
selection,
|
||||
pass,
|
||||
vec2(screen.x, screen.y / 2.0) + vec2(-size.x + x_offset, y),
|
||||
card,
|
||||
) {
|
||||
return Some(value);
|
||||
}
|
||||
let mut y = (cards.len() as f32 * -size.y) / 2.;
|
||||
for card in cards {
|
||||
let pos = vec2(screen.x, screen.y / 2.0) + vec2(-size.x + x_offset, y);
|
||||
draw_card(rc, rect_from(pos, size), selection, card)?;
|
||||
|
||||
y += size.y;
|
||||
}
|
||||
y += size.y;
|
||||
}
|
||||
None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn draw_card(
|
||||
rc: &RenderContext,
|
||||
size: Vec2,
|
||||
rect: Rect,
|
||||
selection: Option<&SelectionInfo>,
|
||||
pass: i32,
|
||||
pos: Vec2,
|
||||
card: &HandCard,
|
||||
) -> Option<StateUpdate> {
|
||||
) -> RenderResult {
|
||||
let c = get_card_object(rc, card, selection);
|
||||
|
||||
if pass == 0 {
|
||||
draw_rectangle(pos.x, pos.y, size.x, size.y, c.color);
|
||||
let (thickness, border) = highlight(rc, &c, selection);
|
||||
draw_rectangle_lines(pos.x, pos.y, size.x, size.y, thickness, border);
|
||||
rc.draw_rectangle_with_text(rect, c.color, &c.name);
|
||||
let (thickness, border) = highlight(rc, &c, selection);
|
||||
rc.draw_rectangle_lines(rect, thickness, border);
|
||||
|
||||
rc.state.draw_text(&c.name, pos.x + 10., pos.y + 22.);
|
||||
} else {
|
||||
let rect = Rect::new(pos.x, pos.y, size.x, size.y);
|
||||
|
||||
// tooltip should be shown on top of everything
|
||||
show_tooltip_for_rect(rc, &c.description, rect, 150.);
|
||||
|
||||
if left_mouse_button_pressed_in_rect(rect, rc) {
|
||||
if let Some(s) = selection {
|
||||
return Some(StateUpdate::OpenDialog(ActiveDialog::HandCardsRequest(
|
||||
s.selection.clone().toggle(c.id),
|
||||
)));
|
||||
}
|
||||
if can_play_card(rc, card) {
|
||||
return Some(play_card(rc, card));
|
||||
}
|
||||
if button_pressed(rect, rc, &c.description, 150.) {
|
||||
if let Some(s) = selection {
|
||||
return StateUpdate::open_dialog(ActiveDialog::HandCardsRequest(
|
||||
s.selection.clone().toggle(c.id),
|
||||
));
|
||||
}
|
||||
if can_play_card(rc, card) {
|
||||
return play_card(rc, card);
|
||||
}
|
||||
}
|
||||
None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn can_play_card(rc: &RenderContext, card: &HandCard) -> bool {
|
||||
|
|
@ -162,7 +136,7 @@ fn can_play_card(rc: &RenderContext, card: &HandCard) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn play_card(rc: &RenderContext, card: &HandCard) -> StateUpdate {
|
||||
fn play_card(rc: &RenderContext, card: &HandCard) -> RenderResult {
|
||||
match card {
|
||||
HandCard::ActionCard(a) => StateUpdate::execute_with_confirm(
|
||||
vec![format!(
|
||||
|
|
@ -229,17 +203,24 @@ fn get_card_object(
|
|||
card.clone(),
|
||||
WONDER_CARD_COLOR,
|
||||
&w.name(),
|
||||
vec![
|
||||
w.description.clone(),
|
||||
format!("Cost: {}", w.cost.to_string()),
|
||||
format!("Required advance: {}", w.required_advance.name(rc.game)),
|
||||
],
|
||||
wonder_description(rc, w),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
||||
pub(crate) fn wonder_description(rc: &RenderContext, w: &WonderInfo) -> Vec<String> {
|
||||
let mut description = vec![];
|
||||
break_text(&mut description, w.description.as_str());
|
||||
description.push(format!("Cost: {}", w.cost));
|
||||
description.push(format!(
|
||||
"Required advance: {}",
|
||||
w.required_advance.name(rc.game)
|
||||
));
|
||||
description
|
||||
}
|
||||
|
||||
pub(crate) fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
||||
let a = rc.game.cache.get_action_card(id);
|
||||
|
||||
let name = match &a.tactics_card {
|
||||
|
|
@ -267,7 +248,7 @@ fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
|||
if !cost.is_free() {
|
||||
description.push(format!("Cost: {cost}"));
|
||||
}
|
||||
break_text(a.civil_card.description.as_str(), 30, &mut description);
|
||||
break_text(&mut description, a.civil_card.description.as_str());
|
||||
if let Some(t) = &a.tactics_card {
|
||||
description.extend(vec![
|
||||
format!("Tactics: {}", t.name),
|
||||
|
|
@ -293,7 +274,7 @@ fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
|||
}
|
||||
),
|
||||
]);
|
||||
break_text(t.description.as_str(), 30, &mut description);
|
||||
break_text(&mut description, t.description.as_str());
|
||||
}
|
||||
HandCardObject::new(
|
||||
HandCard::ActionCard(id),
|
||||
|
|
@ -303,7 +284,7 @@ fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
|||
)
|
||||
}
|
||||
|
||||
fn objective_card_object(
|
||||
pub(crate) fn objective_card_object(
|
||||
rc: &RenderContext,
|
||||
id: u8,
|
||||
selection: Option<&SelectionInfo>,
|
||||
|
|
@ -313,7 +294,7 @@ fn objective_card_object(
|
|||
let mut description = vec![];
|
||||
for o in &card.objectives {
|
||||
description.push(format!("Objective: {}", o.name));
|
||||
break_text(o.description.as_str(), 30, &mut description);
|
||||
break_text(&mut description, o.description.as_str());
|
||||
}
|
||||
|
||||
let name = selection
|
||||
|
|
@ -333,7 +314,10 @@ fn objective_card_object(
|
|||
)
|
||||
}
|
||||
|
||||
pub fn select_cards_dialog(rc: &RenderContext, s: &MultiSelection<HandCard>) -> StateUpdate {
|
||||
pub(crate) fn select_cards_dialog(
|
||||
rc: &RenderContext,
|
||||
s: &MultiSelection<HandCard>,
|
||||
) -> RenderResult {
|
||||
bottom_centered_text(
|
||||
rc,
|
||||
format!(
|
||||
|
|
@ -355,6 +339,6 @@ pub fn select_cards_dialog(rc: &RenderContext, s: &MultiSelection<HandCard>) ->
|
|||
) {
|
||||
StateUpdate::response(EventResponse::SelectHandCards(s.selected.clone()))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::action_buttons::{base_or_custom_action, custom_action_buttons};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::collect_ui::CollectResources;
|
||||
use crate::construct_ui::{ConstructionPayment, ConstructionProject};
|
||||
use crate::custom_phase_ui::{SelectedStructureInfo, SelectedStructureStatus};
|
||||
|
|
@ -8,12 +8,15 @@ use crate::happiness_ui::{
|
|||
open_increase_happiness_dialog,
|
||||
};
|
||||
use crate::hex_ui;
|
||||
use crate::layout_ui::{draw_scaled_icon, draw_scaled_icon_with_tooltip, is_in_circle};
|
||||
use crate::layout_ui::{
|
||||
draw_scaled_icon, draw_scaled_icon_with_tooltip, is_in_circle, is_mouse_pressed,
|
||||
};
|
||||
use crate::log_ui::break_text;
|
||||
use crate::map_ui::{move_units_buttons, show_map_action_buttons};
|
||||
use crate::recruit_unit_ui::RecruitAmount;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::select_ui::HighlightType;
|
||||
use crate::tooltip::{add_tooltip_description, show_tooltip_for_circle};
|
||||
use crate::tooltip::show_tooltip_for_circle;
|
||||
use itertools::Itertools;
|
||||
use macroquad::math::f32;
|
||||
use macroquad::prelude::*;
|
||||
|
|
@ -31,19 +34,19 @@ use server::structure::Structure;
|
|||
use server::unit::{UnitType, Units};
|
||||
use std::ops::Add;
|
||||
|
||||
pub struct IconAction<'a> {
|
||||
pub(crate) struct IconAction<'a> {
|
||||
pub texture: &'a Texture2D,
|
||||
pub tooltip: Vec<String>,
|
||||
pub warning: bool,
|
||||
pub action: Box<dyn Fn() -> StateUpdate + 'a>,
|
||||
pub action: Box<dyn Fn() -> RenderResult + 'a>,
|
||||
}
|
||||
|
||||
impl<'a> IconAction<'a> {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
texture: &'a Texture2D,
|
||||
tooltip: Vec<String>,
|
||||
action: Box<dyn Fn() -> StateUpdate + 'a>,
|
||||
action: Box<dyn Fn() -> RenderResult + 'a>,
|
||||
) -> IconAction<'a> {
|
||||
IconAction {
|
||||
texture,
|
||||
|
|
@ -54,14 +57,14 @@ impl<'a> IconAction<'a> {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_warning(self, warning: bool) -> IconAction<'a> {
|
||||
pub(crate) fn with_warning(self, warning: bool) -> IconAction<'a> {
|
||||
IconAction { warning, ..self }
|
||||
}
|
||||
}
|
||||
|
||||
pub type IconActionVec<'a> = Vec<IconAction<'a>>;
|
||||
pub(crate) type IconActionVec<'a> = Vec<IconAction<'a>>;
|
||||
|
||||
pub fn show_city_menu<'a>(rc: &'a RenderContext, city: &'a City) -> StateUpdate {
|
||||
pub(crate) fn show_city_menu<'a>(rc: &'a RenderContext, city: &'a City) -> RenderResult {
|
||||
let base_icons: IconActionVec<'a> = vec![
|
||||
increase_happiness_button(rc, city),
|
||||
collect_resources_button(rc, city),
|
||||
|
|
@ -161,8 +164,8 @@ fn building_icons<'a>(rc: &'a RenderContext, city: &'a City) -> IconActionVec<'a
|
|||
&rc.assets().buildings[&b],
|
||||
tooltip,
|
||||
Box::new(move || {
|
||||
can.clone().map_or(StateUpdate::None, |cost_info| {
|
||||
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(
|
||||
can.clone().map_or(NO_UPDATE, |cost_info| {
|
||||
StateUpdate::open_dialog(ActiveDialog::ConstructionPayment(
|
||||
ConstructionPayment::new(
|
||||
rc,
|
||||
city,
|
||||
|
|
@ -221,7 +224,7 @@ fn collect_resources_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option
|
|||
))
|
||||
}
|
||||
|
||||
pub fn city_labels(game: &Game, city: &City) -> Vec<String> {
|
||||
pub(crate) fn city_labels(game: &Game, city: &City) -> Vec<String> {
|
||||
[
|
||||
vec![format!(
|
||||
"City: {}, {}, {} {}",
|
||||
|
|
@ -258,7 +261,7 @@ fn draw_selected_state(
|
|||
center: Vec2,
|
||||
size: f32,
|
||||
info: &SelectedStructureInfo,
|
||||
) -> Option<StateUpdate> {
|
||||
) -> RenderResult {
|
||||
let ActiveDialog::StructuresRequest(d, r) = &rc.state.active_dialog else {
|
||||
panic!("Expected StructuresRequest");
|
||||
};
|
||||
|
|
@ -267,26 +270,26 @@ fn draw_selected_state(
|
|||
} else {
|
||||
info.highlight_type()
|
||||
};
|
||||
draw_circle_lines(center.x, center.y, size, 3., t.color());
|
||||
rc.draw_circle_lines(center, size, 3., t.color());
|
||||
|
||||
if let Some(tooltip) = &info.tooltip {
|
||||
show_tooltip_for_circle(rc, &[tooltip.clone()], center, size);
|
||||
}
|
||||
|
||||
if info.status != SelectedStructureStatus::Invalid
|
||||
&& is_mouse_button_pressed(MouseButton::Left)
|
||||
&& is_mouse_pressed(rc)
|
||||
&& is_in_circle(rc.mouse_pos(), center, size)
|
||||
{
|
||||
Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
|
||||
StateUpdate::open_dialog(ActiveDialog::StructuresRequest(
|
||||
d.clone(),
|
||||
r.clone().toggle(info.clone()),
|
||||
)))
|
||||
))
|
||||
} else {
|
||||
None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
|
||||
pub(crate) fn draw_city(rc: &RenderContext, city: &City) -> RenderResult {
|
||||
let c = hex_ui::center(city.position);
|
||||
let owner = city.player_index;
|
||||
|
||||
|
|
@ -296,26 +299,20 @@ pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
|
|||
};
|
||||
|
||||
if city.is_activated() {
|
||||
draw_circle(c.x, c.y, 18.0, WHITE);
|
||||
rc.draw_circle(c, 18.0, WHITE);
|
||||
}
|
||||
draw_circle(c.x, c.y, 15.0, rc.player_color(owner));
|
||||
rc.draw_circle(c, 15.0, rc.player_color(owner));
|
||||
|
||||
if let Some(h) = highlighted
|
||||
.iter()
|
||||
.find(|s| s.position == city.position && matches!(s.structure, Structure::CityCenter))
|
||||
{
|
||||
if let Some(u) = draw_selected_state(rc, c, 15., h) {
|
||||
return Some(u);
|
||||
}
|
||||
draw_selected_state(rc, c, 15., h)?;
|
||||
} else {
|
||||
draw_mood_state(rc, city, c);
|
||||
}
|
||||
|
||||
let i = match draw_wonders(rc, city, c, owner, highlighted) {
|
||||
Ok(value) => value,
|
||||
Err(value) => return Some(value),
|
||||
};
|
||||
|
||||
let i = draw_wonders(rc, city, c, owner, highlighted)?;
|
||||
draw_buildings(rc, city, c, highlighted, i)
|
||||
}
|
||||
|
||||
|
|
@ -355,11 +352,11 @@ fn draw_buildings(
|
|||
center: Vec2,
|
||||
highlighted: &[SelectedStructureInfo],
|
||||
mut i: usize,
|
||||
) -> Option<StateUpdate> {
|
||||
) -> RenderResult {
|
||||
for player_index in 0..4 {
|
||||
for b in &city.pieces.buildings(Some(player_index)) {
|
||||
let p = building_position(city, center, i, *b);
|
||||
draw_circle(p.x, p.y, BUILDING_SIZE, rc.player_color(player_index));
|
||||
rc.draw_circle(p, BUILDING_SIZE, rc.player_color(player_index));
|
||||
|
||||
let mut tooltip = vec![b.name().to_string()];
|
||||
add_building_description(rc, &mut tooltip, *b);
|
||||
|
|
@ -376,17 +373,15 @@ fn draw_buildings(
|
|||
s.position == city.position
|
||||
&& matches!(s.structure, Structure::Building(bb) if bb == *b)
|
||||
}) {
|
||||
if let Some(u) = draw_selected_state(rc, p, BUILDING_SIZE, h) {
|
||||
return Some(u);
|
||||
}
|
||||
draw_selected_state(rc, p, BUILDING_SIZE, h)?;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn add_building_description(rc: &RenderContext, parts: &mut Vec<String>, b: Building) {
|
||||
pub(crate) fn add_building_description(rc: &RenderContext, parts: &mut Vec<String>, b: Building) {
|
||||
let pile = rc
|
||||
.shown_player
|
||||
.building_cost(rc.game, b, CostTrigger::WithModifiers)
|
||||
|
|
@ -399,7 +394,7 @@ pub fn add_building_description(rc: &RenderContext, parts: &mut Vec<String>, b:
|
|||
parts.push(format!("Base cost: {BUILDING_COST}"));
|
||||
parts.push(format!("Current cost: {pile}"));
|
||||
}
|
||||
add_tooltip_description(parts, b.description());
|
||||
break_text(parts, b.description());
|
||||
}
|
||||
|
||||
#[allow(clippy::result_large_err)]
|
||||
|
|
@ -409,18 +404,16 @@ fn draw_wonders(
|
|||
c: Vec2,
|
||||
owner: usize,
|
||||
highlighted: &[SelectedStructureInfo],
|
||||
) -> Result<usize, StateUpdate> {
|
||||
) -> Result<usize, Box<StateUpdate>> {
|
||||
let mut i = 0;
|
||||
for w in &city.pieces.wonders {
|
||||
let p = hex_ui::rotate_around(c, 20.0, 90 * i);
|
||||
draw_circle(p.x, p.y, 18.0, rc.player_color(owner));
|
||||
rc.draw_circle(p, 18.0, rc.player_color(owner));
|
||||
let size = 20.;
|
||||
if let Some(h) = highlighted.iter().find(|s| {
|
||||
s.position == city.position && matches!(&s.structure, Structure::Wonder(n) if n == w)
|
||||
}) {
|
||||
if let Some(u) = draw_selected_state(rc, p, 18., h) {
|
||||
return Err(u);
|
||||
}
|
||||
draw_selected_state(rc, p, 18., h)?;
|
||||
} else {
|
||||
draw_scaled_icon(
|
||||
rc,
|
||||
|
|
@ -435,7 +428,7 @@ fn draw_wonders(
|
|||
Ok(i)
|
||||
}
|
||||
|
||||
pub fn building_position(city: &City, center: Vec2, i: usize, building: Building) -> Vec2 {
|
||||
pub(crate) fn building_position(city: &City, center: Vec2, i: usize, building: Building) -> Vec2 {
|
||||
if matches!(building, Building::Port) {
|
||||
let r: f32 = city
|
||||
.position
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use macroquad::input::{MouseButton, is_mouse_button_pressed};
|
||||
use macroquad::prelude::clear_background;
|
||||
use macroquad::prelude::*;
|
||||
|
||||
|
|
@ -9,38 +8,44 @@ use server::position::Position;
|
|||
use crate::advance_ui::{pay_advance_dialog, show_paid_advance_menu};
|
||||
use crate::cards_ui::show_cards;
|
||||
use crate::client_state::{
|
||||
ActiveDialog, CameraMode, DialogChooser, State, StateUpdate, StateUpdates,
|
||||
ActiveDialog, CameraMode, DialogChooser, NO_UPDATE, RenderResult, State, StateUpdate,
|
||||
};
|
||||
use crate::collect_ui::collect_dialog;
|
||||
use crate::construct_ui::pay_construction_dialog;
|
||||
use crate::event_ui::{custom_phase_event_origin, event_help};
|
||||
use crate::happiness_ui::{increase_happiness_click, increase_happiness_menu};
|
||||
use crate::hex_ui::pixel_to_coordinate;
|
||||
use crate::info_ui::{InfoDialog, show_info_dialog};
|
||||
use crate::layout_ui::{
|
||||
ICON_SIZE, bottom_center_anchor, bottom_centered_text_with_offset,
|
||||
draw_scaled_icon_with_tooltip, icon_pos, top_right_texture,
|
||||
draw_scaled_icon_with_tooltip, icon_pos, is_mouse_pressed, top_right_texture,
|
||||
};
|
||||
use crate::log_ui::show_log;
|
||||
use crate::log_ui::{LogDialog, show_log};
|
||||
use crate::map_ui::{draw_map, explore_dialog, show_tile_menu};
|
||||
use crate::player_ui::{player_select, show_global_controls, show_top_center, show_top_left};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::render_context::{RenderContext, RenderStage};
|
||||
use crate::unit_ui::unit_selection_click;
|
||||
use crate::{
|
||||
cards_ui, custom_phase_ui, dialog_ui, map_ui, move_ui, recruit_unit_ui, status_phase_ui,
|
||||
tooltip,
|
||||
};
|
||||
|
||||
fn render_with_mutable_state(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
|
||||
fn render_with_mutable_state(game: &Game, state: &mut State, features: &Features) -> RenderResult {
|
||||
tooltip::update(state);
|
||||
if !state.active_dialog.is_modal() {
|
||||
map_ui::pan_and_zoom(state);
|
||||
}
|
||||
if matches!(state.active_dialog, ActiveDialog::Log) {
|
||||
state.log_scroll += mouse_wheel().1;
|
||||
if let ActiveDialog::Log(d) = &mut state.active_dialog {
|
||||
d.log_scroll += mouse_wheel().1;
|
||||
}
|
||||
|
||||
set_y_zoom(state);
|
||||
render(&state.render_context(game), features)
|
||||
clear_background(WHITE);
|
||||
let () = render(&state.render_context(game, RenderStage::Map), features)
|
||||
.expect("all updates should be in Tooltip stage");
|
||||
let () = render(&state.render_context(game, RenderStage::UI), features)
|
||||
.expect("all updates should be in Tooltip stage");
|
||||
render(&state.render_context(game, RenderStage::Tooltip), features)
|
||||
}
|
||||
|
||||
fn set_y_zoom(state: &mut State) {
|
||||
|
|
@ -51,39 +56,37 @@ fn set_y_zoom(state: &mut State) {
|
|||
state.camera.zoom.y = state.camera.zoom.x * w / h;
|
||||
}
|
||||
|
||||
fn render(rc: &RenderContext, features: &Features) -> StateUpdate {
|
||||
clear_background(WHITE);
|
||||
|
||||
fn render(rc: &RenderContext, features: &Features) -> RenderResult {
|
||||
let state = &rc.state;
|
||||
let show_map = !state.active_dialog.is_modal();
|
||||
let show_map = !state.active_dialog.is_modal() && rc.stage.is_map();
|
||||
let show_ui = !state.active_dialog.is_modal() && rc.stage.is_ui();
|
||||
|
||||
let mut updates = StateUpdates::new();
|
||||
if show_map {
|
||||
updates.add(rc.with_camera(CameraMode::World, draw_map));
|
||||
rc.with_camera(CameraMode::World, draw_map)?;
|
||||
}
|
||||
if !state.active_dialog.is_modal() {
|
||||
if show_ui {
|
||||
show_top_left(rc);
|
||||
}
|
||||
if show_map {
|
||||
show_top_center(rc);
|
||||
}
|
||||
if !state.active_dialog.is_modal() {
|
||||
updates.add(show_cards(rc));
|
||||
updates.add(player_select(rc));
|
||||
updates.add(show_global_controls(rc, features));
|
||||
if show_ui {
|
||||
show_cards(rc)?;
|
||||
player_select(rc)?;
|
||||
show_global_controls(rc, features)?;
|
||||
}
|
||||
|
||||
if top_right_texture(rc, &rc.assets().log, icon_pos(-1, 0), "Show log") {
|
||||
if let ActiveDialog::Log = state.active_dialog {
|
||||
return StateUpdate::CloseDialog;
|
||||
if let ActiveDialog::Log(_) = state.active_dialog {
|
||||
return StateUpdate::close_dialog();
|
||||
}
|
||||
return StateUpdate::OpenDialog(ActiveDialog::Log);
|
||||
return StateUpdate::open_dialog(ActiveDialog::Log(LogDialog::new()));
|
||||
}
|
||||
if top_right_texture(rc, &rc.assets().advances, icon_pos(-2, 0), "Show advances") {
|
||||
if state.active_dialog.is_advance() {
|
||||
return StateUpdate::CloseDialog;
|
||||
return StateUpdate::close_dialog();
|
||||
}
|
||||
return StateUpdate::OpenDialog(ActiveDialog::AdvanceMenu);
|
||||
return StateUpdate::open_dialog(ActiveDialog::AdvanceMenu);
|
||||
}
|
||||
if top_right_texture(
|
||||
rc,
|
||||
|
|
@ -95,27 +98,35 @@ fn render(rc: &RenderContext, features: &Features) -> StateUpdate {
|
|||
"Show permanent effects"
|
||||
},
|
||||
) {
|
||||
return StateUpdate::ToggleShowPermanentEffects;
|
||||
return StateUpdate::of(StateUpdate::ToggleShowPermanentEffects);
|
||||
}
|
||||
if top_right_texture(rc, &rc.assets().info, icon_pos(-4, 0), "Show info") {
|
||||
if let ActiveDialog::Info(_) = state.active_dialog {
|
||||
return StateUpdate::close_dialog();
|
||||
}
|
||||
return StateUpdate::open_dialog(ActiveDialog::Info(InfoDialog::new(
|
||||
rc.shown_player.civilization.name.clone(),
|
||||
)));
|
||||
}
|
||||
|
||||
let can_control = rc.can_control_shown_player();
|
||||
if can_control {
|
||||
if let Some(u) = &state.pending_update {
|
||||
updates.add(dialog_ui::show_pending_update(u, rc));
|
||||
dialog_ui::show_pending_update(u, rc)?;
|
||||
}
|
||||
}
|
||||
|
||||
if can_control || state.active_dialog.show_for_other_player() {
|
||||
updates.add(render_active_dialog(rc));
|
||||
render_active_dialog(rc)?;
|
||||
}
|
||||
|
||||
if let Some(pos) = state.focused_tile {
|
||||
if matches!(state.active_dialog, ActiveDialog::None) {
|
||||
updates.add(show_tile_menu(rc, pos));
|
||||
show_tile_menu(rc, pos)?;
|
||||
}
|
||||
}
|
||||
updates.add(rc.with_camera(CameraMode::World, try_click));
|
||||
updates.result()
|
||||
rc.with_camera(CameraMode::World, try_click)?;
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub async fn init(features: &Features) -> State {
|
||||
|
|
@ -138,16 +149,19 @@ pub fn render_and_update(
|
|||
}
|
||||
}
|
||||
|
||||
let update = render_with_mutable_state(game, state, features);
|
||||
state.update(game, update)
|
||||
match render_with_mutable_state(game, state, features) {
|
||||
Err(u) => state.update(game, *u),
|
||||
Ok(()) => GameSyncRequest::None,
|
||||
}
|
||||
}
|
||||
|
||||
fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
|
||||
fn render_active_dialog(rc: &RenderContext) -> RenderResult {
|
||||
let state = rc.state;
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::None | ActiveDialog::WaitingForUpdate => StateUpdate::None,
|
||||
ActiveDialog::None | ActiveDialog::WaitingForUpdate => NO_UPDATE,
|
||||
ActiveDialog::DialogChooser(d) => dialog_chooser(rc, d),
|
||||
ActiveDialog::Log => show_log(rc),
|
||||
ActiveDialog::Log(d) => show_log(rc, d),
|
||||
ActiveDialog::Info(d) => show_info_dialog(rc, d),
|
||||
|
||||
// playing actions
|
||||
ActiveDialog::IncreaseHappiness(h) => increase_happiness_menu(rc, h),
|
||||
|
|
@ -185,7 +199,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
fn dialog_chooser(rc: &RenderContext, c: &DialogChooser) -> StateUpdate {
|
||||
fn dialog_chooser(rc: &RenderContext, c: &DialogChooser) -> RenderResult {
|
||||
let h = -50.;
|
||||
bottom_centered_text_with_offset(
|
||||
rc,
|
||||
|
|
@ -209,51 +223,47 @@ fn dialog_chooser(rc: &RenderContext, c: &DialogChooser) -> StateUpdate {
|
|||
bottom_center_anchor(rc) + offset + vec2(100., -70.),
|
||||
ICON_SIZE,
|
||||
) {
|
||||
return StateUpdate::OpenDialog(d.clone());
|
||||
return StateUpdate::open_dialog(d.clone());
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn try_click(rc: &RenderContext) -> StateUpdate {
|
||||
let game = rc.game;
|
||||
pub(crate) fn try_click(rc: &RenderContext) -> RenderResult {
|
||||
if !is_mouse_pressed(rc) {
|
||||
return NO_UPDATE;
|
||||
}
|
||||
|
||||
let mouse_pos = rc.mouse_pos();
|
||||
let pos = Position::from_coordinate(pixel_to_coordinate(mouse_pos));
|
||||
|
||||
if !game.map.tiles.contains_key(&pos) {
|
||||
return StateUpdate::None;
|
||||
}
|
||||
|
||||
if !is_mouse_button_pressed(MouseButton::Left) {
|
||||
return StateUpdate::None;
|
||||
if !rc.game.map.tiles.contains_key(&pos) {
|
||||
return NO_UPDATE;
|
||||
}
|
||||
|
||||
if rc.can_control_shown_player() {
|
||||
let update = controlling_player_click(rc, mouse_pos, pos);
|
||||
if !matches!(update, StateUpdate::None) {
|
||||
return update;
|
||||
}
|
||||
controlling_player_click(rc, mouse_pos, pos)?;
|
||||
}
|
||||
StateUpdate::SetFocusedTile(pos)
|
||||
StateUpdate::set_focused_tile(pos)
|
||||
}
|
||||
|
||||
fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position) -> StateUpdate {
|
||||
fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position) -> RenderResult {
|
||||
match &rc.state.active_dialog {
|
||||
ActiveDialog::CollectResources(_) => StateUpdate::None,
|
||||
ActiveDialog::CollectResources(_) => NO_UPDATE,
|
||||
ActiveDialog::MoveUnits(s) => move_ui::click(rc, pos, s, mouse_pos),
|
||||
ActiveDialog::ReplaceUnits(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
|
||||
StateUpdate::OpenDialog(ActiveDialog::ReplaceUnits(new.clone()))
|
||||
StateUpdate::open_dialog(ActiveDialog::ReplaceUnits(new.clone()))
|
||||
}),
|
||||
ActiveDialog::PositionRequest(r) => {
|
||||
StateUpdate::OpenDialog(ActiveDialog::PositionRequest(r.clone().toggle(pos)))
|
||||
StateUpdate::open_dialog(ActiveDialog::PositionRequest(r.clone().toggle(pos)))
|
||||
}
|
||||
ActiveDialog::UnitsRequest(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
|
||||
StateUpdate::OpenDialog(ActiveDialog::UnitsRequest(new.clone()))
|
||||
StateUpdate::open_dialog(ActiveDialog::UnitsRequest(new.clone()))
|
||||
}),
|
||||
ActiveDialog::IncreaseHappiness(h) if h.city_restriction.is_none_or(|r| r == pos) => {
|
||||
increase_happiness_click(rc, pos, h)
|
||||
}
|
||||
_ => StateUpdate::SetFocusedTile(pos),
|
||||
_ => StateUpdate::set_focused_tile(pos),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +275,7 @@ pub struct Features {
|
|||
|
||||
impl Features {
|
||||
#[must_use]
|
||||
pub fn get_asset(&self, asset: &str) -> String {
|
||||
pub(crate) fn get_asset(&self, asset: &str) -> String {
|
||||
format!("{}{}", self.assets_url, asset)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ use crate::dialog_ui::BaseOrCustomDialog;
|
|||
use crate::event_ui::{custom_phase_event_help, custom_phase_event_origin, event_help, pay_help};
|
||||
use crate::happiness_ui::IncreaseHappinessConfig;
|
||||
use crate::layout_ui::FONT_SIZE;
|
||||
use crate::log_ui::get_log_end;
|
||||
use crate::log_ui::{LogDialog, get_log_end};
|
||||
use crate::map_ui::ExploreResolutionConfig;
|
||||
use crate::move_ui::{MoveIntent, MovePayment, MoveSelection};
|
||||
use crate::payment_ui::{Payment, new_gain};
|
||||
use crate::recruit_unit_ui::{RecruitAmount, RecruitSelection};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::render_context::{RenderContext, RenderStage};
|
||||
use crate::status_phase_ui::ChooseAdditionalAdvances;
|
||||
use macroquad::prelude::*;
|
||||
use server::action::Action;
|
||||
|
|
@ -30,10 +30,11 @@ use server::movement::{CurrentMove, MoveDestination};
|
|||
use server::playing_actions::PlayingActionType;
|
||||
use server::position::Position;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ActiveDialog {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum ActiveDialog {
|
||||
None,
|
||||
Log,
|
||||
Log(LogDialog),
|
||||
Info(InfoDialog),
|
||||
WaitingForUpdate,
|
||||
DialogChooser(Box<DialogChooser>),
|
||||
|
||||
|
|
@ -69,42 +70,11 @@ pub enum ActiveDialog {
|
|||
|
||||
impl ActiveDialog {
|
||||
#[must_use]
|
||||
pub fn title(&self) -> &str {
|
||||
match self {
|
||||
ActiveDialog::None => "none",
|
||||
ActiveDialog::DialogChooser(_) => "dialog chooser",
|
||||
ActiveDialog::Log => "log",
|
||||
ActiveDialog::WaitingForUpdate => "waiting for update",
|
||||
ActiveDialog::IncreaseHappiness(_) => "increase happiness",
|
||||
ActiveDialog::AdvanceMenu => "advance menu",
|
||||
ActiveDialog::AdvancePayment(_) => "advance payment",
|
||||
ActiveDialog::ConstructionPayment(_) => "construction payment",
|
||||
ActiveDialog::CollectResources(_) => "collect resources",
|
||||
ActiveDialog::RecruitUnitSelection(_) => "recruit unit selection",
|
||||
ActiveDialog::ReplaceUnits(_) => "replace units",
|
||||
ActiveDialog::MoveUnits(_) => "move units",
|
||||
ActiveDialog::MovePayment(_) => "move payment",
|
||||
ActiveDialog::ExploreResolution(_) => "explore resolution",
|
||||
ActiveDialog::ChangeGovernmentType => "change government type",
|
||||
ActiveDialog::ChooseAdditionalAdvances(_) => "choose additional advances",
|
||||
ActiveDialog::ResourceRewardRequest(_) => "trade route selection",
|
||||
ActiveDialog::AdvanceRequest(_) => "advance selection",
|
||||
ActiveDialog::PaymentRequest(_) => "custom phase payment request",
|
||||
ActiveDialog::PlayerRequest(_) => "custom phase player request",
|
||||
ActiveDialog::PositionRequest(_) => "custom phase position request",
|
||||
ActiveDialog::UnitTypeRequest(_) => "custom phase unit request",
|
||||
ActiveDialog::UnitsRequest(_) => "custom phase units request",
|
||||
ActiveDialog::StructuresRequest(_, _) => "custom phase structures request",
|
||||
ActiveDialog::BoolRequest(_) => "custom phase bool request",
|
||||
ActiveDialog::HandCardsRequest(_) => "custom phase hand cards request",
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn help_message(&self, rc: &RenderContext) -> Vec<String> {
|
||||
pub(crate) fn help_message(&self, rc: &RenderContext) -> Vec<String> {
|
||||
match self {
|
||||
ActiveDialog::None
|
||||
| ActiveDialog::Log
|
||||
| ActiveDialog::Log(_)
|
||||
| ActiveDialog::Info(_)
|
||||
| ActiveDialog::DialogChooser(_)
|
||||
| ActiveDialog::AdvanceMenu => vec![],
|
||||
ActiveDialog::IncreaseHappiness(h) => {
|
||||
|
|
@ -190,17 +160,17 @@ impl ActiveDialog {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn show_for_other_player(&self) -> bool {
|
||||
matches!(self, ActiveDialog::Log | ActiveDialog::PlayerRequest(_)) | self.is_advance()
|
||||
pub(crate) fn show_for_other_player(&self) -> bool {
|
||||
self.is_modal() || matches!(self, ActiveDialog::PlayerRequest(_))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_modal(&self) -> bool {
|
||||
matches!(self, ActiveDialog::Log) || self.is_advance()
|
||||
pub(crate) fn is_modal(&self) -> bool {
|
||||
matches!(self, ActiveDialog::Log(_) | ActiveDialog::Info(_)) || self.is_advance()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_advance(&self) -> bool {
|
||||
pub(crate) fn is_advance(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
ActiveDialog::AdvanceMenu
|
||||
|
|
@ -212,23 +182,22 @@ impl ActiveDialog {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PendingUpdate {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct PendingUpdate {
|
||||
pub action: Action,
|
||||
pub warning: Vec<String>,
|
||||
pub info: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DialogChooser {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct DialogChooser {
|
||||
pub title: String,
|
||||
pub options: Vec<(Option<EventOrigin>, ActiveDialog)>,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone)]
|
||||
pub enum StateUpdate {
|
||||
None,
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum StateUpdate {
|
||||
OpenDialog(ActiveDialog),
|
||||
CloseDialog,
|
||||
Cancel,
|
||||
|
|
@ -243,13 +212,41 @@ pub enum StateUpdate {
|
|||
ToggleAiPlay,
|
||||
}
|
||||
|
||||
pub(crate) type RenderResult = Result<(), Box<StateUpdate>>;
|
||||
|
||||
pub(crate) const NO_UPDATE: RenderResult = Ok(());
|
||||
|
||||
impl StateUpdate {
|
||||
pub fn execute(action: Action) -> StateUpdate {
|
||||
StateUpdate::Execute(action)
|
||||
pub(crate) fn of(update: StateUpdate) -> RenderResult {
|
||||
Err(Box::new(update))
|
||||
}
|
||||
|
||||
pub fn execute_with_warning(action: Action, warning: Vec<String>) -> StateUpdate {
|
||||
if warning.is_empty() {
|
||||
pub(crate) fn open_dialog(dialog: ActiveDialog) -> RenderResult {
|
||||
Self::of(StateUpdate::OpenDialog(dialog))
|
||||
}
|
||||
|
||||
pub(crate) fn close_dialog() -> RenderResult {
|
||||
Self::of(StateUpdate::CloseDialog)
|
||||
}
|
||||
|
||||
pub(crate) fn execute(action: Action) -> RenderResult {
|
||||
Self::of(StateUpdate::Execute(action))
|
||||
}
|
||||
|
||||
pub(crate) fn cancel() -> RenderResult {
|
||||
Self::of(StateUpdate::Cancel)
|
||||
}
|
||||
|
||||
pub(crate) fn set_focused_tile(pos: Position) -> RenderResult {
|
||||
Self::of(StateUpdate::SetFocusedTile(pos))
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_pending_update(confirm: bool) -> RenderResult {
|
||||
Self::of(StateUpdate::ResolvePendingUpdate(confirm))
|
||||
}
|
||||
|
||||
pub(crate) fn execute_with_warning(action: Action, warning: Vec<String>) -> RenderResult {
|
||||
Self::of(if warning.is_empty() {
|
||||
StateUpdate::Execute(action)
|
||||
} else {
|
||||
StateUpdate::ExecuteWithWarning(PendingUpdate {
|
||||
|
|
@ -257,18 +254,22 @@ impl StateUpdate {
|
|||
warning,
|
||||
info: vec![],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute_with_confirm(info: Vec<String>, action: Action) -> StateUpdate {
|
||||
StateUpdate::ExecuteWithWarning(PendingUpdate {
|
||||
action,
|
||||
warning: vec![],
|
||||
info,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn execute_activation(action: Action, warning: Vec<String>, city: &City) -> StateUpdate {
|
||||
pub(crate) fn execute_with_confirm(info: Vec<String>, action: Action) -> RenderResult {
|
||||
Self::of(StateUpdate::ExecuteWithWarning(PendingUpdate {
|
||||
action,
|
||||
warning: vec![],
|
||||
info,
|
||||
}))
|
||||
}
|
||||
|
||||
pub(crate) fn execute_activation(
|
||||
action: Action,
|
||||
warning: Vec<String>,
|
||||
city: &City,
|
||||
) -> RenderResult {
|
||||
if city.is_activated() {
|
||||
match city.mood_state {
|
||||
MoodState::Happy => {
|
||||
|
|
@ -288,33 +289,33 @@ impl StateUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn dialog_chooser(
|
||||
pub(crate) fn dialog_chooser(
|
||||
title: &str,
|
||||
options: Vec<(Option<EventOrigin>, ActiveDialog)>,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
match options.len() {
|
||||
0 => {
|
||||
panic!("no dialog options provided");
|
||||
}
|
||||
1 => StateUpdate::OpenDialog(options[0].1.clone()),
|
||||
_ => StateUpdate::OpenDialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
1 => StateUpdate::open_dialog(options[0].1.clone()),
|
||||
_ => StateUpdate::open_dialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
title: title.to_string(),
|
||||
options,
|
||||
}))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn response(action: EventResponse) -> StateUpdate {
|
||||
StateUpdate::Execute(Action::Response(action))
|
||||
pub(crate) fn response(action: EventResponse) -> RenderResult {
|
||||
Self::execute(Action::Response(action))
|
||||
}
|
||||
|
||||
pub fn move_units(
|
||||
pub(crate) fn move_units(
|
||||
rc: &RenderContext,
|
||||
pos: Option<Position>,
|
||||
intent: MoveIntent,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let game = rc.game;
|
||||
StateUpdate::OpenDialog(ActiveDialog::MoveUnits(MoveSelection::new(
|
||||
StateUpdate::open_dialog(ActiveDialog::MoveUnits(MoveSelection::new(
|
||||
game.active_player(),
|
||||
pos,
|
||||
game,
|
||||
|
|
@ -322,68 +323,32 @@ impl StateUpdate {
|
|||
&CurrentMove::None,
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn or(self, other: impl FnOnce() -> StateUpdate) -> StateUpdate {
|
||||
match self {
|
||||
StateUpdate::None => other(),
|
||||
_ => self,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub struct StateUpdates {
|
||||
updates: Vec<StateUpdate>,
|
||||
}
|
||||
|
||||
impl Default for StateUpdates {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl StateUpdates {
|
||||
pub fn new() -> StateUpdates {
|
||||
StateUpdates { updates: vec![] }
|
||||
}
|
||||
pub fn add(&mut self, update: StateUpdate) {
|
||||
if !matches!(update, StateUpdate::None) {
|
||||
self.updates.push(update);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn result(self) -> StateUpdate {
|
||||
self.updates
|
||||
.into_iter()
|
||||
.find(|u| !matches!(u, StateUpdate::None))
|
||||
.unwrap_or(StateUpdate::None)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MousePosition {
|
||||
pub(crate) struct MousePosition {
|
||||
pub position: Vec2,
|
||||
pub time: f64,
|
||||
}
|
||||
|
||||
pub enum CameraMode {
|
||||
pub(crate) enum CameraMode {
|
||||
Screen,
|
||||
World,
|
||||
}
|
||||
|
||||
use crate::info_ui::InfoDialog;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use server::ai::AI;
|
||||
use server::events::EventOrigin;
|
||||
|
||||
pub struct State {
|
||||
pub assets: Assets,
|
||||
pub(crate) assets: Assets,
|
||||
pub control_player: Option<usize>,
|
||||
pub show_player: usize,
|
||||
pub active_dialog: ActiveDialog,
|
||||
pub pending_update: Option<PendingUpdate>,
|
||||
pub(crate) active_dialog: ActiveDialog,
|
||||
pub(crate) pending_update: Option<PendingUpdate>,
|
||||
pub camera: Camera2D,
|
||||
pub screen_size: Vec2,
|
||||
pub mouse_positions: Vec<MousePosition>,
|
||||
pub log_scroll: f32,
|
||||
pub(crate) mouse_positions: Vec<MousePosition>,
|
||||
pub focused_tile: Option<Position>,
|
||||
pub show_permanent_effects: bool,
|
||||
pub ai_autoplay: bool,
|
||||
|
|
@ -412,7 +377,6 @@ impl State {
|
|||
},
|
||||
screen_size: vec2(0., 0.),
|
||||
mouse_positions: vec![],
|
||||
log_scroll: 0.0,
|
||||
focused_tile: None,
|
||||
pan_map: false,
|
||||
show_permanent_effects: false,
|
||||
|
|
@ -423,24 +387,28 @@ impl State {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn render_context<'a>(&'a self, game: &'a Game) -> RenderContext<'a> {
|
||||
pub(crate) fn render_context<'a>(
|
||||
&'a self,
|
||||
game: &'a Game,
|
||||
stage: RenderStage,
|
||||
) -> RenderContext<'a> {
|
||||
RenderContext {
|
||||
shown_player: game.player(self.show_player),
|
||||
game,
|
||||
state: self,
|
||||
camera_mode: CameraMode::Screen,
|
||||
stage,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
pub(crate) fn clear(&mut self) {
|
||||
self.active_dialog = ActiveDialog::None;
|
||||
self.pending_update = None;
|
||||
self.focused_tile = None;
|
||||
}
|
||||
|
||||
pub fn update(&mut self, game: &Game, update: StateUpdate) -> GameSyncRequest {
|
||||
pub(crate) fn update(&mut self, game: &Game, update: StateUpdate) -> GameSyncRequest {
|
||||
match update {
|
||||
StateUpdate::None => GameSyncRequest::None,
|
||||
StateUpdate::Execute(a) => GameSyncRequest::ExecuteAction(a),
|
||||
StateUpdate::ExecuteWithWarning(update) => {
|
||||
self.pending_update = Some(update);
|
||||
|
|
@ -460,9 +428,9 @@ impl State {
|
|||
GameSyncRequest::None
|
||||
}
|
||||
}
|
||||
StateUpdate::OpenDialog(dialog) => {
|
||||
if matches!(dialog, ActiveDialog::Log) {
|
||||
self.log_scroll = get_log_end(game, self.screen_size.y);
|
||||
StateUpdate::OpenDialog(mut dialog) => {
|
||||
if let ActiveDialog::Log(d) = &mut dialog {
|
||||
d.log_scroll = get_log_end(game, self.screen_size.y);
|
||||
}
|
||||
let d = self.game_state_dialog(game);
|
||||
if matches!(dialog, ActiveDialog::AdvanceMenu) && d.is_advance() {
|
||||
|
|
@ -508,11 +476,11 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_dialog(&mut self, dialog: ActiveDialog) {
|
||||
pub(crate) fn set_dialog(&mut self, dialog: ActiveDialog) {
|
||||
self.active_dialog = dialog;
|
||||
}
|
||||
|
||||
pub fn update_from_game(&mut self, game: &Game) -> GameSyncRequest {
|
||||
pub(crate) fn update_from_game(&mut self, game: &Game) -> GameSyncRequest {
|
||||
let dialog = self.game_state_dialog(game);
|
||||
self.clear();
|
||||
self.active_dialog = dialog;
|
||||
|
|
@ -520,7 +488,7 @@ impl State {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn game_state_dialog(&self, game: &Game) -> ActiveDialog {
|
||||
pub(crate) fn game_state_dialog(&self, game: &Game) -> ActiveDialog {
|
||||
if let Some(e) = &game.current_event_handler() {
|
||||
return match &e.request {
|
||||
PersistentEventRequest::Payment(r) => ActiveDialog::PaymentRequest(
|
||||
|
|
@ -601,15 +569,15 @@ impl State {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn measure_text(&self, text: &str) -> TextDimensions {
|
||||
pub(crate) fn measure_text(&self, text: &str) -> TextDimensions {
|
||||
measure_text(text, Some(&self.assets.font), FONT_SIZE, 1.0)
|
||||
}
|
||||
|
||||
pub fn draw_text(&self, text: &str, x: f32, y: f32) {
|
||||
pub(crate) fn draw_text(&self, text: &str, x: f32, y: f32) {
|
||||
self.draw_text_with_color(text, x, y, BLACK);
|
||||
}
|
||||
|
||||
pub fn draw_text_with_color(&self, text: &str, x: f32, y: f32, color: Color) {
|
||||
pub(crate) fn draw_text_with_color(&self, text: &str, x: f32, y: f32, color: Color) {
|
||||
draw_text_ex(
|
||||
text,
|
||||
x,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::{BaseOrCustomDialog, OkTooltip, cancel_button, ok_button};
|
||||
use crate::event_ui::event_help;
|
||||
use crate::hex_ui;
|
||||
use crate::layout_ui::{draw_scaled_icon, is_in_circle, left_mouse_button_pressed};
|
||||
use crate::layout_ui::{draw_scaled_icon, is_in_circle, mouse_pressed_position};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::resource_ui::{new_resource_map, resource_name, show_resource_pile};
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::BLACK;
|
||||
use macroquad::math::{Vec2, vec2};
|
||||
use macroquad::prelude::WHITE;
|
||||
use macroquad::shapes::draw_circle;
|
||||
use server::action::Action;
|
||||
use server::collect::{
|
||||
Collect, CollectInfo, PositionCollection, add_collect, get_total_collection,
|
||||
|
|
@ -22,8 +21,8 @@ use server::position::Position;
|
|||
use server::resource::ResourceType;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CollectResources {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct CollectResources {
|
||||
player_index: usize,
|
||||
city_position: Position,
|
||||
collections: Vec<PositionCollection>,
|
||||
|
|
@ -32,7 +31,7 @@ pub struct CollectResources {
|
|||
}
|
||||
|
||||
impl CollectResources {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
player_index: usize,
|
||||
city_position: Position,
|
||||
custom: BaseOrCustomDialog,
|
||||
|
|
@ -47,7 +46,7 @@ impl CollectResources {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn help_text(&self, rc: &RenderContext) -> Vec<String> {
|
||||
pub(crate) fn help_text(&self, rc: &RenderContext) -> Vec<String> {
|
||||
let extra = self.extra_resources();
|
||||
let mut r = vec![
|
||||
self.custom.title.clone(),
|
||||
|
|
@ -60,11 +59,11 @@ impl CollectResources {
|
|||
r
|
||||
}
|
||||
|
||||
pub fn extra_resources(&self) -> i8 {
|
||||
pub(crate) fn extra_resources(&self) -> i8 {
|
||||
self.info.max_selection as i8 - tiles_used(&self.collections) as i8
|
||||
}
|
||||
|
||||
pub fn collected(&self) -> ResourcePile {
|
||||
pub(crate) fn collected(&self) -> ResourcePile {
|
||||
self.collections
|
||||
.clone()
|
||||
.into_iter()
|
||||
|
|
@ -73,7 +72,7 @@ impl CollectResources {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> StateUpdate {
|
||||
pub(crate) fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> RenderResult {
|
||||
show_resource_pile(rc, &collect.collected());
|
||||
|
||||
let game = rc.game;
|
||||
|
|
@ -111,9 +110,9 @@ pub fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> StateUp
|
|||
);
|
||||
}
|
||||
if cancel_button(rc) {
|
||||
return StateUpdate::Cancel;
|
||||
return StateUpdate::cancel();
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn click_collect_option(
|
||||
|
|
@ -121,7 +120,7 @@ fn click_collect_option(
|
|||
col: &CollectResources,
|
||||
p: Position,
|
||||
pile: &ResourcePile,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let c = add_collect(&col.info, p, pile, &col.collections);
|
||||
|
||||
let i = possible_resource_collections(
|
||||
|
|
@ -134,13 +133,13 @@ fn click_collect_option(
|
|||
let mut new = col.clone();
|
||||
new.info = i;
|
||||
new.collections = c;
|
||||
StateUpdate::OpenDialog(ActiveDialog::CollectResources(new))
|
||||
StateUpdate::open_dialog(ActiveDialog::CollectResources(new))
|
||||
}
|
||||
|
||||
pub fn draw_resource_collect_tile(rc: &RenderContext, pos: Position) -> StateUpdate {
|
||||
pub(crate) fn draw_resource_collect_tile(rc: &RenderContext, pos: Position) -> RenderResult {
|
||||
let state = &rc.state;
|
||||
let ActiveDialog::CollectResources(collect) = &state.active_dialog else {
|
||||
return StateUpdate::None;
|
||||
return NO_UPDATE;
|
||||
};
|
||||
|
||||
let Some(possible) = collect
|
||||
|
|
@ -149,7 +148,7 @@ pub fn draw_resource_collect_tile(rc: &RenderContext, pos: Position) -> StateUpd
|
|||
.get(&pos)
|
||||
.map(|v| v.iter().sorted_by_key(ToString::to_string).collect_vec())
|
||||
else {
|
||||
return StateUpdate::None;
|
||||
return NO_UPDATE;
|
||||
};
|
||||
|
||||
let tile_collects = collect
|
||||
|
|
@ -171,8 +170,8 @@ pub fn draw_resource_collect_tile(rc: &RenderContext, pos: Position) -> StateUpd
|
|||
|
||||
let pile_collect = tile_collects.iter().find(|r| &r.pile == pile);
|
||||
let color = if pile_collect.is_some() { BLACK } else { WHITE };
|
||||
draw_circle(center.x, center.y, radius, color);
|
||||
if let Some(p) = left_mouse_button_pressed(rc) {
|
||||
rc.draw_circle(center, radius, color);
|
||||
if let Some(p) = mouse_pressed_position(rc) {
|
||||
if is_in_circle(p, center, radius) {
|
||||
return click_collect_option(rc, collect, pos, pile);
|
||||
}
|
||||
|
|
@ -191,12 +190,11 @@ pub fn draw_resource_collect_tile(rc: &RenderContext, pos: Position) -> StateUpd
|
|||
if let Some(r) = pile_collect {
|
||||
let times = r.times;
|
||||
if times > 1 {
|
||||
rc.state
|
||||
.draw_text(&format!("{times}"), center.x + 20., center.y + 5.);
|
||||
rc.draw_text(&format!("{times}"), center.x + 20., center.y + 5.);
|
||||
}
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn draw_collect_item(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, RenderResult, StateUpdate};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::recruit_unit_ui::RecruitSelection;
|
||||
use crate::render_context::RenderContext;
|
||||
|
|
@ -11,7 +11,10 @@ use server::playing_actions::PlayingAction;
|
|||
use server::position::Position;
|
||||
use server::recruit::Recruit;
|
||||
|
||||
pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) -> StateUpdate {
|
||||
pub(crate) fn pay_construction_dialog(
|
||||
rc: &RenderContext,
|
||||
cp: &ConstructionPayment,
|
||||
) -> RenderResult {
|
||||
let city = rc.game.get_any_city(cp.city_position);
|
||||
payment_dialog(
|
||||
rc,
|
||||
|
|
@ -43,22 +46,21 @@ pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) ->
|
|||
)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ConstructionProject {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum ConstructionProject {
|
||||
Building(Building, Option<Position>),
|
||||
Units(RecruitSelection),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConstructionPayment {
|
||||
pub player_index: usize,
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ConstructionPayment {
|
||||
pub city_position: Position,
|
||||
pub project: ConstructionProject,
|
||||
pub payment: Payment<String>,
|
||||
}
|
||||
|
||||
impl ConstructionPayment {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
rc: &RenderContext,
|
||||
city: &City,
|
||||
name: &str,
|
||||
|
|
@ -66,7 +68,6 @@ impl ConstructionPayment {
|
|||
cost: &CostInfo,
|
||||
) -> ConstructionPayment {
|
||||
ConstructionPayment {
|
||||
player_index: city.player_index,
|
||||
city_position: city.position,
|
||||
project,
|
||||
payment: rc.new_payment(&cost.cost, name.to_string(), name, false),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::advance_ui::{AdvanceState, show_advance_menu};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::{BaseOrCustomDialog, OkTooltip, cancel_button_with_tooltip, ok_button};
|
||||
use crate::layout_ui::{bottom_center_anchor, bottom_centered_text, icon_pos};
|
||||
use crate::payment_ui::{Payment, multi_payment_dialog, payment_dialog};
|
||||
|
|
@ -23,36 +23,38 @@ use server::resource_pile::ResourcePile;
|
|||
use server::structure::Structure;
|
||||
use server::unit::{Unit, validate_units_selection};
|
||||
|
||||
pub fn custom_phase_payment_dialog(
|
||||
pub(crate) fn custom_phase_payment_dialog(
|
||||
rc: &RenderContext,
|
||||
payments: &[Payment<String>],
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let update = multi_payment_dialog(
|
||||
rc,
|
||||
payments,
|
||||
|p| ActiveDialog::PaymentRequest(p.clone()),
|
||||
payments.len() == 1 && payments[0].optional,
|
||||
|p| StateUpdate::Execute(Action::Response(EventResponse::Payment(p.clone()))),
|
||||
|p| StateUpdate::response(EventResponse::Payment(p.clone())),
|
||||
);
|
||||
if matches!(update, StateUpdate::Cancel) {
|
||||
return StateUpdate::Execute(Action::Response(EventResponse::Payment(vec![
|
||||
ResourcePile::empty(),
|
||||
])));
|
||||
if matches!(&update, Err(u) if matches!(**u, StateUpdate::Cancel)) {
|
||||
return StateUpdate::response(EventResponse::Payment(vec![ResourcePile::empty()]));
|
||||
}
|
||||
update
|
||||
}
|
||||
|
||||
pub fn payment_reward_dialog(rc: &RenderContext, payment: &Payment<String>) -> StateUpdate {
|
||||
pub(crate) fn payment_reward_dialog(rc: &RenderContext, payment: &Payment<String>) -> RenderResult {
|
||||
payment_dialog(
|
||||
rc,
|
||||
payment,
|
||||
false,
|
||||
|p| ActiveDialog::ResourceRewardRequest(p.clone()),
|
||||
|p| StateUpdate::Execute(Action::Response(EventResponse::ResourceReward(p))),
|
||||
|p| StateUpdate::response(EventResponse::ResourceReward(p)),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn advance_reward_dialog(rc: &RenderContext, r: &AdvanceRequest, name: &str) -> StateUpdate {
|
||||
pub(crate) fn advance_reward_dialog(
|
||||
rc: &RenderContext,
|
||||
r: &AdvanceRequest,
|
||||
name: &str,
|
||||
) -> RenderResult {
|
||||
let possible = &r.choices;
|
||||
show_advance_menu(
|
||||
rc,
|
||||
|
|
@ -75,40 +77,33 @@ pub fn advance_reward_dialog(rc: &RenderContext, r: &AdvanceRequest, name: &str)
|
|||
)
|
||||
}
|
||||
|
||||
pub fn unit_request_dialog(rc: &RenderContext, r: &UnitTypeRequest) -> StateUpdate {
|
||||
pub(crate) fn unit_request_dialog(rc: &RenderContext, r: &UnitTypeRequest) -> RenderResult {
|
||||
bottom_centered_text(rc, &r.description);
|
||||
|
||||
let c = &r.choices;
|
||||
let anchor = bottom_center_anchor(rc) + vec2(0., 60.);
|
||||
for pass in 0..2 {
|
||||
for (i, u) in c.iter().enumerate() {
|
||||
let x = (c.len() - i) as i8 - 1;
|
||||
let center = icon_pos(x, -2) + anchor;
|
||||
for (i, u) in c.iter().enumerate() {
|
||||
let x = (c.len() - i) as i8 - 1;
|
||||
let center = icon_pos(x, -2) + anchor;
|
||||
|
||||
if pass == 0 {
|
||||
if draw_unit_type(rc, HighlightType::None, center, *u, r.player_index, 20.) {
|
||||
return StateUpdate::Execute(Action::Response(EventResponse::SelectUnitType(
|
||||
*u,
|
||||
)));
|
||||
}
|
||||
} else {
|
||||
let mut tooltip = vec![u.name(rc.game).to_string()];
|
||||
add_unit_description(rc, &mut tooltip, *u);
|
||||
show_tooltip_for_circle(rc, &tooltip, center, 20.);
|
||||
}
|
||||
if draw_unit_type(rc, HighlightType::None, center, *u, r.player_index, 20.) {
|
||||
return StateUpdate::response(EventResponse::SelectUnitType(*u));
|
||||
}
|
||||
let mut tooltip = vec![u.name(rc.game).to_string()];
|
||||
add_unit_description(rc, &mut tooltip, *u);
|
||||
show_tooltip_for_circle(rc, &tooltip, center, 20.);
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UnitsSelection {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct UnitsSelection {
|
||||
pub player: usize,
|
||||
pub selection: MultiSelection<u32>,
|
||||
}
|
||||
|
||||
impl UnitsSelection {
|
||||
pub fn new(r: &UnitsRequest) -> Self {
|
||||
pub(crate) fn new(r: &UnitsRequest) -> Self {
|
||||
UnitsSelection {
|
||||
player: r.player,
|
||||
selection: MultiSelection::new(r.request.clone()),
|
||||
|
|
@ -130,7 +125,7 @@ impl UnitSelection for UnitsSelection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select_units_dialog(rc: &RenderContext, s: &UnitsSelection) -> StateUpdate {
|
||||
pub(crate) fn select_units_dialog(rc: &RenderContext, s: &UnitsSelection) -> RenderResult {
|
||||
let selected = &s.selection.selected;
|
||||
bottom_centered_text(
|
||||
rc,
|
||||
|
|
@ -153,12 +148,12 @@ pub fn select_units_dialog(rc: &RenderContext, s: &UnitsSelection) -> StateUpdat
|
|||
) {
|
||||
StateUpdate::response(EventResponse::SelectUnits(selected.clone()))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MultiSelection<T>
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MultiSelection<T>
|
||||
where
|
||||
T: Clone + PartialEq + Ord,
|
||||
{
|
||||
|
|
@ -167,18 +162,18 @@ where
|
|||
}
|
||||
|
||||
impl<T: Clone + PartialEq + Ord> MultiSelection<T> {
|
||||
pub fn new(request: MultiRequest<T>) -> Self {
|
||||
pub(crate) fn new(request: MultiRequest<T>) -> Self {
|
||||
MultiSelection {
|
||||
request,
|
||||
selected: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
pub(crate) fn is_valid(&self) -> bool {
|
||||
self.request.is_valid(&self.selected)
|
||||
}
|
||||
|
||||
pub fn toggle(self, value: T) -> Self {
|
||||
pub(crate) fn toggle(self, value: T) -> Self {
|
||||
if let Some(i) = self.selected.iter().position(|s| s == &value) {
|
||||
let mut new = self.clone();
|
||||
new.selected.remove(i);
|
||||
|
|
@ -193,23 +188,23 @@ impl<T: Clone + PartialEq + Ord> MultiSelection<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub enum SelectedStructureStatus {
|
||||
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Debug)]
|
||||
pub(crate) enum SelectedStructureStatus {
|
||||
Valid,
|
||||
Warn,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd)]
|
||||
pub struct SelectedStructureInfo {
|
||||
#[derive(Clone, PartialEq, Eq, Ord, PartialOrd, Debug)]
|
||||
pub(crate) struct SelectedStructureInfo {
|
||||
pub position: Position,
|
||||
pub structure: Structure,
|
||||
pub(crate) structure: Structure,
|
||||
pub status: SelectedStructureStatus,
|
||||
pub tooltip: Option<String>,
|
||||
}
|
||||
|
||||
impl SelectedStructureInfo {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
position: Position,
|
||||
structure: Structure,
|
||||
status: SelectedStructureStatus,
|
||||
|
|
@ -223,11 +218,11 @@ impl SelectedStructureInfo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> SelectedStructure {
|
||||
pub(crate) fn selected(&self) -> SelectedStructure {
|
||||
SelectedStructure::new(self.position, self.structure.clone())
|
||||
}
|
||||
|
||||
pub fn highlight_type(&self) -> HighlightType {
|
||||
pub(crate) fn highlight_type(&self) -> HighlightType {
|
||||
match self.status {
|
||||
SelectedStructureStatus::Valid => HighlightType::Choices,
|
||||
SelectedStructureStatus::Warn => HighlightType::Warn,
|
||||
|
|
@ -236,11 +231,11 @@ impl SelectedStructureInfo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select_structures_dialog(
|
||||
pub(crate) fn select_structures_dialog(
|
||||
rc: &RenderContext,
|
||||
d: Option<&BaseOrCustomDialog>,
|
||||
s: &MultiSelection<SelectedStructureInfo>,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
bottom_centered_text(
|
||||
rc,
|
||||
format!(
|
||||
|
|
@ -266,7 +261,7 @@ pub fn select_structures_dialog(
|
|||
) {
|
||||
if let Some(d) = d {
|
||||
if s.selected.is_empty() {
|
||||
return StateUpdate::CloseDialog;
|
||||
return StateUpdate::close_dialog();
|
||||
}
|
||||
StateUpdate::execute(Action::Playing(PlayingAction::InfluenceCultureAttempt(
|
||||
InfluenceCultureAttempt::new(s.selected[0].selected(), d.action_type.clone()),
|
||||
|
|
@ -275,7 +270,7 @@ pub fn select_structures_dialog(
|
|||
StateUpdate::response(EventResponse::SelectStructures(sel))
|
||||
}
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +290,7 @@ pub(crate) fn multi_select_tooltip<T: Clone + PartialEq + Ord>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn bool_request_dialog(rc: &RenderContext, description: &str) -> StateUpdate {
|
||||
pub(crate) fn bool_request_dialog(rc: &RenderContext, description: &str) -> RenderResult {
|
||||
bottom_centered_text(rc, description);
|
||||
if ok_button(rc, OkTooltip::Valid("OK".to_string())) {
|
||||
return bool_answer(true);
|
||||
|
|
@ -303,14 +298,14 @@ pub fn bool_request_dialog(rc: &RenderContext, description: &str) -> StateUpdate
|
|||
if cancel_button_with_tooltip(rc, "Decline") {
|
||||
return bool_answer(false);
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn bool_answer(answer: bool) -> StateUpdate {
|
||||
StateUpdate::Execute(Action::Response(EventResponse::Bool(answer)))
|
||||
fn bool_answer(answer: bool) -> RenderResult {
|
||||
StateUpdate::execute(Action::Response(EventResponse::Bool(answer)))
|
||||
}
|
||||
|
||||
pub fn player_request_dialog(rc: &RenderContext, r: &PlayerRequest) -> StateUpdate {
|
||||
pub(crate) fn player_request_dialog(rc: &RenderContext, r: &PlayerRequest) -> RenderResult {
|
||||
choose_player_dialog(rc, &r.choices, |p| {
|
||||
Action::Response(EventResponse::SelectPlayer(p))
|
||||
})
|
||||
|
|
@ -319,7 +314,7 @@ pub fn player_request_dialog(rc: &RenderContext, r: &PlayerRequest) -> StateUpda
|
|||
pub(crate) fn position_request_dialog(
|
||||
rc: &RenderContext,
|
||||
s: &MultiSelection<Position>,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
bottom_centered_text(
|
||||
rc,
|
||||
format!("{}: {} selected", s.request.description, s.selected.len()).as_str(),
|
||||
|
|
@ -327,6 +322,6 @@ pub(crate) fn position_request_dialog(
|
|||
if ok_button(rc, multi_select_tooltip(s, s.is_valid(), "positions")) {
|
||||
StateUpdate::response(EventResponse::SelectPositions(s.selected.clone()))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
use crate::client_state::{PendingUpdate, StateUpdate};
|
||||
use crate::client_state::{NO_UPDATE, PendingUpdate, RenderResult, StateUpdate};
|
||||
use crate::layout_ui::{bottom_centered_text_with_offset, bottom_right_texture, icon_pos};
|
||||
use crate::render_context::RenderContext;
|
||||
use macroquad::math::{Vec2, vec2};
|
||||
use server::playing_actions::PlayingActionType;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum OkTooltip {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum OkTooltip {
|
||||
Valid(String),
|
||||
Invalid(String),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BaseOrCustomDialog {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct BaseOrCustomDialog {
|
||||
pub title: String,
|
||||
pub action_type: PlayingActionType,
|
||||
}
|
||||
|
||||
pub fn show_pending_update(update: &PendingUpdate, rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn show_pending_update(update: &PendingUpdate, rc: &RenderContext) -> RenderResult {
|
||||
let state = &rc.state;
|
||||
let t = if update.warning.is_empty() {
|
||||
if state.active_dialog.is_modal() {
|
||||
|
|
@ -30,31 +30,31 @@ pub fn show_pending_update(update: &PendingUpdate, rc: &RenderContext) -> StateU
|
|||
bottom_centered_text_with_offset(rc, t, vec2(0., 30.), &[]);
|
||||
|
||||
if ok_button(rc, OkTooltip::Valid("OK".to_string())) {
|
||||
return StateUpdate::ResolvePendingUpdate(true);
|
||||
return StateUpdate::resolve_pending_update(true);
|
||||
}
|
||||
if cancel_button(rc) {
|
||||
return StateUpdate::ResolvePendingUpdate(false);
|
||||
return StateUpdate::resolve_pending_update(false);
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn cancel_button(rc: &RenderContext) -> bool {
|
||||
pub(crate) fn cancel_button(rc: &RenderContext) -> bool {
|
||||
cancel_button_with_tooltip(rc, "Cancel")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn cancel_button_with_tooltip(rc: &RenderContext, tooltip: &str) -> bool {
|
||||
pub(crate) fn cancel_button_with_tooltip(rc: &RenderContext, tooltip: &str) -> bool {
|
||||
bottom_right_texture(rc, &rc.assets().cancel, cancel_button_pos(), tooltip)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn cancel_button_pos() -> Vec2 {
|
||||
pub(crate) fn cancel_button_pos() -> Vec2 {
|
||||
icon_pos(-7, -1)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn ok_button(rc: &RenderContext, ok_tooltip: OkTooltip) -> bool {
|
||||
pub(crate) fn ok_button(rc: &RenderContext, ok_tooltip: OkTooltip) -> bool {
|
||||
let pos = icon_pos(-8, -1);
|
||||
match ok_tooltip {
|
||||
OkTooltip::Valid(tooltip) => bottom_right_texture(rc, &rc.assets().ok, pos, &tooltip),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use crate::log_ui::{break_each, break_text};
|
||||
use crate::payment_ui::Payment;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip::add_tooltip_description;
|
||||
use server::events::EventOrigin;
|
||||
|
||||
#[must_use]
|
||||
pub fn event_help(rc: &RenderContext, origin: &EventOrigin) -> Vec<String> {
|
||||
pub(crate) fn event_help(rc: &RenderContext, origin: &EventOrigin) -> Vec<String> {
|
||||
let mut h = vec![origin.name(rc.game)];
|
||||
let cache = &rc.game.cache;
|
||||
let d = match origin {
|
||||
|
|
@ -22,19 +22,20 @@ pub fn event_help(rc: &RenderContext, origin: &EventOrigin) -> Vec<String> {
|
|||
}
|
||||
EventOrigin::SpecialAdvance(s) => vec![s.info(rc.game).description.clone()],
|
||||
};
|
||||
h.extend(d);
|
||||
|
||||
break_each(&mut h, &d);
|
||||
h
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn custom_phase_event_help(rc: &RenderContext, description: &str) -> Vec<String> {
|
||||
pub(crate) fn custom_phase_event_help(rc: &RenderContext, description: &str) -> Vec<String> {
|
||||
let mut h = event_help(rc, &custom_phase_event_origin(rc));
|
||||
add_tooltip_description(&mut h, description);
|
||||
break_text(&mut h, description);
|
||||
h
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn custom_phase_event_origin(rc: &RenderContext) -> EventOrigin {
|
||||
pub(crate) fn custom_phase_event_origin(rc: &RenderContext) -> EventOrigin {
|
||||
rc.game
|
||||
.current_event()
|
||||
.origin_override
|
||||
|
|
@ -49,7 +50,7 @@ pub fn custom_phase_event_origin(rc: &RenderContext) -> EventOrigin {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn pay_help<T: Clone>(rc: &RenderContext, p: &Payment<T>) -> Vec<String> {
|
||||
pub(crate) fn pay_help<T: Clone>(rc: &RenderContext, p: &Payment<T>) -> Vec<String> {
|
||||
let mut result = vec!["Pay resources".to_string()];
|
||||
for o in p.cost.modifiers.clone() {
|
||||
result.extend(event_help(rc, &o));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::action_buttons::base_or_custom_action;
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::BaseOrCustomDialog;
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
|
|
@ -15,8 +15,8 @@ use server::player::CostTrigger;
|
|||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct IncreaseHappinessConfig {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct IncreaseHappinessConfig {
|
||||
pub steps: Vec<(Position, u8)>,
|
||||
pub payment: Payment<String>,
|
||||
pub custom: BaseOrCustomDialog,
|
||||
|
|
@ -24,7 +24,7 @@ pub struct IncreaseHappinessConfig {
|
|||
}
|
||||
|
||||
impl IncreaseHappinessConfig {
|
||||
pub fn new(rc: &RenderContext, custom: BaseOrCustomDialog) -> IncreaseHappinessConfig {
|
||||
pub(crate) fn new(rc: &RenderContext, custom: BaseOrCustomDialog) -> IncreaseHappinessConfig {
|
||||
let p = rc.shown_player;
|
||||
let steps = p.cities.iter().map(|c| (c.position, 0)).collect();
|
||||
let city_restriction = happiness_city_restriction(rc.shown_player, &custom.action_type);
|
||||
|
|
@ -61,34 +61,31 @@ impl IncreaseHappinessConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn open_increase_happiness_dialog(
|
||||
pub(crate) fn open_increase_happiness_dialog(
|
||||
rc: &RenderContext,
|
||||
actions: &[PlayingActionType],
|
||||
init: impl Fn(IncreaseHappinessConfig) -> IncreaseHappinessConfig,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
base_or_custom_action(rc, actions, "Increase happiness", |custom| {
|
||||
ActiveDialog::IncreaseHappiness(init(IncreaseHappinessConfig::new(rc, custom)))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn increase_happiness_click(
|
||||
pub(crate) fn increase_happiness_click(
|
||||
rc: &RenderContext,
|
||||
pos: Position,
|
||||
h: &IncreaseHappinessConfig,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
if let Some(city) = rc.shown_player.try_get_city(pos) {
|
||||
add_increase_happiness(rc, city, h.clone()).map_or(
|
||||
StateUpdate::None,
|
||||
|increase_happiness| {
|
||||
StateUpdate::OpenDialog(ActiveDialog::IncreaseHappiness(increase_happiness))
|
||||
},
|
||||
)
|
||||
add_increase_happiness(rc, city, h.clone()).map_or(NO_UPDATE, |increase_happiness| {
|
||||
StateUpdate::open_dialog(ActiveDialog::IncreaseHappiness(increase_happiness))
|
||||
})
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_increase_happiness(
|
||||
pub(crate) fn add_increase_happiness(
|
||||
rc: &RenderContext,
|
||||
city: &City,
|
||||
mut increase_happiness: IncreaseHappinessConfig,
|
||||
|
|
@ -151,7 +148,7 @@ fn increase_happiness_new_steps(
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn can_afford_increase_happiness(
|
||||
pub(crate) fn can_afford_increase_happiness(
|
||||
rc: &RenderContext,
|
||||
city: &City,
|
||||
steps: u8,
|
||||
|
|
@ -176,7 +173,7 @@ pub fn can_afford_increase_happiness(
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn available_happiness_actions_for_city(
|
||||
pub(crate) fn available_happiness_actions_for_city(
|
||||
game: &Game,
|
||||
player: usize,
|
||||
position: Position,
|
||||
|
|
@ -195,7 +192,10 @@ pub fn available_happiness_actions_for_city(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn increase_happiness_menu(rc: &RenderContext, h: &IncreaseHappinessConfig) -> StateUpdate {
|
||||
pub(crate) fn increase_happiness_menu(
|
||||
rc: &RenderContext,
|
||||
h: &IncreaseHappinessConfig,
|
||||
) -> RenderResult {
|
||||
payment_dialog(
|
||||
rc,
|
||||
&h.payment,
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@ const SHORT_SIZE: f32 = SIZE * 0.866_025_4;
|
|||
|
||||
const SPACING: Spacing = Spacing::FlatTop(SIZE);
|
||||
|
||||
pub fn center(pos: Position) -> Vec2 {
|
||||
pub(crate) fn center(pos: Position) -> Vec2 {
|
||||
let c = pos.coordinate();
|
||||
let p = c.to_pixel(SPACING);
|
||||
to_screen(Vec2::new(p.0, p.1))
|
||||
}
|
||||
|
||||
pub enum HexFeature {
|
||||
pub(crate) enum HexFeature {
|
||||
Exhausted,
|
||||
ExplorerToken,
|
||||
}
|
||||
|
||||
pub fn draw_hex(
|
||||
pub(crate) fn draw_hex(
|
||||
p: Position,
|
||||
text_color: Color,
|
||||
overlay: Color,
|
||||
|
|
@ -39,32 +39,33 @@ pub fn draw_hex(
|
|||
rc: &RenderContext,
|
||||
) {
|
||||
let c = center(p);
|
||||
if let Some(terrain) = terrain {
|
||||
draw_texture_ex(
|
||||
terrain,
|
||||
c.x - SIZE,
|
||||
c.y - SHORT_SIZE,
|
||||
WHITE,
|
||||
DrawTextureParams {
|
||||
source: Some(Rect::new(0., 0., 298., 257.)),
|
||||
dest_size: Some(vec2(SIZE * 2.0, SHORT_SIZE * 2.)),
|
||||
..Default::default()
|
||||
},
|
||||
if rc.stage.is_main() {
|
||||
if let Some(terrain) = terrain {
|
||||
draw_texture_ex(
|
||||
terrain,
|
||||
c.x - SIZE,
|
||||
c.y - SHORT_SIZE,
|
||||
WHITE,
|
||||
DrawTextureParams {
|
||||
source: Some(Rect::new(0., 0., 298., 257.)),
|
||||
dest_size: Some(vec2(SIZE * 2.0, SHORT_SIZE * 2.)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Terrain::Unexplored
|
||||
draw_hexagon(c.x, c.y, SIZE, 2.0, false, DARKGRAY, BEIGE);
|
||||
}
|
||||
draw_hexagon(c.x, c.y, SIZE, 2.0, false, DARKGRAY, overlay);
|
||||
let text_y = c.y - 35.0;
|
||||
rc.draw_text_with_color(&p.to_string(), c.x - 30.0, text_y, text_color);
|
||||
rc.draw_text_with_color(
|
||||
&block_for_position(rc.game, p).0.to_string(),
|
||||
c.x + 10.0,
|
||||
text_y,
|
||||
text_color,
|
||||
);
|
||||
} else {
|
||||
// Terrain::Unexplored
|
||||
draw_hexagon(c.x, c.y, SIZE, 2.0, false, DARKGRAY, BEIGE);
|
||||
}
|
||||
draw_hexagon(c.x, c.y, SIZE, 2.0, false, DARKGRAY, overlay);
|
||||
let text_y = c.y - 35.0;
|
||||
rc.state
|
||||
.draw_text_with_color(&p.to_string(), c.x - 30.0, text_y, text_color);
|
||||
rc.state.draw_text_with_color(
|
||||
&block_for_position(rc.game, p).0.to_string(),
|
||||
c.x + 10.0,
|
||||
text_y,
|
||||
text_color,
|
||||
);
|
||||
|
||||
for f in features {
|
||||
match f {
|
||||
|
|
@ -92,29 +93,29 @@ pub fn draw_hex(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pixel_to_coordinate(p: Vec2) -> Coordinate {
|
||||
pub(crate) fn pixel_to_coordinate(p: Vec2) -> Coordinate {
|
||||
let p = to_game(Vec2::new(p.x, p.y));
|
||||
Coordinate::from_pixel(p.x, p.y, SPACING)
|
||||
}
|
||||
|
||||
pub fn rotate_around(center: Vec2, radius: f32, angle_deg: usize) -> Vec2 {
|
||||
pub(crate) fn rotate_around(center: Vec2, radius: f32, angle_deg: usize) -> Vec2 {
|
||||
rotate_around_rad(center, radius, PI / 180.0 * (angle_deg as f32))
|
||||
}
|
||||
|
||||
pub fn rotate_around_rad(center: Vec2, radius: f32, angle_rad: f32) -> Vec2 {
|
||||
pub(crate) fn rotate_around_rad(center: Vec2, radius: f32, angle_rad: f32) -> Vec2 {
|
||||
Vec2::new(
|
||||
center.x + radius * f32::cos(angle_rad),
|
||||
center.y + radius * f32::sin(angle_rad),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn to_screen(p: Vec2) -> Vec2 {
|
||||
pub(crate) fn to_screen(p: Vec2) -> Vec2 {
|
||||
let x = p.x + LEFT_BORDER;
|
||||
let y = TOP_BORDER - p.y;
|
||||
Vec2::new(x, y)
|
||||
}
|
||||
|
||||
pub fn to_game(p: Vec2) -> Vec2 {
|
||||
pub(crate) fn to_game(p: Vec2) -> Vec2 {
|
||||
let x = p.x - LEFT_BORDER;
|
||||
let y = TOP_BORDER - p.y;
|
||||
Vec2::new(x, y)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use server::content::persistent_events::MultiRequest;
|
|||
use server::cultural_influence::available_influence_culture;
|
||||
use server::game::Game;
|
||||
|
||||
pub fn new_cultural_influence_dialog(
|
||||
pub(crate) fn new_cultural_influence_dialog(
|
||||
game: &Game,
|
||||
player: usize,
|
||||
d: BaseOrCustomDialog,
|
||||
|
|
|
|||
348
client/src/info_ui.rs
Normal file
348
client/src/info_ui.rs
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
use crate::cards_ui::{action_card_object, objective_card_object, wonder_description};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::layout_ui::button_pressed;
|
||||
use crate::log_ui::{break_each, break_text};
|
||||
use crate::render_context::RenderContext;
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::Color;
|
||||
use macroquad::math::{Rect, Vec2, vec2};
|
||||
use macroquad::prelude::{BLACK, BLUE, GREEN, MAGENTA, WHITE, YELLOW};
|
||||
use server::action_card::ActionCard;
|
||||
use server::civilization::Civilization;
|
||||
use server::content::civilizations;
|
||||
use server::game::Game;
|
||||
use server::incident::Incident;
|
||||
use server::objective_card::ObjectiveCard;
|
||||
use server::wonder::{Wonder, WonderInfo};
|
||||
use std::fmt::Display;
|
||||
use std::ops::Mul;
|
||||
|
||||
enum VisibleCardLocation {
|
||||
DiscardPile,
|
||||
Public,
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl VisibleCardLocation {
|
||||
pub(crate) fn from_piles<T: PartialEq>(card: &T, discarded: &[T], public: &[T]) -> Self {
|
||||
if discarded.contains(card) {
|
||||
VisibleCardLocation::DiscardPile
|
||||
} else if public.contains(card) {
|
||||
VisibleCardLocation::Public
|
||||
} else {
|
||||
VisibleCardLocation::Unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for VisibleCardLocation {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
VisibleCardLocation::DiscardPile => write!(f, "Discard Pile"),
|
||||
VisibleCardLocation::Public => write!(f, "Public"),
|
||||
VisibleCardLocation::Unknown => write!(f, "Unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct InfoDialog {
|
||||
pub select: InfoCategory,
|
||||
pub civilization: String,
|
||||
pub wonder: Wonder,
|
||||
pub incident: u8,
|
||||
pub action_card: u8,
|
||||
pub objective_card: u8,
|
||||
}
|
||||
|
||||
impl InfoDialog {
|
||||
pub(crate) fn new(civilization: String) -> Self {
|
||||
InfoDialog {
|
||||
select: InfoCategory::Civilization,
|
||||
civilization,
|
||||
wonder: Wonder::Colosseum,
|
||||
incident: 1,
|
||||
action_card: 1,
|
||||
objective_card: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum InfoCategory {
|
||||
Civilization,
|
||||
Wonder,
|
||||
Incident,
|
||||
ActionCard,
|
||||
ObjectiveCard,
|
||||
}
|
||||
|
||||
pub(crate) fn show_info_dialog(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
show_category(
|
||||
rc,
|
||||
d,
|
||||
0,
|
||||
InfoCategory::Civilization,
|
||||
"Civilizations",
|
||||
show_civilizations,
|
||||
)?;
|
||||
show_wonders(rc, d)?;
|
||||
show_incidents(rc, d)?;
|
||||
show_action_cards(rc, d)?;
|
||||
show_objective_cards(rc, d)?;
|
||||
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn show_incidents(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
show_category(rc, d, 2, InfoCategory::Incident, "Events", |rc, d| {
|
||||
show_category_items::<Incident, u8>(
|
||||
rc,
|
||||
d,
|
||||
|g| g.cache.get_incidents(),
|
||||
|i| &i.id,
|
||||
|i| i.name.clone(),
|
||||
|i| {
|
||||
let mut d: Vec<String> = vec![];
|
||||
break_each(&mut d, &i.description(rc.game));
|
||||
d
|
||||
},
|
||||
|d| &d.incident,
|
||||
|d, i| d.incident = i,
|
||||
// todo public from permanent effects
|
||||
|i| VisibleCardLocation::from_piles(&i.id, &rc.game.incidents_discarded, &[]),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn show_action_cards(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
show_category(
|
||||
rc,
|
||||
d,
|
||||
3,
|
||||
InfoCategory::ActionCard,
|
||||
"Action Cards",
|
||||
|rc, d| {
|
||||
show_category_items::<ActionCard, u8>(
|
||||
rc,
|
||||
d,
|
||||
|g| g.cache.get_action_cards(),
|
||||
|i| &i.id,
|
||||
ActionCard::name,
|
||||
|i| action_card_object(rc, i.id).description,
|
||||
|d| &d.action_card,
|
||||
|d, i| d.action_card = i,
|
||||
|i| VisibleCardLocation::from_piles(&i.id, &rc.game.action_cards_discarded, &[]),
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn show_objective_cards(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
show_category(
|
||||
rc,
|
||||
d,
|
||||
4,
|
||||
InfoCategory::ObjectiveCard,
|
||||
"Objective Cards",
|
||||
|rc, d| {
|
||||
show_category_items::<ObjectiveCard, u8>(
|
||||
rc,
|
||||
d,
|
||||
|g| g.cache.get_objective_cards(),
|
||||
|i| &i.id,
|
||||
ObjectiveCard::name,
|
||||
|i| objective_card_object(rc, i.id, None).description,
|
||||
|d| &d.objective_card,
|
||||
|d, i| d.objective_card = i,
|
||||
|i| {
|
||||
VisibleCardLocation::from_piles(
|
||||
&i.id,
|
||||
&[],
|
||||
&rc.game
|
||||
.players
|
||||
.iter()
|
||||
.flat_map(|p| p.completed_objectives.iter().map(|o| o.card))
|
||||
.collect_vec(),
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn show_wonders(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
show_category(rc, d, 1, InfoCategory::Wonder, "Wonders", |rc, d| {
|
||||
show_category_items::<WonderInfo, Wonder>(
|
||||
rc,
|
||||
d,
|
||||
|g| g.cache.get_wonders(),
|
||||
|w| &w.wonder,
|
||||
WonderInfo::name,
|
||||
|w| wonder_description(rc, w),
|
||||
|d| &d.wonder,
|
||||
|d, w| d.wonder = w,
|
||||
|w| {
|
||||
VisibleCardLocation::from_piles(
|
||||
&w.wonder,
|
||||
&[],
|
||||
&rc.game
|
||||
.players
|
||||
.iter()
|
||||
.flat_map(
|
||||
// todo destroyed wonders
|
||||
|p| p.wonders_built.clone(),
|
||||
)
|
||||
.collect_vec(),
|
||||
)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn show_category(
|
||||
rc: &RenderContext,
|
||||
d: &InfoDialog,
|
||||
x: usize,
|
||||
category: InfoCategory,
|
||||
name: &str,
|
||||
show: impl Fn(&RenderContext, &InfoDialog) -> RenderResult,
|
||||
) -> RenderResult {
|
||||
let pos = vec2(x as f32, 0.);
|
||||
let selected = d.select == category;
|
||||
if draw_button(rc, name, pos, &[], selected) {
|
||||
let mut new = d.clone();
|
||||
new.select = category;
|
||||
return StateUpdate::open_dialog(ActiveDialog::Info(new));
|
||||
}
|
||||
if selected {
|
||||
show(rc, d)?;
|
||||
}
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn show_civilizations(rc: &RenderContext, d: &InfoDialog) -> RenderResult {
|
||||
for (i, c) in civilizations::get_all_uncached()
|
||||
.iter()
|
||||
.filter(|c| c.is_human())
|
||||
.sorted_by_key(|c| c.name.clone())
|
||||
.enumerate()
|
||||
{
|
||||
let selected = c.name == d.civilization;
|
||||
if draw_button(rc, &c.name, vec2(i as f32, 1.), &[], selected) {
|
||||
let mut new = d.clone();
|
||||
new.civilization.clone_from(&c.name);
|
||||
return StateUpdate::open_dialog(ActiveDialog::Info(new));
|
||||
}
|
||||
if selected {
|
||||
show_civilization(rc, c);
|
||||
}
|
||||
}
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn show_civilization(rc: &RenderContext, c: &Civilization) {
|
||||
for (i, a) in c.special_advances.iter().enumerate() {
|
||||
let mut tooltip: Vec<String> = vec![];
|
||||
let label = &format!("Name: {}", a.name);
|
||||
break_text(&mut tooltip, label);
|
||||
let label = &format!("Required advance: {}", a.requirement.name(rc.game));
|
||||
break_text(&mut tooltip, label);
|
||||
let label = &a.description;
|
||||
break_text(&mut tooltip, label);
|
||||
|
||||
draw_button(rc, &a.name, vec2(i as f32, 2.), &tooltip, false);
|
||||
}
|
||||
for (i, l) in c.leaders.iter().enumerate() {
|
||||
let mut tooltip: Vec<String> = vec![];
|
||||
let label = &format!("Name: {}", l.name);
|
||||
break_text(&mut tooltip, label);
|
||||
for a in &l.abilities {
|
||||
tooltip.push(format!("Leader ability: {}", a.name));
|
||||
let label = &a.description;
|
||||
break_text(&mut tooltip, label);
|
||||
}
|
||||
|
||||
draw_button(rc, &l.name, vec2(i as f32, 3.), &tooltip, false);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_category_items<T: Clone, K: PartialEq + Ord + Clone>(
|
||||
rc: &RenderContext,
|
||||
dialog: &InfoDialog,
|
||||
get_all: impl Fn(&Game) -> &Vec<T>,
|
||||
get_key: impl Fn(&T) -> &K,
|
||||
name: impl Fn(&T) -> String,
|
||||
description: impl Fn(&T) -> Vec<String>,
|
||||
get_selected: impl Fn(&InfoDialog) -> &K,
|
||||
set_selected: impl Fn(&mut InfoDialog, K),
|
||||
get_location: impl Fn(&T) -> VisibleCardLocation,
|
||||
) -> RenderResult {
|
||||
for (i, info) in get_all(rc.game)
|
||||
.iter()
|
||||
.sorted_by_key(|info| get_key(info))
|
||||
.enumerate()
|
||||
{
|
||||
let selected = get_key(info) == get_selected(dialog);
|
||||
let name = name(info);
|
||||
let mut desc = description(info);
|
||||
let location = get_location(info);
|
||||
desc.insert(0, format!("Location: {location}"));
|
||||
|
||||
if draw_button_with_color(
|
||||
rc,
|
||||
&name,
|
||||
vec2(i.rem_euclid(8) as f32, ((i / 8) + 1) as f32),
|
||||
&desc,
|
||||
selected,
|
||||
match location {
|
||||
VisibleCardLocation::DiscardPile => BLUE,
|
||||
VisibleCardLocation::Public => YELLOW,
|
||||
VisibleCardLocation::Unknown => GREEN,
|
||||
},
|
||||
) {
|
||||
let mut new = dialog.clone();
|
||||
set_selected(&mut new, get_key(info).clone());
|
||||
return StateUpdate::open_dialog(ActiveDialog::Info(new));
|
||||
}
|
||||
}
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn draw_button(
|
||||
rc: &RenderContext,
|
||||
text: &str,
|
||||
pos: Vec2,
|
||||
tooltip: &[String],
|
||||
selected: bool,
|
||||
) -> bool {
|
||||
let color = match pos.y {
|
||||
0. => YELLOW,
|
||||
1. => GREEN,
|
||||
2. => BLUE,
|
||||
3. => MAGENTA,
|
||||
_ => WHITE,
|
||||
};
|
||||
draw_button_with_color(rc, text, pos, tooltip, selected, color)
|
||||
}
|
||||
|
||||
fn draw_button_with_color(
|
||||
rc: &RenderContext,
|
||||
text: &str,
|
||||
pos: Vec2,
|
||||
tooltip: &[String],
|
||||
selected: bool,
|
||||
color: Color,
|
||||
) -> bool {
|
||||
let button_size = vec2(140., 40.);
|
||||
let rect_pos = pos.mul(button_size) + vec2(20., 40.);
|
||||
let rect = Rect::new(rect_pos.x, rect_pos.y, 135., 30.);
|
||||
|
||||
rc.draw_rectangle_with_text(rect, color, text);
|
||||
|
||||
if selected {
|
||||
rc.draw_rectangle_lines(rect, 4., BLACK);
|
||||
}
|
||||
|
||||
button_pressed(rect, rc, tooltip, 50.)
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::log_ui::break_text;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip;
|
||||
use crate::tooltip::show_tooltip_for_rect;
|
||||
use macroquad::color::WHITE;
|
||||
use macroquad::math::{Vec2, f32, vec2};
|
||||
use macroquad::prelude::*;
|
||||
|
|
@ -11,35 +11,44 @@ pub const MARGIN: f32 = 10.;
|
|||
|
||||
pub const FONT_SIZE: u16 = 20;
|
||||
|
||||
pub fn icon_offset(i: i8) -> f32 {
|
||||
pub(crate) fn icon_offset(i: i8) -> f32 {
|
||||
f32::from(i) * 1.4 * ICON_SIZE
|
||||
}
|
||||
|
||||
pub fn icon_pos(x: i8, y: i8) -> Vec2 {
|
||||
pub(crate) fn icon_pos(x: i8, y: i8) -> Vec2 {
|
||||
vec2(icon_offset(x), icon_offset(y))
|
||||
}
|
||||
|
||||
pub fn top_center_texture(rc: &RenderContext, texture: &Texture2D, p: Vec2, tooltip: &str) -> bool {
|
||||
pub(crate) fn top_center_texture(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
tooltip: &str,
|
||||
) -> bool {
|
||||
let anchor = top_center_anchor(rc);
|
||||
draw_icon(rc, texture, tooltip, anchor + p)
|
||||
}
|
||||
|
||||
pub fn top_centered_text(rc: &RenderContext, text: &str, p: Vec2) {
|
||||
pub(crate) fn top_centered_text(rc: &RenderContext, text: &str, p: Vec2) {
|
||||
let p = top_center_anchor(rc) + p;
|
||||
rc.state
|
||||
.draw_text(text, p.x - rc.state.measure_text(text).width / 2., p.y);
|
||||
rc.draw_text(text, p.x - rc.state.measure_text(text).width / 2., p.y);
|
||||
}
|
||||
|
||||
pub fn top_center_anchor(rc: &RenderContext) -> Vec2 {
|
||||
pub(crate) fn top_center_anchor(rc: &RenderContext) -> Vec2 {
|
||||
vec2(rc.state.screen_size.x / 2., MARGIN)
|
||||
}
|
||||
|
||||
pub fn top_right_texture(rc: &RenderContext, texture: &Texture2D, p: Vec2, tooltip: &str) -> bool {
|
||||
pub(crate) fn top_right_texture(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
tooltip: &str,
|
||||
) -> bool {
|
||||
let anchor = vec2(rc.state.screen_size.x - MARGIN, MARGIN);
|
||||
draw_icon(rc, texture, tooltip, anchor + p)
|
||||
}
|
||||
|
||||
pub fn bottom_left_texture(
|
||||
pub(crate) fn bottom_left_texture(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
|
|
@ -49,7 +58,7 @@ pub fn bottom_left_texture(
|
|||
draw_scaled_icon_with_tooltip(rc, texture, tooltip, anchor + p, ICON_SIZE)
|
||||
}
|
||||
|
||||
pub fn bottom_center_texture(
|
||||
pub(crate) fn bottom_center_texture(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
|
|
@ -59,7 +68,7 @@ pub fn bottom_center_texture(
|
|||
draw_icon(rc, texture, tooltip, anchor + p)
|
||||
}
|
||||
|
||||
pub fn bottom_centered_text_with_offset(
|
||||
pub(crate) fn bottom_centered_text_with_offset(
|
||||
rc: &RenderContext,
|
||||
text: &str,
|
||||
offset: Vec2,
|
||||
|
|
@ -76,24 +85,24 @@ pub fn bottom_centered_text_with_offset(
|
|||
dimensions.width,
|
||||
dimensions.height,
|
||||
);
|
||||
tooltip::show_tooltip_for_rect(rc, tooltip, rect, 50.);
|
||||
show_tooltip_for_rect(rc, tooltip, rect, 50.);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bottom_centered_text(rc: &RenderContext, text: &str) {
|
||||
pub(crate) fn bottom_centered_text(rc: &RenderContext, text: &str) {
|
||||
bottom_centered_text_with_offset(rc, text, vec2(0., 0.), &[]);
|
||||
}
|
||||
|
||||
pub fn bottom_center_text(rc: &RenderContext, text: &str, p: Vec2) {
|
||||
pub(crate) fn bottom_center_text(rc: &RenderContext, text: &str, p: Vec2) {
|
||||
let p = bottom_center_anchor(rc) + p;
|
||||
rc.state.draw_text(text, p.x, p.y);
|
||||
rc.draw_text(text, p.x, p.y);
|
||||
}
|
||||
|
||||
pub fn bottom_center_anchor(rc: &RenderContext) -> Vec2 {
|
||||
pub(crate) fn bottom_center_anchor(rc: &RenderContext) -> Vec2 {
|
||||
vec2(rc.state.screen_size.x / 2., rc.state.screen_size.y - MARGIN)
|
||||
}
|
||||
|
||||
pub fn bottom_right_texture(
|
||||
pub(crate) fn bottom_right_texture(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
|
|
@ -106,11 +115,16 @@ pub fn bottom_right_texture(
|
|||
draw_icon(rc, texture, tooltip, anchor + p)
|
||||
}
|
||||
|
||||
pub fn draw_icon(rc: &RenderContext, texture: &Texture2D, tooltip: &str, origin: Vec2) -> bool {
|
||||
pub(crate) fn draw_icon(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
tooltip: &str,
|
||||
origin: Vec2,
|
||||
) -> bool {
|
||||
draw_scaled_icon(rc, texture, tooltip, origin, ICON_SIZE)
|
||||
}
|
||||
|
||||
pub fn draw_scaled_icon(
|
||||
pub(crate) fn draw_scaled_icon(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
tooltip: &str,
|
||||
|
|
@ -121,54 +135,85 @@ pub fn draw_scaled_icon(
|
|||
vec![]
|
||||
} else {
|
||||
let mut parts: Vec<String> = vec![];
|
||||
break_text(tooltip, 70, &mut parts);
|
||||
break_text(&mut parts, tooltip);
|
||||
parts
|
||||
};
|
||||
|
||||
draw_scaled_icon_with_tooltip(rc, texture, &t, origin, size)
|
||||
}
|
||||
|
||||
pub fn draw_scaled_icon_with_tooltip(
|
||||
pub(crate) fn draw_scaled_icon_with_tooltip(
|
||||
rc: &RenderContext,
|
||||
texture: &Texture2D,
|
||||
tooltip: &[String],
|
||||
origin: Vec2,
|
||||
size: f32,
|
||||
) -> bool {
|
||||
draw_texture_ex(
|
||||
texture,
|
||||
origin.x,
|
||||
origin.y,
|
||||
WHITE,
|
||||
DrawTextureParams {
|
||||
dest_size: Some(vec2(size, size)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let rect = Rect::new(origin.x, origin.y, size, size);
|
||||
if !tooltip.is_empty() {
|
||||
tooltip::show_tooltip_for_rect(rc, tooltip, rect, 50.);
|
||||
if rc.stage.is_main() {
|
||||
draw_texture_ex(
|
||||
texture,
|
||||
origin.x,
|
||||
origin.y,
|
||||
WHITE,
|
||||
DrawTextureParams {
|
||||
dest_size: Some(vec2(size, size)),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
left_mouse_button_pressed_in_rect(rect, rc)
|
||||
|
||||
button_pressed(Rect::new(origin.x, origin.y, size, size), rc, tooltip, 50.)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn left_mouse_button_pressed_in_rect(rect: Rect, rc: &RenderContext) -> bool {
|
||||
left_mouse_button_pressed(rc).is_some_and(|p| rect.contains(p))
|
||||
pub(crate) fn button_pressed(
|
||||
rect: Rect,
|
||||
rc: &RenderContext,
|
||||
tooltip: &[String],
|
||||
right_offset: f32,
|
||||
) -> bool {
|
||||
if !tooltip.is_empty() {
|
||||
show_tooltip_for_rect(rc, tooltip, rect, right_offset);
|
||||
}
|
||||
mouse_pressed_position(rc).is_some_and(|p| rect.contains(p))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_in_circle(mouse_pos: Vec2, center: Vec2, radius: f32) -> bool {
|
||||
pub(crate) fn is_in_circle(mouse_pos: Vec2, center: Vec2, radius: f32) -> bool {
|
||||
let d = vec2(center.x - mouse_pos.x, center.y - mouse_pos.y);
|
||||
d.length() <= radius
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn left_mouse_button_pressed(rc: &RenderContext) -> Option<Vec2> {
|
||||
if is_mouse_button_pressed(MouseButton::Left) {
|
||||
Some(rc.screen_to_world(mouse_position().into()))
|
||||
pub(crate) fn mouse_pressed_position(rc: &RenderContext) -> Option<Vec2> {
|
||||
is_mouse_pressed(rc).then_some(rc.screen_to_world(mouse_position().into()))
|
||||
}
|
||||
|
||||
pub(crate) fn is_mouse_pressed(rc: &RenderContext) -> bool {
|
||||
rc.stage.is_tooltip() && is_mouse_button_pressed(MouseButton::Left)
|
||||
}
|
||||
|
||||
pub(crate) fn rect_from(p: Vec2, size: Vec2) -> Rect {
|
||||
Rect::new(p.x, p.y, size.x, size.y)
|
||||
}
|
||||
|
||||
pub(crate) fn limit_str(
|
||||
s: &str,
|
||||
max_width: f32,
|
||||
measure: impl Fn(&str) -> TextDimensions,
|
||||
) -> String {
|
||||
let mut limited = String::new();
|
||||
for c in s.chars() {
|
||||
limited.push(c);
|
||||
if measure(&limited).width > max_width {
|
||||
limited.pop();
|
||||
limited.push_str("..");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if limited.is_empty() {
|
||||
s.to_string()
|
||||
} else {
|
||||
None
|
||||
limited
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ mod event_ui;
|
|||
mod happiness_ui;
|
||||
mod hex_ui;
|
||||
mod influence_ui;
|
||||
mod info_ui;
|
||||
mod layout_ui;
|
||||
mod log_ui;
|
||||
mod map_ui;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,34 @@
|
|||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{NO_UPDATE, RenderResult};
|
||||
use crate::render_context::RenderContext;
|
||||
use macroquad::math::vec2;
|
||||
use server::game::Game;
|
||||
|
||||
pub fn show_log(rc: &RenderContext) -> StateUpdate {
|
||||
draw_log(rc.game, rc.state.log_scroll, |label: &str, y: f32| {
|
||||
let p = vec2(30., y * 25. + 20.);
|
||||
rc.state.draw_text(label, p.x, p.y);
|
||||
});
|
||||
StateUpdate::None
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct LogDialog {
|
||||
pub log_scroll: f32,
|
||||
}
|
||||
|
||||
pub fn get_log_end(game: &Game, height: f32) -> f32 {
|
||||
impl Default for LogDialog {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl LogDialog {
|
||||
pub(crate) fn new() -> Self {
|
||||
LogDialog { log_scroll: 0. }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn show_log(rc: &RenderContext, d: &LogDialog) -> RenderResult {
|
||||
draw_log(rc.game, d.log_scroll, |label: &str, y: f32| {
|
||||
let p = vec2(30., y * 25. + 20.);
|
||||
rc.draw_text(label, p.x, p.y);
|
||||
});
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub(crate) fn get_log_end(game: &Game, height: f32) -> f32 {
|
||||
let mut end = 0.;
|
||||
draw_log(game, 0., |_label: &str, y: f32| {
|
||||
end = y;
|
||||
|
|
@ -32,7 +49,7 @@ fn draw_log(game: &Game, start_scroll: f32, mut render: impl FnMut(&str, f32)) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn multiline_label(label: &str, len: usize, mut print: impl FnMut(&str)) {
|
||||
pub(crate) fn multiline_label(label: &str, len: usize, mut print: impl FnMut(&str)) {
|
||||
let mut line = String::new();
|
||||
label.split(' ').for_each(|s| {
|
||||
if line.len() + s.len() > len {
|
||||
|
|
@ -49,8 +66,14 @@ pub fn multiline_label(label: &str, len: usize, mut print: impl FnMut(&str)) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn break_text(label: &str, len: usize, result: &mut Vec<String>) {
|
||||
multiline_label(label, len, |label: &str| {
|
||||
pub(crate) fn break_text(result: &mut Vec<String>, label: &str) {
|
||||
multiline_label(label, 70, |label: &str| {
|
||||
result.push(label.to_string());
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn break_each(result: &mut Vec<String>, labels: &[String]) {
|
||||
for label in labels {
|
||||
break_text(result, label);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use crate::city_ui::{IconAction, IconActionVec, draw_city, show_city_menu};
|
||||
use crate::client_state::{ActiveDialog, MAX_OFFSET, MIN_OFFSET, State, StateUpdate, ZOOM};
|
||||
use crate::client_state::{
|
||||
ActiveDialog, MAX_OFFSET, MIN_OFFSET, NO_UPDATE, RenderResult, State, StateUpdate, ZOOM,
|
||||
};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button_pos, ok_button};
|
||||
use crate::hex_ui::HexFeature;
|
||||
use crate::layout_ui::{
|
||||
|
|
@ -32,8 +34,8 @@ const fn color(r: u8, g: u8, b: u8, a: f32) -> Color {
|
|||
Color::new(r as f32 / 255., g as f32 / 255., b as f32 / 255., a)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ExploreResolutionConfig {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ExploreResolutionConfig {
|
||||
pub block: UnexploredBlock,
|
||||
pub rotation: Rotation,
|
||||
}
|
||||
|
|
@ -45,7 +47,7 @@ fn terrain_font_color(t: &Terrain) -> Color {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn terrain_name(t: &Terrain) -> &'static str {
|
||||
pub(crate) fn terrain_name(t: &Terrain) -> &'static str {
|
||||
match t {
|
||||
Terrain::Barren => "Barren",
|
||||
Terrain::Mountain => "Mountain",
|
||||
|
|
@ -57,7 +59,7 @@ pub fn terrain_name(t: &Terrain) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn draw_map(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn draw_map(rc: &RenderContext) -> RenderResult {
|
||||
let game = rc.game;
|
||||
let overlay_terrain = get_overlay(rc);
|
||||
for (pos, t) in &game.map.tiles {
|
||||
|
|
@ -83,10 +85,7 @@ pub fn draw_map(rc: &RenderContext) -> StateUpdate {
|
|||
&features,
|
||||
rc,
|
||||
);
|
||||
let update = collect_ui::draw_resource_collect_tile(rc, *pos);
|
||||
if !matches!(update, StateUpdate::None) {
|
||||
return update;
|
||||
}
|
||||
collect_ui::draw_resource_collect_tile(rc, *pos)?;
|
||||
}
|
||||
// get from current event
|
||||
if let Some(c) = get_combat(game) {
|
||||
|
|
@ -96,15 +95,13 @@ pub fn draw_map(rc: &RenderContext) -> StateUpdate {
|
|||
if !matches!(&state.active_dialog, ActiveDialog::CollectResources(_)) {
|
||||
for p in &game.players {
|
||||
for city in &p.cities {
|
||||
if let Some(u) = draw_city(rc, city) {
|
||||
return u;
|
||||
}
|
||||
draw_city(rc, city)?;
|
||||
}
|
||||
}
|
||||
unit_ui::draw_units(rc, false);
|
||||
unit_ui::draw_units(rc, true);
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn get_overlay(rc: &RenderContext) -> HashMap<Position, Terrain> {
|
||||
|
|
@ -120,7 +117,7 @@ fn get_overlay(rc: &RenderContext) -> HashMap<Position, Terrain> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pan_and_zoom(state: &mut State) {
|
||||
pub(crate) fn pan_and_zoom(state: &mut State) {
|
||||
let (_, wheel) = mouse_wheel();
|
||||
let new_zoom = state.camera.zoom + wheel * 0.0001;
|
||||
let x = new_zoom.x;
|
||||
|
|
@ -224,7 +221,7 @@ fn highlight_if(b: bool) -> Color {
|
|||
alpha_overlay(if b { 0.5 } else { 0. })
|
||||
}
|
||||
|
||||
pub fn show_tile_menu(rc: &RenderContext, pos: Position) -> StateUpdate {
|
||||
pub(crate) fn show_tile_menu(rc: &RenderContext, pos: Position) -> RenderResult {
|
||||
if let Some(city) = rc.game.try_get_any_city(pos) {
|
||||
if rc.can_control_shown_player() && rc.shown_player.index == city.player_index {
|
||||
return show_city_menu(rc, city);
|
||||
|
|
@ -257,7 +254,7 @@ fn found_city_button<'a>(rc: &'a RenderContext<'a>, pos: Position) -> Option<Ico
|
|||
})
|
||||
}
|
||||
|
||||
pub fn move_units_button<'a>(
|
||||
pub(crate) fn move_units_button<'a>(
|
||||
rc: &'a RenderContext,
|
||||
pos: Position,
|
||||
move_intent: MoveIntent,
|
||||
|
|
@ -274,7 +271,7 @@ pub fn move_units_button<'a>(
|
|||
))
|
||||
}
|
||||
|
||||
pub fn move_units_buttons<'a>(rc: &'a RenderContext, pos: Position) -> Vec<IconAction<'a>> {
|
||||
pub(crate) fn move_units_buttons<'a>(rc: &'a RenderContext, pos: Position) -> Vec<IconAction<'a>> {
|
||||
let mut res = vec![];
|
||||
if let Some(action) = move_units_button(rc, pos, MoveIntent::Land) {
|
||||
res.push(action);
|
||||
|
|
@ -288,28 +285,23 @@ pub fn move_units_buttons<'a>(rc: &'a RenderContext, pos: Position) -> Vec<IconA
|
|||
res
|
||||
}
|
||||
|
||||
pub fn show_map_action_buttons(rc: &RenderContext, icons: &IconActionVec) -> StateUpdate {
|
||||
for pass in 0..2 {
|
||||
for (i, icon) in icons.iter().enumerate() {
|
||||
let p = icon_pos(-(icons.len() as i8) / 2 + i as i8, -1);
|
||||
let center = bottom_center_anchor(rc) + p + vec2(15., 15.);
|
||||
let radius = 20.;
|
||||
if pass == 0 {
|
||||
if icon.warning {
|
||||
draw_circle(center.x, center.y, radius, RED);
|
||||
}
|
||||
if bottom_center_texture(rc, icon.texture, p, "") {
|
||||
return (icon.action)();
|
||||
}
|
||||
} else {
|
||||
show_tooltip_for_circle(rc, &icon.tooltip, center, radius);
|
||||
}
|
||||
pub(crate) fn show_map_action_buttons(rc: &RenderContext, icons: &IconActionVec) -> RenderResult {
|
||||
for (i, icon) in icons.iter().enumerate() {
|
||||
let p = icon_pos(-(icons.len() as i8) / 2 + i as i8, -1);
|
||||
let center = bottom_center_anchor(rc) + p + vec2(15., 15.);
|
||||
let radius = 20.;
|
||||
if icon.warning {
|
||||
rc.draw_circle(center, radius, RED);
|
||||
}
|
||||
if bottom_center_texture(rc, icon.texture, p, "") {
|
||||
return (icon.action)();
|
||||
}
|
||||
show_tooltip_for_circle(rc, &icon.tooltip, center, radius);
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn explore_dialog(rc: &RenderContext, r: &ExploreResolutionConfig) -> StateUpdate {
|
||||
pub(crate) fn explore_dialog(rc: &RenderContext, r: &ExploreResolutionConfig) -> RenderResult {
|
||||
if ok_button(
|
||||
rc,
|
||||
OkTooltip::Valid("Accept current tile rotation".to_string()),
|
||||
|
|
@ -326,8 +318,8 @@ pub fn explore_dialog(rc: &RenderContext, r: &ExploreResolutionConfig) -> StateU
|
|||
) {
|
||||
let mut new = r.clone();
|
||||
new.rotation = (r.rotation + 3).rem(6);
|
||||
return StateUpdate::OpenDialog(ActiveDialog::ExploreResolution(new));
|
||||
return StateUpdate::open_dialog(ActiveDialog::ExploreResolution(new));
|
||||
}
|
||||
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::cancel_button_with_tooltip;
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
|
|
@ -18,20 +18,20 @@ use server::resource_pile::ResourcePile;
|
|||
use server::unit::{Unit, UnitType};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum MoveIntent {
|
||||
pub(crate) enum MoveIntent {
|
||||
Land,
|
||||
Sea,
|
||||
Disembark,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MovePayment {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct MovePayment {
|
||||
pub action: MovementAction,
|
||||
pub payment: Payment<String>,
|
||||
}
|
||||
|
||||
impl MoveIntent {
|
||||
pub fn to_predicate(self) -> impl Fn(&Unit) -> bool {
|
||||
pub(crate) fn to_predicate(self) -> impl Fn(&Unit) -> bool {
|
||||
match self {
|
||||
MoveIntent::Land => |u: &Unit| u.is_land_based() && !u.is_transported(),
|
||||
MoveIntent::Sea => |u: &Unit| !u.is_land_based(),
|
||||
|
|
@ -39,7 +39,7 @@ impl MoveIntent {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn toolip(&self) -> &str {
|
||||
pub(crate) fn toolip(&self) -> &str {
|
||||
match self {
|
||||
MoveIntent::Land => "Move land units",
|
||||
MoveIntent::Sea => "Move sea units",
|
||||
|
|
@ -47,7 +47,7 @@ impl MoveIntent {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn icon<'a>(self, rc: &'a RenderContext) -> &'a Texture2D {
|
||||
pub(crate) fn icon<'a>(self, rc: &'a RenderContext) -> &'a Texture2D {
|
||||
match self {
|
||||
MoveIntent::Land => &rc.assets().move_units,
|
||||
MoveIntent::Sea => rc.assets().unit(UnitType::Ship, rc.shown_player),
|
||||
|
|
@ -56,7 +56,12 @@ impl MoveIntent {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn click(rc: &RenderContext, pos: Position, s: &MoveSelection, mouse_pos: Vec2) -> StateUpdate {
|
||||
pub(crate) fn click(
|
||||
rc: &RenderContext,
|
||||
pos: Position,
|
||||
s: &MoveSelection,
|
||||
mouse_pos: Vec2,
|
||||
) -> RenderResult {
|
||||
let game = rc.game;
|
||||
let p = game.player(s.player_index);
|
||||
let carrier = click_unit(rc, pos, mouse_pos, p, false);
|
||||
|
|
@ -82,7 +87,7 @@ pub fn click(rc: &RenderContext, pos: Position, s: &MoveSelection, mouse_pos: Ve
|
|||
));
|
||||
|
||||
if !cost.is_free() {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::MovePayment(MovePayment {
|
||||
return StateUpdate::open_dialog(ActiveDialog::MovePayment(MovePayment {
|
||||
action,
|
||||
payment: rc.new_payment(&cost, "Move units".to_string(), "Move units", true),
|
||||
}));
|
||||
|
|
@ -92,7 +97,7 @@ pub fn click(rc: &RenderContext, pos: Position, s: &MoveSelection, mouse_pos: Ve
|
|||
_ => {
|
||||
if s.start.is_some_and(|p| p != pos) {
|
||||
// first need to deselect units
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
} else {
|
||||
click_unit(rc, pos, mouse_pos, p, true).map_or_else(
|
||||
|| tile_clicked(pos, s, game, p),
|
||||
|
|
@ -109,7 +114,7 @@ fn unit_clicked(
|
|||
game: &Game,
|
||||
p: &Player,
|
||||
unit_id: u32,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let mut new = s.clone();
|
||||
new.start = Some(pos);
|
||||
let is_transported = p.get_unit(unit_id).is_transported();
|
||||
|
|
@ -122,28 +127,28 @@ fn unit_clicked(
|
|||
unit_selection_changed(pos, game, new)
|
||||
}
|
||||
|
||||
fn tile_clicked(pos: Position, s: &MoveSelection, game: &Game, p: &Player) -> StateUpdate {
|
||||
fn tile_clicked(pos: Position, s: &MoveSelection, game: &Game, p: &Player) -> RenderResult {
|
||||
let mut new = s.clone();
|
||||
new.start = Some(pos);
|
||||
if new.units.is_empty() {
|
||||
new.units = movable_units(pos, game, p, |u| !u.is_transported());
|
||||
unit_selection_changed(pos, game, new)
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
||||
fn unit_selection_changed(pos: Position, game: &Game, mut new: MoveSelection) -> StateUpdate {
|
||||
fn unit_selection_changed(pos: Position, game: &Game, mut new: MoveSelection) -> RenderResult {
|
||||
if new.units.is_empty() {
|
||||
new.destinations.list.clear();
|
||||
new.start = None;
|
||||
} else {
|
||||
new.destinations = possible_move_destinations(game, new.player_index, &new.units, pos);
|
||||
}
|
||||
StateUpdate::OpenDialog(ActiveDialog::MoveUnits(new))
|
||||
StateUpdate::open_dialog(ActiveDialog::MoveUnits(new))
|
||||
}
|
||||
|
||||
pub fn movable_units(
|
||||
pub(crate) fn movable_units(
|
||||
pos: Position,
|
||||
game: &Game,
|
||||
p: &Player,
|
||||
|
|
@ -163,7 +168,7 @@ pub fn movable_units(
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MoveSelection {
|
||||
pub(crate) struct MoveSelection {
|
||||
pub player_index: usize,
|
||||
pub units: Vec<u32>,
|
||||
pub start: Option<Position>,
|
||||
|
|
@ -171,7 +176,7 @@ pub struct MoveSelection {
|
|||
}
|
||||
|
||||
impl MoveSelection {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
player_index: usize,
|
||||
start: Option<Position>,
|
||||
game: &Game,
|
||||
|
|
@ -225,16 +230,16 @@ impl MoveSelection {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn move_units_dialog(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn move_units_dialog(rc: &RenderContext) -> RenderResult {
|
||||
if matches!(rc.game.state, GameState::Playing)
|
||||
&& cancel_button_with_tooltip(rc, "Back to playing actions")
|
||||
{
|
||||
return StateUpdate::CloseDialog;
|
||||
return StateUpdate::close_dialog();
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub(crate) fn move_payment_dialog(rc: &RenderContext, mp: &MovePayment) -> StateUpdate {
|
||||
pub(crate) fn move_payment_dialog(rc: &RenderContext, mp: &MovePayment) -> RenderResult {
|
||||
payment_dialog(
|
||||
rc,
|
||||
&mp.payment.clone(),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::OkTooltip;
|
||||
use crate::event_ui::event_help;
|
||||
use crate::layout_ui::{
|
||||
|
|
@ -16,13 +16,13 @@ use server::resource::ResourceType;
|
|||
use server::resource_pile::ResourcePile;
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct ResourcePayment {
|
||||
pub(crate) struct ResourcePayment {
|
||||
pub resource: ResourceType,
|
||||
pub selectable: CountSelector,
|
||||
}
|
||||
|
||||
impl ResourcePayment {
|
||||
pub fn new(resource: ResourceType, current: u8, min: u8, max: u8) -> ResourcePayment {
|
||||
pub(crate) fn new(resource: ResourceType, current: u8, min: u8, max: u8) -> ResourcePayment {
|
||||
ResourcePayment {
|
||||
resource,
|
||||
selectable: CountSelector { current, min, max },
|
||||
|
|
@ -37,7 +37,7 @@ impl HasCountSelectableObject for ResourcePayment {
|
|||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct Payment<T: Clone> {
|
||||
pub(crate) struct Payment<T: Clone> {
|
||||
pub value: T,
|
||||
pub name: String,
|
||||
pub cost: PaymentOptions,
|
||||
|
|
@ -51,7 +51,7 @@ where
|
|||
T: Clone,
|
||||
{
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
cost: &PaymentOptions,
|
||||
available: &ResourcePile,
|
||||
value: T,
|
||||
|
|
@ -68,7 +68,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_resource_pile(&self) -> ResourcePile {
|
||||
pub(crate) fn to_resource_pile(&self) -> ResourcePile {
|
||||
let r = &self.current;
|
||||
ResourcePile::new(
|
||||
Self::current(r, ResourceType::Food),
|
||||
|
|
@ -81,18 +81,12 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, r: ResourceType) -> &mut ResourcePayment {
|
||||
pub(crate) fn get_mut(&mut self, r: ResourceType) -> &mut ResourcePayment {
|
||||
self.current
|
||||
.iter_mut()
|
||||
.find(|p| p.resource == r)
|
||||
.unwrap_or_else(|| panic!("Resource {r} not found in payment"))
|
||||
}
|
||||
pub fn get(&self, r: ResourceType) -> &ResourcePayment {
|
||||
self.current
|
||||
.iter()
|
||||
.find(|p| p.resource == r)
|
||||
.unwrap_or_else(|| panic!("Resource {r} not found in payment"))
|
||||
}
|
||||
|
||||
fn current(r: &[ResourcePayment], resource_type: ResourceType) -> u8 {
|
||||
r.iter()
|
||||
|
|
@ -102,7 +96,7 @@ where
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_gain(reward: &ResourceReward, name: &str) -> Payment<String> {
|
||||
pub(crate) fn new_gain(reward: &ResourceReward, name: &str) -> Payment<String> {
|
||||
let options = &reward.payment_options;
|
||||
let a = options.default.amount();
|
||||
let mut available = ResourcePile::empty();
|
||||
|
|
@ -112,13 +106,13 @@ pub fn new_gain(reward: &ResourceReward, name: &str) -> Payment<String> {
|
|||
Payment::new(options, &available, name.to_string(), name, false)
|
||||
}
|
||||
|
||||
pub fn payment_dialog<T: Clone>(
|
||||
pub(crate) fn payment_dialog<T: Clone>(
|
||||
rc: &RenderContext,
|
||||
payment: &Payment<T>,
|
||||
may_cancel: bool,
|
||||
to_dialog: impl FnOnce(Payment<T>) -> ActiveDialog,
|
||||
execute_action: impl FnOnce(ResourcePile) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
execute_action: impl FnOnce(ResourcePile) -> RenderResult,
|
||||
) -> RenderResult {
|
||||
multi_payment_dialog(
|
||||
rc,
|
||||
&[payment.clone()],
|
||||
|
|
@ -128,13 +122,13 @@ pub fn payment_dialog<T: Clone>(
|
|||
)
|
||||
}
|
||||
|
||||
pub fn multi_payment_dialog<T: Clone>(
|
||||
pub(crate) fn multi_payment_dialog<T: Clone>(
|
||||
rc: &RenderContext,
|
||||
payments: &[Payment<T>],
|
||||
to_dialog: impl FnOnce(Vec<Payment<T>>) -> ActiveDialog,
|
||||
may_cancel: bool,
|
||||
execute_action: impl FnOnce(Vec<ResourcePile>) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
execute_action: impl FnOnce(Vec<ResourcePile>) -> RenderResult,
|
||||
) -> RenderResult {
|
||||
let tooltip = ok_tooltip(payments, payments[0].available.clone());
|
||||
let mut exec = false;
|
||||
let mut added: Option<Payment<T>> = None;
|
||||
|
|
@ -165,7 +159,7 @@ pub fn multi_payment_dialog<T: Clone>(
|
|||
offset + vec2(0., -30.),
|
||||
&[],
|
||||
);
|
||||
let result = select_ui::count_dialog(
|
||||
select_ui::count_dialog(
|
||||
rc,
|
||||
payment,
|
||||
|p| p.current.clone(),
|
||||
|
|
@ -189,37 +183,33 @@ pub fn multi_payment_dialog<T: Clone>(
|
|||
|| tooltip.clone(),
|
||||
|| {
|
||||
exec = true;
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
},
|
||||
|_, o| types.contains(&o.resource),
|
||||
|_, o| {
|
||||
added = Some(plus(payment.clone(), o.resource));
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
},
|
||||
|_, o| {
|
||||
removed = Some(minus(payment.clone(), o.resource));
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
},
|
||||
offset,
|
||||
may_cancel,
|
||||
);
|
||||
)?;
|
||||
|
||||
if let Some(p) = added {
|
||||
return StateUpdate::OpenDialog(to_dialog(replace_updated_payment(&p, payments)));
|
||||
return StateUpdate::open_dialog(to_dialog(replace_updated_payment(&p, payments)));
|
||||
}
|
||||
if let Some(p) = removed {
|
||||
return StateUpdate::OpenDialog(to_dialog(replace_updated_payment(&p, payments)));
|
||||
return StateUpdate::open_dialog(to_dialog(replace_updated_payment(&p, payments)));
|
||||
}
|
||||
|
||||
if exec {
|
||||
return execute_action(payments.iter().map(Payment::to_resource_pile).collect());
|
||||
}
|
||||
|
||||
if !matches!(result, StateUpdate::None) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn ok_tooltip<T: Clone>(payments: &[Payment<T>], mut available: ResourcePile) -> OkTooltip {
|
||||
|
|
@ -274,14 +264,7 @@ fn resource_payment(options: &PaymentOptions, available: &ResourcePile) -> Vec<R
|
|||
.into_iter()
|
||||
.map(|e| {
|
||||
let resource_type = e.0;
|
||||
ResourcePayment {
|
||||
resource: resource_type,
|
||||
selectable: CountSelector {
|
||||
current: e.1,
|
||||
min: 0,
|
||||
max: available.get(&resource_type),
|
||||
},
|
||||
}
|
||||
ResourcePayment::new(resource_type, e.1, 0, available.get(&resource_type))
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -289,12 +272,12 @@ fn resource_payment(options: &PaymentOptions, available: &ResourcePile) -> Vec<R
|
|||
resources
|
||||
}
|
||||
|
||||
pub fn plus<T: Clone>(mut payment: Payment<T>, t: ResourceType) -> Payment<T> {
|
||||
pub(crate) fn plus<T: Clone>(mut payment: Payment<T>, t: ResourceType) -> Payment<T> {
|
||||
payment.get_mut(t).selectable.current += 1;
|
||||
payment
|
||||
}
|
||||
|
||||
pub fn minus<T: Clone>(mut payment: Payment<T>, t: ResourceType) -> Payment<T> {
|
||||
pub(crate) fn minus<T: Clone>(mut payment: Payment<T>, t: ResourceType) -> Payment<T> {
|
||||
payment.get_mut(t).selectable.current -= 1;
|
||||
payment
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
use crate::action_buttons::action_buttons;
|
||||
use crate::city_ui::city_labels;
|
||||
use crate::client::Features;
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::{OkTooltip, ok_button};
|
||||
use crate::layout_ui::{
|
||||
ICON_SIZE, bottom_center_texture, bottom_centered_text, bottom_right_texture, icon_pos,
|
||||
left_mouse_button_pressed_in_rect, top_center_anchor, top_center_texture,
|
||||
ICON_SIZE, bottom_center_texture, bottom_centered_text, bottom_right_texture, button_pressed,
|
||||
icon_pos, top_center_anchor, top_center_texture,
|
||||
};
|
||||
use crate::log_ui::multiline_label;
|
||||
use crate::map_ui::terrain_name;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::resource_ui::{new_resource_map, resource_name};
|
||||
use crate::tooltip::{show_tooltip_for_circle, show_tooltip_for_rect};
|
||||
use crate::tooltip::show_tooltip_for_circle;
|
||||
use crate::unit_ui;
|
||||
use itertools::Itertools;
|
||||
use macroquad::math::vec2;
|
||||
|
|
@ -30,7 +30,7 @@ use server::resource::ResourceType;
|
|||
use server::status_phase::get_status_phase;
|
||||
use server::victory_points::victory_points_parts;
|
||||
|
||||
pub fn player_select(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn player_select(rc: &RenderContext) -> RenderResult {
|
||||
let game = rc.game;
|
||||
let players = game.human_players(game.starting_player_index);
|
||||
|
||||
|
|
@ -47,14 +47,14 @@ pub fn player_select(rc: &RenderContext) -> StateUpdate {
|
|||
|
||||
let w = if shown { size + 10. } else { size };
|
||||
let x = pos.x - w + size;
|
||||
draw_rectangle(x, pos.y, w, size, color);
|
||||
draw_rectangle_lines(x, pos.y, w, size, 2.0, BLACK);
|
||||
let rect = Rect::new(x, pos.y, w, size);
|
||||
rc.draw_rectangle(rect, color);
|
||||
rc.draw_rectangle_lines(rect, 2.0, BLACK);
|
||||
let text = format!("{}", pl.victory_points(game));
|
||||
|
||||
let state = rc.state;
|
||||
state.draw_text(&text, pos.x + 10., pos.y + 27.);
|
||||
rc.draw_text(&text, pos.x + 10., pos.y + 27.);
|
||||
|
||||
if game.active_player() == pl.index {
|
||||
if game.active_player() == pl.index && rc.stage.is_main() {
|
||||
draw_texture_ex(
|
||||
&rc.assets().active_player,
|
||||
x - 20.,
|
||||
|
|
@ -67,42 +67,39 @@ pub fn player_select(rc: &RenderContext) -> StateUpdate {
|
|||
);
|
||||
}
|
||||
|
||||
let rect = Rect::new(x, pos.y, w, size);
|
||||
let tooltip = if state.control_player.is_some_and(|p| p == pl.index) {
|
||||
let tooltip = if rc.state.control_player.is_some_and(|p| p == pl.index) {
|
||||
format!("{pl} (You)")
|
||||
} else {
|
||||
pl.get_name()
|
||||
};
|
||||
show_tooltip_for_rect(rc, &[tooltip], rect, 50.);
|
||||
if !shown && left_mouse_button_pressed_in_rect(rect, rc) {
|
||||
return StateUpdate::SetShownPlayer(pl.index);
|
||||
if button_pressed(rect, rc, &[tooltip], 50.) && !shown {
|
||||
return StateUpdate::of(StateUpdate::SetShownPlayer(pl.index));
|
||||
}
|
||||
|
||||
y += size;
|
||||
}
|
||||
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn top_icon_with_label(
|
||||
pub(crate) fn top_icon_with_label(
|
||||
rc: &RenderContext,
|
||||
label: &str,
|
||||
texture: &Texture2D,
|
||||
p: Vec2,
|
||||
tooltip: &str,
|
||||
) {
|
||||
let state = rc.state;
|
||||
let dimensions = state.measure_text(label);
|
||||
let dimensions = rc.state.measure_text(label);
|
||||
let x = (ICON_SIZE - dimensions.width) / 2.0;
|
||||
state.draw_text(
|
||||
rc.draw_text(
|
||||
label,
|
||||
state.screen_size.x / 2.0 + p.x + x,
|
||||
rc.state.screen_size.x / 2.0 + p.x + x,
|
||||
p.y + ICON_SIZE + 30.,
|
||||
);
|
||||
top_center_texture(rc, texture, p, tooltip);
|
||||
}
|
||||
|
||||
pub fn bottom_icon_with_label(
|
||||
pub(crate) fn bottom_icon_with_label(
|
||||
rc: &RenderContext,
|
||||
label: &str,
|
||||
texture: &Texture2D,
|
||||
|
|
@ -112,7 +109,7 @@ pub fn bottom_icon_with_label(
|
|||
let state = rc.state;
|
||||
let dimensions = state.measure_text(label);
|
||||
let x = (ICON_SIZE - dimensions.width) / 2.0;
|
||||
state.draw_text(
|
||||
rc.draw_text(
|
||||
label,
|
||||
rc.state.screen_size.x / 2.0 + p.x + x,
|
||||
rc.state.screen_size.y + p.y + 35.,
|
||||
|
|
@ -120,7 +117,7 @@ pub fn bottom_icon_with_label(
|
|||
bottom_center_texture(rc, texture, p, tooltip);
|
||||
}
|
||||
|
||||
pub fn show_top_center(rc: &RenderContext) {
|
||||
pub(crate) fn show_top_center(rc: &RenderContext) {
|
||||
let player = rc.shown_player;
|
||||
|
||||
let pos = icon_pos(3, 0);
|
||||
|
|
@ -171,16 +168,15 @@ pub fn show_top_center(rc: &RenderContext) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn show_top_left(rc: &RenderContext) {
|
||||
let state = rc.state;
|
||||
pub(crate) fn show_top_left(rc: &RenderContext) {
|
||||
let mut p = vec2(10., 10.);
|
||||
let mut label = |label: &str| {
|
||||
multiline_label(label, 30, |label: &str| {
|
||||
p = vec2(p.x, p.y + 25.);
|
||||
if p.y > state.screen_size.y - 150. {
|
||||
if p.y > rc.state.screen_size.y - 150. {
|
||||
p = vec2(p.x + 350., 85.);
|
||||
}
|
||||
state.draw_text(label, p.x, p.y);
|
||||
rc.draw_text(label, p.x, p.y);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -238,21 +234,21 @@ pub fn show_top_left(rc: &RenderContext) {
|
|||
}
|
||||
}
|
||||
|
||||
if rc.shown_player_is_active() || state.active_dialog.show_for_other_player() {
|
||||
for m in state.active_dialog.help_message(rc) {
|
||||
if rc.shown_player_is_active() || rc.state.active_dialog.show_for_other_player() {
|
||||
for m in rc.state.active_dialog.help_message(rc) {
|
||||
label(&m);
|
||||
}
|
||||
}
|
||||
|
||||
if rc.shown_player_is_active() {
|
||||
if let Some(u) = &state.pending_update {
|
||||
if let Some(u) = &rc.state.pending_update {
|
||||
for m in &u.info {
|
||||
label(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(position) = state.focused_tile {
|
||||
if let Some(position) = rc.state.focused_tile {
|
||||
show_focused_tile(&mut label, game, position);
|
||||
}
|
||||
|
||||
|
|
@ -309,7 +305,7 @@ fn show_permanent_effects(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_combat(game: &Game) -> Option<&CombatStats> {
|
||||
pub(crate) fn get_combat(game: &Game) -> Option<&CombatStats> {
|
||||
game.events.last().and_then(|e| match &e.event_type {
|
||||
PersistentEventType::CombatStart(c) => Some(&c.stats),
|
||||
PersistentEventType::CombatRoundStart(s) => Some(&s.combat.stats),
|
||||
|
|
@ -319,7 +315,7 @@ pub fn get_combat(game: &Game) -> Option<&CombatStats> {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn show_global_controls(rc: &RenderContext, features: &Features) -> StateUpdate {
|
||||
pub(crate) fn show_global_controls(rc: &RenderContext, features: &Features) -> RenderResult {
|
||||
let assets = rc.assets();
|
||||
let can_control = rc.can_control_shown_player();
|
||||
if can_control {
|
||||
|
|
@ -330,26 +326,23 @@ pub fn show_global_controls(rc: &RenderContext, features: &Features) -> StateUpd
|
|||
}
|
||||
}
|
||||
if game.can_redo() && bottom_right_texture(rc, &assets.redo, icon_pos(-5, -1), "Redo") {
|
||||
return StateUpdate::Execute(Action::Redo);
|
||||
return StateUpdate::execute(Action::Redo);
|
||||
}
|
||||
if game.can_undo() && bottom_right_texture(rc, &assets.undo, icon_pos(-6, -1), "Undo") {
|
||||
return StateUpdate::Execute(Action::Undo);
|
||||
return StateUpdate::execute(Action::Undo);
|
||||
}
|
||||
|
||||
if can_control {
|
||||
let update = action_buttons(rc);
|
||||
if !matches!(update, StateUpdate::None) {
|
||||
return update;
|
||||
}
|
||||
action_buttons(rc)?;
|
||||
}
|
||||
}
|
||||
|
||||
if features.import_export {
|
||||
if bottom_right_texture(rc, &assets.export, icon_pos(-1, -3), "Export") {
|
||||
return StateUpdate::Export;
|
||||
return StateUpdate::of(StateUpdate::Export);
|
||||
}
|
||||
if bottom_right_texture(rc, &assets.import, icon_pos(-2, -3), "Import") {
|
||||
return StateUpdate::Import;
|
||||
return StateUpdate::of(StateUpdate::Import);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -366,11 +359,11 @@ pub fn show_global_controls(rc: &RenderContext, features: &Features) -> StateUpd
|
|||
&assets.play
|
||||
};
|
||||
if bottom_right_texture(rc, texture, icon_pos(-3, -3), tooltip) {
|
||||
return StateUpdate::ToggleAiPlay;
|
||||
return StateUpdate::of(StateUpdate::ToggleAiPlay);
|
||||
}
|
||||
}
|
||||
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
fn can_end_move(game: &Game) -> Option<&str> {
|
||||
|
|
@ -384,7 +377,7 @@ fn can_end_move(game: &Game) -> Option<&str> {
|
|||
}
|
||||
}
|
||||
|
||||
fn end_move(game: &Game) -> StateUpdate {
|
||||
fn end_move(game: &Game) -> RenderResult {
|
||||
if let GameState::Movement(m) = &game.state {
|
||||
let movement_actions_left = m.movement_actions_left;
|
||||
return StateUpdate::execute_with_warning(
|
||||
|
|
@ -408,11 +401,11 @@ fn end_move(game: &Game) -> StateUpdate {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn choose_player_dialog(
|
||||
pub(crate) fn choose_player_dialog(
|
||||
rc: &RenderContext,
|
||||
choices: &[usize],
|
||||
execute: impl Fn(usize) -> Action,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let player = rc.shown_player.index;
|
||||
if rc.can_control_active_player() && choices.contains(&player) {
|
||||
bottom_centered_text(rc, &format!("Select {}", rc.shown_player.get_name()));
|
||||
|
|
@ -420,5 +413,5 @@ pub fn choose_player_dialog(
|
|||
return StateUpdate::execute(execute(player));
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use itertools::Itertools;
|
||||
use macroquad::prelude::*;
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::construct_ui::{ConstructionPayment, ConstructionProject};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
|
||||
use crate::render_context::RenderContext;
|
||||
|
|
@ -17,15 +17,15 @@ use server::recruit::{recruit_cost, recruit_cost_without_replaced};
|
|||
use server::unit::UnitType::{Cavalry, Elephant, Infantry, Leader, Settler, Ship};
|
||||
use server::unit::{Unit, UnitType, Units, get_units_to_replace};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SelectableUnit {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct SelectableUnit {
|
||||
pub unit_type: UnitType,
|
||||
pub selectable: CountSelector,
|
||||
cost: Result<CostInfo, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RecruitAmount {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct RecruitAmount {
|
||||
player_index: usize,
|
||||
city_position: Position,
|
||||
pub units: Units,
|
||||
|
|
@ -39,19 +39,19 @@ impl HasCountSelectableObject for SelectableUnit {
|
|||
}
|
||||
|
||||
impl RecruitAmount {
|
||||
pub fn new_selection(
|
||||
pub(crate) fn new_selection(
|
||||
game: &Game,
|
||||
player_index: usize,
|
||||
city_position: Position,
|
||||
units: Units,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let player = game.player(player_index);
|
||||
let selectable: Vec<SelectableUnit> = new_units(player)
|
||||
.into_iter()
|
||||
.map(|u| selectable_unit(city_position, &units, player, u, game))
|
||||
.collect();
|
||||
|
||||
StateUpdate::OpenDialog(ActiveDialog::RecruitUnitSelection(RecruitAmount {
|
||||
StateUpdate::open_dialog(ActiveDialog::RecruitUnitSelection(RecruitAmount {
|
||||
player_index,
|
||||
city_position,
|
||||
units,
|
||||
|
|
@ -104,17 +104,16 @@ fn new_units(player: &Player) -> Vec<UnitType> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RecruitSelection {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct RecruitSelection {
|
||||
pub player: usize,
|
||||
pub amount: RecruitAmount,
|
||||
pub available_units: Units,
|
||||
pub need_replacement: Units,
|
||||
pub replaced_units: Vec<u32>,
|
||||
}
|
||||
|
||||
impl RecruitSelection {
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
game: &Game,
|
||||
player: usize,
|
||||
amount: RecruitAmount,
|
||||
|
|
@ -126,17 +125,16 @@ impl RecruitSelection {
|
|||
RecruitSelection {
|
||||
player,
|
||||
amount,
|
||||
available_units,
|
||||
need_replacement,
|
||||
replaced_units,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_finished(&self) -> bool {
|
||||
pub(crate) fn is_finished(&self) -> bool {
|
||||
self.need_replacement.is_empty()
|
||||
}
|
||||
|
||||
pub fn confirm(&self, game: &Game) -> OkTooltip {
|
||||
pub(crate) fn confirm(&self, game: &Game) -> OkTooltip {
|
||||
recruit_cost(
|
||||
game,
|
||||
game.player(self.amount.player_index),
|
||||
|
|
@ -166,7 +164,7 @@ impl UnitSelection for RecruitSelection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
|
||||
pub(crate) fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> RenderResult {
|
||||
let game = rc.game;
|
||||
let radius = 20.;
|
||||
select_ui::count_dialog(
|
||||
|
|
@ -203,7 +201,7 @@ pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
|
|||
if sel.is_finished() {
|
||||
open_dialog(rc, a.city_position, sel)
|
||||
} else {
|
||||
StateUpdate::OpenDialog(ActiveDialog::ReplaceUnits(sel))
|
||||
StateUpdate::open_dialog(ActiveDialog::ReplaceUnits(sel))
|
||||
}
|
||||
},
|
||||
|_s, _u| true,
|
||||
|
|
@ -222,7 +220,7 @@ pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
|
|||
)
|
||||
}
|
||||
|
||||
fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> StateUpdate {
|
||||
fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> RenderResult {
|
||||
let p = rc.shown_player.index;
|
||||
let cost = recruit_cost(
|
||||
rc.game,
|
||||
|
|
@ -233,7 +231,7 @@ fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> Sta
|
|||
CostTrigger::WithModifiers,
|
||||
)
|
||||
.unwrap();
|
||||
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(ConstructionPayment::new(
|
||||
StateUpdate::open_dialog(ActiveDialog::ConstructionPayment(ConstructionPayment::new(
|
||||
rc,
|
||||
rc.game.city(p, city),
|
||||
&format!(
|
||||
|
|
@ -245,16 +243,16 @@ fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> Sta
|
|||
)))
|
||||
}
|
||||
|
||||
fn update_selection(game: &Game, s: &RecruitAmount, units: Units) -> StateUpdate {
|
||||
fn update_selection(game: &Game, s: &RecruitAmount, units: Units) -> RenderResult {
|
||||
RecruitAmount::new_selection(game, s.player_index, s.city_position, units)
|
||||
}
|
||||
|
||||
pub fn replace_dialog(rc: &RenderContext, sel: &RecruitSelection) -> StateUpdate {
|
||||
pub(crate) fn replace_dialog(rc: &RenderContext, sel: &RecruitSelection) -> RenderResult {
|
||||
if ok_button(rc, sel.confirm(rc.game)) {
|
||||
open_dialog(rc, sel.amount.city_position, sel.clone())
|
||||
} else if cancel_button(rc) {
|
||||
StateUpdate::Cancel
|
||||
StateUpdate::cancel()
|
||||
} else {
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,66 @@
|
|||
use crate::assets::Assets;
|
||||
use crate::client_state::{CameraMode, State, StateUpdate};
|
||||
use crate::client_state::{CameraMode, RenderResult, State};
|
||||
use crate::layout_ui::limit_str;
|
||||
use crate::payment_ui::Payment;
|
||||
use macroquad::camera::set_default_camera;
|
||||
use macroquad::color::{Color, PINK, YELLOW};
|
||||
use macroquad::input::mouse_position;
|
||||
use macroquad::math::{Vec2, bool};
|
||||
use macroquad::prelude::{BLACK, LIME, SKYBLUE, WHITE, set_camera};
|
||||
use macroquad::prelude::{BLACK, LIME, Rect, SKYBLUE, WHITE, set_camera};
|
||||
use server::game::Game;
|
||||
use server::payment::PaymentOptions;
|
||||
use server::player::Player;
|
||||
use server::playing_actions::PlayingActionType;
|
||||
|
||||
pub struct RenderContext<'a> {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum RenderStage {
|
||||
Map,
|
||||
UI,
|
||||
Tooltip,
|
||||
}
|
||||
|
||||
impl RenderStage {
|
||||
pub(crate) fn is_main(self) -> bool {
|
||||
!self.is_tooltip()
|
||||
}
|
||||
|
||||
pub(crate) fn is_ui(self) -> bool {
|
||||
self == RenderStage::UI || self == RenderStage::Tooltip
|
||||
}
|
||||
|
||||
pub(crate) fn is_map(self) -> bool {
|
||||
self == RenderStage::Map || self == RenderStage::Tooltip
|
||||
}
|
||||
|
||||
pub(crate) fn is_tooltip(self) -> bool {
|
||||
self == RenderStage::Tooltip
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct RenderContext<'a> {
|
||||
pub game: &'a Game,
|
||||
pub state: &'a State,
|
||||
pub shown_player: &'a Player, // the player that is being shown
|
||||
pub shown_player: &'a Player,
|
||||
pub camera_mode: CameraMode,
|
||||
pub stage: RenderStage,
|
||||
}
|
||||
|
||||
impl RenderContext<'_> {
|
||||
pub fn assets(&self) -> &Assets {
|
||||
pub(crate) fn assets(&self) -> &Assets {
|
||||
&self.state.assets
|
||||
}
|
||||
|
||||
pub fn with_camera(
|
||||
pub(crate) fn with_camera(
|
||||
&self,
|
||||
mode: CameraMode,
|
||||
f: impl FnOnce(&RenderContext) -> StateUpdate + Sized,
|
||||
) -> StateUpdate {
|
||||
f: impl FnOnce(&RenderContext) -> RenderResult + Sized,
|
||||
) -> RenderResult {
|
||||
let next = RenderContext {
|
||||
game: self.game,
|
||||
state: self.state,
|
||||
shown_player: self.shown_player,
|
||||
camera_mode: mode,
|
||||
stage: self.stage,
|
||||
};
|
||||
next.set_camera();
|
||||
let update = f(&next);
|
||||
|
|
@ -48,45 +76,41 @@ impl RenderContext<'_> {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn world_to_screen(&self, point: Vec2) -> Vec2 {
|
||||
match self.camera_mode {
|
||||
CameraMode::Screen => point,
|
||||
CameraMode::World => self.state.camera.world_to_screen(point),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn screen_to_world(&self, point: Vec2) -> Vec2 {
|
||||
pub(crate) fn screen_to_world(&self, point: Vec2) -> Vec2 {
|
||||
match self.camera_mode {
|
||||
CameraMode::Screen => point,
|
||||
CameraMode::World => self.state.camera.screen_to_world(point),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_play_action_for_player(&self, action: &PlayingActionType, player: usize) -> bool {
|
||||
pub(crate) fn can_play_action_for_player(
|
||||
&self,
|
||||
action: &PlayingActionType,
|
||||
player: usize,
|
||||
) -> bool {
|
||||
self.can_play_action(action) && self.game.active_player() == player
|
||||
}
|
||||
|
||||
pub fn can_play_action(&self, action: &PlayingActionType) -> bool {
|
||||
pub(crate) fn can_play_action(&self, action: &PlayingActionType) -> bool {
|
||||
self.can_control_shown_player()
|
||||
&& action
|
||||
.is_available(self.game, self.shown_player.index)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub fn can_control_shown_player(&self) -> bool {
|
||||
pub(crate) fn can_control_shown_player(&self) -> bool {
|
||||
self.can_control_active_player() && self.shown_player_is_active()
|
||||
}
|
||||
|
||||
pub fn can_control_active_player(&self) -> bool {
|
||||
pub(crate) fn can_control_active_player(&self) -> bool {
|
||||
self.state.control_player == Some(self.game.active_player())
|
||||
}
|
||||
|
||||
pub fn shown_player_is_active(&self) -> bool {
|
||||
pub(crate) fn shown_player_is_active(&self) -> bool {
|
||||
self.game.active_player() == self.state.show_player
|
||||
}
|
||||
|
||||
pub fn new_payment<T: Clone>(
|
||||
pub(crate) fn new_payment<T: Clone>(
|
||||
&self,
|
||||
cost: &PaymentOptions,
|
||||
value: T,
|
||||
|
|
@ -97,7 +121,7 @@ impl RenderContext<'_> {
|
|||
Payment::new(cost, available, value, name, optional)
|
||||
}
|
||||
|
||||
pub fn player_color(&self, player_index: usize) -> Color {
|
||||
pub(crate) fn player_color(&self, player_index: usize) -> Color {
|
||||
let c = &self.game.player(player_index).civilization;
|
||||
if c.is_barbarian() {
|
||||
return WHITE;
|
||||
|
|
@ -114,7 +138,60 @@ impl RenderContext<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mouse_pos(&self) -> Vec2 {
|
||||
pub(crate) fn mouse_pos(&self) -> Vec2 {
|
||||
self.screen_to_world(mouse_position().into())
|
||||
}
|
||||
|
||||
pub(crate) fn draw_limited_text(&self, text: &str, x: f32, y: f32, max_width: f32) {
|
||||
if self.stage.is_main() {
|
||||
self.state.draw_text(
|
||||
&limit_str(text, max_width, |t| self.state.measure_text(t)),
|
||||
x,
|
||||
y,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_text(&self, text: &str, x: f32, y: f32) {
|
||||
if self.stage.is_main() {
|
||||
self.state.draw_text(text, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_text_with_color(&self, text: &str, x: f32, y: f32, color: Color) {
|
||||
if self.stage.is_main() {
|
||||
self.state.draw_text_with_color(text, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_rectangle(&self, r: Rect, color: Color) {
|
||||
if self.stage.is_main() {
|
||||
macroquad::prelude::draw_rectangle(r.x, r.y, r.w, r.h, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_rectangle_with_text(&self, r: Rect, color: Color, text: &str) {
|
||||
if self.stage.is_main() {
|
||||
self.draw_rectangle(r, color);
|
||||
self.draw_limited_text(text, r.x + 10., r.y + 22., r.w - 30.);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_rectangle_lines(&self, r: Rect, thickness: f32, color: Color) {
|
||||
if self.stage.is_main() {
|
||||
macroquad::prelude::draw_rectangle_lines(r.x, r.y, r.w, r.h, thickness, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_circle(&self, c: Vec2, r: f32, color: Color) {
|
||||
if self.stage.is_main() {
|
||||
macroquad::prelude::draw_circle(c.x, c.y, r, color);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn draw_circle_lines(&self, c: Vec2, r: f32, thickness: f32, color: Color) {
|
||||
if self.stage.is_main() {
|
||||
macroquad::prelude::draw_circle_lines(c.x, c.y, r, thickness, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use server::resource::ResourceType;
|
|||
use server::resource_pile::ResourcePile;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn resource_name(t: ResourceType) -> &'static str {
|
||||
pub(crate) fn resource_name(t: ResourceType) -> &'static str {
|
||||
match t {
|
||||
ResourceType::Food => "Food",
|
||||
ResourceType::Wood => "Wood",
|
||||
|
|
@ -19,7 +19,7 @@ pub fn resource_name(t: ResourceType) -> &'static str {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_resource_map(p: &ResourcePile) -> HashMap<ResourceType, u8> {
|
||||
pub(crate) fn new_resource_map(p: &ResourcePile) -> HashMap<ResourceType, u8> {
|
||||
let mut m: HashMap<ResourceType, u8> = HashMap::new();
|
||||
add_resource(&mut m, p.food, ResourceType::Food);
|
||||
add_resource(&mut m, p.wood, ResourceType::Wood);
|
||||
|
|
@ -35,7 +35,7 @@ fn add_resource(m: &mut HashMap<ResourceType, u8>, amount: u8, resource_type: Re
|
|||
m.insert(resource_type, amount);
|
||||
}
|
||||
|
||||
pub fn show_resource_pile(rc: &RenderContext, p: &ResourcePile) {
|
||||
pub(crate) fn show_resource_pile(rc: &RenderContext, p: &ResourcePile) {
|
||||
let resource_map = new_resource_map(p);
|
||||
let show: Vec<ResourceType> = ResourceType::all()
|
||||
.into_iter()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{NO_UPDATE, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
|
||||
use crate::layout_ui::{ICON_SIZE, bottom_center_anchor, bottom_center_texture};
|
||||
use crate::render_context::RenderContext;
|
||||
|
|
@ -7,7 +7,7 @@ use macroquad::math::{Vec2, bool, vec2};
|
|||
use macroquad::prelude::{GRAY, RED};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
pub struct CountSelector {
|
||||
pub(crate) struct CountSelector {
|
||||
pub current: u8,
|
||||
pub min: u8,
|
||||
pub max: u8,
|
||||
|
|
@ -18,79 +18,74 @@ pub trait HasCountSelectableObject {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn count_dialog<C, O: HasCountSelectableObject>(
|
||||
pub(crate) fn count_dialog<C, O: HasCountSelectableObject>(
|
||||
rc: &RenderContext,
|
||||
container: &C,
|
||||
get_objects: impl Fn(&C) -> Vec<O>,
|
||||
draw: impl Fn(&O, Vec2),
|
||||
draw_tooltip: impl Fn(&O, Vec2),
|
||||
is_valid: impl FnOnce() -> OkTooltip,
|
||||
execute_action: impl FnOnce() -> StateUpdate,
|
||||
execute_action: impl FnOnce() -> RenderResult,
|
||||
show: impl Fn(&C, &O) -> bool,
|
||||
plus: impl FnOnce(&C, &O) -> StateUpdate,
|
||||
minus: impl FnOnce(&C, &O) -> StateUpdate,
|
||||
plus: impl FnOnce(&C, &O) -> RenderResult,
|
||||
minus: impl FnOnce(&C, &O) -> RenderResult,
|
||||
offset: Vec2,
|
||||
may_cancel: bool,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let objects = get_objects(container)
|
||||
.into_iter()
|
||||
.filter(|o| show(container, o))
|
||||
.collect::<Vec<_>>();
|
||||
let start_x = objects.len() as f32 * -1. / 2.;
|
||||
let anchor = bottom_center_anchor(rc);
|
||||
for pass in 0..2 {
|
||||
for (i, o) in objects.iter().enumerate() {
|
||||
let x = (start_x + i as f32) * ICON_SIZE * 2.;
|
||||
let c = o.counter();
|
||||
for (i, o) in objects.iter().enumerate() {
|
||||
let x = (start_x + i as f32) * ICON_SIZE * 2.;
|
||||
let c = o.counter();
|
||||
|
||||
let point = vec2(x + 7., -60.) + anchor + offset;
|
||||
if pass == 0 {
|
||||
draw(o, point);
|
||||
let current_pos = vec2(x + 13., -ICON_SIZE) + anchor + offset;
|
||||
rc.state.draw_text_with_color(
|
||||
&format!("{}", c.current),
|
||||
current_pos.x,
|
||||
current_pos.y,
|
||||
BLACK,
|
||||
);
|
||||
if c.current > c.min
|
||||
&& bottom_center_texture(
|
||||
rc,
|
||||
&rc.assets().minus,
|
||||
vec2(x - 15., -ICON_SIZE) + offset,
|
||||
"Remove one",
|
||||
)
|
||||
{
|
||||
return minus(container, o);
|
||||
}
|
||||
if c.current < c.max
|
||||
&& bottom_center_texture(
|
||||
rc,
|
||||
&rc.assets().plus,
|
||||
vec2(x + 15., -ICON_SIZE) + offset,
|
||||
"Add one",
|
||||
)
|
||||
{
|
||||
return plus(container, o);
|
||||
}
|
||||
} else {
|
||||
draw_tooltip(o, point);
|
||||
}
|
||||
let point = vec2(x + 7., -60.) + anchor + offset;
|
||||
draw(o, point);
|
||||
let current_pos = vec2(x + 13., -ICON_SIZE) + anchor + offset;
|
||||
rc.draw_text_with_color(
|
||||
&format!("{}", c.current),
|
||||
current_pos.x,
|
||||
current_pos.y,
|
||||
BLACK,
|
||||
);
|
||||
if c.current > c.min
|
||||
&& bottom_center_texture(
|
||||
rc,
|
||||
&rc.assets().minus,
|
||||
vec2(x - 15., -ICON_SIZE) + offset,
|
||||
"Remove one",
|
||||
)
|
||||
{
|
||||
return minus(container, o);
|
||||
}
|
||||
if c.current < c.max
|
||||
&& bottom_center_texture(
|
||||
rc,
|
||||
&rc.assets().plus,
|
||||
vec2(x + 15., -ICON_SIZE) + offset,
|
||||
"Add one",
|
||||
)
|
||||
{
|
||||
return plus(container, o);
|
||||
}
|
||||
draw_tooltip(o, point);
|
||||
}
|
||||
|
||||
if ok_button(rc, is_valid()) {
|
||||
return execute_action();
|
||||
}
|
||||
if may_cancel && cancel_button(rc) {
|
||||
return StateUpdate::Cancel;
|
||||
return StateUpdate::cancel();
|
||||
}
|
||||
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub enum HighlightType {
|
||||
pub(crate) enum HighlightType {
|
||||
None,
|
||||
Primary,
|
||||
Choices,
|
||||
|
|
@ -99,7 +94,7 @@ pub enum HighlightType {
|
|||
}
|
||||
|
||||
impl HighlightType {
|
||||
pub fn color(self) -> Color {
|
||||
pub(crate) fn color(self) -> Color {
|
||||
match self {
|
||||
HighlightType::None => BLACK,
|
||||
HighlightType::Primary => WHITE,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use crate::advance_ui::{AdvanceState, show_advance_menu};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, RenderResult, StateUpdate};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button_with_tooltip, ok_button};
|
||||
use crate::render_context::RenderContext;
|
||||
use server::advance::Advance;
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::status_phase::ChangeGovernment;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ChooseAdditionalAdvances {
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct ChooseAdditionalAdvances {
|
||||
government: String,
|
||||
possible: Vec<Advance>,
|
||||
selected: Vec<Advance>,
|
||||
|
|
@ -25,7 +25,7 @@ impl ChooseAdditionalAdvances {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn change_government_type_dialog(rc: &RenderContext) -> StateUpdate {
|
||||
pub(crate) fn change_government_type_dialog(rc: &RenderContext) -> RenderResult {
|
||||
show_advance_menu(
|
||||
rc,
|
||||
"Change government",
|
||||
|
|
@ -65,17 +65,17 @@ pub fn change_government_type_dialog(rc: &RenderContext) -> StateUpdate {
|
|||
.filter(|a| rc.shown_player.has_advance(a.advance))
|
||||
.count()
|
||||
- 1;
|
||||
StateUpdate::OpenDialog(ActiveDialog::ChooseAdditionalAdvances(
|
||||
StateUpdate::open_dialog(ActiveDialog::ChooseAdditionalAdvances(
|
||||
ChooseAdditionalAdvances::new(g.clone(), additional, needed),
|
||||
))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn choose_additional_advances_dialog(
|
||||
pub(crate) fn choose_additional_advances_dialog(
|
||||
rc: &RenderContext,
|
||||
choose: &ChooseAdditionalAdvances,
|
||||
) -> StateUpdate {
|
||||
) -> RenderResult {
|
||||
let t = if choose.selected.len() == choose.needed {
|
||||
OkTooltip::Valid("Change government type".to_string())
|
||||
} else {
|
||||
|
|
@ -89,7 +89,7 @@ pub fn choose_additional_advances_dialog(
|
|||
}
|
||||
|
||||
if cancel_button_with_tooltip(rc, "Back to choose government type") {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::ChangeGovernmentType);
|
||||
return StateUpdate::open_dialog(ActiveDialog::ChangeGovernmentType);
|
||||
}
|
||||
show_advance_menu(
|
||||
rc,
|
||||
|
|
@ -111,7 +111,7 @@ pub fn choose_additional_advances_dialog(
|
|||
} else {
|
||||
selected.push(a.advance);
|
||||
}
|
||||
StateUpdate::OpenDialog(ActiveDialog::ChooseAdditionalAdvances(
|
||||
StateUpdate::open_dialog(ActiveDialog::ChooseAdditionalAdvances(
|
||||
ChooseAdditionalAdvances {
|
||||
government: choose.government.clone(),
|
||||
possible: choose.possible.clone(),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::client_state::{CameraMode, MousePosition, State, StateUpdate};
|
||||
use crate::log_ui::break_text;
|
||||
use crate::client_state::{MousePosition, State};
|
||||
use crate::layout_ui::rect_from;
|
||||
use crate::render_context::RenderContext;
|
||||
use macroquad::color::{Color, GRAY};
|
||||
use macroquad::input::mouse_position;
|
||||
|
|
@ -8,7 +8,7 @@ use macroquad::prelude::{draw_circle, draw_rectangle, get_time};
|
|||
|
||||
const TOOLTIP_DELAY: f64 = 0.5;
|
||||
|
||||
pub fn update(state: &mut State) {
|
||||
pub(crate) fn update(state: &mut State) {
|
||||
let now = get_time();
|
||||
state
|
||||
.mouse_positions
|
||||
|
|
@ -20,20 +20,21 @@ pub fn update(state: &mut State) {
|
|||
}
|
||||
|
||||
fn is_rect_tooltip_active(rc: &RenderContext, rect: Rect) -> bool {
|
||||
rc.state
|
||||
.mouse_positions
|
||||
.iter()
|
||||
.all(|mp| rect.contains(rc.screen_to_world(mp.position)))
|
||||
rc.stage.is_tooltip()
|
||||
&& rc
|
||||
.state
|
||||
.mouse_positions
|
||||
.iter()
|
||||
.all(|mp| rect.contains(rc.screen_to_world(mp.position)))
|
||||
}
|
||||
|
||||
pub fn show_tooltip_for_rect(
|
||||
pub(crate) fn show_tooltip_for_rect(
|
||||
rc: &RenderContext,
|
||||
tooltip: &[String],
|
||||
rect: Rect,
|
||||
right_offset: f32,
|
||||
) {
|
||||
let origin = rect.point();
|
||||
let screen_origin = rc.world_to_screen(rect.point());
|
||||
if is_rect_tooltip_active(rc, rect) {
|
||||
draw_rectangle(
|
||||
origin.x,
|
||||
|
|
@ -42,28 +43,28 @@ pub fn show_tooltip_for_rect(
|
|||
rect.size().y,
|
||||
Color::new(0.0, 0.0, 0.0, 0.5),
|
||||
);
|
||||
let _ = rc.with_camera(CameraMode::Screen, |rc| {
|
||||
show_tooltip_text(rc, tooltip, screen_origin, right_offset);
|
||||
StateUpdate::None
|
||||
});
|
||||
show_tooltip_text(rc, tooltip, rect.point(), right_offset);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_circle_tooltip_active(rc: &RenderContext, center: Vec2, radius: f32) -> bool {
|
||||
rc.state
|
||||
.mouse_positions
|
||||
.iter()
|
||||
.all(|mp| (center - rc.screen_to_world(mp.position)).length() < radius)
|
||||
rc.stage.is_tooltip()
|
||||
&& rc
|
||||
.state
|
||||
.mouse_positions
|
||||
.iter()
|
||||
.all(|mp| (center - rc.screen_to_world(mp.position)).length() < radius)
|
||||
}
|
||||
|
||||
pub fn show_tooltip_for_circle(rc: &RenderContext, tooltip: &[String], center: Vec2, radius: f32) {
|
||||
let screen_center = rc.world_to_screen(center);
|
||||
pub(crate) fn show_tooltip_for_circle(
|
||||
rc: &RenderContext,
|
||||
tooltip: &[String],
|
||||
center: Vec2,
|
||||
radius: f32,
|
||||
) {
|
||||
if is_circle_tooltip_active(rc, center, radius) {
|
||||
draw_circle(center.x, center.y, radius, Color::new(0.0, 0.0, 0.0, 0.5));
|
||||
let _ = rc.with_camera(CameraMode::Screen, |rc| {
|
||||
show_tooltip_text(rc, tooltip, screen_center + vec2(radius, radius), 50.);
|
||||
StateUpdate::None
|
||||
});
|
||||
show_tooltip_text(rc, tooltip, center + vec2(radius, radius), 50.);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ fn show_tooltip_text(rc: &RenderContext, tooltip: &[String], origin: Vec2, right
|
|||
vec2(acc.x.max(d.width), acc.y + 20.)
|
||||
});
|
||||
|
||||
let tooltip_rect = Rect::new(origin.x, origin.y, total.x, total.y);
|
||||
let tooltip_rect = rect_from(origin, total);
|
||||
let w = tooltip_rect.size().x + 10.;
|
||||
let sx = state.screen_size.x - right_offset;
|
||||
let x = tooltip_rect.left().min(sx - w);
|
||||
|
|
@ -86,7 +87,3 @@ fn show_tooltip_text(rc: &RenderContext, tooltip: &[String], origin: Vec2, right
|
|||
state.draw_text(line, x + 5., y + 20. + i as f32 * 20.);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_tooltip_description(parts: &mut Vec<String>, label: &str) {
|
||||
break_text(label, 70, parts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
use macroquad::math::{Vec2, u32, vec2};
|
||||
use macroquad::shapes::draw_circle;
|
||||
|
||||
use server::game::Game;
|
||||
use server::position::Position;
|
||||
use server::unit::{Unit, UnitType, carried_units};
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, NO_UPDATE, RenderResult};
|
||||
use crate::hex_ui;
|
||||
use crate::select_ui::HighlightType;
|
||||
|
||||
use crate::layout_ui::{draw_scaled_icon_with_tooltip, is_in_circle};
|
||||
use crate::log_ui::break_text;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip::{add_tooltip_description, show_tooltip_for_circle};
|
||||
use crate::tooltip::show_tooltip_for_circle;
|
||||
use itertools::Itertools;
|
||||
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
|
||||
use server::movement::{MoveDestination, MovementRestriction};
|
||||
use server::player::Player;
|
||||
use server::wonder::Wonder;
|
||||
|
||||
pub struct UnitPlace {
|
||||
pub(crate) struct UnitPlace {
|
||||
pub center: Vec2,
|
||||
pub radius: f32,
|
||||
}
|
||||
|
||||
impl UnitPlace {
|
||||
pub fn new(center: Vec2, radius: f32) -> UnitPlace {
|
||||
pub(crate) fn new(center: Vec2, radius: f32) -> UnitPlace {
|
||||
UnitPlace { center, radius }
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ struct UnitHighlight {
|
|||
highlight_type: HighlightType,
|
||||
}
|
||||
|
||||
pub fn draw_unit_type(
|
||||
pub(crate) fn draw_unit_type(
|
||||
rc: &RenderContext,
|
||||
unit_highlight_type: HighlightType,
|
||||
center: Vec2,
|
||||
|
|
@ -48,13 +48,8 @@ pub fn draw_unit_type(
|
|||
} else {
|
||||
radius + 2.
|
||||
};
|
||||
draw_circle(center.x, center.y, r, unit_highlight_type.color());
|
||||
draw_circle(
|
||||
center.x,
|
||||
center.y,
|
||||
radius - 2.,
|
||||
rc.player_color(player_index),
|
||||
);
|
||||
rc.draw_circle(center, r, unit_highlight_type.color());
|
||||
rc.draw_circle(center, radius - 2., rc.player_color(player_index));
|
||||
let icon_size = radius * 1.1;
|
||||
|
||||
draw_scaled_icon_with_tooltip(
|
||||
|
|
@ -88,7 +83,7 @@ fn unit_place(rc: &RenderContext, index: usize, position: Position) -> UnitPlace
|
|||
}
|
||||
}
|
||||
|
||||
pub fn click_unit(
|
||||
pub(crate) fn click_unit(
|
||||
rc: &RenderContext,
|
||||
pos: Position,
|
||||
mouse_pos: Vec2,
|
||||
|
|
@ -121,7 +116,7 @@ pub fn click_unit(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn draw_units(rc: &RenderContext, tooltip: bool) {
|
||||
pub(crate) fn draw_units(rc: &RenderContext, tooltip: bool) {
|
||||
let player = rc.shown_player.index;
|
||||
let highlighted_units = match rc.state.active_dialog {
|
||||
ActiveDialog::MoveUnits(ref s) => {
|
||||
|
|
@ -252,13 +247,13 @@ pub trait UnitSelection {
|
|||
fn player_index(&self) -> usize;
|
||||
}
|
||||
|
||||
pub fn unit_selection_click<T: UnitSelection + Clone>(
|
||||
pub(crate) fn unit_selection_click<T: UnitSelection + Clone>(
|
||||
rc: &RenderContext,
|
||||
pos: Position,
|
||||
mouse_pos: Vec2,
|
||||
sel: &T,
|
||||
on_change: impl Fn(T) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
on_change: impl Fn(T) -> RenderResult,
|
||||
) -> RenderResult {
|
||||
let p = rc.game.player(sel.player_index());
|
||||
if let Some(unit_id) = click_unit(rc, pos, mouse_pos, p, true) {
|
||||
if sel.can_select(rc.game, p.get_unit(unit_id)) {
|
||||
|
|
@ -267,10 +262,13 @@ pub fn unit_selection_click<T: UnitSelection + Clone>(
|
|||
return on_change(new);
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
NO_UPDATE
|
||||
}
|
||||
|
||||
pub fn units_on_tile(game: &Game, pos: Position) -> impl Iterator<Item = (usize, Unit)> + '_ {
|
||||
pub(crate) fn units_on_tile(
|
||||
game: &Game,
|
||||
pos: Position,
|
||||
) -> impl Iterator<Item = (usize, Unit)> + '_ {
|
||||
game.players.iter().flat_map(move |p| {
|
||||
p.units.iter().filter_map(move |unit| {
|
||||
if unit.position == pos {
|
||||
|
|
@ -282,7 +280,7 @@ pub fn units_on_tile(game: &Game, pos: Position) -> impl Iterator<Item = (usize,
|
|||
})
|
||||
}
|
||||
|
||||
pub fn unit_label(unit: &Unit, army_move: bool, game: &Game) -> String {
|
||||
pub(crate) fn unit_label(unit: &Unit, army_move: bool, game: &Game) -> String {
|
||||
let name = unit.unit_type.name(game);
|
||||
let mut notes = vec![];
|
||||
|
||||
|
|
@ -320,7 +318,7 @@ pub fn unit_label(unit: &Unit, army_move: bool, game: &Game) -> String {
|
|||
format!("{name}{suffix}")
|
||||
}
|
||||
|
||||
pub fn unit_selection_clicked(unit_id: u32, units: &mut Vec<u32>) {
|
||||
pub(crate) fn unit_selection_clicked(unit_id: u32, units: &mut Vec<u32>) {
|
||||
if units.contains(&unit_id) {
|
||||
// deselect unit
|
||||
units.retain(|&id| id != unit_id);
|
||||
|
|
@ -329,13 +327,13 @@ pub fn unit_selection_clicked(unit_id: u32, units: &mut Vec<u32>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_unit_description(rc: &RenderContext, parts: &mut Vec<String>, u: UnitType) {
|
||||
pub(crate) fn add_unit_description(rc: &RenderContext, parts: &mut Vec<String>, u: UnitType) {
|
||||
parts.push(format!("Cost: {}", u.cost()));
|
||||
add_tooltip_description(parts, &u.description());
|
||||
break_text(parts, &u.description());
|
||||
if let UnitType::Leader(l) = u {
|
||||
for a in &rc.game.cache.get_leader(&l).abilities {
|
||||
parts.push(format!("Leader ability: {}", a.name));
|
||||
add_tooltip_description(parts, &a.description);
|
||||
break_text(parts, &a.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
too-many-arguments-threshold = 8
|
||||
too-many-arguments-threshold = 10
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||
use std::fmt::Display;
|
||||
use std::ops::{Add, Sub};
|
||||
|
||||
use crate::city_pieces::lose_building;
|
||||
use crate::content::custom_actions::CustomActionType::ForcedLabor;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::events::{EventOrigin, EventPlayer};
|
||||
|
|
@ -368,8 +369,11 @@ pub(crate) fn lose_city(game: &mut Game, player: &EventPlayer, position: Positio
|
|||
}
|
||||
|
||||
pub(crate) fn raze_city(game: &mut Game, player: &EventPlayer, position: Position) {
|
||||
let city = lose_city(game, player, position);
|
||||
for wonder in &city.pieces.wonders {
|
||||
for b in &player.get(game).get_city(position).pieces.buildings(None) {
|
||||
lose_building(game, player, *b, position);
|
||||
}
|
||||
for wonder in &player.get(game).get_city(position).pieces.wonders.clone() {
|
||||
destroy_wonder(game, player, *wonder, position);
|
||||
}
|
||||
lose_city(game, player, position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ pub struct Civilization {
|
|||
}
|
||||
|
||||
impl Civilization {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
name: &str,
|
||||
special_advances: Vec<SpecialAdvanceInfo>,
|
||||
|
|
@ -25,14 +26,17 @@ impl Civilization {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_barbarian(&self) -> bool {
|
||||
self.name == BARBARIANS
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_pirates(&self) -> bool {
|
||||
self.name == PIRATES
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_human(&self) -> bool {
|
||||
!self.is_barbarian() && !self.is_pirates()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -368,24 +368,30 @@ pub(crate) fn conquer_city(
|
|||
attacker: &EventPlayer,
|
||||
defender: &EventPlayer,
|
||||
) {
|
||||
let city = lose_city(game, defender, position);
|
||||
let attacker_is_human = attacker.get(game).is_human();
|
||||
let size = city.mood_modified_size(attacker.get(game));
|
||||
let d = defender.get(game);
|
||||
let size = d.get_city(position).mood_modified_size(d);
|
||||
if attacker_is_human {
|
||||
attacker.gain_resources(game, ResourcePile::gold(size as u8));
|
||||
}
|
||||
|
||||
if attacker.get(game).is_city_available() {
|
||||
let city = lose_city(game, defender, position);
|
||||
gain_city(game, attacker, city);
|
||||
if attacker_is_human {
|
||||
take_over_city(game, position, attacker, defender);
|
||||
}
|
||||
set_city_mood(game, position, &attacker.origin, Angry);
|
||||
} else {
|
||||
raze_city(game, defender, position);
|
||||
if attacker_is_human {
|
||||
attacker.gain_resources(game, ResourcePile::gold(city.size() as u8));
|
||||
attacker
|
||||
.with_origin(EventOrigin::Ability("Raze captured city".to_string()))
|
||||
.gain_resources(
|
||||
game,
|
||||
ResourcePile::gold(defender.get(game).get_city(position).size() as u8),
|
||||
);
|
||||
}
|
||||
raze_city(game, defender, position);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,44 +54,52 @@ fn war_ships() -> AdvanceBuilder {
|
|||
|
||||
fn cartography() -> AdvanceBuilder {
|
||||
AdvanceInfo::builder(
|
||||
Advance::Cartography,"Cartography",
|
||||
"Gain 1 idea after a move action where you moved a Ship. If you used navigation, gain an additional 1 culture token.", )
|
||||
.with_advance_bonus(CultureToken)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.before_move,
|
||||
0,
|
||||
|game, i, (), p| {
|
||||
// info is the action that we last used this ability for
|
||||
let key = game.actions_left.to_string();
|
||||
if p.get(game).event_info.get("Cartography").is_some_and(|info| info == &key) {
|
||||
return;
|
||||
}
|
||||
let mut ship = false;
|
||||
let mut navigation = false;
|
||||
for id in &i.units {
|
||||
let unit = p.get(game).get_unit(*id);
|
||||
if unit.is_ship() {
|
||||
ship = true;
|
||||
if !unit.position.is_neighbor(i.to) {
|
||||
navigation = true;
|
||||
}
|
||||
Advance::Cartography,
|
||||
"Cartography",
|
||||
"Gain 1 idea after a move action where you moved a Ship. \
|
||||
If you used navigation, gain an additional 1 culture token.",
|
||||
)
|
||||
.with_advance_bonus(CultureToken)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.before_move,
|
||||
0,
|
||||
|game, i, (), p| {
|
||||
if game.map.is_land(i.from) {
|
||||
// ship construction (or no ship at all)
|
||||
return;
|
||||
}
|
||||
|
||||
// info is the action that we last used this ability for
|
||||
let key = game.actions_left.to_string();
|
||||
if p.get(game)
|
||||
.event_info
|
||||
.get("Cartography")
|
||||
.is_some_and(|info| info == &key)
|
||||
{
|
||||
return;
|
||||
}
|
||||
let mut ship = false;
|
||||
let mut navigation = false;
|
||||
for id in &i.units {
|
||||
let unit = p.get(game).get_unit(*id);
|
||||
if unit.is_ship() {
|
||||
ship = true;
|
||||
if !unit.position.is_neighbor(i.to) {
|
||||
navigation = true;
|
||||
}
|
||||
}
|
||||
if ship {
|
||||
p.get_mut(game).event_info.insert("Cartography".to_string(), key);
|
||||
p.gain_resources(
|
||||
game,
|
||||
ResourcePile::ideas(1),
|
||||
);
|
||||
if navigation {
|
||||
p.gain_resources(
|
||||
game,
|
||||
ResourcePile::culture_tokens(1),
|
||||
);
|
||||
}
|
||||
}
|
||||
if ship {
|
||||
p.get_mut(game)
|
||||
.event_info
|
||||
.insert("Cartography".to_string(), key);
|
||||
p.gain_resources(game, ResourcePile::ideas(1));
|
||||
if navigation {
|
||||
p.gain_resources(game, ResourcePile::culture_tokens(1));
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::ability_initializer::{
|
|||
AbilityInitializerBuilder, AbilityInitializerSetup, AbilityListeners,
|
||||
};
|
||||
use crate::advance::{Advance, gain_advance_without_payment};
|
||||
use crate::city::{City, activate_city};
|
||||
use crate::city::{City, MoodState, activate_city};
|
||||
use crate::content::ability::AbilityBuilder;
|
||||
use crate::content::advances::AdvanceGroup;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
|
|
@ -44,7 +44,11 @@ impl LeaderAbility {
|
|||
action,
|
||||
|c| c.any_times().action().tokens(1),
|
||||
move |b| use_get_advance(b, group),
|
||||
move |game, p| !advances_in_group(game, p, group).is_empty(),
|
||||
move |game, p| {
|
||||
!advances_in_group(game, p, group).is_empty()
|
||||
&& p.try_get_city(leader_position(p))
|
||||
.is_some_and(|c| c.mood_state == MoodState::Happy)
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ pub mod cache;
|
|||
pub mod card;
|
||||
pub mod city;
|
||||
pub mod city_pieces;
|
||||
mod civilization;
|
||||
pub mod civilization;
|
||||
pub mod collect;
|
||||
pub mod combat;
|
||||
mod combat_listeners;
|
||||
|
|
|
|||
|
|
@ -245,7 +245,15 @@ fn reachable_with_navigation(player: &Player, units: &[u32], map: &Map) -> Vec<M
|
|||
}
|
||||
});
|
||||
if let Some(ship) = ship {
|
||||
let start = ship.neighbors().into_iter().find(|n| map.is_outside(*n));
|
||||
let start = ship.neighbors().into_iter().find(|n| {
|
||||
// otherwise we might have the ship position as only neighbor
|
||||
map.is_outside(*n)
|
||||
&& n.neighbors()
|
||||
.iter()
|
||||
.filter(|nn| map.is_inside(**nn))
|
||||
.count()
|
||||
> 1
|
||||
});
|
||||
if let Some(start) = start {
|
||||
let mut perimeter = vec![ship];
|
||||
|
||||
|
|
|
|||
|
|
@ -349,7 +349,6 @@ pub struct OnAdvanceInfo {
|
|||
|
||||
pub struct MoveInfo {
|
||||
pub units: Vec<u32>,
|
||||
#[allow(dead_code)]
|
||||
pub from: Position,
|
||||
pub to: Position,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::city::execute_found_city_action;
|
|||
use crate::collect::{Collect, base_collect_event_origin, execute_collect};
|
||||
use crate::construct::Construct;
|
||||
use crate::content::ability::{
|
||||
Ability, advance_event_origin, combat_event_origin, recruit_event_origin,
|
||||
Ability, advance_event_origin, construct_event_origin, recruit_event_origin,
|
||||
};
|
||||
use crate::content::custom_actions::{
|
||||
CustomAction, CustomActionActivation, CustomActionType, can_play_custom_action,
|
||||
|
|
@ -128,7 +128,7 @@ impl PlayingActionType {
|
|||
match self {
|
||||
PlayingActionType::Advance => advance_event_origin(),
|
||||
PlayingActionType::FoundCity => EventOrigin::Ability("Found City".to_string()),
|
||||
PlayingActionType::Construct => combat_event_origin(),
|
||||
PlayingActionType::Construct => construct_event_origin(),
|
||||
PlayingActionType::Collect => base_collect_event_origin(),
|
||||
PlayingActionType::Recruit => recruit_event_origin(),
|
||||
PlayingActionType::IncreaseHappiness => happiness_base_event_origin(),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use crate::events::EventOrigin;
|
|||
use crate::game::Game;
|
||||
use enumset::EnumSetType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
|
||||
#[derive(EnumSetType, Serialize, Deserialize, Debug, Ord, PartialOrd, Hash)]
|
||||
pub enum SpecialAdvance {
|
||||
|
|
@ -55,6 +56,16 @@ pub enum SpecialAdvanceRequirement {
|
|||
Advance(Advance),
|
||||
}
|
||||
|
||||
impl SpecialAdvanceRequirement {
|
||||
#[must_use]
|
||||
pub fn name(&self, game: &Game) -> String {
|
||||
match self {
|
||||
SpecialAdvanceRequirement::AnyGovernment => "Any government".to_string(),
|
||||
SpecialAdvanceRequirement::Advance(a) => a.info(game).name.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SpecialAdvanceInfo {
|
||||
pub advance: SpecialAdvance,
|
||||
|
|
|
|||
|
|
@ -300,8 +300,13 @@ where
|
|||
"Pay to change government",
|
||||
)])
|
||||
},
|
||||
move |_game, _s, v| {
|
||||
set_paid2(v, true);
|
||||
move |game, s, v| {
|
||||
let cost = &s.choice[0];
|
||||
if cost.is_empty() {
|
||||
s.log(game, "Keep current government");
|
||||
} else {
|
||||
set_paid2(v, true);
|
||||
}
|
||||
},
|
||||
)
|
||||
.add_persistent_event_listener(
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ pub(crate) fn draw_wonder_from_pile(game: &mut Game) -> Option<Wonder> {
|
|||
"Wonders",
|
||||
|game| &mut game.wonders_left,
|
||||
|_| Vec::new(),
|
||||
|_| vec![],
|
||||
|_| vec![], // not used since wonders are not shuffled
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,17 @@ fn test_direct_capture_city_fortress() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_capture_and_raze_city() {
|
||||
JSON.test(
|
||||
"capture_and_raze_city",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
move_action(vec![0, 1, 2, 3], Position::from_offset("C1")),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_direct_capture_city_only_fortress() {
|
||||
JSON.test(
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -347,8 +347,7 @@
|
|||
"Player1: City Development: Pay 1 culture token, Gain 1 action, You may build a building in a city without spending an action and without paying resources."
|
||||
],
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay nothing with Captivi, Construct Only, Gain Fortress at C2",
|
||||
"Player1: Construct Building: Pay 1 action, Pay nothing with Captivi, Construct Only, Gain Fortress at C2",
|
||||
"Player1: Captivi: May replace resources with mood tokens"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -231,17 +231,6 @@
|
|||
"city_mood": "Angry"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -254,6 +243,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -314,8 +314,8 @@
|
|||
"log": [
|
||||
[
|
||||
"Player1: Move: marched 2 settlers, 2 infantry, 1 cavalry and 1 elephant from C2 to C1",
|
||||
"Player2: Combat: Lose city C1",
|
||||
"Player1: Combat: Gain 1 gold, Gain city C1",
|
||||
"Player2: Combat: Lose city C1",
|
||||
"Player1: Waste: Could not store 1 gold"
|
||||
],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -253,17 +253,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -276,6 +265,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -253,17 +253,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -276,6 +265,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -250,17 +250,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -273,6 +262,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -475,8 +475,7 @@
|
|||
"Player2: Waste: Could not store 2 ideas"
|
||||
],
|
||||
[
|
||||
"Player2: Combat: Pay 1 action",
|
||||
"Player2: Construct Building: Pay 1 wood and 1 ore with State Religion, Gain Temple at C1",
|
||||
"Player2: Construct Building: Pay 1 action, Pay 1 wood and 1 ore with State Religion, Gain Temple at C1",
|
||||
"Player2: State Religion: Reduce the food cost to 0"
|
||||
],
|
||||
[
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -438,8 +438,7 @@
|
|||
"Player1: Writing: Draw an action card, Draw an objective card, Gain 1 culture token"
|
||||
],
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 ore, Gain Academy at A1",
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 ore, Gain Academy at A1",
|
||||
"Player1: Academy: Gain 2 ideas"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -284,8 +284,7 @@
|
|||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 ore, City C2 became Neutral, Gain Observatory at C2",
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 ore, City C2 became Neutral, Gain Observatory at C2",
|
||||
"Player1: Observatory: Draw an action card, Observatory gained 1 action card"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -267,8 +267,7 @@
|
|||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 ore, Gain Port at A1 at the water tile A2"
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 ore, Gain Port at A1 at the water tile A2"
|
||||
]
|
||||
],
|
||||
"undo_limit": 0,
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -287,8 +287,7 @@
|
|||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 ore, City C2 became Neutral, Gain Observatory at C2",
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 ore, City C2 became Neutral, Gain Observatory at C2",
|
||||
"Player1: Observatory: Draw an action card, Observatory gained 1 action card"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -415,17 +415,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -438,6 +427,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -333,17 +333,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -356,6 +345,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -417,17 +417,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -440,6 +429,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -281,8 +281,7 @@
|
|||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 mood token with Captivi, Gain Market at A1",
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 mood token with Captivi, Gain Market at A1",
|
||||
"Player1: Captivi: May replace resources with mood tokens"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -413,17 +413,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -436,6 +425,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -418,17 +418,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -441,6 +430,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D8"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -346,17 +346,6 @@
|
|||
"Ability": "Move"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "B2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -369,6 +358,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "B2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -479,8 +479,8 @@
|
|||
],
|
||||
[
|
||||
"Player1: Move: marched 1 infantry from C2 to B2, Pay 1 action",
|
||||
"Player2: Combat: Lose city B2, Lose Port at B2",
|
||||
"Player1: Combat: Gain 2 gold, Gain city B2, Gain Port at B2 at the water tile C3, City B2 became Angry"
|
||||
"Player1: Combat: Gain 2 gold, Gain city B2, Gain Port at B2 at the water tile C3, City B2 became Angry",
|
||||
"Player2: Combat: Lose city B2, Lose Port at B2"
|
||||
],
|
||||
[
|
||||
"Player1: Provinces: Pay 1 culture token, City B2 became Happy",
|
||||
|
|
|
|||
|
|
@ -311,17 +311,6 @@
|
|||
"Ability": "Move"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -334,6 +323,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "D1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -392,8 +392,8 @@
|
|||
"log": [
|
||||
[
|
||||
"Player1: Move: marched Ragnar Lodbrok from E2 to D1, Pay 1 action",
|
||||
"Player2: Combat: Lose city D1",
|
||||
"Player1: Combat: Gain 1 gold, Gain city D1, City D1 became Angry",
|
||||
"Player2: Combat: Lose city D1",
|
||||
"Player1: Prey: Gain 2 gold",
|
||||
"Player2: Place Settler: Gain 1 settler at B2",
|
||||
"Player1: Waste: Could not store 1 gold"
|
||||
|
|
|
|||
234
server/tests/test_games/combat/capture_and_raze_city.json
Normal file
234
server/tests/test_games/combat/capture_and_raze_city.json
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
{
|
||||
"state": {
|
||||
"Movement": {
|
||||
"movement_actions_left": 2
|
||||
}
|
||||
},
|
||||
"players": [
|
||||
{
|
||||
"id": 0,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 5,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"mood_state": "Happy",
|
||||
"position": "A1"
|
||||
},
|
||||
{
|
||||
"mood_state": "Neutral",
|
||||
"activations": 8,
|
||||
"position": "C2"
|
||||
}
|
||||
],
|
||||
"destroyed_structures": {
|
||||
"cities": 6
|
||||
},
|
||||
"units": [
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Infantry",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Cavalry",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Infantry",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Elephant",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 7
|
||||
}
|
||||
],
|
||||
"civilization": "Rome",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining",
|
||||
"Tactics"
|
||||
],
|
||||
"incident_tokens": 2,
|
||||
"next_unit_id": 8
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"city_pieces": {
|
||||
"fortress": 1,
|
||||
"wonders": [
|
||||
"GreatWall"
|
||||
]
|
||||
},
|
||||
"mood_state": "Angry",
|
||||
"activations": 2,
|
||||
"position": "C1"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"civilization": "Greece",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining",
|
||||
"Tactics"
|
||||
],
|
||||
"incident_tokens": 3,
|
||||
"next_unit_id": 2
|
||||
}
|
||||
],
|
||||
"map": {
|
||||
"tiles": [
|
||||
[
|
||||
"A1",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"A2",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"A3",
|
||||
{
|
||||
"Exhausted": "Forest"
|
||||
}
|
||||
],
|
||||
[
|
||||
"B1",
|
||||
"Mountain"
|
||||
],
|
||||
[
|
||||
"B2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"B3",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"C1",
|
||||
"Barren"
|
||||
],
|
||||
[
|
||||
"C2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"C3",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"D2",
|
||||
"Water"
|
||||
]
|
||||
]
|
||||
},
|
||||
"starting_player_index": 0,
|
||||
"current_player_index": 0,
|
||||
"action_log": [
|
||||
{
|
||||
"age": 1,
|
||||
"rounds": [
|
||||
{
|
||||
"round": 1,
|
||||
"players": [
|
||||
{
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"action_log_index": 0,
|
||||
"log": [],
|
||||
"undo_limit": 0,
|
||||
"actions_left": 1,
|
||||
"round": 1,
|
||||
"age": 1,
|
||||
"messages": [
|
||||
"The game has started"
|
||||
],
|
||||
"dice_roll_outcomes": [
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
11,
|
||||
11,
|
||||
11,
|
||||
11
|
||||
],
|
||||
"wonders_left": [
|
||||
"Pyramids"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,359 @@
|
|||
{
|
||||
"state": {
|
||||
"Movement": {
|
||||
"movement_actions_left": 1,
|
||||
"moved_units": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
},
|
||||
"players": [
|
||||
{
|
||||
"id": 0,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 5,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"mood_state": "Happy",
|
||||
"position": "A1"
|
||||
},
|
||||
{
|
||||
"mood_state": "Neutral",
|
||||
"activations": 8,
|
||||
"position": "C2"
|
||||
}
|
||||
],
|
||||
"destroyed_structures": {
|
||||
"cities": 6
|
||||
},
|
||||
"units": [
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"movement_restrictions": [
|
||||
"Battle"
|
||||
],
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Cavalry",
|
||||
"movement_restrictions": [
|
||||
"Battle"
|
||||
],
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"movement_restrictions": [
|
||||
"Battle"
|
||||
],
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Elephant",
|
||||
"movement_restrictions": [
|
||||
"Battle"
|
||||
],
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"id": 7
|
||||
}
|
||||
],
|
||||
"civilization": "Rome",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining",
|
||||
"Tactics"
|
||||
],
|
||||
"incident_tokens": 2,
|
||||
"next_unit_id": 8
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
},
|
||||
"civilization": "Greece",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining",
|
||||
"Tactics"
|
||||
],
|
||||
"incident_tokens": 3,
|
||||
"next_unit_id": 2
|
||||
}
|
||||
],
|
||||
"map": {
|
||||
"tiles": [
|
||||
[
|
||||
"A1",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"A2",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"A3",
|
||||
{
|
||||
"Exhausted": "Forest"
|
||||
}
|
||||
],
|
||||
[
|
||||
"B1",
|
||||
"Mountain"
|
||||
],
|
||||
[
|
||||
"B2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"B3",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"C1",
|
||||
"Barren"
|
||||
],
|
||||
[
|
||||
"C2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"C3",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"D2",
|
||||
"Water"
|
||||
]
|
||||
]
|
||||
},
|
||||
"starting_player_index": 0,
|
||||
"current_player_index": 0,
|
||||
"action_log": [
|
||||
{
|
||||
"age": 1,
|
||||
"rounds": [
|
||||
{
|
||||
"round": 1,
|
||||
"players": [
|
||||
{
|
||||
"index": 0,
|
||||
"actions": [
|
||||
{
|
||||
"action": {
|
||||
"Movement": {
|
||||
"Move": {
|
||||
"units": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3
|
||||
],
|
||||
"destination": "C1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"combat_stats": {
|
||||
"round": 1,
|
||||
"battleground": "CityWithFortress",
|
||||
"attacker": {
|
||||
"position": "C2",
|
||||
"player": 0,
|
||||
"present": {
|
||||
"infantry": 2,
|
||||
"cavalry": 1,
|
||||
"elephants": 1
|
||||
}
|
||||
},
|
||||
"defender": {
|
||||
"position": "C1",
|
||||
"player": 1,
|
||||
"present": {
|
||||
"infantry": 2
|
||||
},
|
||||
"losses": {
|
||||
"infantry": 2
|
||||
}
|
||||
},
|
||||
"result": "AttackerWins",
|
||||
"city_mood": "Angry"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"player": 1,
|
||||
"Units": {
|
||||
"units": {
|
||||
"infantry": 2
|
||||
},
|
||||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
"resources": {
|
||||
"gold": 1
|
||||
},
|
||||
"balance": "Gain"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
"resources": {
|
||||
"gold": 3
|
||||
},
|
||||
"balance": "Gain"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Raze captured city"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": {
|
||||
"Building": "Fortress"
|
||||
},
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": {
|
||||
"Wonder": "GreatWall"
|
||||
},
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1: Move: marched 2 infantry, 1 cavalry and 1 elephant from C2 to C1"
|
||||
],
|
||||
[
|
||||
"Combat round 1",
|
||||
"Player1: Combat: Attacking with 2 infantry, 1 cavalry and 1 elephant, Roll 6 (infantry, +1 combat value), 6 (infantry, +1 combat value), 6 (infantry, no bonus), 6 (infantry, no bonus) for combined combat value of 26 and gets 2 hits against defending units, Gain 1 gold",
|
||||
"Player2: Combat: Defending with 2 infantry, Roll 1 (leader, no bonus), 1 (leader, no bonus), 1 (leader, no bonus) for combined combat value of 3 and gets 0 hits against attacking units, Combat modifiers: fortress added one extra die, fortress cancelled one hit, Lost 2 infantry at C1, Lose Fortress at C1, Lose Great Wall at C1, Lose city C1",
|
||||
"Player2: Choose Casualties: Remove all defending units",
|
||||
"Attacker wins",
|
||||
"Player1: Raze captured city: Gain 3 gold",
|
||||
"Player1: Waste: Could not store 4 gold"
|
||||
]
|
||||
],
|
||||
"undo_limit": 1,
|
||||
"actions_left": 1,
|
||||
"round": 1,
|
||||
"age": 1,
|
||||
"messages": [
|
||||
"The game has started"
|
||||
],
|
||||
"dice_roll_outcomes": [
|
||||
1,
|
||||
1
|
||||
],
|
||||
"dice_roll_log": [
|
||||
11,
|
||||
11,
|
||||
11,
|
||||
11,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"wonders_left": [
|
||||
"Pyramids"
|
||||
]
|
||||
}
|
||||
|
|
@ -411,17 +411,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -434,6 +423,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -280,17 +280,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -303,6 +292,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -253,17 +253,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -276,6 +265,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -254,17 +254,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -277,6 +266,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -235,17 +235,6 @@
|
|||
"city_mood": "Angry"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -258,6 +247,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -260,17 +260,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -283,6 +272,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -319,17 +319,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -342,6 +331,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -272,17 +272,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 2,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -295,6 +284,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 2,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@
|
|||
"balance": "Loss"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
"Ability": "Construct Building"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -499,8 +499,7 @@
|
|||
"Player1: Great Engineer: Great Engineer: You may build a building in a city without spending an action and without activating it., Gain 1 action"
|
||||
],
|
||||
[
|
||||
"Player1: Combat: Pay 1 action",
|
||||
"Player1: Construct Building: Pay 1 food, 1 wood and 1 ore with Captivi, Construct Only, Gain Fortress at C2",
|
||||
"Player1: Construct Building: Pay 1 action, Pay 1 food, 1 wood and 1 ore with Captivi, Construct Only, Gain Fortress at C2",
|
||||
"Player1: Captivi: May replace resources with mood tokens"
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -360,17 +360,6 @@
|
|||
"Advance": "Tactics"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -383,6 +372,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -452,8 +452,8 @@
|
|||
"Player2: Tactical Retreat: Player2 withdraws to B1",
|
||||
"Player1: Solar Eclipse: Gain 1 victory point for the Solar Eclipse",
|
||||
"Attacker wins",
|
||||
"Player2: Combat: Lose city C1, Lose Temple at C1",
|
||||
"Player1: Combat: Gain 1 gold, Gain city C1, Gain Temple at C1"
|
||||
"Player1: Combat: Gain 1 gold, Gain city C1, Gain Temple at C1",
|
||||
"Player2: Combat: Lose city C1, Lose Temple at C1"
|
||||
]
|
||||
],
|
||||
"undo_limit": 3,
|
||||
|
|
|
|||
|
|
@ -391,17 +391,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -414,6 +403,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -306,17 +306,6 @@
|
|||
"city_mood": "Neutral"
|
||||
},
|
||||
"items": [
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "B2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -329,6 +318,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "B2"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
@ -431,8 +431,8 @@
|
|||
"log": [
|
||||
[
|
||||
"Player1: Move: disembarked 1 cavalry and 1 elephant from C3 to B2",
|
||||
"Player2: Combat: Lose city B2, Lose Port at B2",
|
||||
"Player1: Combat: Gain 2 gold, Gain city B2, Gain Port at B2 at the water tile C3, City B2 became Angry",
|
||||
"Player2: Combat: Lose city B2, Lose Port at B2",
|
||||
"Player2: Place Settler: Gain 1 settler at C1",
|
||||
"Player1: Waste: Could not store 2 gold"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -267,17 +267,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -290,6 +279,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -263,17 +263,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -286,6 +275,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
|
|
@ -4,16 +4,24 @@
|
|||
{
|
||||
"event_type": {
|
||||
"StatusPhase": {
|
||||
"ChangeGovernmentType": true
|
||||
"DetermineFirstPlayer": 0
|
||||
}
|
||||
},
|
||||
"player": 0,
|
||||
"last_priority_used": 0,
|
||||
"handler": {
|
||||
"priority": 0,
|
||||
"request": "ChangeGovernment",
|
||||
"request": {
|
||||
"SelectPlayer": {
|
||||
"choices": [
|
||||
0,
|
||||
1
|
||||
],
|
||||
"description": "Determine the first player"
|
||||
}
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Change Government"
|
||||
"Ability": "Determine First Player"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +271,7 @@
|
|||
"Player2: Raze city: Did not raze a city"
|
||||
],
|
||||
[
|
||||
"Player1: Change Government: Pay nothing"
|
||||
"Player1: Change Government: Pay nothing, Keep current government"
|
||||
]
|
||||
],
|
||||
"undo_limit": 1,
|
||||
|
|
|
|||
|
|
@ -445,17 +445,6 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Resources": {
|
||||
|
|
@ -468,6 +457,17 @@
|
|||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 1,
|
||||
"Structure": {
|
||||
"structure": "CityCenter",
|
||||
"balance": "Loss",
|
||||
"position": "C1"
|
||||
},
|
||||
"origin": {
|
||||
"Ability": "Combat"
|
||||
}
|
||||
},
|
||||
{
|
||||
"player": 0,
|
||||
"Structure": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue