mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Extract 'create_new_button' function from 'update'
This commit is contained in:
parent
099ddea165
commit
fc618b2222
@ -5,14 +5,14 @@ use super::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
i18n::Localization,
|
i18n::Localization,
|
||||||
ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable},
|
ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable},
|
||||||
window::GameInput,
|
window::{GameInput, KeyMouse},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
};
|
};
|
||||||
use client::Client;
|
use client::Client;
|
||||||
use common::comp::{SkillSet, Stats};
|
use common::comp::{SkillSet, Stats};
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
widget::{self, Button, Image, Text},
|
widget::{self, Button, Image, Text},
|
||||||
widget_ids, Color, Colorable, Positionable, Sizeable, Widget, WidgetCommon,
|
widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget, WidgetCommon,
|
||||||
};
|
};
|
||||||
widget_ids! {
|
widget_ids! {
|
||||||
struct Ids {
|
struct Ids {
|
||||||
@ -130,7 +130,6 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
Some(inv) => inv,
|
Some(inv) => inv,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
let key_layout = &self.global_state.window.key_layout;
|
|
||||||
let localized_strings = self.localized_strings;
|
let localized_strings = self.localized_strings;
|
||||||
let arrow_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; //Animation timer
|
let arrow_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; //Animation timer
|
||||||
|
|
||||||
@ -189,18 +188,13 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Bag)
|
.get_binding(GameInput::Bag)
|
||||||
{
|
{
|
||||||
Text::new(bag.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.bag, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&bag,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.bag,
|
||||||
.color(BLACK)
|
state.ids.bag_text_bg,
|
||||||
.set(state.ids.bag_text_bg, ui);
|
state.ids.bag_text,
|
||||||
Text::new(bag.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.bag_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.bag_text, ui);
|
|
||||||
}
|
}
|
||||||
if !self.show_bag {
|
if !self.show_bag {
|
||||||
let space_used = inventory.populated_slots();
|
let space_used = inventory.populated_slots();
|
||||||
@ -250,18 +244,13 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Settings)
|
.get_binding(GameInput::Settings)
|
||||||
{
|
{
|
||||||
Text::new(settings.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.settings_button, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&settings,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.settings_button,
|
||||||
.color(BLACK)
|
state.ids.settings_text_bg,
|
||||||
.set(state.ids.settings_text_bg, ui);
|
state.ids.settings_text,
|
||||||
Text::new(settings.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.settings_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.settings_text, ui);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Social
|
// Social
|
||||||
@ -288,18 +277,13 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Social)
|
.get_binding(GameInput::Social)
|
||||||
{
|
{
|
||||||
Text::new(social.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.social_button, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&social,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.social_button,
|
||||||
.color(BLACK)
|
state.ids.social_text_bg,
|
||||||
.set(state.ids.social_text_bg, ui);
|
state.ids.social_text,
|
||||||
Text::new(social.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.social_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.social_text, ui);
|
|
||||||
};
|
};
|
||||||
// Map
|
// Map
|
||||||
if Button::image(self.imgs.map_button)
|
if Button::image(self.imgs.map_button)
|
||||||
@ -325,18 +309,13 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Map)
|
.get_binding(GameInput::Map)
|
||||||
{
|
{
|
||||||
Text::new(map.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.map_button, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&map,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.map_button,
|
||||||
.color(BLACK)
|
state.ids.map_text_bg,
|
||||||
.set(state.ids.map_text_bg, ui);
|
state.ids.map_text,
|
||||||
Text::new(map.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.map_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.map_text, ui);
|
|
||||||
}
|
}
|
||||||
// Diary
|
// Diary
|
||||||
let unspent_sp = self.skill_set.has_available_sp();
|
let unspent_sp = self.skill_set.has_available_sp();
|
||||||
@ -367,18 +346,13 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Spellbook)
|
.get_binding(GameInput::Spellbook)
|
||||||
{
|
{
|
||||||
Text::new(spell.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.spellbook_button, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&spell,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.spellbook_button,
|
||||||
.color(BLACK)
|
state.ids.spellbook_text_bg,
|
||||||
.set(state.ids.spellbook_text_bg, ui);
|
state.ids.spellbook_text,
|
||||||
Text::new(spell.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.spellbook_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.spellbook_text, ui);
|
|
||||||
}
|
}
|
||||||
// Unspent SP indicator
|
// Unspent SP indicator
|
||||||
if unspent_sp {
|
if unspent_sp {
|
||||||
@ -427,20 +401,44 @@ impl<'a> Widget for Buttons<'a> {
|
|||||||
.controls
|
.controls
|
||||||
.get_binding(GameInput::Crafting)
|
.get_binding(GameInput::Crafting)
|
||||||
{
|
{
|
||||||
Text::new(crafting.display_string(key_layout).as_str())
|
self.create_new_button_with_shadow(
|
||||||
.bottom_right_with_margins_on(state.ids.crafting_button, 0.0, 0.0)
|
ui,
|
||||||
.font_size(10)
|
&crafting,
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
state.ids.crafting_button,
|
||||||
.color(BLACK)
|
state.ids.crafting_text_bg,
|
||||||
.set(state.ids.crafting_text_bg, ui);
|
state.ids.crafting_text,
|
||||||
Text::new(crafting.display_string(key_layout).as_str())
|
);
|
||||||
.bottom_right_with_margins_on(state.ids.crafting_text_bg, 1.0, 1.0)
|
|
||||||
.font_size(10)
|
|
||||||
.font_id(self.fonts.cyri.conrod_id)
|
|
||||||
.color(TEXT_COLOR)
|
|
||||||
.set(state.ids.crafting_text, ui);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Buttons<'a> {
|
||||||
|
fn create_new_button_with_shadow(
|
||||||
|
&self,
|
||||||
|
ui: &mut UiCell,
|
||||||
|
key_mouse: &KeyMouse,
|
||||||
|
button_identifier: widget::Id,
|
||||||
|
text_background: widget::Id,
|
||||||
|
text: widget::Id,
|
||||||
|
) {
|
||||||
|
let key_layout = &self.global_state.window.key_layout;
|
||||||
|
|
||||||
|
//Create shadow
|
||||||
|
Text::new(key_mouse.display_string(key_layout).as_str())
|
||||||
|
.bottom_right_with_margins_on(button_identifier, 0.0, 0.0)
|
||||||
|
.font_size(10)
|
||||||
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.color(BLACK)
|
||||||
|
.set(text_background, ui);
|
||||||
|
|
||||||
|
//Create button
|
||||||
|
Text::new(key_mouse.display_string(key_layout).as_str())
|
||||||
|
.bottom_right_with_margins_on(text_background, 1.0, 1.0)
|
||||||
|
.font_size(10)
|
||||||
|
.font_id(self.fonts.cyri.conrod_id)
|
||||||
|
.color(TEXT_COLOR)
|
||||||
|
.set(text, ui);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user