Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor, bug fixes #172

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/action_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn base_or_custom_available(
custom: &CustomActionType,
) -> bool {
rc.can_play_action(action)
|| (rc.game.state == GameState::Playing
|| (rc.game.state() == &GameState::Playing
&& rc
.game
.is_custom_action_available(rc.shown_player.index, custom))
Expand Down
27 changes: 3 additions & 24 deletions client/src/advance_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use server::content::advances;
use server::game::GameState;
use server::player::Player;
use server::playing_actions::PlayingAction;
use server::status_phase::StatusPhaseAction;
use std::ops::Rem;

const COLUMNS: usize = 6;
Expand All @@ -39,7 +38,9 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
|a, p| {
if p.has_advance(&a.name) {
AdvanceState::Owned
} else if game.state == GameState::Playing && game.actions_left > 0 && p.can_advance(a)
} else if game.state() == &GameState::Playing
&& game.actions_left > 0
&& p.can_advance(a)
{
AdvanceState::Available
} else {
Expand All @@ -50,28 +51,6 @@ pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
)
}

pub fn show_free_advance_menu(rc: &RenderContext) -> StateUpdate {
show_advance_menu(
rc,
"Select a free advance",
|a, p| {
if p.can_advance_free(a) {
AdvanceState::Available
} else if p.has_advance(&a.name) {
AdvanceState::Owned
} else {
AdvanceState::Unavailable
}
},
|a| {
StateUpdate::execute_with_confirm(
vec![format!("Select {} as a free advance?", a.name)],
Action::StatusPhase(StatusPhaseAction::FreeAdvance(a.name.clone())),
)
},
)
}

pub fn show_advance_menu(
rc: &RenderContext,
title: &str,
Expand Down
32 changes: 9 additions & 23 deletions client/src/city_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use server::city::{City, MoodState};
use server::city_pieces::Building;
use server::collect::possible_resource_collections;
use server::content::custom_actions::CustomActionType;
use server::content::custom_phase_actions::Structure;
use server::content::custom_phase_actions::{SelectedStructure, Structure};
use server::game::Game;
use server::playing_actions::PlayingActionType;
use server::position::Position;
Expand Down Expand Up @@ -257,26 +257,12 @@ fn structure_selected(
let ActiveDialog::StructuresRequest(r) = &rc.state.active_dialog else {
panic!("invalid state");
};
if let Some(i) = r
.structures
.iter()
.position(|(pos, s)| s == &h.structure && pos == &position)
{
let mut new = r.clone();
new.structures.remove(i);
return Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
new,
)));
}
if r.request.choices.contains(&(position, h.structure.clone())) {
let mut new = r.clone();
new.structures.push((position, h.structure.clone()));
return Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
new,
)));
};
Some(StateUpdate::OpenDialog(ActiveDialog::StructuresRequest(
r.clone().toggle((position, h.structure.clone())),
)))
} else {
None
}
None
}

pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
Expand All @@ -285,13 +271,13 @@ pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {

let highlighted = match rc.state.active_dialog {
ActiveDialog::StructuresRequest(ref s) => highlight_structures(
&position_structures(city, &s.structures),
&position_structures(city, &s.selected),
HighlightType::Primary,
)
.into_iter()
.chain(highlight_structures(
&position_structures(city, &s.request.choices),
HighlightType::Secondary,
HighlightType::Choices,
))
.collect_vec(),
_ => vec![],
Expand Down Expand Up @@ -415,7 +401,7 @@ fn draw_wonders(
Ok(i)
}

fn position_structures(city: &City, list: &[(Position, Structure)]) -> Vec<Structure> {
fn position_structures(city: &City, list: &[SelectedStructure]) -> Vec<Structure> {
list.iter()
.filter_map(|(pos, st)| {
if pos == &city.position {
Expand Down
31 changes: 8 additions & 23 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use macroquad::prelude::clear_background;
use macroquad::prelude::*;

use server::action::Action;
use server::content::custom_phase_actions::CurrentEventResponse;
use server::game::Game;
use server::position::Position;

use crate::advance_ui::{pay_advance_dialog, show_free_advance_menu, show_paid_advance_menu};
use crate::advance_ui::{pay_advance_dialog, show_paid_advance_menu};
use crate::client_state::{
ActiveDialog, CameraMode, DialogChooser, State, StateUpdate, StateUpdates,
};
Expand All @@ -22,7 +21,6 @@ use crate::log_ui::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::status_phase_ui::raze_city_confirm_dialog;
use crate::unit_ui::unit_selection_click;
use crate::{
custom_actions_ui, custom_phase_ui, dialog_ui, influence_ui, map_ui, move_ui, recruit_unit_ui,
Expand Down Expand Up @@ -97,7 +95,7 @@ fn render(rc: &RenderContext, features: &Features) -> StateUpdate {
updates.add(show_tile_menu(rc, pos));
}
}
updates.add(try_click(rc));
updates.add(rc.with_camera(CameraMode::World, try_click));
updates.result()
}

Expand Down Expand Up @@ -130,8 +128,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
match &state.active_dialog {
ActiveDialog::None
| ActiveDialog::WaitingForUpdate
| ActiveDialog::CulturalInfluence(_)
| ActiveDialog::PositionRequest(_) => StateUpdate::None,
| ActiveDialog::CulturalInfluence(_) => StateUpdate::None,
ActiveDialog::DialogChooser(d) => dialog_chooser(rc, d),
ActiveDialog::Log => show_log(rc),

Expand All @@ -143,23 +140,17 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
ActiveDialog::CollectResources(c) => collect_dialog(rc, c),
ActiveDialog::RecruitUnitSelection(s) => recruit_unit_ui::select_dialog(rc, s),
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::replace_dialog(rc, r),
ActiveDialog::CulturalInfluenceResolution(r) => {
influence_ui::cultural_influence_resolution_dialog(rc, r)
}
ActiveDialog::ExploreResolution(r) => explore_dialog(rc, r),
ActiveDialog::MoveUnits(_) => move_ui::move_units_dialog(rc),
ActiveDialog::MovePayment(p) => move_ui::move_payment_dialog(rc, p),

//status phase
ActiveDialog::FreeAdvance => show_free_advance_menu(rc),
ActiveDialog::RazeSize1City => status_phase_ui::raze_city_dialog(rc),
ActiveDialog::CompleteObjectives => status_phase_ui::complete_objectives_dialog(rc),
ActiveDialog::ChangeGovernmentType => status_phase_ui::change_government_type_dialog(rc),
ActiveDialog::ChangeGovernmentType(r) => {
status_phase_ui::change_government_type_dialog(rc, r)
}
ActiveDialog::ChooseAdditionalAdvances(a) => {
status_phase_ui::choose_additional_advances_dialog(rc, a)
}
ActiveDialog::DetermineFirstPlayer => status_phase_ui::determine_first_player_dialog(rc),

ActiveDialog::Sports((p, pos)) => custom_actions_ui::sports(rc, p, *pos),
ActiveDialog::Taxes(p) => custom_actions_ui::taxes(rc, p),
ActiveDialog::Theaters(p) => custom_actions_ui::theaters(rc, p),
Expand All @@ -174,6 +165,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
ActiveDialog::UnitsRequest(r) => custom_phase_ui::select_units_dialog(rc, r),
ActiveDialog::StructuresRequest(r) => custom_phase_ui::select_structures_dialog(rc, r),
ActiveDialog::BoolRequest => custom_phase_ui::bool_request_dialog(rc),
ActiveDialog::PositionRequest(r) => custom_phase_ui::position_request_dialog(rc, r),
}
}

Expand Down Expand Up @@ -223,15 +215,8 @@ fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position)
ActiveDialog::ReplaceUnits(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
StateUpdate::OpenDialog(ActiveDialog::ReplaceUnits(new.clone()))
}),
ActiveDialog::RazeSize1City => raze_city_confirm_dialog(rc, pos),
ActiveDialog::PositionRequest(r) => {
if r.choices.contains(&pos) {
StateUpdate::Execute(Action::CustomPhaseEvent(
CurrentEventResponse::SelectPosition(pos),
))
} else {
StateUpdate::None
}
StateUpdate::OpenDialog(ActiveDialog::PositionRequest(r.clone().toggle(pos)))
}
ActiveDialog::UnitsRequest(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
StateUpdate::OpenDialog(ActiveDialog::UnitsRequest(new.clone()))
Expand Down
Loading