Merge branch 'CapsizeGlimmer/enter_world_with_enter' into 'master'

Enter the world by pressing "enter" at character selection

Closes #530

See merge request veloren/veloren!922
This commit is contained in:
Monty Marz 2020-05-04 18:51:31 +00:00
commit e5a87f4338
2 changed files with 24 additions and 4 deletions

View File

@ -68,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added dungeon entrances
- Villagers tools and clothing
- Cultists clothing
- You can start the game by pressing "enter" from the character selection menu
### Changed

View File

@ -19,6 +19,8 @@ use common::{
use conrod_core::{
color,
color::TRANSPARENT,
event::{Event as WorldEvent, Input},
input::{Button as ButtonType, Key},
position::Relative,
widget::{text_box::Event as TextBoxEvent, Button, Image, Rectangle, Scrollbar, Text, TextBox},
widget_ids, Borderable, Color, Colorable, Labelable, Positionable, Sizeable, UiCell, Widget,
@ -405,6 +407,26 @@ impl CharSelectionUi {
// TODO: Split this into multiple modules or functions.
fn update_layout(&mut self, global_state: &mut GlobalState, client: &Client) -> Vec<Event> {
let mut events = Vec::new();
let can_enter_world = match &self.mode {
Mode::Select(opt) => opt.is_some(),
Mode::Create { .. } => false,
};
// Handle enter keypress to enter world
if can_enter_world {
for event in self.ui.ui.global_input().events() {
match event {
// TODO allow this to be rebound
WorldEvent::Raw(Input::Press(ButtonType::Keyboard(Key::Return)))
| WorldEvent::Raw(Input::Press(ButtonType::Keyboard(Key::Return2)))
| WorldEvent::Raw(Input::Press(ButtonType::Keyboard(Key::NumPadEnter))) => {
events.push(Event::Play)
},
_ => {},
}
}
}
let (ref mut ui_widgets, ref mut tooltip_manager) = self.ui.set_widgets();
let version = format!(
"{}-{}",
@ -567,10 +589,7 @@ impl CharSelectionUi {
.label_font_id(self.fonts.cyri.conrod_id)
.label_y(conrod_core::position::Relative::Scalar(3.0));
if match &self.mode {
Mode::Select(opt) => opt.is_some(),
Mode::Create { .. } => true,
} {
if can_enter_world {
if enter_button
.hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press)