WIP settings menu
This commit is contained in:
parent
a6b1e50dc5
commit
529bcad32c
|
@ -111,6 +111,7 @@ pub struct RectButton {
|
|||
pub is_selected: bool,
|
||||
pub is_hovering: bool,
|
||||
pub color_anim: Animation<EaseInQuad, Color>,
|
||||
pub label: Option<Label>,
|
||||
}
|
||||
|
||||
impl Button for RectButton {
|
||||
|
@ -124,7 +125,30 @@ impl RectButton {
|
|||
pub const HOVER_COLOR: Color = Color::new(1., 1., 1., 0.8);
|
||||
pub const SELECTED_COLOR: Color = Color::new(1., 1., 0., 1.);
|
||||
|
||||
pub fn new(rect: Rect, rounded_corners: CornerFlags, radius: f32) -> Self {
|
||||
pub fn new(
|
||||
label: Option<LabelText>,
|
||||
rect: Rect,
|
||||
rounded_corners: CornerFlags,
|
||||
radius: f32,
|
||||
) -> Self {
|
||||
let label_height_scale = 0.7;
|
||||
let label_baseline_scale = 0.25;
|
||||
|
||||
let label = label.map(|text| {
|
||||
let scale = rect.height() * label_height_scale;
|
||||
let alignment = HorizontalAlignment::Center;
|
||||
let left = rect.bl.x;
|
||||
let right = rect.tr.x;
|
||||
let baseline = rect.bl.y;
|
||||
let baseline = (rect.height() * label_baseline_scale) + baseline;
|
||||
let color = Color::BLACK;
|
||||
let center_y = false;
|
||||
|
||||
Label::new(
|
||||
text, alignment, scale, color, left, right, baseline, center_y,
|
||||
)
|
||||
});
|
||||
|
||||
Self {
|
||||
rect,
|
||||
rounded_corners,
|
||||
|
@ -138,6 +162,7 @@ impl RectButton {
|
|||
Self::INACTIVE_COLOR,
|
||||
Self::INACTIVE_COLOR,
|
||||
),
|
||||
label,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +180,10 @@ impl Widget for RectButton {
|
|||
self.radius,
|
||||
self.color_anim.get(),
|
||||
);
|
||||
|
||||
if let Some(label) = self.label.as_mut() {
|
||||
label.draw(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
|
||||
|
|
|
@ -238,7 +238,7 @@ impl TabMenu {
|
|||
};
|
||||
|
||||
let rect = Rect::from_xy_size(pos, tab_size);
|
||||
tabs.push(RectButton::new(rect, corners, radius));
|
||||
tabs.push(RectButton::new(None, rect, corners, radius));
|
||||
}
|
||||
|
||||
let tab_list_height = Self::TAB_NUM as f32 * Self::TAB_HEIGHT;
|
||||
|
|
|
@ -29,6 +29,7 @@ pub trait FixedWidth {
|
|||
pub struct MainMenu {
|
||||
pub menu: SlotMenu<RoundButton>,
|
||||
pub inventory: Reveal<Offset<TabMenu>>,
|
||||
pub settings: Reveal<Offset<SettingsMenu>>,
|
||||
}
|
||||
|
||||
impl MainMenu {
|
||||
|
@ -37,7 +38,7 @@ impl MainMenu {
|
|||
|
||||
impl Default for MainMenu {
|
||||
fn default() -> Self {
|
||||
let icon_font = Font::new("Iosevka Nerd Font");
|
||||
let icon_font = Font::new("Leon Sans");
|
||||
let icons = ["", "", "", "", "", ""];
|
||||
|
||||
let mut buttons = Vec::new();
|
||||
|
@ -51,13 +52,22 @@ impl Default for MainMenu {
|
|||
buttons.push(button);
|
||||
}
|
||||
|
||||
let submenu_spacing_right = Vec2::new(Self::SUBMENU_SPACING, 0.0);
|
||||
let reveal_slide = -0.02;
|
||||
let reveal_duration = 0.1;
|
||||
|
||||
let inventory = TabMenu::new();
|
||||
let inventory = Offset::new(inventory, Vec2::new(Self::SUBMENU_SPACING, 0.0));
|
||||
let inventory = Reveal::new(inventory, -0.02, 0.1);
|
||||
let inventory = Offset::new(inventory, submenu_spacing_right);
|
||||
let inventory = Reveal::new(inventory, reveal_slide, reveal_duration);
|
||||
|
||||
let settings = SettingsMenu::new();
|
||||
let settings = Offset::new(settings, submenu_spacing_right);
|
||||
let settings = Reveal::new(settings, reveal_slide, reveal_duration);
|
||||
|
||||
Self {
|
||||
menu: SlotMenu::new(buttons, 0.18),
|
||||
inventory,
|
||||
settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,21 +83,26 @@ impl Widget for MainMenu {
|
|||
match self.menu.get_event() {
|
||||
SlotMenuEvent::SubmenuOpen(0) => self.inventory.show(),
|
||||
SlotMenuEvent::SubmenuClose(0) => self.inventory.hide(),
|
||||
SlotMenuEvent::SubmenuOpen(4) => self.settings.show(),
|
||||
SlotMenuEvent::SubmenuClose(4) => self.settings.hide(),
|
||||
_ => {}
|
||||
};
|
||||
|
||||
self.menu.update(dt);
|
||||
self.inventory.update(dt);
|
||||
self.settings.update(dt);
|
||||
}
|
||||
|
||||
fn draw(&mut self, ctx: &DrawContext) {
|
||||
self.menu.draw(&ctx);
|
||||
self.inventory.draw(&ctx);
|
||||
self.settings.draw(&ctx);
|
||||
}
|
||||
|
||||
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
|
||||
self.menu.on_cursor_event(kind, at);
|
||||
self.inventory.on_cursor_event(kind, at);
|
||||
self.settings.on_cursor_event(kind, at);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,3 +145,53 @@ impl Widget for Inventory {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SettingsMenu {
|
||||
pub menu: SlotMenu<RectButton>,
|
||||
}
|
||||
|
||||
impl SettingsMenu {
|
||||
pub fn new() -> Self {
|
||||
let font = Font::new("Leon Sans");
|
||||
let button_texts = ["Graphics", "Sound", "Interface", "Network", "Account"];
|
||||
let button_size = Vec2::new(0.4, 0.1);
|
||||
let button_rect = Rect::from_xy_size(Vec2::new(0.0, -button_size.y / 2.0), button_size);
|
||||
|
||||
let mut buttons = Vec::new();
|
||||
for text in button_texts.iter() {
|
||||
let text = LabelText {
|
||||
font,
|
||||
text: text.to_string(),
|
||||
};
|
||||
|
||||
let button = RectButton::new(Some(text), button_rect, CornerFlags::empty(), 0.0);
|
||||
buttons.push(button);
|
||||
}
|
||||
|
||||
let menu = SlotMenu::new(buttons, 0.12);
|
||||
|
||||
Self { menu }
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for SettingsMenu {
|
||||
fn update(&mut self, dt: f32) {
|
||||
if let Some(button) = self.menu.get_was_clicked() {
|
||||
self.menu.select(button);
|
||||
}
|
||||
|
||||
match self.menu.get_event() {
|
||||
_ => {}
|
||||
};
|
||||
|
||||
self.menu.update(dt);
|
||||
}
|
||||
|
||||
fn draw(&mut self, ctx: &DrawContext) {
|
||||
self.menu.draw(ctx);
|
||||
}
|
||||
|
||||
fn on_cursor_event(&mut self, kind: CursorEventKind, at: Vec2) {
|
||||
self.menu.on_cursor_event(kind, at);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue