Skip to content

Commit

Permalink
fix: sfx hover agile. serverlist op-icon fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamtowards committed Mar 30, 2024
1 parent 179dbd2 commit 3ce234f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 92 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

/assets/models/
/assets/items/
/assets/sounds/


.DS_Store
Binary file added assets/sounds/music/limbo.ogg
Binary file not shown.
Binary file added assets/sounds/music/radiance.ogg
Binary file not shown.
Binary file added assets/sounds/ui/button.ogg
Binary file not shown.
Binary file added assets/sounds/ui/button_large.ogg
Binary file not shown.
26 changes: 13 additions & 13 deletions src/ui/main_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bevy_egui::{
use bevy_renet::renet::{transport::NetcodeClientTransport, RenetClient};

use crate::game_client::{ClientInfo, EthertiaClient, WorldInfo};
use super::{CurrentUI, UiExtra};
use super::{sfx_play, CurrentUI, UiExtra};


pub fn ui_main_menu(
Expand Down Expand Up @@ -74,30 +74,30 @@ pub fn ui_main_menu(

ui.with_layout(Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.horizontal(|ui| {
if ui.selectable_label(false, "").on_hover_text("Github Repository").clicked() {
if sfx_play(ui.selectable_label(false, "")).on_hover_text("Github Repository").clicked() {
ui.ctx().open_url(OpenUrl::new_tab("https://github.com/Dreamtowards/Ethertum"));
}
if ui.selectable_label(false, "").on_hover_text("Steam").clicked() {
if sfx_play(ui.selectable_label(false, "")).on_hover_text("Steam").clicked() {
ui.ctx().open_url(OpenUrl::new_tab("https://github.com/Dreamtowards/Ethertum"));
}
if ui.selectable_label(false, "").on_hover_text("YouTube").clicked() {
if sfx_play(ui.selectable_label(false, "")).on_hover_text("YouTube").clicked() {
ui.ctx().open_url(OpenUrl::new_tab("https://github.com/Dreamtowards/Ethertum"));
}
if ui.selectable_label(false, "⛓").on_hover_text("Wiki & Documentations").clicked() {
if sfx_play(ui.selectable_label(false, "⛓")).on_hover_text("Wiki & Documentations").clicked() {
ui.ctx().open_url(OpenUrl::new_tab("https://docs.ethertia.com"));
}
ui.label("|");
ui.selectable_label(false, ""); // Windows
ui.selectable_label(false, "🐧");
ui.selectable_label(false, "");
ui.selectable_label(false, ""); // Android
sfx_play(ui.selectable_label(false, "")); // Windows
sfx_play(ui.selectable_label(false, "🐧"));
sfx_play(ui.selectable_label(false, ""));
sfx_play(ui.selectable_label(false, "")); // Android
ui.label("·");
// ui.selectable_label(false, ""); // Texture
ui.selectable_label(false, "⛶");
ui.selectable_label(false, "⛭");
ui.selectable_label(false, "🖴"); // Disk
sfx_play(ui.selectable_label(false, "⛶"));
sfx_play(ui.selectable_label(false, "⛭"));
sfx_play(ui.selectable_label(false, "🖴")); // Disk
// ui.selectable_label(false, "☢");
ui.selectable_label(false, "⎆");
sfx_play(ui.selectable_label(false, "⎆"));
});
ui.label(format!("v{}\n0 mods loaded.", std::env!("CARGO_PKG_VERSION")));
});
Expand Down
62 changes: 16 additions & 46 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,17 @@ fn setup_egui_style(mut egui_settings: ResMut<EguiSettings>, mut ctx: EguiContex
// egui_settings.scale_factor = 1.;
}

// #[derive(Component)]
// pub struct SfxButtonHover;
// #[derive(Component)]
// pub struct SfxButtonClick;


// for SFX
static mut SFX_BTN_HOVERED: bool = false;
static mut SFX_BTN_HOVERED_ID: egui::Id = egui::Id::NULL;
static mut SFX_BTN_CLICKED: bool = false;

// static mut SFX_BTN_HOVER: Handle<AudioSource> = Handle::Weak(AssetId::invalid());
// static mut SFX_BTN_CLICK: Handle<AudioSource> = Handle::Weak(AssetId::invalid());

fn play_bgm(
asset_server: Res<AssetServer>,
mut cmds: Commands,
mut limbo_played: Local<bool>,
mut last_hovered: Local<bool>,
) {

if !*limbo_played {
Expand All @@ -208,15 +201,14 @@ fn play_bgm(
}

unsafe {
// Switched to Hovered -> Play Sound
if SFX_BTN_HOVERED && !*last_hovered {
static mut LAST_HOVERED_ID: egui::Id = egui::Id::NULL;
if SFX_BTN_HOVERED_ID != LAST_HOVERED_ID {
cmds.spawn(AudioBundle {
source: asset_server.load("sounds/ui/button.ogg"),
settings: PlaybackSettings::DESPAWN
});
}
*last_hovered = SFX_BTN_HOVERED;
SFX_BTN_HOVERED = false;
LAST_HOVERED_ID = SFX_BTN_HOVERED_ID;

if SFX_BTN_CLICKED {
cmds.spawn(AudioBundle {
Expand All @@ -226,23 +218,6 @@ fn play_bgm(
}
SFX_BTN_CLICKED = false;
}

// unsafe {
// SFX_BTN_CLICK = asset_server.load("sounds/ui/button_large.ogg");
// SFX_BTN_HOVER = asset_server.load("sounds/ui/button.ogg");
// }
// SFX_BTN_CLICK = asset_server.load("sounds/ui/button_large.ogg");
// SFX_BTN_HOVER = asset_server.load("sounds/ui/button.ogg");

// cmds.spawn((AudioBundle {
// source: asset_server.load("sounds/ui/button.ogg"),
// ..default()
// }, SfxButtonHover));

// cmds.spawn((AudioBundle {
// source: asset_server.load("sounds/ui/button_large.ogg"),
// ..default()
// }, SfxButtonClick));
}


Expand Down Expand Up @@ -283,7 +258,7 @@ pub fn ui_lr_panel(
});
strip.cell(|ui| {
ui.with_layout(Layout::bottom_up(egui::Align::Min), |ui| {
if ui.selectable_label(false, "⬅Back").clicked() {
if sfx_play(ui.selectable_label(false, "⬅Back")).clicked() {
next_ui.set(CurrentUI::MainMenu);
}
});
Expand Down Expand Up @@ -315,26 +290,21 @@ trait UiExtra {

}

pub fn sfx_play(resp: Response) -> Response {
if resp.hovered() {
unsafe{SFX_BTN_HOVERED_ID = resp.id;}
}
if resp.clicked() {
unsafe{SFX_BTN_CLICKED = true;}
}
resp
}

impl UiExtra for Ui {

fn btn_normal(&mut self, text: impl Into<WidgetText>) -> Response {
self.add_space(4.);
let resp = self.add_sized([220., 24.], egui::Button::new(text));
if resp.hovered() {
unsafe{SFX_BTN_HOVERED = true;}
// cmds.spawn(AudioBundle {
// source: unsafe{SFX_BTN_HOVER.clone()},
// ..default()
// });
}
if resp.clicked() {
unsafe{SFX_BTN_CLICKED = true;}
// cmds.spawn(AudioBundle {
// source: unsafe{SFX_BTN_CLICK.clone()},
// ..default()
// });
}
resp
sfx_play(self.add_sized([220., 24.], egui::Button::new(text)))
}
fn btn_borderless(&mut self, text: impl Into<WidgetText>) -> Response {
self.add_sized([190., 22.], egui::SelectableLabel::new(false, text))
Expand Down
45 changes: 21 additions & 24 deletions src/ui/serverlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_egui::{egui::{self, Align2, Color32, Layout, Ui, Widget}, EguiContexts}
use bevy_renet::renet::RenetClient;
use crate::game_client::{ClientInfo, EthertiaClient, ServerListItem};

use super::{ui_lr_panel, CurrentUI};
use super::{sfx_play, ui_lr_panel, CurrentUI, UiExtra};

use super::new_egui_window;

Expand Down Expand Up @@ -35,7 +35,7 @@ pub fn ui_connecting_server(

ui.add_space(h * 0.3);

if ui.button("Cancel").clicked() {
if ui.btn_normal("Cancel").clicked() {
// todo: Interrupt Connection without handle Result.
next_ui.set(CurrentUI::MainMenu);
net_client.disconnect();
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn ui_disconnected_reason(

ui.add_space(h * 0.3);

if ui.button("Back to title").clicked() {
if ui.btn_normal("Back to title").clicked() {
next_ui.set(CurrentUI::MainMenu);
}
});
Expand All @@ -89,14 +89,13 @@ pub fn ui_serverlist(


ui_lr_panel(ui, false, |ui| {
if ui.selectable_label(false, "Add Server").clicked() {
// next_ui_1 = CurrentUI::ServerListItemAdd;
if sfx_play(ui.selectable_label(false, "Add Server")).clicked() {
do_new_server = true;
}
if ui.selectable_label(false, "Direct Connect").clicked() {
if sfx_play(ui.selectable_label(false, "Direct Connect")).clicked() {

}
if ui.selectable_label(false, "Refresh").clicked() {
if sfx_play(ui.selectable_label(false, "Refresh")).clicked() {
do_refresh = true;
}
}, &mut next_ui, |ui| {
Expand All @@ -113,7 +112,7 @@ pub fn ui_serverlist(
ui.colored_label(Color32::WHITE, server_item.name.clone()).on_hover_text(server_item.addr.clone());

ui.with_layout(Layout::right_to_left(egui::Align::Min), |ui| {
ui.label("21ms 12/64");
ui.label("21ms · 12/64");
});
}
});
Expand All @@ -124,22 +123,22 @@ pub fn ui_serverlist(
ui.label(&server_item.addr);
}

ui.with_layout(Layout::right_to_left(egui::Align::Min), |ui| {
ui.with_layout(Layout::right_to_left(egui::Align::Max), |ui| {
if editing {
if ui.button("Done").clicked() {
if sfx_play(ui.button("✅")).clicked() {
*edit_i = None;
}
} else {
if ui.button("🗑").on_hover_text("Delete").clicked() {
if sfx_play(ui.button("🗑")).on_hover_text("Delete").clicked() {
del_i = Some(idx);
}
if ui.button("🔧").on_hover_text("Edit").clicked() {
if sfx_play(ui.button("⛭")).on_hover_text("Edit").clicked() {
*edit_i = Some(idx);
}
if ui.button("⟲").on_hover_text("Refresh Status").clicked() {
if sfx_play(ui.button("⟲")).on_hover_text("Refresh Status").clicked() {

}
if ui.button("Join").clicked() {
if sfx_play(ui.button("▶")).on_hover_text("Join & Play").clicked() {
join_addr = Some(server_item.addr.clone());
}
}
Expand All @@ -152,6 +151,7 @@ pub fn ui_serverlist(

if do_new_server {
serverlist.push(ServerListItem { name: "Server Name".into(), addr: "0.0.0.0:4000".into() });
ui.scroll_to_cursor(Some(egui::Align::BOTTOM));
}
if do_refresh {
match crate::util::get_server_list("https://ethertia.com/server-info.json") {
Expand Down Expand Up @@ -183,14 +183,14 @@ pub fn ui_localsaves(
new_egui_window("Local Saves").show(ctx.ctx_mut(), |ui| {

ui_lr_panel(ui, false, |ui| {
if ui.selectable_label(false, "New World").clicked() {
if sfx_play(ui.selectable_label(false, "New World")).clicked() {

}
if ui.selectable_label(false, "Refresh").clicked() {
if sfx_play(ui.selectable_label(false, "Refresh")).clicked() {

}
}, &mut next_ui, |ui| {
for i in 0..8 {
for i in 0..28 {
ui.group(|ui| {
ui.horizontal(|ui| {
ui.colored_label(Color32::WHITE, "World Name").on_hover_text(
Expand All @@ -205,15 +205,12 @@ Inhabited: 10.3 hours");
});
ui.horizontal(|ui| {
ui.label("Survival · Cheats");
ui.with_layout(Layout::right_to_left(egui::Align::Min), |ui| {
if ui.button("Del").clicked() {

ui.with_layout(Layout::right_to_left(egui::Align::Max), |ui| {
if sfx_play(ui.button("🗑")).on_hover_text("Delete").clicked() {
}
if ui.button("Edit").clicked() {

if sfx_play(ui.button("⛭")).on_hover_text("Edit").clicked() {
}
if ui.button("Play").clicked() {

if sfx_play(ui.button("▶")).on_hover_text("Play").clicked() {
}
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/ui/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
voxel::{ClientChunkSystem, HitResult}
};

use super::{new_egui_window, ui_lr_panel, CurrentUI};
use super::{new_egui_window, sfx_play, ui_lr_panel, CurrentUI};


#[derive(Default, PartialEq, Debug, Clone, Copy)]
Expand Down Expand Up @@ -52,15 +52,15 @@ pub fn ui_settings(
let curr_settings_panel = settings_panel.clone();

ui_lr_panel(ui, true, |ui| {
ui.selectable_value(&mut *settings_panel, SettingsPanel::General, "General");
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::General, "General"));
ui.separator();
ui.selectable_value(&mut *settings_panel, SettingsPanel::Graphics, "Graphics");
ui.selectable_value(&mut *settings_panel, SettingsPanel::Audio, "Audio");
ui.selectable_value(&mut *settings_panel, SettingsPanel::Controls, "Controls");
ui.selectable_value(&mut *settings_panel, SettingsPanel::Language, "Languages");
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Graphics, "Graphics"));
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Audio, "Audio"));
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Controls, "Controls"));
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Language, "Languages"));
ui.separator();
ui.selectable_value(&mut *settings_panel, SettingsPanel::Mods, "Mods");
ui.selectable_value(&mut *settings_panel, SettingsPanel::Assets, "Assets");
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Mods, "Mods"));
sfx_play(ui.selectable_value(&mut *settings_panel, SettingsPanel::Assets, "Assets"));
}, &mut next_ui, |ui| {

ui.style_mut().spacing.item_spacing.y = 12.;
Expand Down

0 comments on commit 3ce234f

Please sign in to comment.