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

use icons #93

Merged
merged 23 commits into from
Dec 31, 2024
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 .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Server - Release
name: Release

on:
release:
Expand Down
Binary file added client/assets/angry-face-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/down-arrow-circle-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/export-2-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/gold-ingots-gold-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/happy-emoji-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/hour-glass-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/import-3-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/lab-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/left-arrow-circle-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/light-bulb-idea-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/neutral-face-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/redo-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/reset-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/right-arrow-circle-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/rock-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/scroll-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/theater-drama-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/triangle-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/trophy-cup-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/undo-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/up-arrow-circle-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/walk-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/wheat-grain-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/wood-nature-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/zoom-in-1462-svgrepo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/assets/zoom-out-1460-svgrepo-com.png
107 changes: 104 additions & 3 deletions client/src/assets.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::client::Features;
use macroquad::prelude::{load_texture, load_ttf_font, Color, Image, RectOffset, Texture2D};
use crate::resource_ui::ResourceType;
use macroquad::prelude::{load_texture, load_ttf_font, Color, Image, ImageFormat, RectOffset};
use macroquad::texture::Texture2D;
use macroquad::ui::{root_ui, Skin};
use server::map::Terrain;
use server::unit::UnitType;
Expand All @@ -9,18 +11,113 @@ pub struct Assets {
pub terrain: HashMap<Terrain, Texture2D>,
pub units: HashMap<UnitType, Texture2D>,
pub skin: Skin,

// mood icons
pub angry: Texture2D,
pub neutral: Texture2D,
pub happy: Texture2D,

// action icons
pub movement: Texture2D,
pub log: Texture2D,
pub end_turn: Texture2D,
pub advances: Texture2D,
pub redo: Texture2D,
pub reset: Texture2D,
pub undo: Texture2D,

// UI
pub zoom_in: Texture2D,
pub zoom_out: Texture2D,
pub up: Texture2D,
pub down: Texture2D,
pub left: Texture2D,
pub right: Texture2D,
pub victory_points: Texture2D,
pub active_player: Texture2D,

// Admin
pub import: Texture2D,
pub export: Texture2D,

// pub cities: HashMap<CityType, Texture2D>,
// pub resources: HashMap<Resource, Texture2D>,
pub resources: HashMap<ResourceType, Texture2D>,
}

impl Assets {
pub async fn new(features: &Features) -> Self {
let happy = load_png(include_bytes!("../assets/happy-emoji-svgrepo-com.png"));
Self {
terrain: Self::terrain(features).await,
units: HashMap::new(),
skin: Self::skin(features).await,

// mood icons
angry: load_png(include_bytes!("../assets/angry-face-svgrepo-com.png")),
neutral: load_png(include_bytes!("../assets/neutral-face-svgrepo-com.png")),
happy: happy.clone(),

// resource icons
resources: [
(
ResourceType::Food,
load_png(include_bytes!("../assets/wheat-grain-svgrepo-com.png")),
),
(
ResourceType::Wood,
load_png(include_bytes!("../assets/wood-nature-svgrepo-com.png")),
),
(
ResourceType::Ore,
load_png(include_bytes!("../assets/rock-svgrepo-com.png")),
),
(
ResourceType::Ideas,
load_png(include_bytes!("../assets/light-bulb-idea-svgrepo-com.png")),
),
(
ResourceType::Gold,
load_png(include_bytes!("../assets/gold-ingots-gold-svgrepo-com.png")),
),
(ResourceType::MoodTokens, happy.clone()),
(
ResourceType::CultureTokens,
load_png(include_bytes!("../assets/theater-drama-svgrepo-com.png")),
),
]
.iter()
.cloned()
.collect(),

// action icons
advances: load_png(include_bytes!("../assets/lab-svgrepo-com.png")),
end_turn: load_png(include_bytes!("../assets/hour-glass-svgrepo-com.png")),
log: load_png(include_bytes!("../assets/scroll-svgrepo-com.png")),
movement: load_png(include_bytes!("../assets/walk-svgrepo-com.png")),
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")),

// UI
zoom_in: load_png(include_bytes!("../assets/zoom-in-1462-svgrepo-com.png")),
zoom_out: load_png(include_bytes!("../assets/zoom-out-1460-svgrepo-com.png")),
up: load_png(include_bytes!("../assets/up-arrow-circle-svgrepo-com.png")),
down: load_png(include_bytes!(
"../assets/down-arrow-circle-svgrepo-com.png"
)),
left: load_png(include_bytes!(
"../assets/left-arrow-circle-svgrepo-com.png"
)),
right: load_png(include_bytes!(
"../assets/right-arrow-circle-svgrepo-com.png"
)),
victory_points: load_png(include_bytes!("../assets/trophy-cup-svgrepo-com.png")),
active_player: load_png(include_bytes!("../assets/triangle-svgrepo-com.png")),

// Admin
import: load_png(include_bytes!("../assets/import-3-svgrepo-com.png")),
export: load_png(include_bytes!("../assets/export-2-svgrepo-com.png")),
// cities: HashMap::new(),
// resources: HashMap::new(),
}
}

Expand Down Expand Up @@ -142,3 +239,7 @@ impl Assets {
}
}
}

