Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ use model_loader::ModelLoader;
use render::{DamageDigitMaterial, RoseRenderPlugin};
use resources::{
load_ui_resources, run_network_thread, ui_requested_cursor_apply_system, update_ui_resources,
AppState, ClientEntityList, DamageDigitsSpawner, DebugRenderConfig, GameData, InterfaceConfig,
NameTagCache, NetworkThread, NetworkThreadMessage, RenderConfiguration, SelectedTarget,
ServerConfiguration, SoundCache, SoundConfig, SpecularTexture, VfsResource, WorldTime,
ZoneTime,
AppState, ClientEntityList, DamageDigitsSpawner, DebugRenderConfig, GameData, HotkeysConfig,
InterfaceConfig, NameTagCache, NetworkThread, NetworkThreadMessage, RenderConfiguration,
SelectedTarget, ServerConfiguration, SoundCache, SoundConfig, SpecularTexture, VfsResource,
WorldTime, ZoneTime,
};
use scripting::RoseScriptingPlugin;
use systems::{
Expand Down Expand Up @@ -316,6 +316,7 @@ pub struct Config {
pub server: ServerConfig,
pub sound: SoundConfig,
pub interface: InterfaceConfig,
pub hotkeys: HotkeysConfig,
}

pub fn load_config(path: &PathBuf) -> Config {
Expand Down
155 changes: 155 additions & 0 deletions src/resources/hotkeys_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
use egui::{Key, KeyboardShortcut, Modifiers};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Clone)]
#[serde(default)]
pub struct HotkeysConfig {
#[serde(with = "KeyboardShortcutDef")]
pub inventory: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub skills: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub character: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub quests: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub clan: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub settings: KeyboardShortcut,

#[serde(with = "KeyboardShortcutDef")]
pub hotbar_1: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_2: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_3: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_4: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_5: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_6: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_7: KeyboardShortcut,
#[serde(with = "KeyboardShortcutDef")]
pub hotbar_8: KeyboardShortcut,
}

impl Default for HotkeysConfig {
fn default() -> Self {
Self {
inventory: KeyboardShortcut::new(Modifiers::ALT, Key::I),
skills: KeyboardShortcut::new(Modifiers::ALT, Key::S),
character: KeyboardShortcut::new(Modifiers::ALT, Key::A),
quests: KeyboardShortcut::new(Modifiers::ALT, Key::Q),
clan: KeyboardShortcut::new(Modifiers::ALT, Key::N),
settings: KeyboardShortcut::new(Modifiers::ALT, Key::O),

hotbar_1: KeyboardShortcut::new(Modifiers::NONE, Key::F1),
hotbar_2: KeyboardShortcut::new(Modifiers::NONE, Key::F2),
hotbar_3: KeyboardShortcut::new(Modifiers::NONE, Key::F3),
hotbar_4: KeyboardShortcut::new(Modifiers::NONE, Key::F4),
hotbar_5: KeyboardShortcut::new(Modifiers::NONE, Key::F5),
hotbar_6: KeyboardShortcut::new(Modifiers::NONE, Key::F6),
hotbar_7: KeyboardShortcut::new(Modifiers::NONE, Key::F7),
hotbar_8: KeyboardShortcut::new(Modifiers::NONE, Key::F8),
}
}
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "KeyboardShortcut")]
struct KeyboardShortcutDef {
#[serde(with = "ModifiersDef")]
pub modifiers: Modifiers,
#[serde(with = "KeyDef")]
pub key: Key,
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "Modifiers")]
struct ModifiersDef {
pub alt: bool,
pub ctrl: bool,
pub shift: bool,
pub mac_cmd: bool,
pub command: bool,
}

#[derive(Serialize, Deserialize)]
#[serde(remote = "Key")]
enum KeyDef {
ArrowDown,
ArrowLeft,
ArrowRight,
ArrowUp,
Escape,
Tab,
Backspace,
Enter,
Space,
Insert,
Delete,
Home,
End,
PageUp,
PageDown,
Minus,
PlusEquals,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
}
2 changes: 2 additions & 0 deletions src/resources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod debug_inspector;
mod debug_render;
mod game_connection;
mod game_data;
mod hotkeys_config;
mod interface_config;
mod login_connection;
mod login_state;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub use debug_inspector::DebugInspector;
pub use debug_render::DebugRenderConfig;
pub use game_connection::GameConnection;
pub use game_data::GameData;
pub use hotkeys_config::HotkeysConfig;
pub use interface_config::{InterfaceConfig, TargetingType};
pub use login_connection::LoginConnection;
pub use login_state::LoginState;
Expand Down
56 changes: 10 additions & 46 deletions src/ui/ui_game_menu_system.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::{Assets, EventWriter, Local, Res, ResMut};
use bevy::prelude::{Assets, EventWriter, Res, ResMut};
use bevy_egui::{egui, EguiContexts};

use crate::{
Expand All @@ -7,6 +7,7 @@ use crate::{
widgets::{DataBindings, Dialog},
UiSoundEvent, UiStateWindows,
},
Config,
};

