From 194b12d6656a04f87ab99ad3526f1b1af888fdd2 Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 18:51:21 +0200 Subject: [PATCH 1/5] start ui --- src/game.rs | 15 +++++++++++++++ src/main.rs | 8 ++++++-- src/ui.rs | 13 +++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/ui.rs diff --git a/src/game.rs b/src/game.rs index a91fe39..a205c61 100644 --- a/src/game.rs +++ b/src/game.rs @@ -5,6 +5,20 @@ use crate::{ State }; +#[derive(Debug)] +pub struct Gost { + /// current electric charge of the Ghost + charge: u32, + /// max electric charge of the Ghost + max_charge: u32, +} + +impl Default for Gost { + fn default() -> Self { + Self { charge: 100, max_charge: 100 } + } +} + pub fn update(state: &mut State, engine: &mut EngineContext) { match state.activity { Activity::House => house::update(state, engine), @@ -17,4 +31,5 @@ pub fn draw(state: &State, engine: &EngineContext) { Activity::House => house::draw(state, engine), Activity::Overworld => overworld::draw(state, engine) } + crate::ui::draw(state, engine); } diff --git a/src/main.rs b/src/main.rs index 4992bdf..714ecd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,24 @@ mod activities; mod game; +mod ui; use activities::Activity; use comfy::*; +use game::Gost; const GAME_NAME: &str = "Powercreep"; #[derive(Debug)] struct State { - activity: Activity + activity: Activity, + gohst: Gost, } impl Default for State { fn default() -> Self { Self { - activity: Activity::House + activity: Activity::House, + gohst: Default::default(), } } } diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 0000000..3bed45f --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,13 @@ +use comfy::EngineContext; +use comfy::egui; +use comfy::RED; +use crate::State; + +pub fn draw(state: &State, engine: &EngineContext) { + egui::Area::new("batterie_show") + .anchor(egui::Align2::RIGHT_BOTTOM, egui::vec2(0.0, 0.0)) + .show(egui(), |ui| { + let painter = ui.painter(); + + }); +} \ No newline at end of file -- 2.45.2 From 49d565e73ba9a6aecbd89b97bbb54b4beb2b8865 Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 19:40:25 +0200 Subject: [PATCH 2/5] foo --- src/ui.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui.rs b/src/ui.rs index 3bed45f..e426004 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,5 +1,8 @@ +use comfy::egui::Pos2; +use comfy::egui::Rect; use comfy::EngineContext; use comfy::egui; +use comfy::GREEN; use comfy::RED; use crate::State; @@ -8,6 +11,7 @@ pub fn draw(state: &State, engine: &EngineContext) { .anchor(egui::Align2::RIGHT_BOTTOM, egui::vec2(0.0, 0.0)) .show(egui(), |ui| { let painter = ui.painter(); + painter.rect(Rect{min: Pos2::new(0.0, 0.0), max: Pos2::new(32.0, 32.0)}, 0.0, RED, (4.0, GREEN)); }); } \ No newline at end of file -- 2.45.2 From 255df67d7b9c8ee0b1180914636af511600cd996 Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 22:23:31 +0200 Subject: [PATCH 3/5] finish --- src/game.rs | 9 ++++++--- src/main.rs | 4 ++-- src/ui.rs | 42 ++++++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/game.rs b/src/game.rs index a205c61..50b3ac4 100644 --- a/src/game.rs +++ b/src/game.rs @@ -8,14 +8,17 @@ use crate::{ #[derive(Debug)] pub struct Gost { /// current electric charge of the Ghost - charge: u32, + pub charge: f32, /// max electric charge of the Ghost - max_charge: u32, + pub max_charge: f32 } impl Default for Gost { fn default() -> Self { - Self { charge: 100, max_charge: 100 } + Self { + charge: 1000.0, + max_charge: 1000.0 + } } } diff --git a/src/main.rs b/src/main.rs index 714ecd5..5a9073e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,14 +11,14 @@ const GAME_NAME: &str = "Powercreep"; #[derive(Debug)] struct State { activity: Activity, - gohst: Gost, + gohst: Gost } impl Default for State { fn default() -> Self { Self { activity: Activity::House, - gohst: Default::default(), + gohst: Default::default() } } } diff --git a/src/ui.rs b/src/ui.rs index e426004..3bfad43 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,17 +1,31 @@ -use comfy::egui::Pos2; -use comfy::egui::Rect; -use comfy::EngineContext; -use comfy::egui; -use comfy::GREEN; -use comfy::RED; use crate::State; +use comfy::{ + draw_rect, draw_rect_outline, screen_height, screen_to_world, screen_width, + EngineContext, Vec2, BLUE, RED +}; pub fn draw(state: &State, engine: &EngineContext) { - egui::Area::new("batterie_show") - .anchor(egui::Align2::RIGHT_BOTTOM, egui::vec2(0.0, 0.0)) - .show(egui(), |ui| { - let painter = ui.painter(); - painter.rect(Rect{min: Pos2::new(0.0, 0.0), max: Pos2::new(32.0, 32.0)}, 0.0, RED, (4.0, GREEN)); - - }); -} \ No newline at end of file + // seperate fill state into smaller section for better readability + let section_count = 5; + let mut start_positon = screen_to_world(Vec2::new(screen_width(), screen_height())); + // section size in world codinates + let section_size = Vec2::new(0.5, 0.25); + start_positon.x -= 0.5 * section_size.x + 0.5 * section_size.y; + start_positon.y += 0.5 * section_size.y + 0.5 * section_size.y; + // draw fill level + { + let gohst = &state.gohst; + let percent = gohst.charge / gohst.max_charge; + let mut size = section_size; + size.y = section_size.y * section_count as f32 * percent; + let mut position = start_positon; + position.y += 0.5 * -section_size.y + 0.5 * size.y; + draw_rect(position, size, BLUE, 100); + } + // draw sections + for i in 0 .. section_count { + let mut position = start_positon; + position.y += i as f32 * section_size.y; + draw_rect_outline(position, section_size, 0.1, RED, 100); + } +} -- 2.45.2 From f1af8c80a3c475420530a7b6c35fb51b40ec8f13 Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 22:34:31 +0200 Subject: [PATCH 4/5] fix merge; rename ghost --- src/game.rs | 4 ++-- src/main.rs | 7 +++---- src/ui.rs | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/game.rs b/src/game.rs index af3721c..2a2abf2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -6,14 +6,14 @@ use comfy::EngineContext; use std::ops::Sub; #[derive(Debug)] -pub struct Gost { +pub struct Ghost { /// current electric charge of the Ghost pub charge: f32, /// max electric charge of the Ghost pub max_charge: f32 } -impl Default for Gost { +impl Default for Ghost { fn default() -> Self { Self { charge: 1000.0, diff --git a/src/main.rs b/src/main.rs index a2a7054..0f0fe28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,8 @@ mod ui; use self::{ activities::{house::HouseState, overworld::worldgen::Overworld, Activity}, - assets::Assets -use game::Gost; + assets::Assets, + game::Ghost }; use comfy::{ init_game_config, pollster, run_comfy_main_async, EngineContext, EngineState, @@ -26,8 +26,7 @@ const GAME_NAME: &str = "Powercreep"; struct State { setup_called: bool, activity: Activity, - activity: Activity, - gohst: Gost + ghost: Ghost, overworld: Overworld, house: HouseState } diff --git a/src/ui.rs b/src/ui.rs index 3bfad43..364602a 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -4,7 +4,7 @@ use comfy::{ EngineContext, Vec2, BLUE, RED }; -pub fn draw(state: &State, engine: &EngineContext) { +pub fn draw(state: &State, _engine: &EngineContext<'_>) { // seperate fill state into smaller section for better readability let section_count = 5; let mut start_positon = screen_to_world(Vec2::new(screen_width(), screen_height())); @@ -14,7 +14,7 @@ pub fn draw(state: &State, engine: &EngineContext) { start_positon.y += 0.5 * section_size.y + 0.5 * section_size.y; // draw fill level { - let gohst = &state.gohst; + let gohst = &state.ghost; let percent = gohst.charge / gohst.max_charge; let mut size = section_size; size.y = section_size.y * section_count as f32 * percent; -- 2.45.2 From b8132bc876fc53df0b948cee7c1f8b34d634c18c Mon Sep 17 00:00:00 2001 From: luckyturtledev Date: Sat, 6 Jul 2024 22:39:02 +0200 Subject: [PATCH 5/5] fix more ghosts --- src/ui.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index 364602a..7de61ee 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -14,8 +14,8 @@ pub fn draw(state: &State, _engine: &EngineContext<'_>) { start_positon.y += 0.5 * section_size.y + 0.5 * section_size.y; // draw fill level { - let gohst = &state.ghost; - let percent = gohst.charge / gohst.max_charge; + let ghost = &state.ghost; + let percent = ghost.charge / ghost.max_charge; let mut size = section_size; size.y = section_size.y * section_count as f32 * percent; let mut position = start_positon; -- 2.45.2