fn load_png(bytes: &[u8]) -> Texture2D {
Texture2D::from_file_with_format(bytes, Some(ImageFormat::Png))
}
11 changes: 8 additions & 3 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::happiness_ui::{increase_happiness_dialog, increase_happiness_menu};
use crate::hex_ui::pixel_to_coordinate;
use crate::log_ui::show_log;
use crate::map_ui::{draw_map, show_tile_menu};
use crate::player_ui::{show_global_controls, show_globals};
use crate::player_ui::{player_select, show_global_controls, show_top_center, show_top_left};
use crate::status_phase_ui::raze_city_confirm_dialog;
use crate::{combat_ui, dialog_ui, influence_ui, move_ui, recruit_unit_ui, status_phase_ui};

Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn render_and_update(
}

fn render(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
clear_background(BLACK);
clear_background(WHITE);

let player = &state.shown_player(game);

Expand All @@ -64,8 +64,13 @@ fn render(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
draw_map(game, state);
}
let mut updates = StateUpdates::new();
updates.add(show_globals(game, player));
show_top_left(game, player);
show_top_center(game, player, state);
updates.add(player_select(game, player, state));
updates.add(show_global_controls(game, state, features));
if !matches!(state.active_dialog, ActiveDialog::None) || state.active_dialog.is_map_dialog() {
updates.clear();
}

if player.can_control {
if let Some(u) = &state.pending_update {
Expand Down
4 changes: 4 additions & 0 deletions client/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ impl StateUpdates {
}
}

pub fn clear(&mut self) {
self.updates.clear();
}

pub fn result(self) -> StateUpdate {
self.updates
.into_iter()
Expand Down
6 changes: 3 additions & 3 deletions client/src/construct_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use server::city_pieces::Building;
use server::content::custom_actions::CustomAction;
use server::game::Game;
use server::map::{Map, Terrain};
use server::playing_actions::{Construct, PlayingAction};
use server::playing_actions::{Construct, PlayingAction, Recruit};
use server::position::Position;
use server::resource_pile::PaymentOptions;
use server::unit::UnitType;
Expand Down Expand Up @@ -126,13 +126,13 @@ pub fn pay_construction_dialog(
game.get_any_city(cp.city_position).unwrap(),
),
ConstructionProject::Units(r) => StateUpdate::execute_activation(
Action::Playing(PlayingAction::Recruit {
Action::Playing(PlayingAction::Recruit(Recruit {
city_position: cp.city_position,
units: r.amount.units.clone().to_vec(),
payment: cp.payment.to_resource_pile(),
replaced_units: r.replaced_units.clone(),
leader_index: r.amount.leader_index,
}),
})),
vec![],
game.get_any_city(cp.city_position).unwrap(),
),
Expand Down
6 changes: 3 additions & 3 deletions client/src/influence_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use macroquad::ui::Ui;
use server::action::Action;
use server::city_pieces::Building;
use server::game::{CulturalInfluenceResolution, Game};
use server::playing_actions::PlayingAction;
use server::playing_actions::{InfluenceCultureAttempt, PlayingAction};
use server::position::Position;

pub fn add_influence_button(
Expand Down Expand Up @@ -34,12 +34,12 @@ pub fn add_influence_button(
format!("Attempt Influence {building_name} for {cost}"),
) {
return StateUpdate::Execute(Action::Playing(
PlayingAction::InfluenceCultureAttempt {
PlayingAction::InfluenceCultureAttempt(InfluenceCultureAttempt {
starting_city_position: start_position,
target_player_index: menu.city_owner_index,
target_city_position: menu.city_position,
city_piece: building.clone(),
},
}),
));
}
}
Expand Down
83 changes: 69 additions & 14 deletions client/src/layout_ui.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,90 @@
use crate::client_state::ShownPlayer;
use crate::client_state::{ShownPlayer, State};
use macroquad::color::WHITE;
use macroquad::math::{vec2, Vec2};
use macroquad::prelude::*;
use macroquad::ui::root_ui;

pub const ICON_SIZE: f32 = 30.;

pub const MARGIN: f32 = 10.;

pub fn icon_offset(i: i8) -> f32 {
f32::from(i) * 1.4 * ICON_SIZE
}

pub fn icon_pos(x: i8, y: i8) -> Vec2 {
vec2(icon_offset(x), icon_offset(y))
}

pub fn top_left_label(p: Vec2, label: &str) {
root_ui().label(p, label);
root_ui().label(p + vec2(-40., 0.), label);
}

pub fn top_center_label(player: &ShownPlayer, p: Vec2, label: &str) {
root_ui().label(vec2(player.screen_size.x / 2.0, 0.) + p, label);
}

pub fn right_center_label(player: &ShownPlayer, p: Vec2, label: &str) {
root_ui().label(
vec2(player.screen_size.x, player.screen_size.y / 2.0) + p,
label,
);
pub fn top_center_texture(state: &State, texture: &Texture2D, p: Vec2) -> bool {
relative_texture(state, texture, vec2(state.screen_size.x / 2., MARGIN), p)
}

pub fn right_center_button(player: &ShownPlayer, p: Vec2, label: &str) -> bool {
root_ui().button(
vec2(player.screen_size.x, player.screen_size.y / 2.0) + p,
label,
pub fn top_right_texture(state: &State, texture: &Texture2D, p: Vec2) -> bool {
relative_texture(
state,
texture,
vec2(state.screen_size.x - MARGIN, MARGIN),
p,
)
}

pub fn bottom_left_texture(state: &State, texture: &Texture2D, p: Vec2) -> bool {
relative_texture(
state,
texture,
vec2(MARGIN, state.screen_size.y - MARGIN),
p,
)
}

pub fn bottom_left_button(player: &ShownPlayer, p: Vec2, label: &str) -> bool {
root_ui().button(vec2(0., player.screen_size.y) + p, label)
root_ui().button(vec2(MARGIN, player.screen_size.y - MARGIN) + p, label)
}

pub fn bottom_right_texture(state: &State, texture: &Texture2D, p: Vec2) -> bool {
relative_texture(
state,
texture,
vec2(state.screen_size.x - MARGIN, state.screen_size.y - MARGIN),
p,
)
}

fn relative_texture(state: &State, texture: &Texture2D, anchor: Vec2, offset: Vec2) -> bool {
let origin = anchor + offset;
set_default_camera();
draw_texture_ex(
texture,
origin.x,
origin.y,
WHITE,
DrawTextureParams {
dest_size: Some(vec2(ICON_SIZE, ICON_SIZE)),
..Default::default()
},
);

let pressed = left_mouse_button(Rect::new(origin.x, origin.y, ICON_SIZE, ICON_SIZE));
set_camera(&state.camera);
pressed
}

pub fn bottom_right_button(player: &ShownPlayer, p: Vec2, label: &str) -> bool {
root_ui().button(vec2(player.screen_size.x, player.screen_size.y) + p, label)
pub fn left_mouse_button(rect: Rect) -> bool {
if is_mouse_button_pressed(MouseButton::Left) {
let (x, y) = mouse_position();
rect.contains(vec2(x, y))
} else {
false
}
}

pub fn cancel_pos(player: &ShownPlayer) -> Vec2 {
Expand Down
Loading
Loading