Refactor item-related menus
This commit is contained in:
parent
61f2ec5d6a
commit
f096aa36e9
@ -1,13 +1,13 @@
|
|||||||
//! Interface-building output
|
//! Interface-building output
|
||||||
mod cheat_menu;
|
mod cheat_menu;
|
||||||
mod drop_item_menu;
|
mod drop_item_menu;
|
||||||
mod enums;
|
|
||||||
mod game_over_menu;
|
mod game_over_menu;
|
||||||
mod hud;
|
mod hud;
|
||||||
mod identify_menu;
|
mod identify_menu;
|
||||||
mod inventory_menu;
|
mod inventory_menu;
|
||||||
mod item_render;
|
mod item_render;
|
||||||
mod main_menu;
|
mod main_menu;
|
||||||
|
mod menus;
|
||||||
mod ranged_target;
|
mod ranged_target;
|
||||||
mod remove_curse_menu;
|
mod remove_curse_menu;
|
||||||
mod remove_item_menu;
|
mod remove_item_menu;
|
||||||
@ -16,13 +16,13 @@ mod vendor_menu;
|
|||||||
|
|
||||||
pub use cheat_menu::*;
|
pub use cheat_menu::*;
|
||||||
pub use drop_item_menu::*;
|
pub use drop_item_menu::*;
|
||||||
pub use enums::*;
|
|
||||||
pub use game_over_menu::*;
|
pub use game_over_menu::*;
|
||||||
pub use hud::*;
|
pub use hud::*;
|
||||||
pub use identify_menu::*;
|
pub use identify_menu::*;
|
||||||
pub use inventory_menu::*;
|
pub use inventory_menu::*;
|
||||||
pub use item_render::*;
|
pub use item_render::*;
|
||||||
pub use main_menu::*;
|
pub use main_menu::*;
|
||||||
|
pub use menus::*;
|
||||||
pub use ranged_target::*;
|
pub use ranged_target::*;
|
||||||
pub use remove_curse_menu::*;
|
pub use remove_curse_menu::*;
|
||||||
pub use remove_item_menu::*;
|
pub use remove_item_menu::*;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
use ::rltk::prelude::*;
|
||||||
use ::rltk::{Rltk, VirtualKeyCode};
|
use ::rltk::{Rltk, VirtualKeyCode};
|
||||||
|
|
||||||
|
use super::{menu_box, menu_option};
|
||||||
use crate::{colors, State};
|
use crate::{colors, State};
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
@ -13,48 +15,36 @@ pub enum CheatMenuResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult {
|
pub fn show_cheat_mode(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult {
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
let count = 4;
|
let count = 4;
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
let mut y = (25 - (count / 2)) as i32;
|
||||||
ctx.draw_box(
|
menu_box(&mut draw_batch, 15, y, (count + 3) as i32, "Cheating!");
|
||||||
15,
|
draw_batch.print_color(
|
||||||
y - 2,
|
Point::new(18, y + count as i32 + 1),
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BLACK,
|
|
||||||
);
|
|
||||||
ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Cheating!");
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y + count as i32 + 1,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"ESCAPE to cancel",
|
"ESCAPE to cancel",
|
||||||
|
ColorPair::new(colors::YELLOW, colors::BLACK),
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
menu_option(
|
||||||
ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('T'));
|
&mut draw_batch,
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
17,
|
||||||
|
y,
|
||||||
ctx.print(21, y, "Teleport to next level");
|
to_cp437('T'),
|
||||||
|
"Teleport to next level",
|
||||||
|
);
|
||||||
y += 1;
|
y += 1;
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('H'));
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
ctx.print(21, y, "Heal all wounds");
|
|
||||||
|
|
||||||
|
menu_option(&mut draw_batch, 17, y, to_cp437('H'), "Heal all wounds");
|
||||||
y += 1;
|
y += 1;
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('R'));
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
ctx.print(21, y, "Reveal the map");
|
|
||||||
|
|
||||||
|
menu_option(&mut draw_batch, 17, y, to_cp437('R'), "Reveal the map");
|
||||||
y += 1;
|
y += 1;
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(18, y, colors::YELLOW, colors::BLACK, rltk::to_cp437('G'));
|
menu_option(&mut draw_batch, 17, y, to_cp437('G'), "God Mode (No Death)");
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
ctx.print(21, y, "God Mode (No Death)");
|
draw_batch
|
||||||
|
.submit(6000)
|
||||||
|
.expect("Failed to batch draw cheat menu");
|
||||||
|
|
||||||
match ctx.key {
|
match ctx.key {
|
||||||
None => CheatMenuResult::NoResponse,
|
None => CheatMenuResult::NoResponse,
|
||||||
|
@ -1,83 +1,35 @@
|
|||||||
use ::rltk::{Rltk, VirtualKeyCode};
|
use ::rltk::prelude::*;
|
||||||
|
use ::rltk::Rltk;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
||||||
use super::{get_item_color, get_item_display_name};
|
use crate::components::InBackpack;
|
||||||
use crate::components::{InBackpack, Name};
|
use crate::State;
|
||||||
use crate::{colors, State};
|
|
||||||
|
|
||||||
pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
let player_entity = gs.ecs.fetch::<Entity>();
|
let player_entity = gs.ecs.fetch::<Entity>();
|
||||||
let names = gs.ecs.read_storage::<Name>();
|
|
||||||
let backpack = gs.ecs.read_storage::<InBackpack>();
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
||||||
let entities = gs.ecs.entities();
|
let entities = gs.ecs.entities();
|
||||||
|
|
||||||
let inventory = (&backpack, &names)
|
let mut items: Vec<(Entity, String)> = Vec::new();
|
||||||
.join()
|
(&entities, &backpack)
|
||||||
.filter(|item| item.0.owner == *player_entity);
|
|
||||||
let count = inventory.count();
|
|
||||||
|
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
|
||||||
ctx.draw_box(
|
|
||||||
15,
|
|
||||||
y - 2,
|
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BLACK,
|
|
||||||
);
|
|
||||||
ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Drop Which Item?");
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y + count as i32 + 1,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"ESCAPE to cancel",
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut equippable: Vec<Entity> = Vec::new();
|
|
||||||
let mut j = 0;
|
|
||||||
#[allow(clippy::explicit_counter_loop)]
|
|
||||||
for (entity, _pack) in (&entities, &backpack)
|
|
||||||
.join()
|
.join()
|
||||||
.filter(|item| item.1.owner == *player_entity)
|
.filter(|item| item.1.owner == *player_entity)
|
||||||
{
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(
|
|
||||||
18,
|
|
||||||
y,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
97 + j as rltk::FontCharType,
|
|
||||||
);
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
|
|
||||||
ctx.print_color(
|
let result = item_result_menu(
|
||||||
21,
|
&mut draw_batch,
|
||||||
y,
|
"Drop which item?",
|
||||||
get_item_color(&gs.ecs, entity),
|
items.len(),
|
||||||
colors::BLACK,
|
&items,
|
||||||
&get_item_display_name(&gs.ecs, entity),
|
ctx.key,
|
||||||
);
|
);
|
||||||
equippable.push(entity);
|
|
||||||
y += 1;
|
|
||||||
j += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.key {
|
draw_batch
|
||||||
None => (ItemMenuResult::NoResponse, None),
|
.submit(6000)
|
||||||
Some(key) => match key {
|
.expect("Failed to batch render Drop Item Menu");
|
||||||
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
|
||||||
_ => {
|
result
|
||||||
let selection = rltk::letter_to_option(key);
|
|
||||||
if selection > -1 && selection < count as i32 {
|
|
||||||
return (
|
|
||||||
ItemMenuResult::Selected,
|
|
||||||
Some(equippable[selection as usize]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
(ItemMenuResult::NoResponse, None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#[derive(PartialEq, Copy, Clone)]
|
|
||||||
pub enum ItemMenuResult {
|
|
||||||
Cancel,
|
|
||||||
NoResponse,
|
|
||||||
Selected,
|
|
||||||
}
|
|
@ -1,25 +1,27 @@
|
|||||||
use ::rltk::{FontCharType, Rltk, VirtualKeyCode};
|
use ::rltk::prelude::*;
|
||||||
|
use ::rltk::Rltk;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
||||||
use super::{get_item_color, get_item_display_name};
|
|
||||||
use crate::components::{Equipped, InBackpack, Item, Name, ObfuscatedName};
|
use crate::components::{Equipped, InBackpack, Item, Name, ObfuscatedName};
|
||||||
use crate::{colors, MasterDungeonMap, State};
|
use crate::{MasterDungeonMap, State};
|
||||||
|
|
||||||
pub fn identify_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
pub fn identify_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
||||||
use ::rltk::to_cp437;
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
let player_entity = gs.ecs.fetch::<Entity>();
|
let player_entity = gs.ecs.fetch::<Entity>();
|
||||||
let equipped = gs.ecs.read_storage::<Equipped>();
|
let equipped = gs.ecs.read_storage::<Equipped>();
|
||||||
let backpack = gs.ecs.read_storage::<InBackpack>();
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
||||||
let entities = gs.ecs.entities();
|
let entities = gs.ecs.entities();
|
||||||
let items = gs.ecs.read_storage::<Item>();
|
let item_components = gs.ecs.read_storage::<Item>();
|
||||||
let names = gs.ecs.read_storage::<Name>();
|
let names = gs.ecs.read_storage::<Name>();
|
||||||
let dm = gs.ecs.fetch::<MasterDungeonMap>();
|
let dm = gs.ecs.fetch::<MasterDungeonMap>();
|
||||||
let obfuscated = gs.ecs.read_storage::<ObfuscatedName>();
|
let obfuscated = gs.ecs.read_storage::<ObfuscatedName>();
|
||||||
|
|
||||||
let build_cursed_iterator = || {
|
let mut items: Vec<(Entity, String)> = Vec::new();
|
||||||
(&entities, &items).join().filter(|(item_entity, _item)| {
|
(&entities, &item_components)
|
||||||
|
.join()
|
||||||
|
.filter(|(item_entity, _item)| {
|
||||||
let mut keep = false;
|
let mut keep = false;
|
||||||
if let Some(bp) = backpack.get(*item_entity) {
|
if let Some(bp) = backpack.get(*item_entity) {
|
||||||
if bp.owner == *player_entity {
|
if bp.owner == *player_entity {
|
||||||
@ -48,65 +50,18 @@ pub fn identify_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<
|
|||||||
|
|
||||||
keep
|
keep
|
||||||
})
|
})
|
||||||
};
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
||||||
|
|
||||||
let count = build_cursed_iterator().count();
|
let result = item_result_menu(
|
||||||
|
&mut draw_batch,
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
|
||||||
ctx.draw_box(
|
|
||||||
15,
|
|
||||||
y - 2,
|
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BLACK,
|
|
||||||
);
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y - 2,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"Identify Which Item?",
|
"Identify Which Item?",
|
||||||
|
items.len(),
|
||||||
|
&items,
|
||||||
|
ctx.key,
|
||||||
);
|
);
|
||||||
ctx.print_color(
|
draw_batch
|
||||||
18,
|
.submit(6000)
|
||||||
y + count as i32 + 1,
|
.expect("Failed to batch render Identify menu");
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"ESCAPE to cancel",
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut equippable: Vec<Entity> = Vec::new();
|
result
|
||||||
for (j, (entity, _item)) in build_cursed_iterator().enumerate() {
|
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, to_cp437('('));
|
|
||||||
ctx.set(18, y, colors::YELLOW, colors::BLACK, 97 + j as FontCharType);
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, to_cp437(')'));
|
|
||||||
|
|
||||||
ctx.print_color(
|
|
||||||
21,
|
|
||||||
y,
|
|
||||||
get_item_color(&gs.ecs, entity),
|
|
||||||
colors::BLACK,
|
|
||||||
&get_item_display_name(&gs.ecs, entity),
|
|
||||||
);
|
|
||||||
equippable.push(entity);
|
|
||||||
y += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.key {
|
|
||||||
None => (ItemMenuResult::NoResponse, None),
|
|
||||||
Some(key) => match key {
|
|
||||||
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
|
||||||
_ => {
|
|
||||||
let selection = ::rltk::letter_to_option(key);
|
|
||||||
if selection > -1 && selection < count as i32 {
|
|
||||||
return (
|
|
||||||
ItemMenuResult::Selected,
|
|
||||||
Some(equippable[selection as usize]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
(ItemMenuResult::NoResponse, None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,83 +1,29 @@
|
|||||||
use ::rltk::{Rltk, VirtualKeyCode};
|
use ::rltk::prelude::*;
|
||||||
|
use ::rltk::Rltk;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
||||||
use super::{get_item_color, get_item_display_name};
|
use crate::components::InBackpack;
|
||||||
use crate::components::{InBackpack, Name};
|
use crate::State;
|
||||||
use crate::{colors, State};
|
|
||||||
|
|
||||||
pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
let player_entity = gs.ecs.fetch::<Entity>();
|
let player_entity = gs.ecs.fetch::<Entity>();
|
||||||
let names = gs.ecs.read_storage::<Name>();
|
|
||||||
let backpack = gs.ecs.read_storage::<InBackpack>();
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
||||||
let entities = gs.ecs.entities();
|
let entities = gs.ecs.entities();
|
||||||
|
|
||||||
let inventory = (&backpack, &names)
|
let mut items: Vec<(Entity, String)> = Vec::new();
|
||||||
.join()
|
(&entities, &backpack)
|
||||||
.filter(|item| item.0.owner == *player_entity);
|
|
||||||
let count = inventory.count();
|
|
||||||
|
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
|
||||||
ctx.draw_box(
|
|
||||||
15,
|
|
||||||
y - 2,
|
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BLACK,
|
|
||||||
);
|
|
||||||
ctx.print_color(18, y - 2, colors::YELLOW, colors::BLACK, "Inventory");
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y + count as i32 + 1,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"ESCAPE to cancel",
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut equippable: Vec<Entity> = Vec::new();
|
|
||||||
let mut j = 0;
|
|
||||||
#[allow(clippy::explicit_counter_loop)]
|
|
||||||
for (entity, _pack) in (&entities, &backpack)
|
|
||||||
.join()
|
.join()
|
||||||
.filter(|item| item.1.owner == *player_entity)
|
.filter(|item| item.1.owner == *player_entity)
|
||||||
{
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(
|
|
||||||
18,
|
|
||||||
y,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
97 + j as rltk::FontCharType,
|
|
||||||
);
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
|
|
||||||
ctx.print_color(
|
let result = item_result_menu(&mut draw_batch, "Inventory", items.len(), &items, ctx.key);
|
||||||
21,
|
|
||||||
y,
|
|
||||||
get_item_color(&gs.ecs, entity),
|
|
||||||
colors::BLACK,
|
|
||||||
&get_item_display_name(&gs.ecs, entity),
|
|
||||||
);
|
|
||||||
equippable.push(entity);
|
|
||||||
y += 1;
|
|
||||||
j += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.key {
|
draw_batch
|
||||||
None => (ItemMenuResult::NoResponse, None),
|
.submit(6000)
|
||||||
Some(key) => match key {
|
.expect("Failed to batch render Inventory Menu");
|
||||||
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
|
||||||
_ => {
|
result
|
||||||
let selection = rltk::letter_to_option(key);
|
|
||||||
if selection > -1 && selection < count as i32 {
|
|
||||||
return (
|
|
||||||
ItemMenuResult::Selected,
|
|
||||||
Some(equippable[selection as usize]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
(ItemMenuResult::NoResponse, None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
100
src/gui/menus.rs
Normal file
100
src/gui/menus.rs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
use ::rltk::prelude::*;
|
||||||
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
|
use crate::colors;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
|
pub enum ItemMenuResult {
|
||||||
|
Cancel,
|
||||||
|
NoResponse,
|
||||||
|
Selected,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn menu_box<T: ToString>(draw_batch: &mut DrawBatch, x: i32, y: i32, width: i32, title: T) {
|
||||||
|
draw_batch.draw_box(
|
||||||
|
Rect::with_size(x, y - 2, 31, width),
|
||||||
|
ColorPair::new(colors::WHITE, colors::BLACK),
|
||||||
|
);
|
||||||
|
draw_batch.print_color(
|
||||||
|
Point::new(18, y - 2),
|
||||||
|
&title.to_string(),
|
||||||
|
ColorPair::new(colors::MAGENTA, colors::BLACK),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn menu_option<T: ToString>(
|
||||||
|
draw_batch: &mut DrawBatch,
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
hotkey: ::rltk::FontCharType,
|
||||||
|
text: T,
|
||||||
|
) {
|
||||||
|
draw_batch.set(
|
||||||
|
Point::new(x, y),
|
||||||
|
ColorPair::new(colors::WHITE, colors::BLACK),
|
||||||
|
to_cp437('('),
|
||||||
|
);
|
||||||
|
draw_batch.set(
|
||||||
|
Point::new(x + 1, y),
|
||||||
|
ColorPair::new(colors::YELLOW, colors::BLACK),
|
||||||
|
hotkey,
|
||||||
|
);
|
||||||
|
draw_batch.set(
|
||||||
|
Point::new(x + 2, y),
|
||||||
|
ColorPair::new(colors::WHITE, colors::BLACK),
|
||||||
|
to_cp437(')'),
|
||||||
|
);
|
||||||
|
draw_batch.print_color(
|
||||||
|
Point::new(x + 5, y),
|
||||||
|
&text.to_string(),
|
||||||
|
ColorPair::new(colors::YELLOW, colors::BLACK),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn item_result_menu<S: ToString>(
|
||||||
|
draw_batch: &mut DrawBatch,
|
||||||
|
title: S,
|
||||||
|
count: usize,
|
||||||
|
items: &[(Entity, String)],
|
||||||
|
key: Option<VirtualKeyCode>,
|
||||||
|
) -> (ItemMenuResult, Option<Entity>) {
|
||||||
|
let mut y = (25 - (count / 2)) as i32;
|
||||||
|
draw_batch.draw_box(
|
||||||
|
Rect::with_size(15, y - 2, 31, (count + 3) as i32),
|
||||||
|
ColorPair::new(colors::WHITE, colors::BLACK),
|
||||||
|
);
|
||||||
|
draw_batch.print_color(
|
||||||
|
Point::new(18, y - 2),
|
||||||
|
&title.to_string(),
|
||||||
|
ColorPair::new(colors::YELLOW, colors::BLACK),
|
||||||
|
);
|
||||||
|
draw_batch.print_color(
|
||||||
|
Point::new(18, y + count as i32 + 1),
|
||||||
|
"ESCAPE to cancel",
|
||||||
|
ColorPair::new(colors::YELLOW, colors::BLACK),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut item_list: Vec<Entity> = Vec::new();
|
||||||
|
for (j, item) in items.iter().enumerate() {
|
||||||
|
menu_option(draw_batch, 17, y, 97 + j as FontCharType, &item.1);
|
||||||
|
item_list.push(item.0);
|
||||||
|
y += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
match key {
|
||||||
|
None => (ItemMenuResult::NoResponse, None),
|
||||||
|
Some(key) => match key {
|
||||||
|
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
||||||
|
_ => {
|
||||||
|
let selection = ::rltk::letter_to_option(key);
|
||||||
|
if selection > -1 && selection < count as i32 {
|
||||||
|
return (
|
||||||
|
ItemMenuResult::Selected,
|
||||||
|
Some(item_list[selection as usize]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(ItemMenuResult::NoResponse, None)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
use ::rltk::{DistanceAlg, Point, Rltk};
|
use ::rltk::{DistanceAlg, Point, Rltk};
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::ItemMenuResult;
|
||||||
use crate::components::Viewshed;
|
use crate::components::Viewshed;
|
||||||
use crate::{camera, colors, State};
|
use crate::{camera, colors, State};
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use ::rltk::{Rltk, VirtualKeyCode, RGB};
|
use ::rltk::prelude::*;
|
||||||
|
use ::rltk::Rltk;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
||||||
use super::{get_item_color, get_item_display_name};
|
|
||||||
use crate::components::{CursedItem, Equipped, InBackpack, Item, Name};
|
use crate::components::{CursedItem, Equipped, InBackpack, Item, Name};
|
||||||
use crate::{MasterDungeonMap, State};
|
use crate::{MasterDungeonMap, State};
|
||||||
|
|
||||||
@ -11,13 +11,16 @@ pub fn remove_curse_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opt
|
|||||||
let equipped = gs.ecs.read_storage::<Equipped>();
|
let equipped = gs.ecs.read_storage::<Equipped>();
|
||||||
let backpack = gs.ecs.read_storage::<InBackpack>();
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
||||||
let entities = gs.ecs.entities();
|
let entities = gs.ecs.entities();
|
||||||
let items = gs.ecs.read_storage::<Item>();
|
let item_components = gs.ecs.read_storage::<Item>();
|
||||||
let cursed = gs.ecs.read_storage::<CursedItem>();
|
let cursed = gs.ecs.read_storage::<CursedItem>();
|
||||||
let names = gs.ecs.read_storage::<Name>();
|
let names = gs.ecs.read_storage::<Name>();
|
||||||
let dm = gs.ecs.fetch::<MasterDungeonMap>();
|
let dm = gs.ecs.fetch::<MasterDungeonMap>();
|
||||||
|
|
||||||
let build_cursed_iterator = || {
|
let mut draw_batch = DrawBatch::new();
|
||||||
(&entities, &items, &cursed)
|
|
||||||
|
let mut items = Vec::new();
|
||||||
|
|
||||||
|
(&entities, &item_components, &cursed)
|
||||||
.join()
|
.join()
|
||||||
.filter(|(item_entity, _item, _cursed)| {
|
.filter(|(item_entity, _item, _cursed)| {
|
||||||
let mut keep = false;
|
let mut keep = false;
|
||||||
@ -38,83 +41,19 @@ pub fn remove_curse_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opt
|
|||||||
}
|
}
|
||||||
keep
|
keep
|
||||||
})
|
})
|
||||||
};
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
||||||
|
|
||||||
let count = build_cursed_iterator().count();
|
let result = item_result_menu(
|
||||||
|
&mut draw_batch,
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
|
||||||
ctx.draw_box(
|
|
||||||
15,
|
|
||||||
y - 2,
|
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
RGB::named(rltk::WHITE),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
);
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y - 2,
|
|
||||||
RGB::named(rltk::YELLOW),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
"Remove Curse From Which Item?",
|
"Remove Curse From Which Item?",
|
||||||
);
|
items.len(),
|
||||||
ctx.print_color(
|
&items,
|
||||||
18,
|
ctx.key,
|
||||||
y + count as i32 + 1,
|
|
||||||
RGB::named(rltk::YELLOW),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
"ESCAPE to cancel",
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut equippable: Vec<Entity> = Vec::new();
|
draw_batch
|
||||||
for (j, (entity, _item, _cursed)) in build_cursed_iterator().enumerate() {
|
.submit(6000)
|
||||||
ctx.set(
|
.expect("Failed to batch render Remove Curse Menu");
|
||||||
17,
|
|
||||||
y,
|
|
||||||
RGB::named(rltk::WHITE),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
rltk::to_cp437('('),
|
|
||||||
);
|
|
||||||
ctx.set(
|
|
||||||
18,
|
|
||||||
y,
|
|
||||||
RGB::named(rltk::YELLOW),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
97 + j as rltk::FontCharType,
|
|
||||||
);
|
|
||||||
ctx.set(
|
|
||||||
19,
|
|
||||||
y,
|
|
||||||
RGB::named(rltk::WHITE),
|
|
||||||
RGB::named(rltk::BLACK),
|
|
||||||
rltk::to_cp437(')'),
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.print_color(
|
result
|
||||||
21,
|
|
||||||
y,
|
|
||||||
get_item_color(&gs.ecs, entity),
|
|
||||||
RGB::from_f32(0.0, 0.0, 0.0),
|
|
||||||
&get_item_display_name(&gs.ecs, entity),
|
|
||||||
);
|
|
||||||
equippable.push(entity);
|
|
||||||
y += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.key {
|
|
||||||
None => (ItemMenuResult::NoResponse, None),
|
|
||||||
Some(key) => match key {
|
|
||||||
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
|
||||||
_ => {
|
|
||||||
let selection = rltk::letter_to_option(key);
|
|
||||||
if selection > -1 && selection < count as i32 {
|
|
||||||
return (
|
|
||||||
ItemMenuResult::Selected,
|
|
||||||
Some(equippable[selection as usize]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
(ItemMenuResult::NoResponse, None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,91 +1,35 @@
|
|||||||
use ::rltk::{Rltk, VirtualKeyCode};
|
use ::rltk::prelude::*;
|
||||||
|
use ::rltk::Rltk;
|
||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use super::enums::*;
|
use super::{get_item_display_name, item_result_menu, ItemMenuResult};
|
||||||
use super::{get_item_color, get_item_display_name};
|
use crate::components::InBackpack;
|
||||||
use crate::components::{Equipped, Name};
|
use crate::State;
|
||||||
use crate::{colors, State};
|
|
||||||
|
|
||||||
pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option<Entity>) {
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
|
||||||
let player_entity = gs.ecs.fetch::<Entity>();
|
let player_entity = gs.ecs.fetch::<Entity>();
|
||||||
let names = gs.ecs.read_storage::<Name>();
|
let backpack = gs.ecs.read_storage::<InBackpack>();
|
||||||
let backpack = gs.ecs.read_storage::<Equipped>();
|
|
||||||
let entities = gs.ecs.entities();
|
let entities = gs.ecs.entities();
|
||||||
|
|
||||||
let inventory = (&backpack, &names)
|
let mut items: Vec<(Entity, String)> = Vec::new();
|
||||||
.join()
|
(&entities, &backpack)
|
||||||
.filter(|item| item.0.owner == *player_entity);
|
|
||||||
let count = inventory.count();
|
|
||||||
|
|
||||||
let mut y = (25 - (count / 2)) as i32;
|
|
||||||
ctx.draw_box(
|
|
||||||
15,
|
|
||||||
y - 2,
|
|
||||||
31,
|
|
||||||
(count + 3) as i32,
|
|
||||||
colors::WHITE,
|
|
||||||
colors::BLACK,
|
|
||||||
);
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y - 2,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"Remove Which Item?",
|
|
||||||
);
|
|
||||||
ctx.print_color(
|
|
||||||
18,
|
|
||||||
y + count as i32 + 1,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
"ESCAPE to cancel",
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut equippable: Vec<Entity> = Vec::new();
|
|
||||||
let mut j = 0;
|
|
||||||
#[allow(clippy::explicit_counter_loop)]
|
|
||||||
for (entity, _pack) in (&entities, &backpack)
|
|
||||||
.join()
|
.join()
|
||||||
.filter(|item| item.1.owner == *player_entity)
|
.filter(|item| item.1.owner == *player_entity)
|
||||||
{
|
.for_each(|item| items.push((item.0, get_item_display_name(&gs.ecs, item.0))));
|
||||||
ctx.set(17, y, colors::WHITE, colors::BLACK, rltk::to_cp437('('));
|
|
||||||
ctx.set(
|
|
||||||
18,
|
|
||||||
y,
|
|
||||||
colors::YELLOW,
|
|
||||||
colors::BLACK,
|
|
||||||
97 + j as rltk::FontCharType,
|
|
||||||
);
|
|
||||||
ctx.set(19, y, colors::WHITE, colors::BLACK, rltk::to_cp437(')'));
|
|
||||||
|
|
||||||
ctx.print_color(
|
let result = item_result_menu(
|
||||||
21,
|
&mut draw_batch,
|
||||||
y,
|
"Remove which item?",
|
||||||
get_item_color(&gs.ecs, entity),
|
items.len(),
|
||||||
colors::BLACK,
|
&items,
|
||||||
&get_item_display_name(&gs.ecs, entity),
|
ctx.key,
|
||||||
);
|
);
|
||||||
|
|
||||||
equippable.push(entity);
|
draw_batch
|
||||||
y += 1;
|
.submit(6000)
|
||||||
j += 1;
|
.expect("Failed to batch render Remove Item Menu");
|
||||||
}
|
|
||||||
|
|
||||||
match ctx.key {
|
result
|
||||||
None => (ItemMenuResult::NoResponse, None),
|
|
||||||
Some(key) => match key {
|
|
||||||
VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None),
|
|
||||||
_ => {
|
|
||||||
let selection = rltk::letter_to_option(key);
|
|
||||||
if selection > -1 && selection < count as i32 {
|
|
||||||
return (
|
|
||||||
ItemMenuResult::Selected,
|
|
||||||
Some(equippable[selection as usize]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
(ItemMenuResult::NoResponse, None)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user