Use shorter help text format, compact stuff into one format!()

Former-commit-id: 345bef9a2f0714986e4ba6fb24b0bc150023a12e
This commit is contained in:
Yeedo
2019-05-01 23:15:43 +01:00
parent 2a1bc9f025
commit d88ed3fed6
3 changed files with 28 additions and 35 deletions

View File

@ -12,7 +12,7 @@ use common::{assets, figure::Segment};
use conrod_core::{ use conrod_core::{
color, color,
image::Id as ImgId, image::Id as ImgId,
text::font::Id as FontId, text::{self, font::Id as FontId},
widget::{Button, Image, Rectangle, Scrollbar, Text}, widget::{Button, Image, Rectangle, Scrollbar, Text},
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
}; };
@ -629,7 +629,7 @@ impl Hud {
if self.show_help { if self.show_help {
Image::new(self.imgs.window_frame_2) Image::new(self.imgs.window_frame_2)
.top_left_with_margins_on(ui_widgets.window, 3.0, 3.0) .top_left_with_margins_on(ui_widgets.window, 3.0, 3.0)
.w_h(300.0, 450.0) .w_h(300.0, 190.0)
.set(self.ids.help_bg, ui_widgets); .set(self.ids.help_bg, ui_widgets);
Text::new(get_help_text(&self.settings.controls).as_str()) Text::new(get_help_text(&self.settings.controls).as_str())
.color(TEXT_COLOR) .color(TEXT_COLOR)
@ -707,7 +707,7 @@ impl Hud {
.bottom_right_with_margins_on(ui_widgets.window, 5.0, 57.0) .bottom_right_with_margins_on(ui_widgets.window, 5.0, 57.0)
.hover_image(self.imgs.settings_hover) .hover_image(self.imgs.settings_hover)
.press_image(self.imgs.settings_press) .press_image(self.imgs.settings_press)
.label("N") .label(&format!("{:?}", self.settings.controls.settings))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.color(TEXT_COLOR) .color(TEXT_COLOR)
@ -730,7 +730,7 @@ impl Hud {
.left_from(self.ids.social_button, 10.0) .left_from(self.ids.social_button, 10.0)
.hover_image(self.imgs.map_hover) .hover_image(self.imgs.map_hover)
.press_image(self.imgs.map_press) .press_image(self.imgs.map_press)
.label("M") .label(&format!("{:?}", self.settings.controls.map))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
@ -774,7 +774,7 @@ impl Hud {
.left_from(self.ids.settings_button, 10.0) .left_from(self.ids.settings_button, 10.0)
.hover_image(self.imgs.social_hover) .hover_image(self.imgs.social_hover)
.press_image(self.imgs.social_press) .press_image(self.imgs.social_press)
.label("O") .label(&format!("{:?}", self.settings.controls.social))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
@ -800,7 +800,7 @@ impl Hud {
.left_from(self.ids.map_button, 10.0) .left_from(self.ids.map_button, 10.0)
.hover_image(self.imgs.spellbook_hover) .hover_image(self.imgs.spellbook_hover)
.press_image(self.imgs.spellbook_press) .press_image(self.imgs.spellbook_press)
.label("P") .label(&format!("{:?}", self.settings.controls.spellbook))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
@ -826,7 +826,7 @@ impl Hud {
.left_from(self.ids.spellbook_button, 10.0) .left_from(self.ids.spellbook_button, 10.0)
.hover_image(self.imgs.character_hover) .hover_image(self.imgs.character_hover)
.press_image(self.imgs.character_press) .press_image(self.imgs.character_press)
.label("C") .label(&format!("{:?}", self.settings.controls.character_window))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
@ -852,7 +852,7 @@ impl Hud {
.left_from(self.ids.character_button, 10.0) .left_from(self.ids.character_button, 10.0)
.hover_image(self.imgs.qlog_hover) .hover_image(self.imgs.qlog_hover)
.press_image(self.imgs.qlog_press) .press_image(self.imgs.qlog_press)
.label("L") .label(&format!("{:?}", self.settings.controls.quest_log))
.label_font_size(10) .label_font_size(10)
.label_font_id(self.font_metamorph) .label_font_id(self.font_metamorph)
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)
@ -1903,29 +1903,22 @@ impl Hud {
} }
} }
//Get the text to show in the help window, along with the
//length of the longest line in order to resize the window
fn get_help_text(cs: &ControlSettings) -> String { fn get_help_text(cs: &ControlSettings) -> String {
[ format!(
format!("{:?} = Free cursor\n", cs.toggle_cursor), "{free_cursor:?} = Free cursor\n\
format!("{:?} = Open/close menus\n", cs.escape), {escape:?} = Open/close menus\n\
String::from("\n"), \n\
format!("{:?} = Toggle this window\n", cs.help), {help:?} = Toggle this window\n\
format!("{:?} = Toggle interface\n", cs.toggle_interface), {toggle_interface:?} = Toggle interface\n\
String::from("\n"), \n\
format!("{:?} = Open chat\n", cs.enter), {chat:?} = Open chat\n\
String::from("Mouse Wheel = Scroll chat\n"), Mouse Wheel = Scroll chat/zoom",
String::from("\n"), free_cursor = cs.toggle_cursor,
format!("{:?} = Move forward\n", cs.move_forward), escape = cs.escape,
format!("{:?} = Move left\n", cs.move_left), help = cs.help,
format!("{:?} = Move right\n", cs.move_right), toggle_interface = cs.toggle_interface,
format!("{:?} = Move backwards\n", cs.move_back), chat = cs.enter
String::from("\n"), )
format!("{:?} = Map\n", cs.map),
format!("{:?} = Bag\n", cs.bag),
format!("{:?} = Quest log\n", cs.quest_log),
format!("{:?} = Character window\n", cs.character_window),
format!("{:?} = Social\n", cs.social),
format!("{:?} = Spellbook\n", cs.spellbook),
format!("{:?} = Settings\n", cs.settings),
]
.concat()
} }

View File

@ -76,7 +76,7 @@ impl PlayState for CharSelectionState {
return PlayStateResult::Switch(Box::new(SessionState::new( return PlayStateResult::Switch(Box::new(SessionState::new(
&mut global_state.window, &mut global_state.window,
self.client.clone(), self.client.clone(),
global_state.settings.clone() global_state.settings.clone(),
))); )));
} }
} }

View File

@ -165,7 +165,7 @@ impl Window {
.into(); .into();
Vec2::new(w, h) Vec2::new(w, h)
} }
pub fn send_supplement_event(&mut self, event: Event) { pub fn send_supplement_event(&mut self, event: Event) {
self.supplement_events.push(event) self.supplement_events.push(event)
} }
@ -213,4 +213,4 @@ pub enum Event {
Ui(ui::Event), Ui(ui::Event),
/// Game settings have changed /// Game settings have changed
SettingsChanged, SettingsChanged,
} }