Inventory

Former-commit-id: 01df86c3a652e4a36d37edfdcc90dc350c1e5b04
This commit is contained in:
Pfauenauge90 2019-04-02 06:54:27 +02:00
parent 8378663cca
commit a4f96b4642
3 changed files with 407 additions and 380 deletions

View File

@ -16,6 +16,8 @@ use conrod_core::{
widget_ids! {
struct Ids {
// Test
bag_space_add,
// Bag and Inventory
bag,
bag_contents,
@ -24,6 +26,7 @@ widget_ids! {
inv_alignment,
inv_grid,
inv_scrollbar,
inv_slot[],
//help
help,
help_bg,
@ -127,6 +130,7 @@ struct Imgs {
bag_open_press: ImgId,
bag_contents: ImgId,
inv_grid: ImgId,
inv_slot: ImgId,
// Close button
close_button: ImgId,
@ -231,6 +235,7 @@ impl Imgs {
bag_open_press: load("element/buttons/bag/open_press.png"),
bag_contents: load("element/frames/bag.png"),
inv_grid: load("element/frames/inv_grid.png"),
inv_slot: load("element/buttons/x.png"),
// Close button
close_button: load("element/buttons/x.png"),
@ -369,6 +374,7 @@ pub struct Hud {
open_windows: Windows,
map_open: bool,
show_ui: bool,
inventory_space: i32,
settings_tab: SettingsTab,
}
@ -411,6 +417,7 @@ impl Hud {
menu_open: false,
map_open: false,
show_ui: true,
inventory_space: 8,
open_windows: Windows::None,
font_metamorph,
font_opensans,
@ -420,7 +427,22 @@ impl Hud {
fn update_layout(&mut self) -> Vec<Event> {
let mut events = Vec::new();
let ref mut ui_widgets = self.ui.set_widgets();
if self.show_ui {
// Add Bag-Space Button
if Button::image(self.imgs.mmap_button)
.w_h(50.0, 50.0)
.top_right_with_margins_on(ui_widgets.window, 2.0, 2.0)
.label("+1 Space")
.label_font_size(10)
.hover_image(self.imgs.mmap_button_hover)
.press_image(self.imgs.mmap_button_press)
.set(self.ids.bag_space_add, ui_widgets)
.was_clicked()
{
self.inventory_space = self.inventory_space + 1;
};
// Chat box
if let Some(msg) = self
.chat
@ -444,7 +466,7 @@ impl Hud {
F2 = Toggle Interface \n\
\n\
M = Map \n\
I = Inventory \n\
B = Bag \n\
L = Quest-Log \n\
C = Character Window \n\
O = Social \n\
@ -489,7 +511,7 @@ impl Hud {
.set(self.ids.mmap_icons, ui_widgets);
// Title
// TODO Make it display the actual Location
Text::new("Unknown Location")
Text::new("Uncanny Valley")
.mid_top_with_margin_on(self.ids.mmap_frame, 5.0)
.font_size(14)
.rgba(220.0, 220.0, 220.0, 0.8)
@ -708,7 +730,7 @@ impl Hud {
.set(self.ids.inv_alignment, ui_widgets);
// Grid
Image::new(self.imgs.inv_grid)
.w_h(251.0, 951.0)
.w_h(232.0, 1104.0)
.mid_top_with_margin_on(self.ids.inv_alignment, 0.0)
.set(self.ids.inv_grid, ui_widgets);
Scrollbar::y_axis(self.ids.inv_alignment)
@ -727,6 +749,20 @@ impl Hud {
{
self.bag_open = false;
}
//if num > 0 {
//Button::image(self.imgs.inv_slot)
//.mid_top_with_margin_on(self.ids.inv_grid, 8.0)
//.w_h(33.0, 34.0)
//.set(self.ids.inv_slot[0], ui_widgets);
// }
//for i in 1..num {
//Button::image(self.imgs.menu_button)
// .down(10.0)
// .label(&format!("Button {}", i + 1))
// .label_rgb(1.0, 0.4, 1.0)
// .label_font_size(7)
// .set(self.ids.menu_buttons[i], ui_widgets);
}
}
// Bag
if !self.map_open {
@ -738,7 +774,7 @@ impl Hud {
.set(self.ids.bag, ui_widgets);
} else {
Image::new(self.imgs.bag)
.bottom_right_with_margin_on(ui_widgets.window, 20.0)
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.w_h(420.0 / 6.0, 480.0 / 6.0)
.set(self.ids.bag_map_open, ui_widgets);
}
@ -1212,7 +1248,7 @@ impl Hud {
events.push(Event::Quit);
};
}
}
// update whether keyboard is captured
self.typing =
if let Some(widget_id) = ui_widgets.global_input().current.widget_capturing_keyboard {
@ -1231,7 +1267,7 @@ impl Hud {
pub fn toggle_menu(&mut self) {
self.menu_open = !self.menu_open;
}
pub fn toggle_inventory(&mut self) {
pub fn toggle_bag(&mut self) {
self.bag_open = !self.bag_open
}
pub fn toggle_questlog(&mut self) {
@ -1296,8 +1332,6 @@ impl Hud {
self.show_ui = !self.show_ui;
}
pub fn update_grab(&mut self, cursor_grabbed: bool) {
self.cursor_grabbed = cursor_grabbed;
}

View File

@ -122,16 +122,15 @@ impl PlayState for SessionState {
}
let _handled = match event {
Event::Close => return PlayStateResult::Shutdown,
// When 'm' is pressed, open/close the map window
Event::Char('m') => self.hud.toggle_map(),
Event::Char('i') => self.hud.toggle_inventory(),
Event::Char('l') => self.hud.toggle_questlog(),
Event::Char('c') => self.hud.toggle_charwindow(),
Event::Char('o') => self.hud.toggle_social(),
Event::Char('p') => self.hud.toggle_spellbook(),
Event::Char('n') => self.hud.toggle_settings(),
Event::KeyDown(Key::Interface) => self.hud.toggle_help(),
Event::KeyDown(Key::Help) => self.hud.toggle_ui(),
Event::KeyDown(Key::Map) => self.hud.toggle_map(),
Event::KeyDown(Key::Bag) => self.hud.toggle_bag(),
Event::KeyDown(Key::QuestLog) => self.hud.toggle_questlog(),
Event::KeyDown(Key::CharacterWindow) => self.hud.toggle_charwindow(),
Event::KeyDown(Key::Social) => self.hud.toggle_social(),
Event::KeyDown(Key::Spellbook) => self.hud.toggle_spellbook(),
Event::KeyDown(Key::Settings) => self.hud.toggle_settings(),
Event::KeyDown(Key::Help) => self.hud.toggle_help(),
Event::KeyDown(Key::Interface) => self.hud.toggle_ui(),
// Close windows on esc
Event::KeyDown(Key::Escape) => self.hud.toggle_windows(),

View File

@ -1,14 +1,9 @@
use vek::*;
use std::collections::HashMap;
use crate::{
Error,
render::{
Renderer,
TgtColorFmt,
TgtDepthFmt,
},
ui,
render::{Renderer, TgtColorFmt, TgtDepthFmt},
ui, Error,
};
use std::collections::HashMap;
use vek::*;
pub struct Window {
events_loop: glutin::EventsLoop,
@ -19,7 +14,6 @@ pub struct Window {
key_map: HashMap<glutin::VirtualKeyCode, Key>,
}
impl Window {
pub fn new() -> Result<Window, Error> {
let events_loop = glutin::EventsLoop::new();
@ -33,17 +27,13 @@ impl Window {
.with_gl(glutin::GlRequest::Specific(glutin::Api::OpenGl, (3, 2)))
.with_vsync(false);
let (
window,
device,
factory,
tgt_color_view,
tgt_depth_view,
) = gfx_window_glutin::init::<TgtColorFmt, TgtDepthFmt>(
let (window, device, factory, tgt_color_view, tgt_depth_view) =
gfx_window_glutin::init::<TgtColorFmt, TgtDepthFmt>(
win_builder,
ctx_builder,
&events_loop,
).map_err(|err| Error::BackendError(Box::new(err)))?;
)
.map_err(|err| Error::BackendError(Box::new(err)))?;
let mut key_map = HashMap::new();
key_map.insert(glutin::VirtualKeyCode::Tab, Key::ToggleCursor);
@ -54,7 +44,7 @@ impl Window {
key_map.insert(glutin::VirtualKeyCode::S, Key::MoveBack);
key_map.insert(glutin::VirtualKeyCode::D, Key::MoveRight);
key_map.insert(glutin::VirtualKeyCode::M, Key::Map);
key_map.insert(glutin::VirtualKeyCode::I, Key::Inventory);
key_map.insert(glutin::VirtualKeyCode::B, Key::Bag);
key_map.insert(glutin::VirtualKeyCode::L, Key::QuestLog);
key_map.insert(glutin::VirtualKeyCode::C, Key::CharacterWindow);
key_map.insert(glutin::VirtualKeyCode::O, Key::Social);
@ -63,15 +53,9 @@ impl Window {
key_map.insert(glutin::VirtualKeyCode::F1, Key::Help);
key_map.insert(glutin::VirtualKeyCode::F2, Key::Interface);
let tmp = Ok(Self {
events_loop,
renderer: Renderer::new(
device,
factory,
tgt_color_view,
tgt_depth_view,
)?,
renderer: Renderer::new(device, factory, tgt_color_view, tgt_depth_view)?,
window,
cursor_grabbed: false,
needs_refresh_resize: false,
@ -80,8 +64,12 @@ impl Window {
tmp
}
pub fn renderer(&self) -> &Renderer { &self.renderer }
pub fn renderer_mut(&mut self) -> &mut Renderer { &mut self.renderer }
pub fn renderer(&self) -> &Renderer {
&self.renderer
}
pub fn renderer_mut(&mut self) -> &mut Renderer {
&mut self.renderer
}
pub fn fetch_events(&mut self) -> Vec<Event> {
let mut events = vec![];
@ -109,44 +97,45 @@ impl Window {
glutin::WindowEvent::CloseRequested => events.push(Event::Close),
glutin::WindowEvent::Resized(glutin::dpi::LogicalSize { width, height }) => {
let (mut color_view, mut depth_view) = renderer.target_views_mut();
gfx_window_glutin::update_views(
&window,
&mut color_view,
&mut depth_view,
);
gfx_window_glutin::update_views(&window, &mut color_view, &mut depth_view);
events.push(Event::Resize(Vec2::new(width as u32, height as u32)));
},
}
glutin::WindowEvent::ReceivedCharacter(c) => events.push(Event::Char(c)),
glutin::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
glutin::WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode
{
Some(keycode) => match key_map.get(&keycode) {
Some(&key) => events.push(match input.state {
glutin::ElementState::Pressed => Event::KeyDown(key),
_ => Event::KeyUp(key),
}),
_ => {},
_ => {}
},
_ => {},
_ => {}
},
_ => {},
_ => {}
},
glutin::Event::DeviceEvent { event, .. } => match event {
glutin::DeviceEvent::MouseMotion { delta: (dx, dy), .. } if cursor_grabbed =>
events.push(Event::CursorPan(Vec2::new(dx as f32, dy as f32))),
glutin::DeviceEvent::MouseMotion {
delta: (dx, dy), ..
} if cursor_grabbed => {
events.push(Event::CursorPan(Vec2::new(dx as f32, dy as f32)))
}
glutin::DeviceEvent::MouseWheel {
delta: glutin::MouseScrollDelta::LineDelta(_x, y),
..
} if cursor_grabbed => events.push(Event::Zoom(y as f32)),
_ => {},
_ => {}
},
_ => {},
_ => {}
}
});
events
}
pub fn swap_buffers(&self) -> Result<(), Error> {
self.window.swap_buffers()
self.window
.swap_buffers()
.map_err(|err| Error::BackendError(Box::new(err)))
}
@ -157,7 +146,8 @@ impl Window {
pub fn grab_cursor(&mut self, grab: bool) {
self.cursor_grabbed = grab;
self.window.hide_cursor(grab);
self.window.grab_cursor(grab)
self.window
.grab_cursor(grab)
.expect("Failed to grab/ungrab cursor");
}
@ -166,7 +156,11 @@ impl Window {
}
pub fn logical_size(&self) -> Vec2<f64> {
let (w, h) = self.window.get_inner_size().unwrap_or(glutin::dpi::LogicalSize::new(0.0, 0.0)).into();
let (w, h) = self
.window
.get_inner_size()
.unwrap_or(glutin::dpi::LogicalSize::new(0.0, 0.0))
.into();
Vec2::new(w, h)
}
}
@ -182,7 +176,7 @@ pub enum Key {
Enter,
Escape,
Map,
Inventory,
Bag,
QuestLog,
CharacterWindow,
Social,