Separate bag + buttons into own file

Former-commit-id: 08e3b640adb85266ce7a739008fa26e1caee0ebf
This commit is contained in:
timokoesters 2019-05-04 12:43:37 +02:00 committed by Imbris
parent abd960aa48
commit 819e0a200f
4 changed files with 439 additions and 443 deletions

125
voxygen/src/hud/bag.rs Normal file
View File

@ -0,0 +1,125 @@
use conrod_core::{
builder_methods, color,
text::font,
widget::{self, Button, Image, Rectangle, Text, Scrollbar},
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
use super::{
img_ids::Imgs,
font_ids::Fonts,
TEXT_COLOR,
};
widget_ids! {
struct Ids {
bag_close,
bag_contents,
inv_alignment,
inv_grid,
inv_scrollbar,
inv_slot_0,
map_title,
}
}
#[derive(WidgetCommon)]
pub struct Bag<'a> {
inventory_space: u32,
imgs: &'a Imgs,
fonts: &'a Fonts,
#[conrod(common_builder)]
common: widget::CommonBuilder,
style: (),
}
impl<'a> Bag<'a> {
pub fn new(inventory_space: u32, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self {
inventory_space,
imgs,
fonts,
common: widget::CommonBuilder::default(),
style: (),
}
}
}
pub struct State {
ids: Ids,
}
pub enum Event {
Close,
}
impl<'a> Widget for Bag<'a> {
type State = State;
type Style = ();
type Event = Option<Event>;
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: Ids::new(id_gen),
}
}
fn style(&self) -> Self::Style {
()
}
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs {
id,
state,
ui,
style,
..
} = args;
// Contents
Image::new(self.imgs.bag_contents)
.w_h(307.0, 545.0)
.bottom_right_with_margins_on(ui.window, 90.0, 5.0)
.set(state.ids.bag_contents, ui);
// Alignment for Grid
Rectangle::fill_with([246.0, 465.0], color::TRANSPARENT)
.top_left_with_margins_on(state.ids.bag_contents, 27.0, 23.0)
.scroll_kids()
.scroll_kids_vertically()
.set(state.ids.inv_alignment, ui);
// Grid
Image::new(self.imgs.inv_grid)
.w_h(232.0, 1104.0)
.mid_top_with_margin_on(state.ids.inv_alignment, 0.0)
.set(state.ids.inv_grid, ui);
Scrollbar::y_axis(state.ids.inv_alignment)
.thickness(5.0)
.rgba(0.86, 0.86, 0.86, 0.1)
.set(state.ids.inv_scrollbar, ui);
// X-button
if Button::image(self.imgs.close_button)
.w_h(244.0 * 0.22 / 3.0, 244.0 * 0.22 / 3.0)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(state.ids.bag_contents, 5.0, 17.0)
.set(state.ids.bag_close, ui)
.was_clicked()
{
return Some(Event::Close);
}
if self.inventory_space > 0 {
// First Slot
Button::image(self.imgs.inv_slot)
.top_left_with_margins_on(state.ids.inv_grid, 5.0, 5.0)
.w_h(40.0, 40.0)
.set(state.ids.inv_slot_0, ui);
}
None
}
}

253
voxygen/src/hud/buttons.rs Normal file
View File

