mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move minimap into own file
Former-commit-id: 7c4a9b0930c899fc8e5089920c3ee5c717561a1a
This commit is contained in:
parent
81c5a070c5
commit
54cc96f0d1
115
voxygen/src/hud/minimap.rs
Normal file
115
voxygen/src/hud/minimap.rs
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
use conrod_core::{
|
||||||
|
color,
|
||||||
|
widget::{self, Text, Button, Image, Rectangle},
|
||||||
|
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::{TEXT_COLOR, Show, font_ids::Fonts, img_ids::Imgs};
|
||||||
|
|
||||||
|
widget_ids! {
|
||||||
|
struct Ids {
|
||||||
|
mmap_frame,
|
||||||
|
mmap_frame_bg,
|
||||||
|
mmap_location,
|
||||||
|
mmap_button,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(WidgetCommon)]
|
||||||
|
pub struct MiniMap<'a> {
|
||||||
|
show: &'a mut Show,
|
||||||
|
|
||||||
|
imgs: &'a Imgs,
|
||||||
|
fonts: &'a Fonts,
|
||||||
|
|
||||||
|
#[conrod(common_builder)]
|
||||||
|
common: widget::CommonBuilder,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> MiniMap<'a> {
|
||||||
|
pub fn new(show: &'a mut Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||||
|
Self {
|
||||||
|
show,
|
||||||
|
imgs,
|
||||||
|
fonts,
|
||||||
|
common: widget::CommonBuilder::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct State {
|
||||||
|
ids: Ids,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Event {
|
||||||
|
Close,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Widget for MiniMap<'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 { state, ui, .. } = args;
|
||||||
|
|
||||||
|
if self.show.mini_map {
|
||||||
|
Image::new(self.imgs.mmap_frame)
|
||||||
|
.w_h(100.0 * 2.0, 100.0 * 2.0)
|
||||||
|
.top_right_with_margins_on(ui.window, 5.0, 5.0)
|
||||||
|
.set(state.ids.mmap_frame, ui);
|
||||||
|
|
||||||
|
Rectangle::fill_with([92.0 * 2.0, 82.0 * 2.0], color::TRANSPARENT)
|
||||||
|
.mid_top_with_margin_on(state.ids.mmap_frame, 13.0 * 2.0 + 2.0)
|
||||||
|
.set(state.ids.mmap_frame_bg, ui);
|
||||||
|
} else {
|
||||||
|
Image::new(self.imgs.mmap_frame_closed)
|
||||||
|
.w_h(100.0 * 2.0, 11.0 * 2.0)
|
||||||
|
.top_right_with_margins_on(ui.window, 5.0, 5.0)
|
||||||
|
.set(state.ids.mmap_frame, ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
if Button::image(if self.show.mini_map {
|
||||||
|
self.imgs.mmap_open
|
||||||
|
} else {
|
||||||
|
self.imgs.mmap_closed
|
||||||
|
})
|
||||||
|
.w_h(100.0 * 0.2, 100.0 * 0.2)
|
||||||
|
.hover_image(if self.show.mini_map {
|
||||||
|
self.imgs.mmap_open_hover
|
||||||
|
} else {
|
||||||
|
self.imgs.mmap_closed_hover
|
||||||
|
})
|
||||||
|
.press_image(if self.show.mini_map {
|
||||||
|
self.imgs.mmap_open_press
|
||||||
|
} else {
|
||||||
|
self.imgs.mmap_closed_press
|
||||||
|
})
|
||||||
|
.top_right_with_margins_on(state.ids.mmap_frame, 0.0, 0.0)
|
||||||
|
.set(state.ids.mmap_button, ui)
|
||||||
|
.was_clicked()
|
||||||
|
{
|
||||||
|
self.show.toggle_mini_map();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Title
|
||||||
|
// Make it display the actual location
|
||||||
|
Text::new("Uncanny Valley")
|
||||||
|
.mid_top_with_margin_on(state.ids.mmap_frame, 3.0)
|
||||||
|
.font_size(14)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(state.ids.mmap_location, ui);
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
mod bag;
|
mod bag;
|
||||||
mod buttons;
|
mod buttons;
|
||||||
mod character_window;
|
mod character_window;
|
||||||
|
mod minimap;
|
||||||
mod chat;
|
mod chat;
|
||||||
mod esc_menu;
|
mod esc_menu;
|
||||||
mod font_ids;
|
mod font_ids;
|
||||||
@ -13,6 +14,7 @@ mod small_window;
|
|||||||
use bag::Bag;
|
use bag::Bag;
|
||||||
use buttons::Buttons;
|
use buttons::Buttons;
|
||||||
use character_window::CharacterWindow;
|
use character_window::CharacterWindow;
|
||||||
|
use minimap::MiniMap;
|
||||||
use chat::Chat;
|
use chat::Chat;
|
||||||
use esc_menu::EscMenu;
|
use esc_menu::EscMenu;
|
||||||
use font_ids::Fonts;
|
use font_ids::Fonts;
|
||||||
@ -56,12 +58,6 @@ widget_ids! {
|
|||||||
help,
|
help,
|
||||||
help_bg,
|
help_bg,
|
||||||
|
|
||||||
// Mini-Map
|
|
||||||
mmap_frame,
|
|
||||||
mmap_frame_bg,
|
|
||||||
mmap_location,
|
|
||||||
mmap_button,
|
|
||||||
|
|
||||||
// Window Frames
|
// Window Frames
|
||||||
window_frame_0,
|
window_frame_0,
|
||||||
window_frame_1,
|
window_frame_1,
|
||||||
@ -77,6 +73,7 @@ widget_ids! {
|
|||||||
chat,
|
chat,
|
||||||
map,
|
map,
|
||||||
character_window,
|
character_window,
|
||||||
|
minimap,
|
||||||
bag,
|
bag,
|
||||||
skillbar,
|
skillbar,
|
||||||
buttons,
|
buttons,
|
||||||
@ -118,13 +115,16 @@ impl Show {
|
|||||||
fn toggle_bag(&mut self) {
|
fn toggle_bag(&mut self) {
|
||||||
self.bag = !self.bag
|
self.bag = !self.bag
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_map(&mut self) {
|
fn toggle_map(&mut self) {
|
||||||
self.map = !self.map;
|
self.map = !self.map;
|
||||||
self.bag = false;
|
self.bag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_mini_map(&mut self) {
|
fn toggle_mini_map(&mut self) {
|
||||||
self.mini_map = !self.mini_map;
|
self.mini_map = !self.mini_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_small(&mut self, target: SmallWindowType) {
|
fn toggle_small(&mut self, target: SmallWindowType) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Small(small) if small == target => Windows::None,
|
Windows::Small(small) if small == target => Windows::None,
|
||||||
@ -136,6 +136,7 @@ impl Show {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_charwindow(&mut self) {
|
fn toggle_charwindow(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::CharacterAnd(small) => match small {
|
Windows::CharacterAnd(small) => match small {
|
||||||
@ -147,6 +148,7 @@ impl Show {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_settings(&mut self) {
|
fn toggle_settings(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Settings => Windows::None,
|
Windows::Settings => Windows::None,
|
||||||
@ -154,9 +156,11 @@ impl Show {
|
|||||||
};
|
};
|
||||||
self.bag = false;
|
self.bag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_help(&mut self) {
|
fn toggle_help(&mut self) {
|
||||||
self.help = !self.help
|
self.help = !self.help
|
||||||
}
|
}
|
||||||
|
|
||||||
fn toggle_ui(&mut self) {
|
fn toggle_ui(&mut self) {
|
||||||
self.ui = !self.ui;
|
self.ui = !self.ui;
|
||||||
}
|
}
|
||||||
@ -255,6 +259,7 @@ impl Hud {
|
|||||||
.font_size(14)
|
.font_size(14)
|
||||||
.set(self.ids.fps_counter, ui_widgets);
|
.set(self.ids.fps_counter, ui_widgets);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Bag-Space Button
|
// Add Bag-Space Button
|
||||||
if self.show.inventory_test_button {
|
if self.show.inventory_test_button {
|
||||||
if Button::image(self.imgs.grid_button)
|
if Button::image(self.imgs.grid_button)
|
||||||
@ -270,6 +275,7 @@ impl Hud {
|
|||||||
self.inventory_space += 1;
|
self.inventory_space += 1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Help Text
|
// Help Text
|
||||||
if self.show.help {
|
if self.show.help {
|
||||||
Image::new(self.imgs.window_frame_2)
|
Image::new(self.imgs.window_frame_2)
|
||||||
@ -295,6 +301,7 @@ impl Hud {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bag button and icons near it
|
||||||
match Buttons::new(
|
match Buttons::new(
|
||||||
&self.show.open_windows,
|
&self.show.open_windows,
|
||||||
self.show.map,
|
self.show.map,
|
||||||
@ -312,54 +319,8 @@ impl Hud {
|
|||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minimap
|
// MiniMap
|
||||||
|
MiniMap::new(&mut self.show, &self.imgs, &self.fonts).set(self.ids.minimap, ui_widgets);
|
||||||
if self.show.mini_map {
|
|
||||||
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.show.mini_map {
|
|
||||||
self.imgs.mmap_open
|
|
||||||
} else {
|
|
||||||
self.imgs.mmap_closed
|
|
||||||
})
|
|
||||||
.w_h(100.0 * 0.2, 100.0 * 0.2)
|
|
||||||
.hover_image(if self.show.mini_map {
|
|
||||||
self.imgs.mmap_open_hover
|
|
||||||
} else {
|
|
||||||
self.imgs.mmap_closed_hover
|
|
||||||
})
|
|
||||||
.press_image(if self.show.mini_map {
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
self.show.toggle_mini_map();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Title
|
|
||||||
// Make it display the actual location
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Bag contents
|
// Bag contents
|
||||||
if self.show.bag {
|
if self.show.bag {
|
||||||
@ -371,6 +332,7 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skillbar
|
||||||
Skillbar::new(&self.imgs, &self.fonts).set(self.ids.skillbar, ui_widgets);
|
Skillbar::new(&self.imgs, &self.fonts).set(self.ids.skillbar, ui_widgets);
|
||||||
|
|
||||||
// Chat box
|
// Chat box
|
||||||
@ -393,7 +355,6 @@ impl Hud {
|
|||||||
//or when the Char Window is opened they will appear right from it.
|
//or when the Char Window is opened they will appear right from it.
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
|
||||||
if let Windows::Settings = self.show.open_windows {
|
if let Windows::Settings = self.show.open_windows {
|
||||||
match SettingsWindow::new(&mut self.show, &self.imgs, &self.fonts)
|
match SettingsWindow::new(&mut self.show, &self.imgs, &self.fonts)
|
||||||
.set(self.ids.settings_window, ui_widgets)
|
.set(self.ids.settings_window, ui_widgets)
|
||||||
|
Loading…
Reference in New Issue
Block a user