Skip to content

Commit

Permalink
feat: ui improvements, added inventory and equipment displays
Browse files Browse the repository at this point in the history
  • Loading branch information
zr3 committed Feb 7, 2024
1 parent ffe0a4f commit b6d7ab1
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ at each level, the game uses an LLM to summarize what happened, and also to come

✔️ m6: cicd, auth, backend

m7: cleanup, bug fixes and feedback
✔️ m7: cleanup, bug fixes and feedback

m8: final polish

Expand Down
2 changes: 1 addition & 1 deletion delightful-thyme/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<p>[SPACE] : pick up, portal, interact on item you stand on</p>
<p>[I] : inventory</p>
<p>[D] : drop item on ground</p>
<p>[R] : remove (unwear/unwield) an item</p>
<p>[E] : remove (unwear/unwield) equipment</p>
<p>[ENTER] : see what is on the screen (scan all)</p>
<p>[MOUSE HOVER] : see what is on the screen (under mouse)</p>
</section>
Expand Down
11 changes: 10 additions & 1 deletion wild-thyme/src/game_loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
components::{
HighlightObject, Ranged, TeleportsPlayer, WantsToDropItem, WantsToRemoveItem,
HighlightObject, Ranged, TeleportsPlayer, Viewshed, WantsToDropItem, WantsToRemoveItem,
WantsToUseItem,
},
discovery_system,
Expand All @@ -24,6 +24,15 @@ impl State {
match current_runstate {
// core game loop
RunState::CoreLevelStart => {
{
let player_entity = self.ecs.fetch::<Entity>();
let mut viewshed_components = self.ecs.write_storage::<Viewshed>();
let vs = viewshed_components.get_mut(*player_entity);
if let Some(vs) = vs {
// start in the dark on all levels except druid levels
vs.dirty = self.ecs.fetch::<LevelStats>().level % 5 == 0;
}
}
self.run_systems();
return RunState::CorePreRound;
}
Expand Down
98 changes: 82 additions & 16 deletions wild-thyme/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use specs::prelude::*;
use crate::{
components::{
Backpack, CombatStats, Equipped, Hidden, HighlightObject, HungerClock, HungerState,
InBackpack, Viewshed,
InBackpack, Renderable, Viewshed,
},
gamelog::LogEntry,
get_visible_tooltips,
Expand Down Expand Up @@ -33,13 +33,77 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
43,
79,
6,
RGB::from_hex("#c9c9c9").expect("hardcoded"),
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
// inventory side box
ctx.draw_box(
76,
0,
2,
11,
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
ctx.print_color(
77,
0,
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
"I",
);
let player_entity = ecs.fetch::<Entity>();
let backpack_items = ecs.read_storage::<InBackpack>();
let renderables = ecs.read_storage::<Renderable>();
let inventory = (&backpack_items, &renderables)
.join()
.filter(|item| item.0.owner == *player_entity);
let mut item_index = 0;
for (_inpack, renderable) in inventory {
ctx.set(
77,
1 + item_index,
renderable.fg,
renderable.bg,
renderable.glyph,
);
item_index += 1;
}
// equipment side box
ctx.draw_box(
76,
13,
2,
3,
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
ctx.print_color(
77,
13,
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
"E",
);
let equipped_items = ecs.read_storage::<Equipped>();
let currently_equipped = (&equipped_items, &renderables)
.join()
.filter(|item| item.0.owner == *player_entity);
item_index = 0;
for (_equipped, renderable) in currently_equipped {
ctx.set(
77,
14 + item_index,
renderable.fg,
renderable.bg,
renderable.glyph,
);
item_index += 1;
}

// depth level
let map = ecs.fetch::<Map>();
let depth = format!("depth: {}", map.depth);
let depth = format!("trail: {}", map.depth);
ctx.print_color(
2,
43,
Expand Down Expand Up @@ -127,8 +191,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
false => RGB::from_hex("#606060").expect("hardcoded"),
},
LogEntry::Alert { .. } => match s.read {
true => RGB::from_hex("#803030").expect("hardcoded"),
false => RGB::from_hex("#d07060").expect("hardcoded"),
true => RGB::from_hex("#653030").expect("hardcoded"),
false => RGB::from_hex("#a04040").expect("hardcoded"),
},
};
ctx.print_color(2, y, color, RGB::named(rltk::BLACK), line);
Expand Down Expand Up @@ -286,6 +350,7 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
let backpack_items = gs.ecs.read_storage::<InBackpack>();
let backpacks = gs.ecs.read_storage::<Backpack>();
let entities = gs.ecs.entities();
let renderables = gs.ecs.read_storage::<Renderable>();

let inventory = (&backpack_items, &names)
.join()
Expand All @@ -301,7 +366,7 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
y - 2,
31,
(count + 3) as i32,
RGB::named(rltk::WHITE),
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
let padding;
Expand Down Expand Up @@ -340,7 +405,7 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option

let mut equippable: Vec<Entity> = Vec::new();
let mut j = 0;
for (entity, _pack, name) in (&entities, &backpack_items, &names)
for (entity, _pack, name, renderable) in (&entities, &backpack_items, &names, &renderables)
.join()
.filter(|item| item.1.owner == *player_entity)
{
Expand All @@ -365,8 +430,15 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
RGB::named(rltk::BLACK),
rltk::to_cp437(')'),
);
ctx.set(21, y, renderable.fg, renderable.bg, renderable.glyph);

ctx.print(21, y, &name.name.to_string());
ctx.print_color(
23,
y,
RGB::from_hex("#a0a0a0").expect("hardcoded"),
RGB::named(rltk::BLACK),
&name.name.to_string(),
);
equippable.push(entity);
y += 1;
j += 1;
Expand Down Expand Up @@ -407,7 +479,7 @@ pub fn show_drop_item(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option
y - 2,
31,
(count + 3) as i32,
RGB::named(rltk::WHITE),
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
ctx.print_color(
Expand Down Expand Up @@ -494,7 +566,7 @@ pub fn show_remove_item(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti
y - 2,
31,
(count + 3) as i32,
RGB::named(rltk::WHITE),
RGB::named(rltk::BURLYWOOD),
RGB::named(rltk::BLACK),
);
ctx.print_color(
Expand Down Expand Up @@ -643,12 +715,6 @@ pub fn game_over(ctx: &mut Rltk, stats: &OverallStats) -> GameOverResult {
"OH NO YOU DIED!!",
);

ctx.print_color_centered(
15,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
format!("YOU: {}", stats.name),
);
print_stat(ctx, 16, "deepest level", stats.deepest_level);
print_stat(ctx, 17, "most items held", stats.most_items_held);
print_stat(ctx, 18, "GOOD THYME eaten", stats.thyme_eaten);
Expand Down
4 changes: 2 additions & 2 deletions wild-thyme/src/inventory_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl<'a> System<'a> for UseItemSystem {
let item_maps = magic_mapper.get(used_item.item);
if let Some(_item_maps) = item_maps {
gamelog.log(LogEntry::Alert {
alert: format!("YOU can now SEE this level!"),
alert: format!("YOU can now SEE the trail!"),
});
item_was_used = true;
*runstate = RunState::ActionMagicMapReveal {
Expand Down Expand Up @@ -598,7 +598,7 @@ impl<'a> System<'a> for ItemRemoveSystem {
.expect("should be able to add unequipped item to backpack");
}
if entity == *player_entity {
if backpack_too_full {
if !backpack_too_full {
gamelog.log(LogEntry::Action {
subject: format!("YOU"),
object: format!("{}", name.name),
Expand Down
7 changes: 0 additions & 7 deletions wild-thyme/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,6 @@ impl State {
player_pos_comp.x = player_pos.x;
player_pos_comp.y = player_pos.y;
}

// Mark the player's visibility as dirty
let mut viewshed_components = self.ecs.write_storage::<Viewshed>();
let vs = viewshed_components.get_mut(*player_entity);
if let Some(vs) = vs {
vs.dirty = true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion wild-thyme/src/map_builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn make_builder(new_depth: i32) -> Box<dyn MapBuilder> {
Box::new(TownLevelBuilder::new())
} else if new_depth % 3 == 0 {
Box::new(NestLevelBuilder::new(new_depth))
} else if new_depth % 10 == 0 {
} else if new_depth % 5 == 0 {
Box::new(WizardLevelBuilder::new(new_depth))
} else if new_depth == 13 {
Box::new(SimpleMapBuilder::new(new_depth))
Expand Down
2 changes: 1 addition & 1 deletion wild-thyme/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState {

VirtualKeyCode::I => return RunState::MenuInventory,
VirtualKeyCode::D => return RunState::MenuDropItem,
VirtualKeyCode::R => return RunState::MenuRemoveItem,
VirtualKeyCode::E => return RunState::MenuRemoveItem,

VirtualKeyCode::Return => {
return RunState::ActionShowObjects {
Expand Down

0 comments on commit b6d7ab1

Please sign in to comment.