Skip to content

Commit

Permalink
Client (#104)
Browse files Browse the repository at this point in the history
* settler button to found city

* always show some resources

* fmt
  • Loading branch information
zeitlinger authored Jan 7, 2025
1 parent e260560 commit f4edaca
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
Binary file removed client/assets/castle-manor-14-svgrepo-com.png
Binary file not shown.
2 changes: 0 additions & 2 deletions client/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct Assets {
pub log: Texture2D,
pub end_turn: Texture2D,
pub advances: Texture2D,
pub settle: Texture2D,

// UI
pub redo: Texture2D,
Expand Down Expand Up @@ -64,7 +63,6 @@ impl Assets {
end_turn: load_png(include_bytes!("../assets/hour-glass-svgrepo-com.png")),
log: load_png(include_bytes!("../assets/scroll-svgrepo-com.png")),
move_units: load_png(include_bytes!("../assets/route-start-svgrepo-com.png")),
settle: load_png(include_bytes!("../assets/castle-manor-14-svgrepo-com.png")),

// UI
redo: load_png(include_bytes!("../assets/redo-svgrepo-com.png")),
Expand Down
2 changes: 1 addition & 1 deletion client/src/collect_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn collect_resources_dialog(
state: &State,
player: &ShownPlayer,
) -> StateUpdate {
show_resource_pile(state, player, &collect.collected());
show_resource_pile(state, player, &collect.collected(), &[]);

let city = game.get_city(collect.player_index, collect.city_position);

Expand Down
4 changes: 2 additions & 2 deletions client/src/happiness_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use server::resource_pile::ResourcePile;

use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate};
use crate::dialog_ui::{cancel_button, ok_button, OkTooltip};
use crate::resource_ui::show_resource_pile;
use crate::resource_ui::{show_resource_pile, ResourceType};

#[derive(Clone)]
pub struct IncreaseHappiness {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn increase_happiness_menu(
state: &State,
game: &Game,
) -> StateUpdate {
show_resource_pile(state, player, &h.cost);
show_resource_pile(state, player, &h.cost, &[ResourceType::MoodTokens]);

let tooltip = if player.get(game).resources.can_afford(&h.cost) {
OkTooltip::Valid("Increase happiness".to_string())
Expand Down
4 changes: 2 additions & 2 deletions client/src/influence_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::client_state::{ShownPlayer, State, StateUpdate};
use crate::dialog_ui::{cancel_button_with_tooltip, ok_button, OkTooltip};
use crate::hex_ui;
use crate::layout_ui::is_in_circle;
use crate::resource_ui::show_resource_pile;
use crate::resource_ui::{show_resource_pile, ResourceType};
use crate::tooltip::show_tooltip_for_circle;
use macroquad::input::{is_mouse_button_pressed, MouseButton};
use macroquad::math::Vec2;
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn cultural_influence_resolution_dialog(
) -> StateUpdate {
let name = building_name(r.city_piece);
let pile = ResourcePile::culture_tokens(r.roll_boost_cost);
show_resource_pile(state, player, &pile);
show_resource_pile(state, player, &pile, &[ResourceType::CultureTokens]);
if ok_button(
state,
OkTooltip::Valid(format!("Influence {name} for {pile}")),
Expand Down
2 changes: 1 addition & 1 deletion client/src/local_client/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn setup_local_game() -> Game {
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
add_unit(&mut game, "B3", player_index1, UnitType::Settler);
// game.players[player_index1].active_leader =
// Some(Leader::builder("Alexander", "", "", "", "").build());

Expand Down
6 changes: 3 additions & 3 deletions client/src/map_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use server::game::{Game, GameState};
use server::map::Terrain;
use server::playing_actions::PlayingAction;
use server::position::Position;
use server::unit::{MovementRestriction, Unit};
use server::unit::{MovementRestriction, Unit, UnitType};

use crate::city_ui::{draw_city, show_city_menu, CityMenu, IconAction, IconActionVec};
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate};
Expand Down Expand Up @@ -177,8 +177,8 @@ fn found_city_button(state: &State, settlers: Vec<Unit>) -> Option<IconAction<'_
None
} else {
Some((
&state.assets.settle,
"Settle".to_string(),
&state.assets.units[&UnitType::Settler],
"Found a new city".to_string(),
Box::new(move || {
let settler = settlers
.iter()
Expand Down
9 changes: 7 additions & 2 deletions client/src/resource_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ pub fn resource_name(t: ResourceType) -> &'static str {
}
}

pub fn show_resource_pile(state: &State, player: &ShownPlayer, p: &ResourcePile) {
pub fn show_resource_pile(
state: &State,
player: &ShownPlayer,
p: &ResourcePile,
must_show: &[ResourceType],
) {
let resource_map = new_resource_map(p);
let show: Vec<ResourceType> = resource_types()
.into_iter()
.filter(|r| resource_map[r] > 0)
.filter(|r| resource_map[r] > 0 || must_show.contains(r))
.collect();
for (i, r) in show.iter().rev().enumerate() {
let x = (show.len() - i) as i8 - 3;
Expand Down

0 comments on commit f4edaca

Please sign in to comment.