@ -0,0 +1,253 @@
use conrod_core::{
builder_methods, color,
text::font,
widget::{self, Button, Image, Rectangle, Text},
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
};
use super::{
img_ids::Imgs,
font_ids::Fonts,
small_window::SmallWindowType,
Windows,
TEXT_COLOR,
};
use crate::ui::ToggleButton;
widget_ids! {
struct Ids {
bag,
bag_text,
bag_show_map,
character_button,
character_button_bg,
map_button,
qlog_button,
qlog_button_bg,
settings_button,
social_button,
social_button_bg,
spellbook_button,
spellbook_button_bg,
}
}
#[derive(WidgetCommon)]
pub struct Buttons<'a> {
open_windows: &'a Windows,
show_map: bool,
show_bag: bool,
imgs: &'a Imgs,
fonts: &'a Fonts,
#[conrod(common_builder)]
common: widget::CommonBuilder,
style: (),
}
impl<'a> Buttons<'a> {
pub fn new(open_windows: &'a Windows, show_map: bool, show_bag: bool, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
Self {
open_windows,
show_map,
show_bag,
imgs,
fonts,
common: widget::CommonBuilder::default(),
style: (),
}
}
}
pub struct State {
ids: Ids,
}
pub enum Event {
ToggleBag,
ToggleSettings,
ToggleMap,
ToggleSmall(SmallWindowType),
ToggleCharacter,
}
impl<'a> Widget for Buttons<'a> {
type State = State;
type Style = ();
type Event = Option<Event>;
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
State {
ids: Ids::new(id_gen),
}
}
fn style(&self) -> Self::Style {
()
}
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
let widget::UpdateArgs {
id,
state,
ui,
style,
..
} = args;
// Bag
if !self.show_map {
if self.show_bag != ToggleButton::new(self.show_bag, self.imgs.bag, self.imgs.bag_open)
.bottom_right_with_margins_on(ui.window, 5.0, 5.0)
.hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover)
.press_images(self.imgs.bag_press, self.imgs.bag_open_press)
.w_h(420.0 / 10.0, 480.0 / 10.0)
.set(state.ids.bag, ui) {
return Some(Event::ToggleBag);
}
Text::new("B")
.bottom_right_with_margins_on(state.ids.bag, 0.0, 0.0)
.font_size(10)
.color(TEXT_COLOR)
.set(state.ids.bag_text, ui);
} else {
Image::new(self.imgs.bag)
.bottom_right_with_margins_on(ui.window, 5.0, 5.0)
.w_h(420.0 / 10.0, 480.0 / 10.0)
.set(state.ids.bag_show_map, ui);
Text::new("B")
.bottom_right_with_margins_on(state.ids.bag, 0.0, 0.0)
.font_size(10)
.color(TEXT_COLOR)
.set(state.ids.bag_text, ui);
}
// 0 Settings
if Button::image(self.imgs.settings)
.w_h(29.0, 25.0)
.bottom_right_with_margins_on(ui.window, 5.0, 57.0)
.hover_image(self.imgs.settings_hover)
.press_image(self.imgs.settings_press)
.label("N")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.settings_button, ui)
.was_clicked()
{
return Some(Event::ToggleSettings);
};
// 2 Map
if Button::image(self.imgs.map_button)
.w_h(22.0, 25.0)
.left_from(state.ids.social_button, 10.0)
.hover_image(self.imgs.map_hover)
.press_image(self.imgs.map_press)
.label("M")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.map_button, ui)
.was_clicked()
{
return Some(Event::ToggleMap);
};
// Other Windows can only be accessed, when Settings are closed.
// Opening Settings will close all other Windows including the Bag.
// Opening the Map won't close the windows displayed before.
Image::new(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(state.ids.settings_button, 10.0)
.set(state.ids.social_button_bg, ui);
Image::new(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(state.ids.map_button, 10.0)
.set(state.ids.spellbook_button_bg, ui);
Image::new(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(state.ids.spellbook_button, 10.0)
.set(state.ids.character_button_bg, ui);
Image::new(self.imgs.qlog_button)
.w_h(23.0, 25.0)
.left_from(state.ids.character_button, 10.0)
.set(state.ids.qlog_button_bg, ui);
if !(*self.open_windows == Windows::Settings) && self.show_map == false {
// 1 Social
if Button::image(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(state.ids.settings_button, 10.0)
.hover_image(self.imgs.social_hover)
.press_image(self.imgs.social_press)
.label("O")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.social_button, ui)
.was_clicked()
{
return Some(Event::ToggleSmall(SmallWindowType::Social));
}
// 3 Spellbook
if Button::image(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(state.ids.map_button, 10.0)
.hover_image(self.imgs.spellbook_hover)
.press_image(self.imgs.spellbook_press)
.label("P")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.spellbook_button, ui)
.was_clicked()
{
return Some(Event::ToggleSmall(SmallWindowType::Spellbook));
}
// 4 Char-Window
if Button::image(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(state.ids.spellbook_button, 10.0)
.hover_image(self.imgs.character_hover)
.press_image(self.imgs.character_press)
.label("C")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.character_button, ui)
.was_clicked()
{
return Some(Event::ToggleCharacter);
}
// 5 Quest-Log
if Button::image(self.imgs.qlog_button)
.w_h(23.0, 25.0)
.left_from(state.ids.character_button, 10.0)
.hover_image(self.imgs.qlog_hover)
.press_image(self.imgs.qlog_press)
.label("L")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(state.ids.qlog_button, ui)
.was_clicked()
{
return Some(Event::ToggleSmall(SmallWindowType::QuestLog));
}
}
None
}
}

View File

@ -1,7 +1,9 @@
mod chat;
mod character_window;
mod skillbar;
mod buttons;
mod map;
mod bag;
mod esc_menu;
mod small_window;
mod settings_window;
@ -11,7 +13,9 @@ mod font_ids;
use chat::Chat;
use character_window::CharacterWindow;
use map::Map;
use bag::Bag;
use skillbar::Skillbar;
use buttons::Buttons;
use esc_menu::EscMenu;
use small_window::{SmallWindow, SmallWindowType};
use settings_window::SettingsWindow;
@ -43,80 +47,22 @@ widget_ids! {
struct Ids {
// Test
bag_space_add,
inventorytest_button,
inventorytest_button_label,
// Debug
debug_bg,
debug_button,
debug_button_label,
fps_counter,
// Game Version
version,
// Bag and Inventory
bag,
bag_contents,
bag_close,
bag_map_open,
inv_alignment,
inv_grid_1,
inv_grid_2,
inv_scrollbar,
inv_slot_0,
inv_slot[],
// Buttons
settings_button,
social_button,
map_button,
spellbook_button,
character_button,
qlog_button,
social_button_bg,
spellbook_button_bg,
character_button_bg,
qlog_button_bg,
bag_text,
mmap_button,
// Help
help,
help_bg,
// ESC-Menu
esc_bg,
fireplace,
menu_button_1,
menu_button_2,
menu_button_3,
menu_button_4,
menu_button_5,
// Mini-Map
mmap_frame,
mmap_frame_bg,
mmap_location,
// Action-Bar
xp_bar,
l_click,
r_click,
health_bar,
mana_bar,
sb_grid_l,
sb_grid_r,
sb_grid_bg_l,
sb_grid_bg_r,
xp_bar_progress,
health_bar_color,
mana_bar_color,
// Level Display
level_text,
next_level_text,
// Window Frames
window_frame_0,
window_frame_1,
@ -126,42 +72,15 @@ widget_ids! {
window_frame_5,
// Contents
button_help,
button_help2,
show_help_label,
interface,
video,
sound,
gameplay,
controls,
rectangle,
// 1 Social
social_frame,
social_bg,
social_icon,
social_close,
social_title,
// 3 Spellbook
spellbook_frame,
spellbook_bg,
spellbook_icon,
spellbook_close,
spellbook_title,
// 5 Quest-Log
questlog_frame,
questlog_bg,
questlog_icon,
questlog_close,
questlog_title,
// External
chat,
map,
character_window,
bag,
skillbar,
buttons,
esc_menu,
small_window,
settings_window,
@ -177,7 +96,8 @@ pub enum Event {
// TODO: are these the possible layouts we want?
// TODO: maybe replace this with bitflags
// map not here because it currently is displayed over the top of other open windows
enum Windows {
#[derive(PartialEq)]
pub enum Windows {
Settings, // display settings window
CharacterAnd(Option<SmallWindowType>), // show character window + optionally another
Small(SmallWindowType),
@ -192,16 +112,13 @@ pub struct Hud {
new_messages: VecDeque<String>,
show_help: bool,
show_debug: bool,
bag_open: bool,
show_bag: bool,
esc_menu_open: bool,
open_windows: Windows,
map_open: bool,
mmap_open: bool,
show_map: bool,
show_ui: bool,
inventory_space: u32,
xp_percentage: f64,
hp_percentage: f64,
mana_percentage: f64,
inventorytest_button: bool,
}
@ -225,27 +142,22 @@ impl Hud {
new_messages: VecDeque::new(),
show_help: true,
show_debug: false,
bag_open: false,
show_bag: false,
esc_menu_open: false,
map_open: false,
mmap_open: false,
open_windows: Windows::None,
show_map: false,
show_ui: true,
inventorytest_button: false,
inventory_space: 0,
open_windows: Windows::None,
xp_percentage: 0.4,
hp_percentage: 1.0,
mana_percentage: 1.0,
settings: settings,
}
}
fn update_layout(&mut self, tps: f64) -> Vec<Event> {
// Don't show anything if the UI is toggled off
let mut events = Vec::new();
let ref mut ui_widgets = self.ui.set_widgets();
let version = env!("CARGO_PKG_VERSION");
// Don't show anything if the UI is toggled off
if !self.show_ui {
return events;
}
@ -279,7 +191,7 @@ impl Hud {
.set(self.ids.bag_space_add, ui_widgets)
.was_clicked()
{
self.inventory_space = self.inventory_space + 1;
self.inventory_space += 1;
};
}
@ -315,312 +227,48 @@ impl Hud {
};
}
// Minimap
if self.mmap_open {
Image::new(self.imgs.mmap_frame)
.w_h(100.0 * 2.0, 100.0 * 2.0)
.top_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.set(self.ids.mmap_frame, ui_widgets);
Rectangle::fill_with([92.0 * 2.0, 82.0 * 2.0], color::TRANSPARENT)
.mid_top_with_margin_on(self.ids.mmap_frame, 13.0 * 2.0 + 2.0)
.set(self.ids.mmap_frame_bg, ui_widgets);
} else {
Image::new(self.imgs.mmap_frame_closed)
.w_h(100.0 * 2.0, 11.0 * 2.0)
.top_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.set(self.ids.mmap_frame, ui_widgets);
};
if Button::image(if self.mmap_open {
self.imgs.mmap_open
} else {
self.imgs.mmap_closed
})
.w_h(100.0 * 0.2, 100.0 * 0.2)
.hover_image(if self.mmap_open {
self.imgs.mmap_open_hover
} else {
self.imgs.mmap_closed_hover
})
.press_image(if self.mmap_open {
self.imgs.mmap_open_press
} else {
self.imgs.mmap_closed_press
})
.top_right_with_margins_on(self.ids.mmap_frame, 0.0, 0.0)
.set(self.ids.mmap_button, ui_widgets)
.was_clicked()
match Buttons::new(&self.open_windows, self.show_map, self.show_bag, &self.imgs, &self.fonts)
.set(self.ids.buttons, ui_widgets)
{
self.mmap_open = !self.mmap_open;
};
//Some(buttons::Event::ToggleBag) => self.toggle_bag(),
//Some(buttons::Event::ToggleSettings) => self.toggle_settings(),
//Some(buttons::Event::ToggleCharacter) => self.toggle_charwindow(),
//Some(buttons::Event::ToggleSmall(small)) => self.toggle_small(small),
//Some(buttons::Event::ToggleMap) => self.toggle_map(),
//None => {}
_ => {}
}
// Title
// Make it display the actual location
// Minimap
Image::new(self.imgs.mmap_frame_bg)
.w_h(1750.0 / 8.0, 1650.0 / 8.0)
.top_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.set(self.ids.mmap_frame_bg, ui_widgets);
Image::new(self.imgs.mmap_frame)
.w_h(1750.0 / 8.0, 1650.0 / 8.0)
.top_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.set(self.ids.mmap_frame, ui_widgets);
Text::new("Uncanny Valley")
.mid_top_with_margin_on(self.ids.mmap_frame, 3.0)
.font_size(14)
.color(TEXT_COLOR)
.set(self.ids.mmap_location, ui_widgets);
// Buttons at Bag
// 0 Settings
if Button::image(self.imgs.settings)
.w_h(29.0, 25.0)
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 57.0)
.hover_image(self.imgs.settings_hover)
.press_image(self.imgs.settings_press)
.label(&format!("{:?}", self.settings.controls.settings))
.label_font_size(10)
.label_font_id(self.font_metamorph)
.color(TEXT_COLOR)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.settings_button, ui_widgets)
.was_clicked()
{
self.open_windows = match self.open_windows {
Windows::Settings => Windows::None,
_ => Windows::Settings,
};
self.bag_open = false;
};
// 2 Map
if Button::image(self.imgs.map_button)
.w_h(22.0, 25.0)
.left_from(self.ids.social_button, 10.0)
.hover_image(self.imgs.map_hover)
.press_image(self.imgs.map_press)
.label(&format!("{:?}", self.settings.controls.map))
.label_font_size(10)
.label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.map_button, ui_widgets)
.was_clicked()
{
self.map_open = !self.map_open;
self.bag_open = false;
};
// Other Windows can only be accessed, when Settings are closed.
// Opening Settings will close all other Windows including the Bag.
// Opening the Map won't close the windows displayed before.
Image::new(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(self.ids.settings_button, 10.0)
.set(self.ids.social_button_bg, ui_widgets);
Image::new(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(self.ids.map_button, 10.0)
.set(self.ids.spellbook_button_bg, ui_widgets);
Image::new(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(self.ids.spellbook_button, 10.0)
.set(self.ids.character_button_bg, ui_widgets);
Image::new(self.imgs.qlog_button)
.w_h(23.0, 25.0)
.left_from(self.ids.character_button, 10.0)
.set(self.ids.qlog_button_bg, ui_widgets);
if match self.open_windows {
Windows::Settings => false,
_ => true,
} && self.map_open == false
{
// 1 Social
if Button::image(self.imgs.social_button)
.w_h(25.0, 25.0)
.left_from(self.ids.settings_button, 10.0)
.hover_image(self.imgs.social_hover)
.press_image(self.imgs.social_press)
.label(&format!("{:?}", self.settings.controls.social))
.label_font_size(10)
.label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.social_button, ui_widgets)
.was_clicked()
{
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Social) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Social),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Social) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Social)),
},
Windows::Settings => Windows::Settings,
};
}
// 3 Spellbook
if Button::image(self.imgs.spellbook_button)
.w_h(28.0, 25.0)
.left_from(self.ids.map_button, 10.0)
.hover_image(self.imgs.spellbook_hover)
.press_image(self.imgs.spellbook_press)
.label(&format!("{:?}", self.settings.controls.spellbook))
.label_font_size(10)
.label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.spellbook_button, ui_widgets)
.was_clicked()
{
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Spellbook) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Spellbook),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Spellbook) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Spellbook)),
},
Windows::Settings => Windows::Settings,
};
}
// 4 Char-Window
if Button::image(self.imgs.character_button)
.w_h(27.0, 25.0)
.left_from(self.ids.spellbook_button, 10.0)
.hover_image(self.imgs.character_hover)
.press_image(self.imgs.character_press)
.label(&format!("{:?}", self.settings.controls.character_window))
.label_font_size(10)
.label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.character_button, ui_widgets)
.was_clicked()
{
self.open_windows = match self.open_windows {
Windows::CharacterAnd(small) => match small {
Some(small) => Windows::Small(small),
None => Windows::None,
},
Windows::Small(small) => Windows::CharacterAnd(Some(small)),
Windows::None => Windows::CharacterAnd(None),
Windows::Settings => Windows::Settings,
}
}
// 5 Quest-Log
if Button::image(self.imgs.qlog_button)
.w_h(23.0, 25.0)
.left_from(self.ids.character_button, 10.0)
.hover_image(self.imgs.qlog_hover)
.press_image(self.imgs.qlog_press)
.label("L")
.label_font_size(10)
.label_color(TEXT_COLOR)
.label_y(conrod_core::position::Relative::Scalar(-7.0))
.label_x(conrod_core::position::Relative::Scalar(10.0))
.set(self.ids.qlog_button, ui_widgets)
.was_clicked()
{
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Questlog) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Questlog),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Questlog) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Questlog)),
},
Windows::Settings => Windows::Settings,
};
}
}
// Bag contents
if self.bag_open {
// Contents
Image::new(self.imgs.bag_contents)
.w_h(68.0 * 4.0, 123.0 * 4.0)
.bottom_right_with_margins_on(ui_widgets.window, 60.0, 5.0)
.set(self.ids.bag_contents, ui_widgets);
// Alignment for Grid
Rectangle::fill_with([58.0 * 4.0 - 5.0, 100.0 * 4.0], color::TRANSPARENT)
.top_left_with_margins_on(self.ids.bag_contents, 11.0 * 4.0, 5.0 * 4.0)
.scroll_kids()
.scroll_kids_vertically()
.set(self.ids.inv_alignment, ui_widgets);
// Grid
Image::new(self.imgs.inv_grid)
.w_h(58.0 * 4.0, 111.0 * 4.0)
.mid_top_with_margin_on(self.ids.inv_alignment, 0.0)
.set(self.ids.inv_grid_1, ui_widgets);
Image::new(self.imgs.inv_grid)
.w_h(58.0 * 4.0, 111.0 * 4.0)
.mid_top_with_margin_on(self.ids.inv_alignment, 110.0 * 4.0)
.set(self.ids.inv_grid_2, ui_widgets);
Scrollbar::y_axis(self.ids.inv_alignment)
.thickness(5.0)
.rgba(0.33, 0.33, 0.33, 1.0)
.set(self.ids.inv_scrollbar, ui_widgets);
// X-button
if Button::image(self.imgs.close_button)
.w_h(28.0, 28.0)
.hover_image(self.imgs.close_button_hover)
.press_image(self.imgs.close_button_press)
.top_right_with_margins_on(self.ids.bag_contents, 0.0, 0.0)
.set(self.ids.bag_close, ui_widgets)
.was_clicked()
if self.show_bag {
match Bag::new(self.inventory_space, &self.imgs, &self.fonts)
.set(self.ids.bag, ui_widgets)
{
self.bag_open = false;
Some(bag::Event::Close) => self.show_bag = false,
None => {}
}
if self.inventory_space > 0 {
// First Slot
Button::image(self.imgs.inv_slot)
.top_left_with_margins_on(self.ids.inv_grid_1, 4.0, 4.0)
.w_h(10.0 * 4.0, 10.0 * 4.0)
.set(self.ids.inv_slot_0, ui_widgets);
}
}
// Bag
if !self.map_open && self.show_ui {
self.bag_open = ToggleButton::new(self.bag_open, self.imgs.bag, self.imgs.bag_open)
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.hover_images(self.imgs.bag_hover, self.imgs.bag_open_hover)
.press_images(self.imgs.bag_press, self.imgs.bag_open_press)
.w_h(420.0 / 10.0, 480.0 / 10.0)
.set(self.ids.bag, ui_widgets);
Text::new(&format!("{:?}", self.settings.controls.bag))
.bottom_right_with_margins_on(self.ids.bag, 0.0, 0.0)
.font_size(10)
.font_id(self.font_metamorph)
.color(TEXT_COLOR)
.set(self.ids.bag_text, ui_widgets);
} else {
Image::new(self.imgs.bag)
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 5.0)
.w_h(420.0 / 10.0, 480.0 / 10.0)
.set(self.ids.bag_map_open, ui_widgets);
Text::new(&format!("{:?}", self.settings.controls.bag))
.bottom_right_with_margins_on(self.ids.bag, 0.0, 0.0)
.font_size(10)
.font_id(self.font_metamorph)
.set(self.ids.bag_text, ui_widgets);
}
Skillbar::new(&self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
.set(self.ids.skillbar, ui_widgets);
// Chat box
match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
.set(self.ids.chat, ui_widgets)
{
Some(chat::Event::SendMessage(message)) => {
@ -639,8 +287,6 @@ impl Hud {
if let Windows::Settings = self.open_windows {
match SettingsWindow::new(&self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
.set(self.ids.settings_window, ui_widgets)
{
Some(settings_window::Event::Close) => {
@ -657,8 +303,6 @@ impl Hud {
_ => None,
} {
match SmallWindow::new(small, &self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
.set(self.ids.small_window, ui_widgets)
{
Some(small_window::Event::Close) => self.open_windows = match self.open_windows {
@ -673,8 +317,6 @@ impl Hud {
// Character Window
if let Windows::CharacterAnd(small) = self.open_windows {
match CharacterWindow::new(&self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.w_h(103.0 * 4.0, 122.0 * 4.0) // TODO: replace this with default_width() / height() overrides
.set(self.ids.character_window, ui_widgets)
{
Some(character_window::Event::Close) => self.open_windows = match small {
@ -686,12 +328,11 @@ impl Hud {
}
// Map
if self.map_open {
if self.show_map {
match Map::new(&self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.set(self.ids.map, ui_widgets)
{
Some(map::Event::Close) => self.map_open = false,
Some(map::Event::Close) => self.show_map = false,
None => {}
}
}
@ -700,7 +341,6 @@ impl Hud {
// Esc-menu
if self.esc_menu_open {
match EscMenu::new(&self.imgs, &self.fonts)
.top_left_with_margins_on(ui_widgets.window, 200.0, 215.0)
.set(self.ids.esc_menu, ui_widgets)
{
Some(esc_menu::Event::OpenSettings) => {
@ -725,19 +365,19 @@ impl Hud {
self.esc_menu_open = !self.esc_menu_open;
}
fn toggle_bag(&mut self) {
self.bag_open = !self.bag_open
self.show_bag = !self.show_bag
}
fn toggle_map(&mut self) {
self.map_open = !self.map_open;
self.bag_open = false;
self.show_map = !self.show_map;
self.show_bag = false;
}
fn toggle_questlog(&mut self) {
fn toggle_small(&mut self, target: SmallWindowType) {
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Questlog) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Questlog),
Windows::Small(small) if small == target => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(target),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Questlog) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Questlog)),
Some(small) if small == target => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(target)),
},
Windows::Settings => Windows::Settings,
};
@ -753,34 +393,12 @@ impl Hud {
Windows::Settings => Windows::Settings,
}
}
fn toggle_social(&mut self) {
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Social) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Social),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Social) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Social)),
},
Windows::Settings => Windows::Settings,
};
}
fn toggle_spellbook(&mut self) {
self.open_windows = match self.open_windows {
Windows::Small(SmallWindowType::Spellbook) => Windows::None,
Windows::None | Windows::Small(_) => Windows::Small(SmallWindowType::Spellbook),
Windows::CharacterAnd(small) => match small {
Some(SmallWindowType::Spellbook) => Windows::CharacterAnd(None),
_ => Windows::CharacterAnd(Some(SmallWindowType::Spellbook)),
},
Windows::Settings => Windows::Settings,
};
}
fn toggle_settings(&mut self) {
self.open_windows = match self.open_windows {
Windows::Settings => Windows::None,
_ => Windows::Settings,
};
self.bag_open = false;
self.show_bag = false;
}
fn toggle_help(&mut self) {
self.show_help = !self.show_help
@ -790,17 +408,17 @@ impl Hud {
}
fn toggle_windows(&mut self, global_state: &mut GlobalState) {
if self.bag_open
if self.show_bag
|| self.esc_menu_open
|| self.map_open
|| self.show_map
|| match self.open_windows {
Windows::None => false,
_ => true,
}
{
self.bag_open = false;
self.show_bag = false;
self.esc_menu_open = false;
self.map_open = false;
self.show_map = false;
self.open_windows = Windows::None;
global_state.window.grab_cursor(true);
} else {
@ -856,7 +474,7 @@ impl Hud {
true
}
Key::QuestLog => {
self.toggle_questlog();
self.toggle_small(SmallWindowType::QuestLog);
true
}
Key::CharacterWindow => {
@ -864,11 +482,11 @@ impl Hud {
true
}
Key::Social => {
self.toggle_social();
self.toggle_small(SmallWindowType::Social);
true
}
Key::Spellbook => {
self.toggle_spellbook();
self.toggle_small(SmallWindowType::Spellbook);
true
}
Key::Settings => {

View File

@ -21,11 +21,11 @@ widget_ids! {
}
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq)]
pub enum SmallWindowType {
Spellbook,
Social,
Questlog,
QuestLog,
}
#[derive(WidgetCommon)]
@ -87,7 +87,7 @@ impl<'a> Widget for SmallWindow<'a> {
let (title, icon) = match self.content {
SmallWindowType::Social => ("Social", self.imgs.social_icon),
SmallWindowType::Spellbook => ("Spellbook", self.imgs.spellbook_icon),
SmallWindowType::Questlog => ("Questlog", self.imgs.questlog_icon),
SmallWindowType::QuestLog => ("QuestLog", self.imgs.questlog_icon),
};
// Frame
@ -140,7 +140,7 @@ impl<'a> Widget for SmallWindow<'a> {
match self.content {
SmallWindowType::Social => {}
SmallWindowType::Spellbook => {}
SmallWindowType::Questlog => {}
SmallWindowType::QuestLog => {}
}
None