2021-07-21 11:23:45 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::convert::AsRef;
|
2021-10-25 21:53:27 +00:00
|
|
|
use strum::{AsRefStr, EnumIter, EnumString};
|
2021-07-21 11:23:45 +00:00
|
|
|
|
|
|
|
/// Represents a key that the game recognises after input mapping.
|
|
|
|
#[derive(
|
|
|
|
Clone,
|
|
|
|
Copy,
|
|
|
|
Debug,
|
|
|
|
PartialEq,
|
|
|
|
Eq,
|
|
|
|
PartialOrd,
|
|
|
|
Ord,
|
|
|
|
Hash,
|
|
|
|
Deserialize,
|
|
|
|
Serialize,
|
|
|
|
AsRefStr,
|
|
|
|
EnumIter,
|
2021-10-25 21:53:27 +00:00
|
|
|
EnumString,
|
2021-07-21 11:23:45 +00:00
|
|
|
)]
|
|
|
|
pub enum GameInput {
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-primary")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Primary,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-secondary")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Secondary,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-block")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Block,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot1")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot1,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot2")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot2,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot3")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot3,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot4")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot4,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot5")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot5,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot6")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot6,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot7")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot7,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot8")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot8,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot9")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot9,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-slot10")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Slot10,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-togglecursor")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleCursor,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-moveforward")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MoveForward,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-moveback")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MoveBack,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-moveleft")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MoveLeft,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-moveright")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MoveRight,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-jump")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Jump,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-sit")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Sit,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-dance")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Dance,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-greet")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Greet,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-glide")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Glide,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-climb")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Climb,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-climbdown")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ClimbDown,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-swimup")]
|
2021-07-21 11:23:45 +00:00
|
|
|
SwimUp,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-swimdown")]
|
2021-07-21 11:23:45 +00:00
|
|
|
SwimDown,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-fly")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Fly,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-sneak")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Sneak,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-togglelantern")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleLantern,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-mount")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Mount,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-chat")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Chat,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-command")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Command,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-escape")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Escape,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-map")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Map,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-bag")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Bag,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-trade")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Trade,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-social")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Social,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-crafting")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Crafting,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-spellbook")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Spellbook,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-settings")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Settings,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-toggleinterface")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleInterface,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-help")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Help,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-toggledebug")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleDebug,
|
2021-08-06 19:22:05 +00:00
|
|
|
#[cfg(feature = "egui-ui")]
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-toggle_egui_debug")]
|
2021-08-06 19:22:05 +00:00
|
|
|
ToggleEguiDebug,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-togglechat")]
|
2021-07-26 00:41:01 +00:00
|
|
|
ToggleChat,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-fullscreen")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Fullscreen,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-screenshot")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Screenshot,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-toggleingameui")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleIngameUi,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-roll")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Roll,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-respawn")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Respawn,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-interact")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Interact,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-togglewield")]
|
2021-07-21 11:23:45 +00:00
|
|
|
ToggleWield,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-swaploadout")]
|
2021-07-21 11:23:45 +00:00
|
|
|
SwapLoadout,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-freelook")]
|
2021-07-21 11:23:45 +00:00
|
|
|
FreeLook,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-autowalk")]
|
2021-07-21 11:23:45 +00:00
|
|
|
AutoWalk,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-cameraclamp")]
|
2021-07-21 11:23:45 +00:00
|
|
|
CameraClamp,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-cyclecamera")]
|
2021-07-21 11:23:45 +00:00
|
|
|
CycleCamera,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-select")]
|
2021-07-21 11:23:45 +00:00
|
|
|
Select,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-acceptgroupinvite")]
|
2021-07-21 11:23:45 +00:00
|
|
|
AcceptGroupInvite,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-declinegroupinvite")]
|
2021-07-21 11:23:45 +00:00
|
|
|
DeclineGroupInvite,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-mapzoomin")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MapZoomIn,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-mapzoomout")]
|
2021-07-21 11:23:45 +00:00
|
|
|
MapZoomOut,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-map-locationmarkerbutton")]
|
2022-01-21 18:05:41 +00:00
|
|
|
MapSetMarker,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-spectatespeedboost")]
|
2022-07-05 15:23:37 +00:00
|
|
|
SpectateSpeedBoost,
|
2022-08-23 11:35:16 +00:00
|
|
|
#[strum(serialize = "gameinput-spectateviewpoint")]
|
2022-07-06 09:20:18 +00:00
|
|
|
SpectateViewpoint,
|
2022-09-09 09:39:27 +00:00
|
|
|
#[strum(serialize = "gameinput-mutemaster")]
|
|
|
|
MuteMaster,
|
|
|
|
#[strum(serialize = "gameinput-muteinactivemaster")]
|
|
|
|
MuteInactiveMaster,
|
|
|
|
#[strum(serialize = "gameinput-mutemusic")]
|
2022-05-09 09:55:18 +00:00
|
|
|
MuteMusic,
|
2022-09-09 09:39:27 +00:00
|
|
|
#[strum(serialize = "gameinput-mutesfx")]
|
|
|
|
MuteSfx,
|
|
|
|
#[strum(serialize = "gameinput-muteambience")]
|
|
|
|
MuteAmbience,
|
2021-07-21 11:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl GameInput {
|
|
|
|
pub fn get_localization_key(&self) -> &str { self.as_ref() }
|
|
|
|
|
|
|
|
/// Return true if `a` and `b` are able to be bound to the same key at the
|
|
|
|
/// same time without conflict. For example, the player can't jump and climb
|
|
|
|
/// at the same time, so these can be bound to the same key.
|
|
|
|
pub fn can_share_bindings(a: GameInput, b: GameInput) -> bool {
|
|
|
|
a.get_representative_binding() == b.get_representative_binding()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If two GameInputs are able to be bound at the same time, then they will
|
|
|
|
/// return the same value from this function (the representative value for
|
|
|
|
/// that set). This models the Find operation of a disjoint-set data
|
|
|
|
/// structure.
|
|
|
|
fn get_representative_binding(&self) -> GameInput {
|
|
|
|
match self {
|
|
|
|
GameInput::Jump => GameInput::Jump,
|
|
|
|
GameInput::Climb => GameInput::Jump,
|
|
|
|
GameInput::SwimUp => GameInput::Jump,
|
|
|
|
GameInput::Respawn => GameInput::Jump,
|
|
|
|
|
|
|
|
GameInput::FreeLook => GameInput::FreeLook,
|
|
|
|
GameInput::AutoWalk => GameInput::FreeLook,
|
|
|
|
|
|
|
|
_ => *self,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|