Skip to content

Commit

Permalink
Client (#98)
Browse files Browse the repository at this point in the history
* payment dialog

* collect resources

* collect resources

* collect resources

* collect resources
  • Loading branch information
zeitlinger authored Jan 3, 2025
1 parent 7fc48ab commit 4f67e9d
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 293 deletions.
12 changes: 8 additions & 4 deletions client/src/advance_ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate};
use crate::dialog_ui::dialog;
use crate::payment_ui::{payment_dialog, HasPayment, Payment, ResourcePayment};
use crate::resource_ui::{new_resource_map, ResourceType};
Expand Down Expand Up @@ -220,14 +220,17 @@ fn description(p: &Player, a: &Advance) -> Vec<String> {
parts
}

pub fn pay_advance_dialog(ap: &AdvancePayment, player: &ShownPlayer, game: &Game) -> StateUpdate {
pub fn pay_advance_dialog(
ap: &AdvancePayment,
player: &ShownPlayer,
game: &Game,
state: &State,
) -> StateUpdate {
let a = advances::get_advance_by_name(ap.name.as_str()).unwrap();

if can_advance(game, player, &a) {
payment_dialog(
player,
&format!("Pay for advance {}", ap.name),
description(game.get_player(player.index), &a),
ap,
AdvancePayment::valid,
|ap| {
Expand All @@ -239,6 +242,7 @@ pub fn pay_advance_dialog(ap: &AdvancePayment, player: &ShownPlayer, game: &Game
|ap, r| ap.payment.get(r).selectable.max > 0,
|ap, r| add(ap, r, 1),
|ap, r| add(ap, r, -1),
state,
)
} else {
advance_info(game, player, &a)
Expand Down
15 changes: 8 additions & 7 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use server::position::Position;

use crate::advance_ui::{pay_advance_dialog, show_advance_menu, show_free_advance_menu};
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate, StateUpdates};
use crate::collect_ui::{click_collect_option, collect_resources_dialog};
use crate::collect_ui::collect_resources_dialog;
use crate::construct_ui::pay_construction_dialog;
use crate::happiness_ui::{increase_happiness_dialog, increase_happiness_menu};
use crate::hex_ui::pixel_to_coordinate;
Expand Down Expand Up @@ -62,8 +62,8 @@ fn render(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
..Default::default()
};

draw_map(game, state);
let mut updates = StateUpdates::new();
updates.add(draw_map(game, state));
show_top_left(game, player, state);
show_top_center(game, player, state);
updates.add(player_select(game, player, state));
Expand All @@ -87,9 +87,9 @@ fn render(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
// playing actions
ActiveDialog::IncreaseHappiness(h) => increase_happiness_menu(h, player),
ActiveDialog::AdvanceMenu => show_advance_menu(game, player),
ActiveDialog::AdvancePayment(p) => pay_advance_dialog(p, player, game),
ActiveDialog::ConstructionPayment(p) => pay_construction_dialog(game, p, player),
ActiveDialog::CollectResources(c) => collect_resources_dialog(game, c, player),
ActiveDialog::AdvancePayment(p) => pay_advance_dialog(p, player, game, state),
ActiveDialog::ConstructionPayment(p) => pay_construction_dialog(game, p, player, state),
ActiveDialog::CollectResources(c) => collect_resources_dialog(game, c, state),
ActiveDialog::RecruitUnitSelection(s) => {
recruit_unit_ui::select_dialog(game, s, player, state)
}
Expand Down Expand Up @@ -144,10 +144,11 @@ pub fn try_click(game: &Game, state: &mut State, player: &ShownPlayer) -> StateU

if player.can_control {
match &state.active_dialog {
ActiveDialog::RemoveCasualties(_) | ActiveDialog::CollectResources(_) => {
StateUpdate::None
}
ActiveDialog::MoveUnits(s) => move_ui::click(pos, s, mouse_pos, game),
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::click_replace(pos, r),
ActiveDialog::RemoveCasualties(_s) => StateUpdate::None,
ActiveDialog::CollectResources(col) => click_collect_option(col, pos),
ActiveDialog::RazeSize1City => raze_city_confirm_dialog(game, player, pos),
ActiveDialog::PlaceSettler => {
if player.get(game).get_city(pos).is_some() {
Expand Down
56 changes: 23 additions & 33 deletions client/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,60 +85,58 @@ impl ActiveDialog {
}

#[must_use]
pub fn help_message(&self) -> Option<String> {
pub fn help_message(&self, game: &Game) -> Vec<String> {
match self {
ActiveDialog::None
| ActiveDialog::TileMenu(_)
| ActiveDialog::Log
| ActiveDialog::AdvanceMenu => None,
| ActiveDialog::AdvanceMenu => vec![],
ActiveDialog::IncreaseHappiness(_) => {
Some("Click on a city to increase happiness".to_string())
vec!["Click on a city to increase happiness".to_string()]
}
ActiveDialog::AdvancePayment(a) => {
Some(format!("Click on resources to pay for {}", a.name))
vec![format!("Click on resources to pay for {}", a.name)]
}
ActiveDialog::ConstructionPayment(c) => {
Some(format!("Click on resources to pay for {}", c.name))
vec![format!("Click on resources to pay for {}", c.name)]
}
ActiveDialog::CollectResources(_) => {
Some("Click on a tile to collect resources".to_string())
}
ActiveDialog::RecruitUnitSelection(_) => Some("Click on a unit to recruit".to_string()),
ActiveDialog::ReplaceUnits(_) => Some("Click on a unit to replace".to_string()),
ActiveDialog::CollectResources(collect) => collect.help_text(game),
ActiveDialog::RecruitUnitSelection(_) => vec!["Click on a unit to recruit".to_string()],
ActiveDialog::ReplaceUnits(_) => vec!["Click on a unit to replace".to_string()],
ActiveDialog::MoveUnits(m) => {
if m.start.is_some() {
Some("Click on a highlighted tile to move units".to_string())
vec!["Click on a highlighted tile to move units".to_string()]
} else {
Some("Click on a unit to move".to_string())
vec!["Click on a unit to move".to_string()]
}
}
ActiveDialog::CulturalInfluence => {
Some("Click on a building to influence its culture".to_string())
vec!["Click on a building to influence its culture".to_string()]
}
ActiveDialog::CulturalInfluenceResolution(_) => Some("todo".to_string()),
ActiveDialog::CulturalInfluenceResolution(_) => vec!["todo".to_string()],
ActiveDialog::FreeAdvance => {
Some("Click on an advance to take it for free".to_string())
vec!["Click on an advance to take it for free".to_string()]
}
ActiveDialog::RazeSize1City => {
Some("Click on a city to raze it - or click cancel".to_string())
vec!["Click on a city to raze it - or click cancel".to_string()]
}
ActiveDialog::CompleteObjectives => {
Some("Click on an objective to complete it".to_string())
vec!["Click on an objective to complete it".to_string()]
}
ActiveDialog::DetermineFirstPlayer => {
Some("Click on a player to determine first player".to_string())
vec!["Click on a player to determine first player".to_string()]
}
ActiveDialog::ChangeGovernmentType => {
Some("Click on a government type to change - or click cancel".to_string())
vec!["Click on a government type to change - or click cancel".to_string()]
}
ActiveDialog::ChooseAdditionalAdvances(_) => {
Some("Click on an advance to choose it".to_string())
vec!["Click on an advance to choose it".to_string()]
}
ActiveDialog::PlayActionCard => Some("Click on an action card to play it".to_string()),
ActiveDialog::PlaceSettler => Some("Click on a tile to place a settler".to_string()),
ActiveDialog::Retreat => Some("Click on a unit to retreat".to_string()),
ActiveDialog::RemoveCasualties(_) => Some("Click on a unit to remove it".to_string()),
ActiveDialog::WaitingForUpdate => Some("Waiting for server update".to_string()),
ActiveDialog::PlayActionCard => vec!["Click on an action card to play it".to_string()],
ActiveDialog::PlaceSettler => vec!["Click on a tile to place a settler".to_string()],
ActiveDialog::Retreat => vec!["Click on a unit to retreat".to_string()],
ActiveDialog::RemoveCasualties(_) => vec!["Click on a unit to remove it".to_string()],
ActiveDialog::WaitingForUpdate => vec!["Waiting for server update".to_string()],
}
}

Expand Down Expand Up @@ -365,14 +363,6 @@ impl State {
self.pending_update = None;
}

#[must_use]
pub fn is_collect(&self) -> bool {
if let ActiveDialog::CollectResources(_c) = &self.active_dialog {
return true;
}
false
}

pub fn update(&mut self, game: &Game, update: StateUpdate) -> GameSyncRequest {
match update {
StateUpdate::None => GameSyncRequest::None,
Expand Down
Loading

0 comments on commit 4f67e9d

Please sign in to comment.