veloren/voxygen/src/game_input.rs

205 lines
6.1 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use std::convert::AsRef;
use strum::{AsRefStr, EnumIter, EnumString};
/// Represents a key that the game recognises after input mapping.
#[derive(
Clone,
Copy,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Deserialize,
Serialize,
AsRefStr,
EnumIter,
EnumString,
)]
pub enum GameInput {
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-primary")]
Primary,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-secondary")]
Secondary,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-block")]
Block,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot1")]
Slot1,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot2")]
Slot2,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot3")]
Slot3,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot4")]
Slot4,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot5")]
Slot5,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot6")]
Slot6,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot7")]
Slot7,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot8")]
Slot8,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot9")]
Slot9,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-slot10")]
Slot10,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-togglecursor")]
ToggleCursor,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-moveforward")]
MoveForward,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-moveback")]
MoveBack,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-moveleft")]
MoveLeft,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-moveright")]
MoveRight,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-jump")]
Jump,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-sit")]
Sit,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-dance")]
Dance,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-greet")]
Greet,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-glide")]
Glide,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-climb")]
Climb,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-climbdown")]
ClimbDown,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-swimup")]
SwimUp,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-swimdown")]
SwimDown,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-fly")]
Fly,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-sneak")]
Sneak,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-togglelantern")]
ToggleLantern,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-mount")]
Mount,
2023-04-30 15:45:21 +00:00
#[strum(serialize = "gameinput-stayfollow")]
StayFollow,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-chat")]
Chat,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-command")]
Command,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-escape")]
Escape,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-map")]
Map,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-bag")]
Bag,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-trade")]
Trade,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-social")]
Social,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-crafting")]
Crafting,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-spellbook")]
Spellbook,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-settings")]
Settings,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-toggleinterface")]
ToggleInterface,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-help")]
Help,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-toggledebug")]
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")]
Fullscreen,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-screenshot")]
Screenshot,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-toggleingameui")]
ToggleIngameUi,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-roll")]
Roll,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-respawn")]
Respawn,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-interact")]
Interact,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-togglewield")]
ToggleWield,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-swaploadout")]
SwapLoadout,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-freelook")]
FreeLook,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-autowalk")]
AutoWalk,
2023-08-10 16:55:09 +00:00
#[strum(serialize = "gameinput-zoomin")]
ZoomIn,
#[strum(serialize = "gameinput-zoomout")]
ZoomOut,
#[strum(serialize = "gameinput-zoomlock")]
ZoomLock,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-cameraclamp")]
CameraClamp,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-cyclecamera")]
CycleCamera,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-select")]
Select,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-acceptgroupinvite")]
AcceptGroupInvite,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-declinegroupinvite")]
DeclineGroupInvite,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-mapzoomin")]
MapZoomIn,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-mapzoomout")]
MapZoomOut,
2022-08-23 11:35:16 +00:00
#[strum(serialize = "gameinput-map-locationmarkerbutton")]
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,
#[strum(serialize = "gameinput-mutemaster")]
MuteMaster,
#[strum(serialize = "gameinput-muteinactivemaster")]
MuteInactiveMaster,
#[strum(serialize = "gameinput-mutemusic")]
MuteMusic,
#[strum(serialize = "gameinput-mutesfx")]
MuteSfx,
#[strum(serialize = "gameinput-muteambience")]
MuteAmbience,
2023-10-13 19:28:56 +00:00
#[strum(serialize = "gameinput-togglewalk")]
ToggleWalk,
}
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,
}
}
}