mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
replace typing field with function and cleanup
Former-commit-id: eed8063a12ac475927e9d0eabc0aafc0598ce9ef
This commit is contained in:
parent
009ca0a130
commit
5c63f398ba
@ -1,13 +1,11 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
widget::{self, Button, Image, Rectangle, Text, Scrollbar},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
color,
|
||||
widget::{self, Button, Image, Rectangle, Scrollbar},
|
||||
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use super::{
|
||||
img_ids::Imgs,
|
||||
font_ids::Fonts,
|
||||
TEXT_COLOR,
|
||||
};
|
||||
|
||||
widget_ids! {
|
||||
@ -32,7 +30,6 @@ pub struct Bag<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Bag<'a> {
|
||||
@ -42,7 +39,6 @@ impl<'a> Bag<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,10 +68,8 @@ impl<'a> Widget for Bag<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
@ -105,17 +99,6 @@ impl<'a> Widget for Bag<'a> {
|
||||
.rgba(0.33, 0.33, 0.33, 1.0)
|
||||
.set(state.ids.inv_scrollbar, ui);
|
||||
|
||||
// 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(state.ids.bag_contents, 0.0, 0.0)
|
||||
.set(state.ids.bag_close, ui)
|
||||
.was_clicked()
|
||||
{
|
||||
return Some(Event::Close);
|
||||
}
|
||||
|
||||
if self.inventory_space > 0 {
|
||||
// First Slot
|
||||
@ -125,6 +108,18 @@ impl<'a> Widget for Bag<'a> {
|
||||
.set(state.ids.inv_slot_0, ui);
|
||||
}
|
||||
|
||||
None
|
||||
// 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(state.ids.bag_contents, 0.0, 0.0)
|
||||
.set(state.ids.bag_close, ui)
|
||||
.was_clicked()
|
||||
{
|
||||
Some(Event::Close)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget::{self, Button, Image, Text},
|
||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -43,7 +41,6 @@ pub struct Buttons<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Buttons<'a> {
|
||||
@ -55,7 +52,6 @@ impl<'a> Buttons<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,10 +85,8 @@ impl<'a> Widget for Buttons<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
color,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use super::{
|
||||
img_ids::Imgs,
|
||||
@ -39,7 +38,6 @@ pub struct CharacterWindow<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> CharacterWindow<'a> {
|
||||
@ -48,7 +46,6 @@ impl<'a> CharacterWindow<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +72,6 @@ impl<'a> Widget for CharacterWindow<'a> {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -30,7 +30,6 @@ pub struct Chat<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Chat<'a> {
|
||||
@ -40,7 +39,6 @@ impl<'a> Chat<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +71,7 @@ pub enum Event {
|
||||
impl<'a> Widget for Chat<'a> {
|
||||
type State = State;
|
||||
type Style = ();
|
||||
type Event = (bool, Option<Event>);
|
||||
type Event = Option<Event>;
|
||||
|
||||
fn init_state(&self, id_gen: widget::id::Generator) -> Self::State {
|
||||
State {
|
||||
@ -92,7 +90,6 @@ impl<'a> Widget for Chat<'a> {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
@ -111,6 +108,7 @@ impl<'a> Widget for Chat<'a> {
|
||||
let text_edit = TextEdit::new(&state.input)
|
||||
.w(460.0)
|
||||
.restrict_to_height(false)
|
||||
.color(TEXT_COLOR)
|
||||
.line_spacing(2.0)
|
||||
.font_size(15)
|
||||
.font_id(self.fonts.opensans);
|
||||
@ -154,7 +152,7 @@ impl<'a> Widget for Chat<'a> {
|
||||
.font_size(15)
|
||||
.font_id(self.fonts.opensans)
|
||||
.w(470.0)
|
||||
.rgba(1.0, 1.0, 1.0, 1.0)
|
||||
.color(TEXT_COLOR)
|
||||
.line_spacing(2.0);
|
||||
// Add space between messages
|
||||
let y = match text.get_y_dimension(ui) {
|
||||
@ -186,8 +184,7 @@ impl<'a> Widget for Chat<'a> {
|
||||
}
|
||||
|
||||
// If the chat widget is focused return a focus event to pass the focus to the input box
|
||||
let self_focused = keyboard_capturer == Some(id);
|
||||
let event = if self_focused {
|
||||
if keyboard_capturer == Some(id) {
|
||||
Some(Event::Focus(state.ids.input))
|
||||
}
|
||||
// If enter is pressed and the input box is not empty send the current message
|
||||
@ -205,9 +202,6 @@ impl<'a> Widget for Chat<'a> {
|
||||
Some(Event::SendMessage(msg))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Return whether typing and any event that occured
|
||||
(self_focused || input_focused, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget::{self, Button, Image},
|
||||
widget_ids, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -31,7 +29,6 @@ pub struct EscMenu<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> EscMenu<'a> {
|
||||
@ -40,7 +37,6 @@ impl<'a> EscMenu<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,10 +69,8 @@ impl<'a> Widget for EscMenu<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
use conrod_core::text::Font;
|
||||
|
||||
font_ids! {
|
||||
pub struct Fonts {
|
||||
opensans: "/voxygen/font/OpenSans-Regular.ttf",
|
||||
|
@ -1,14 +1,12 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
color,
|
||||
widget::{self, Button, Image, Rectangle},
|
||||
widget_ids, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
|
||||
use super::{
|
||||
img_ids::Imgs,
|
||||
font_ids::Fonts,
|
||||
TEXT_COLOR,
|
||||
};
|
||||
|
||||
widget_ids! {
|
||||
@ -32,7 +30,6 @@ pub struct Map<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Map<'a> {
|
||||
@ -41,7 +38,6 @@ impl<'a> Map<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,10 +67,8 @@ impl<'a> Widget for Map<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -30,7 +30,7 @@ use crate::{
|
||||
GlobalState,
|
||||
};
|
||||
use conrod_core::{
|
||||
widget::{Button, Image, Text, Id as WidgId, Rectangle}, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, color
|
||||
widget::{self, Button, Image, Text, Rectangle}, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, color, graph
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
@ -60,8 +60,6 @@ widget_ids! {
|
||||
mmap_location,
|
||||
mmap_button,
|
||||
|
||||
|
||||
|
||||
// Window Frames
|
||||
window_frame_0,
|
||||
window_frame_1,
|
||||
@ -190,8 +188,7 @@ pub struct Hud {
|
||||
new_messages: VecDeque<String>,
|
||||
inventory_space: u32,
|
||||
show: Show,
|
||||
to_focus: Option<Option<WidgId>>,
|
||||
typing: bool,
|
||||
to_focus: Option<Option<widget::Id>>,
|
||||
}
|
||||
|
||||
impl Hud {
|
||||
@ -225,7 +222,6 @@ impl Hud {
|
||||
mini_map: false,
|
||||
},
|
||||
to_focus: None,
|
||||
typing: false,
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,10 +365,9 @@ impl Hud {
|
||||
.set(self.ids.skillbar, ui_widgets);
|
||||
|
||||
// Chat box
|
||||
let (typing, event) = Chat::new(&mut self.new_messages, &self.imgs, &self.fonts)
|
||||
.set(self.ids.chat, ui_widgets);
|
||||
self.typing = typing;
|
||||
match event {
|
||||
match Chat::new(&mut self.new_messages, &self.imgs, &self.fonts)
|
||||
.set(self.ids.chat, ui_widgets)
|
||||
{
|
||||
Some(chat::Event::SendMessage(message)) => {
|
||||
events.push(Event::SendMessage(message));
|
||||
}
|
||||
@ -402,11 +397,7 @@ impl Hud {
|
||||
}
|
||||
|
||||
// Small Window
|
||||
if let Some((small, char_window_open)) = match self.show.open_windows {
|
||||
Windows::Small(small) => Some((small, false)),
|
||||
Windows::CharacterAnd(Some(small)) => Some((small, true)),
|
||||
_ => None,
|
||||
} {
|
||||
if let Windows::Small(small) | Windows::CharacterAnd(Some(small)) = self.show.open_windows {
|
||||
match SmallWindow::new(small, &self.show, &self.imgs, &self.fonts)
|
||||
.set(self.ids.small_window, ui_widgets)
|
||||
{
|
||||
@ -442,7 +433,6 @@ impl Hud {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Esc-menu
|
||||
if self.show.esc_menu {
|
||||
match EscMenu::new(&self.imgs, &self.fonts)
|
||||
@ -466,11 +456,25 @@ impl Hud {
|
||||
self.new_messages.push_back(msg);
|
||||
}
|
||||
|
||||
// Checks if a TextEdit widget has the keyboard captured
|
||||
fn typing(&self) -> bool {
|
||||
if let Some(id) = self.ui.widget_capturing_keyboard() {
|
||||
self.ui
|
||||
.widget_graph()
|
||||
.widget(id)
|
||||
.and_then(graph::Container::unique_widget_state::<widget::TextEdit>)
|
||||
.is_some()
|
||||
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_event(&mut self, event: WinEvent, global_state: &mut GlobalState) -> bool {
|
||||
let cursor_grabbed = global_state.window.is_cursor_grabbed();
|
||||
match event {
|
||||
WinEvent::Ui(event) => {
|
||||
if (self.typing && event.is_keyboard() && self.show.ui)
|
||||
if (self.typing() && event.is_keyboard() && self.show.ui)
|
||||
|| !(cursor_grabbed && event.is_keyboard_or_mouse())
|
||||
{
|
||||
self.ui.handle_event(event);
|
||||
@ -484,7 +488,7 @@ impl Hud {
|
||||
_ if !self.show.ui => false,
|
||||
WinEvent::Zoom(_) => !cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
|
||||
WinEvent::KeyDown(Key::Enter) => {
|
||||
self.ui.focus_widget(if self.typing {
|
||||
self.ui.focus_widget(if self.typing() {
|
||||
None
|
||||
} else {
|
||||
Some(self.ids.chat)
|
||||
@ -492,16 +496,15 @@ impl Hud {
|
||||
true
|
||||
}
|
||||
WinEvent::KeyDown(Key::Escape) => {
|
||||
if self.typing {
|
||||
if self.typing() {
|
||||
self.ui.focus_widget(None);
|
||||
self.typing = false;
|
||||
} else {
|
||||
// Close windows on esc
|
||||
self.show.toggle_windows(global_state);
|
||||
}
|
||||
true
|
||||
}
|
||||
WinEvent::KeyDown(key) if !self.typing => match key {
|
||||
WinEvent::KeyDown(key) if !self.typing() => match key {
|
||||
Key::Map => {
|
||||
self.show.toggle_map();
|
||||
true
|
||||
@ -538,9 +541,9 @@ impl Hud {
|
||||
},
|
||||
WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key {
|
||||
Key::ToggleCursor => false,
|
||||
_ => self.typing,
|
||||
_ => self.typing(),
|
||||
},
|
||||
WinEvent::Char(_) => self.typing,
|
||||
WinEvent::Char(_) => self.typing(),
|
||||
WinEvent::SettingsChanged => {
|
||||
self.settings = global_state.settings.clone();
|
||||
true
|
||||
|
@ -1,8 +1,7 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
color,
|
||||
widget::{self, Button, Image, Rectangle, Scrollbar, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use super::{
|
||||
img_ids::Imgs,
|
||||
@ -62,7 +61,6 @@ pub struct SettingsWindow<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> SettingsWindow<'a> {
|
||||
@ -72,7 +70,6 @@ impl<'a> SettingsWindow<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,10 +102,8 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget::{self, Image, Rectangle, Text},
|
||||
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use super::{
|
||||
img_ids::Imgs,
|
||||
@ -37,7 +35,6 @@ pub struct Skillbar<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> Skillbar<'a> {
|
||||
@ -46,7 +43,6 @@ impl<'a> Skillbar<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -74,10 +70,8 @@ impl<'a> Widget for Skillbar<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use conrod_core::{
|
||||
builder_methods, color,
|
||||
text::font,
|
||||
color,
|
||||
widget::{self, Button, Image, Rectangle, Text},
|
||||
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
widget_ids, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
||||
};
|
||||
use crate::hud::Show;
|
||||
use super::{
|
||||
@ -39,7 +38,6 @@ pub struct SmallWindow<'a> {
|
||||
|
||||
#[conrod(common_builder)]
|
||||
common: widget::CommonBuilder,
|
||||
style: (),
|
||||
}
|
||||
|
||||
impl<'a> SmallWindow<'a> {
|
||||
@ -50,7 +48,6 @@ impl<'a> SmallWindow<'a> {
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
style: (),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,10 +77,8 @@ impl<'a> Widget for SmallWindow<'a> {
|
||||
|
||||
fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
|
||||
let widget::UpdateArgs {
|
||||
id,
|
||||
state,
|
||||
ui,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
|
@ -117,7 +117,7 @@ pub struct MainMenuUi {
|
||||
|
||||
impl MainMenuUi {
|
||||
pub fn new(global_state: &mut GlobalState) -> Self {
|
||||
let mut window = &mut global_state.window;
|
||||
let window = &mut global_state.window;
|
||||
let networking = &global_state.settings.networking;
|
||||
let mut ui = Ui::new(window).unwrap();
|
||||
// TODO: adjust/remove this, right now it is used to demonstrate window scaling functionality
|
||||
|
@ -289,6 +289,10 @@ impl Ui {
|
||||
.is_none()
|
||||
}
|
||||
|
||||
// Get the widget graph
|
||||
pub fn widget_graph(&self) -> &Graph {
|
||||
self.ui.widget_graph()
|
||||
}
|
||||
pub fn handle_event(&mut self, event: Event) {
|
||||
match event.0 {
|
||||
Input::Resize(w, h) => self.window_resized = Some(Vec2::new(w, h)),
|
||||
|
Loading…
Reference in New Issue
Block a user