const IID_BTN_CHAR: i32 = 10;
Expand All @@ -20,19 +21,13 @@ const IID_BTN_INFO: i32 = 17;
const IID_BTN_OPTION: i32 = 18;
const IID_BTN_EXIT: i32 = 19;

#[derive(Default)]
pub struct UiGameMenuState {
pub was_open: bool,
pub mouse_up_after_open: bool,
}

pub fn ui_game_menu_system(
mut egui_context: EguiContexts,
mut ui_state_windows: ResMut<UiStateWindows>,
mut ui_state: Local<UiGameMenuState>,
ui_resources: Res<UiResources>,
mut ui_sound_events: EventWriter<UiSoundEvent>,
dialog_assets: Res<Assets<Dialog>>,
config: Res<Config>,
) {
let dialog = if let Some(dialog) = dialog_assets.get(&ui_resources.dialog_game_menu) {
dialog
Expand All @@ -51,7 +46,7 @@ pub fn ui_game_menu_system(
let mut response_button_help = None;
let mut response_button_info = None;

let response = egui::Window::new("Game Menu")
egui::Window::new("Game Menu")
.frame(egui::Frame::none())
.open(&mut ui_state_windows.menu_open)
.title_bar(false)
Expand Down Expand Up @@ -82,100 +77,69 @@ pub fn ui_game_menu_system(
);
});

if let Some(response) = response {
// To avoid clicked_elsewhere being triggered as soon as we open menu,
// we will only look for it after we have detected all mouse buttons
// have been released after opening
if ui_state.mouse_up_after_open {
if response.response.clicked_elsewhere() {
ui_state_windows.menu_open = false;
}
} else if !response
.response
.ctx
.input(|input| input.pointer.any_down())
{
ui_state.mouse_up_after_open = true;
}
} else {
ui_state.mouse_up_after_open = false;
}

if response_button_character_info.map_or(false, |r| r.clicked()) {
ui_state_windows.character_info_open = !ui_state_windows.character_info_open;
ui_state_windows.menu_open = false;
}

if response_button_inventory.map_or(false, |r| r.clicked()) {
ui_state_windows.inventory_open = !ui_state_windows.inventory_open;
ui_state_windows.menu_open = false;
}

if response_button_skill_list.map_or(false, |r| r.clicked()) {
ui_state_windows.skill_list_open = !ui_state_windows.skill_list_open;
ui_state_windows.menu_open = false;
}

if response_button_quest_list.map_or(false, |r| r.clicked()) {
ui_state_windows.quest_list_open = !ui_state_windows.quest_list_open;
ui_state_windows.menu_open = false;
}

if response_button_options.map_or(false, |r| r.clicked()) {
ui_state_windows.settings_open = !ui_state_windows.settings_open;
ui_state_windows.menu_open = false;
}

if response_button_community.map_or(false, |r| r.clicked()) {
// TODO: Community dialog
ui_state_windows.menu_open = false;
}

if response_button_clan.map_or(false, |r| r.clicked()) {
ui_state_windows.clan_open = !ui_state_windows.clan_open;
ui_state_windows.menu_open = false;
}

if response_button_help.map_or(false, |r| r.clicked()) {
// TODO: Help dialog
ui_state_windows.menu_open = false;
}

if response_button_info.map_or(false, |r| r.clicked()) {
// TODO: Info dialog
ui_state_windows.menu_open = false;
}

if response_button_exit.map_or(false, |r| r.clicked()) {
// TODO: Exit dialog
ui_state_windows.menu_open = false;
}

if !egui_context.ctx_mut().wants_keyboard_input() {
egui_context.ctx_mut().input_mut(|input| {
if input.consume_key(egui::Modifiers::ALT, egui::Key::A) {
if input.consume_shortcut(&config.hotkeys.character) {
ui_state_windows.character_info_open = !ui_state_windows.character_info_open;
}

if input.consume_key(egui::Modifiers::ALT, egui::Key::I)
|| input.consume_key(egui::Modifiers::ALT, egui::Key::V)
{
if input.consume_shortcut(&config.hotkeys.inventory) {
ui_state_windows.inventory_open = !ui_state_windows.inventory_open;
}

if input.consume_key(egui::Modifiers::ALT, egui::Key::N) {
if input.consume_shortcut(&config.hotkeys.clan) {
ui_state_windows.clan_open = !ui_state_windows.clan_open;
}

if input.consume_key(egui::Modifiers::ALT, egui::Key::S) {
if input.consume_shortcut(&config.hotkeys.skills) {
ui_state_windows.skill_list_open = !ui_state_windows.skill_list_open;
}

if input.consume_key(egui::Modifiers::ALT, egui::Key::Q) {
if input.consume_shortcut(&config.hotkeys.quests) {
ui_state_windows.quest_list_open = !ui_state_windows.quest_list_open;
}

if input.consume_key(egui::Modifiers::ALT, egui::Key::O) {
if input.consume_shortcut(&config.hotkeys.settings) {
ui_state_windows.settings_open = !ui_state_windows.settings_open;
}
});
Expand Down
Loading
Loading