# Conflicts: # .github/CODEOWNERS # .github/ISSUE_TEMPLATE/config.yml # .github/ISSUE_TEMPLATE/issue_report.md # Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs # Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs # Content.Client/Weapons/Ranged/Systems/GunSystem.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs # Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs # Content.Server/Arcade/SpaceVillainGame/SpaceVillainArcadeComponent.cs # Content.Server/Atmos/EntitySystems/FlammableSystem.cs # Content.Server/Chat/Systems/ChatSystem.cs # Content.Server/Destructible/Thresholds/DamageThreshold.cs # Content.Server/Entry/EntryPoint.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.cs # Content.Server/GuideGenerator/ReagentEntry.cs # Content.Server/IoC/ServerContentIoC.cs # Content.Server/Medical/HealthAnalyzerSystem.cs # Content.Server/Medical/VomitSystem.cs # Content.Server/Radio/EntitySystems/HeadsetSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.cs # Content.Server/Weapons/Ranged/Systems/GunSystem.cs # Content.Shared/Armor/SharedArmorSystem.cs # Content.Shared/Bed/Sleep/SleepingSystem.cs # Content.Shared/Cabinet/ItemCabinetSystem.cs # Content.Shared/Chat/SharedChatSystem.Emote.cs # Content.Shared/Chat/SharedChatSystem.cs # Content.Shared/Clothing/EntitySystems/MaskSystem.cs # Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/EntityEffects/Effects/StatusEffects/GenericStatusEffect.cs # Content.Shared/EntityEffects/Effects/Transform/ExplosionEntityEffect.cs # Content.Shared/Humanoid/HumanoidCharacterAppearance.cs # Content.Shared/IoC/SharedContentIoC.cs # Content.Shared/Lock/LockSystem.cs # Content.Shared/Ninja/Components/NinjaSuitComponent.cs # Content.Shared/Preferences/HumanoidCharacterProfile.cs # Content.Shared/Revenant/Components/RevenantComponent.cs # Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs # Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs # Content.Shared/VendingMachines/SharedVendingMachineSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/Weapons/Ranged/HitscanPrototype.cs # Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs # README.md # Resources/Audio/Weapons/attributions.yml # Resources/Locale/en-US/_strings/ghost/make-ghost-gui.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/statuseffects.ftl # Resources/Locale/en-US/_strings/job/job-description.ftl # Resources/Locale/en-US/_strings/medical/components/crew-monitoring-component.ftl # Resources/Locale/en-US/_strings/npc/hugbot.ftl # Resources/Locale/en-US/_strings/npc/npc-debug.ftl # Resources/Locale/en-US/_strings/speech/speech-triggers.ftl # Resources/Locale/en-US/_strings/ui/stat-values.ftl # Resources/Locale/en-US/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/guidebook/entity-effects/conditions.ftl # Resources/Locale/en-US/guidebook/entity-effects/effects.ftl # Resources/Locale/en-US/guidebook/entity-effects/healthchange.ftl # Resources/Maps/Shuttles/cargo_relic.yml # Resources/Maps/_Sunrise/Station/bagel.yml # Resources/Maps/_Sunrise/Station/barratry.yml # Resources/Maps/_Sunrise/Station/fland.yml # Resources/Maps/_Sunrise/Station/marathon.yml # Resources/Maps/_Sunrise/Station/oasis.yml # Resources/Maps/_Sunrise/Station/packed.yml # Resources/Maps/_Sunrise/Station/plasma.yml # Resources/Maps/_Sunrise/Station/relic.yml # Resources/Maps/_Sunrise/event/clon_mine.yml # Resources/Maps/_Sunrise/event/void.yml # Resources/Prototypes/Body/Prototypes/vox.yml # Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml # Resources/Prototypes/Catalog/Fills/Crates/fun.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/security.yml # Resources/Prototypes/Entities/Clothing/Belt/belts.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml # Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml # Resources/Prototypes/Entities/Mobs/Species/skeleton.yml # Resources/Prototypes/Entities/Objects/Devices/Electronics/base_electronics.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/access.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/airlocks.yml # Resources/Prototypes/Entities/Structures/Doors/MaterialDoors/material_doors.yml # Resources/Prototypes/Entities/Structures/Machines/lathe.yml # Resources/Prototypes/Entities/Structures/Specific/Atmospherics/sensor.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Loadouts/Jobs/Science/scientist.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/Miscellaneous/glasses.yml # Resources/Prototypes/Loadouts/loadout_groups.yml # Resources/Prototypes/Objectives/objectiveGroups.yml # Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml # Resources/Prototypes/Reagents/medicine.yml # Resources/Prototypes/Reagents/narcotics.yml # Resources/Prototypes/Reagents/toxins.yml # Resources/Prototypes/Recipes/Lathes/Packs/biogen.yml # Resources/Prototypes/Recipes/Lathes/Packs/security.yml # Resources/Prototypes/Recipes/Lathes/biogen.yml # Resources/Prototypes/Roles/Antags/nukeops.yml # Resources/Prototypes/Roles/Antags/revolutionary.yml # Resources/Prototypes/Roles/Antags/thief.yml # Resources/Prototypes/Roles/Antags/traitor.yml # Resources/Prototypes/Roles/Antags/wizard.yml # Resources/Prototypes/Roles/Antags/zombie.yml # Resources/Prototypes/Roles/Jobs/Cargo/salvage_specialist.yml # Resources/Prototypes/Roles/Jobs/Civilian/bartender.yml # Resources/Prototypes/Roles/Jobs/Civilian/chef.yml # Resources/Prototypes/Roles/Jobs/Civilian/mime.yml # Resources/Prototypes/Roles/Jobs/Engineering/atmospheric_technician.yml # Resources/Prototypes/Roles/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml # Resources/Prototypes/Roles/Jobs/Medical/chemist.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_doctor.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml # Resources/Prototypes/Roles/Jobs/Medical/paramedic.yml # Resources/Prototypes/Roles/Jobs/Science/borg.yml # Resources/Prototypes/Roles/Jobs/Science/research_assistant.yml # Resources/Prototypes/Roles/Jobs/Science/scientist.yml # Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml # Resources/Prototypes/Roles/Jobs/Security/security_officer.yml # Resources/Prototypes/Roles/Jobs/Security/warden.yml # Resources/Prototypes/Stacks/Materials/crystals.yml # Resources/Prototypes/Stacks/floor_tile_stacks.yml # Resources/Prototypes/tags.yml # Resources/ServerInfo/Guidebook/Science/ArtifactReports.xml # Resources/ServerInfo/Guidebook/Science/Xenoarchaeology.xml # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/equipped-HAND.png # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/mime.rsi/meta.json # Resources/Textures/Effects/speech.rsi/moth3.png # Resources/Textures/Interface/Misc/job_icons.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/mw.png # Resources/Textures/Structures/Machines/microwave.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody0.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody1.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloodyo.png # Resources/Textures/Structures/Machines/microwave.rsi/mwo.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/meta.json # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwo.png # Resources/migration.yml # RobustToolbox
645 lines
24 KiB
C#
645 lines
24 KiB
C#
using System.Numerics;
|
|
using Content.Client.Stylesheets;
|
|
using Content.Shared._Sunrise.SunriseCCVars;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Input;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Input;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
|
|
|
namespace Content.Client.Options.UI.Tabs
|
|
{
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class KeyRebindTab : Control
|
|
{
|
|
// List of key functions that must be registered as toggle instead.
|
|
private static readonly HashSet<BoundKeyFunction> ToggleFunctions = new()
|
|
{
|
|
EngineKeyFunctions.ShowDebugMonitors,
|
|
EngineKeyFunctions.HideUI,
|
|
};
|
|
|
|
[Dependency] private readonly IInputManager _inputManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
private BindButton? _currentlyRebinding;
|
|
|
|
private readonly Dictionary<BoundKeyFunction, KeyControl> _keyControls =
|
|
new();
|
|
|
|
private readonly List<Action> _deferCommands = new();
|
|
|
|
private void HandleToggleUSQWERTYCheckbox(BaseButton.ButtonToggledEventArgs args)
|
|
{
|
|
_cfg.SetCVar(CVars.DisplayUSQWERTYHotkeys, args.Pressed);
|
|
_cfg.SaveToFile();
|
|
}
|
|
|
|
private void InitToggleWalk()
|
|
{
|
|
if (_cfg.GetCVar(CCVars.ToggleWalk))
|
|
{
|
|
ToggleFunctions.Add(EngineKeyFunctions.Walk);
|
|
}
|
|
else
|
|
{
|
|
ToggleFunctions.Remove(EngineKeyFunctions.Walk);
|
|
}
|
|
}
|
|
|
|
private void HandleToggleWalk(BaseButton.ButtonToggledEventArgs args)
|
|
{
|
|
_cfg.SetCVar(CCVars.ToggleWalk, args.Pressed);
|
|
_cfg.SaveToFile();
|
|
InitToggleWalk();
|
|
|
|
if (!_keyControls.TryGetValue(EngineKeyFunctions.Walk, out var keyControl))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var bindingType = args.Pressed ? KeyBindingType.Toggle : KeyBindingType.State;
|
|
for (var i = 0; i <= 1; i++)
|
|
{
|
|
var binding = (i == 0 ? keyControl.BindButton1 : keyControl.BindButton2).Binding;
|
|
if (binding == null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var registration = new KeyBindingRegistration
|
|
{
|
|
Function = EngineKeyFunctions.Walk,
|
|
BaseKey = binding.BaseKey,
|
|
Mod1 = binding.Mod1,
|
|
Mod2 = binding.Mod2,
|
|
Mod3 = binding.Mod3,
|
|
Priority = binding.Priority,
|
|
Type = bindingType,
|
|
CanFocus = binding.CanFocus,
|
|
CanRepeat = binding.CanRepeat,
|
|
};
|
|
|
|
_deferCommands.Add(() =>
|
|
{
|
|
_inputManager.RemoveBinding(binding);
|
|
_inputManager.RegisterBinding(registration);
|
|
});
|
|
}
|
|
|
|
_deferCommands.Add(_inputManager.SaveToUserData);
|
|
}
|
|
|
|
// Sunrise-Start
|
|
private void HandleHoldLookUp(BaseButton.ButtonToggledEventArgs args)
|
|
{
|
|
_cfg.SetCVar(SunriseCCVars.HoldLookUp, args.Pressed);
|
|
_cfg.SaveToFile();
|
|
}
|
|
// Sunrise-End
|
|
|
|
private void HandleStaticStorageUI(BaseButton.ButtonToggledEventArgs args)
|
|
{
|
|
_cfg.SetCVar(CCVars.StaticStorageUI, args.Pressed);
|
|
_cfg.SaveToFile();
|
|
}
|
|
|
|
public KeyRebindTab()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
ResetAllButton.OnPressed += _ =>
|
|
{
|
|
_deferCommands.Add(() =>
|
|
{
|
|
_inputManager.ResetAllBindings();
|
|
_inputManager.SaveToUserData();
|
|
});
|
|
};
|
|
|
|
var first = true;
|
|
|
|
void AddHeader(string headerContents)
|
|
{
|
|
if (!first)
|
|
{
|
|
KeybindsContainer.AddChild(new Control { MinSize = new Vector2(0, 8) });
|
|
}
|
|
|
|
first = false;
|
|
KeybindsContainer.AddChild(new Label
|
|
{
|
|
Text = Loc.GetString(headerContents),
|
|
FontColorOverride = StyleNano.NanoGold,
|
|
StyleClasses = { StyleNano.StyleClassLabelKeyText }
|
|
});
|
|
}
|
|
|
|
void AddButton(BoundKeyFunction function)
|
|
{
|
|
var control = new KeyControl(this, function);
|
|
KeybindsContainer.AddChild(control);
|
|
_keyControls.Add(function, control);
|
|
}
|
|
|
|
void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.ButtonToggledEventArgs>? callBackOnClick)
|
|
{
|
|
CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) };
|
|
newCheckBox.Pressed = currentState;
|
|
newCheckBox.OnToggled += callBackOnClick;
|
|
|
|
KeybindsContainer.AddChild(newCheckBox);
|
|
}
|
|
|
|
// Sunrise-Start
|
|
AddHeader("ui-options-header-extra");
|
|
AddButton(ContentKeyFunctions.ToggleStanding);
|
|
AddButton(ContentKeyFunctions.CockGun);
|
|
AddButton(ContentKeyFunctions.MeleeGunAttack);
|
|
AddButton(ContentKeyFunctions.Jump);
|
|
AddButton(ContentKeyFunctions.Reloading);
|
|
AddButton(ContentKeyFunctions.Interact);
|
|
AddButton(ContentKeyFunctions.LookUp);
|
|
AddButton(ContentKeyFunctions.OpenMentorHelp);
|
|
AddButton(ContentKeyFunctions.OpenHelpChoice);
|
|
AddCheckBox("ui-options-function-hold-look-up", _cfg.GetCVar(SunriseCCVars.HoldLookUp), HandleHoldLookUp);
|
|
// Sunrise-End
|
|
|
|
AddHeader("ui-options-header-general");
|
|
AddCheckBox("ui-options-hotkey-keymap", _cfg.GetCVar(CVars.DisplayUSQWERTYHotkeys), HandleToggleUSQWERTYCheckbox);
|
|
|
|
AddHeader("ui-options-header-movement");
|
|
AddButton(EngineKeyFunctions.MoveUp);
|
|
AddButton(EngineKeyFunctions.MoveLeft);
|
|
AddButton(EngineKeyFunctions.MoveDown);
|
|
AddButton(EngineKeyFunctions.MoveRight);
|
|
AddButton(EngineKeyFunctions.Walk);
|
|
AddCheckBox("ui-options-hotkey-toggle-walk", _cfg.GetCVar(CCVars.ToggleWalk), HandleToggleWalk);
|
|
InitToggleWalk();
|
|
AddButton(ContentKeyFunctions.ToggleKnockdown);
|
|
|
|
AddHeader("ui-options-header-camera");
|
|
AddButton(EngineKeyFunctions.CameraRotateLeft);
|
|
AddButton(EngineKeyFunctions.CameraRotateRight);
|
|
AddButton(EngineKeyFunctions.CameraReset);
|
|
AddButton(ContentKeyFunctions.ZoomIn);
|
|
AddButton(ContentKeyFunctions.ZoomOut);
|
|
AddButton(ContentKeyFunctions.ResetZoom);
|
|
|
|
AddHeader("ui-options-header-interaction-basic");
|
|
AddButton(EngineKeyFunctions.Use);
|
|
AddButton(EngineKeyFunctions.UseSecondary);
|
|
AddButton(ContentKeyFunctions.UseItemInHand);
|
|
AddButton(ContentKeyFunctions.AltUseItemInHand);
|
|
AddButton(ContentKeyFunctions.ActivateItemInWorld);
|
|
AddButton(ContentKeyFunctions.AltActivateItemInWorld);
|
|
AddButton(ContentKeyFunctions.Drop);
|
|
AddButton(ContentKeyFunctions.ExamineEntity);
|
|
AddButton(ContentKeyFunctions.SwapHands);
|
|
AddButton(ContentKeyFunctions.SwapHandsReverse);
|
|
AddButton(ContentKeyFunctions.MoveStoredItem);
|
|
AddButton(ContentKeyFunctions.RotateStoredItem);
|
|
AddButton(ContentKeyFunctions.SaveItemLocation);
|
|
|
|
AddHeader("ui-options-header-interaction-adv");
|
|
AddButton(ContentKeyFunctions.SmartEquipBackpack);
|
|
AddButton(ContentKeyFunctions.SmartEquipBelt);
|
|
AddButton(ContentKeyFunctions.SmartEquipPocket1);
|
|
AddButton(ContentKeyFunctions.SmartEquipPocket2);
|
|
AddButton(ContentKeyFunctions.SmartEquipSuitStorage);
|
|
AddButton(ContentKeyFunctions.OpenBackpack);
|
|
AddButton(ContentKeyFunctions.OpenBelt);
|
|
AddButton(ContentKeyFunctions.ThrowItemInHand);
|
|
AddButton(ContentKeyFunctions.TryPullObject);
|
|
AddButton(ContentKeyFunctions.MovePulledObject);
|
|
AddButton(ContentKeyFunctions.ReleasePulledObject);
|
|
AddButton(ContentKeyFunctions.Point);
|
|
AddButton(ContentKeyFunctions.RotateObjectClockwise);
|
|
AddButton(ContentKeyFunctions.RotateObjectCounterclockwise);
|
|
AddButton(ContentKeyFunctions.FlipObject);
|
|
|
|
AddHeader("ui-options-header-ui");
|
|
AddButton(ContentKeyFunctions.FocusChat);
|
|
AddButton(ContentKeyFunctions.FocusLocalChat);
|
|
AddButton(ContentKeyFunctions.FocusEmote);
|
|
AddButton(ContentKeyFunctions.FocusWhisperChat);
|
|
AddButton(ContentKeyFunctions.FocusRadio);
|
|
AddButton(ContentKeyFunctions.FocusLOOC);
|
|
AddButton(ContentKeyFunctions.FocusOOC);
|
|
AddButton(ContentKeyFunctions.FocusAdminChat);
|
|
AddButton(ContentKeyFunctions.FocusDeadChat);
|
|
AddButton(ContentKeyFunctions.FocusConsoleChat);
|
|
AddButton(ContentKeyFunctions.CycleChatChannelForward);
|
|
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
|
|
AddButton(ContentKeyFunctions.OpenCharacterMenu);
|
|
AddButton(ContentKeyFunctions.OpenCraftingMenu);
|
|
AddButton(ContentKeyFunctions.OpenGuidebook);
|
|
AddButton(ContentKeyFunctions.OpenInventoryMenu);
|
|
AddButton(ContentKeyFunctions.OpenAHelp);
|
|
AddButton(ContentKeyFunctions.OpenActionsMenu);
|
|
AddButton(ContentKeyFunctions.OpenEmotesMenu);
|
|
AddButton(ContentKeyFunctions.ToggleRoundEndSummaryWindow);
|
|
AddButton(ContentKeyFunctions.OpenEntitySpawnWindow);
|
|
AddButton(ContentKeyFunctions.OpenSandboxWindow);
|
|
AddButton(ContentKeyFunctions.OpenTileSpawnWindow);
|
|
AddButton(ContentKeyFunctions.OpenDecalSpawnWindow);
|
|
AddButton(ContentKeyFunctions.OpenAdminMenu);
|
|
AddButton(EngineKeyFunctions.WindowCloseAll);
|
|
AddButton(EngineKeyFunctions.WindowCloseRecent);
|
|
AddButton(EngineKeyFunctions.EscapeMenu);
|
|
AddButton(ContentKeyFunctions.EscapeContext);
|
|
|
|
AddHeader("ui-options-header-misc");
|
|
AddButton(ContentKeyFunctions.TakeScreenshot);
|
|
AddButton(ContentKeyFunctions.TakeScreenshotNoUI);
|
|
AddButton(ContentKeyFunctions.ToggleFullscreen);
|
|
|
|
AddHeader("ui-options-header-hotbar");
|
|
foreach (var boundKey in ContentKeyFunctions.GetHotbarBoundKeys())
|
|
{
|
|
AddButton(boundKey);
|
|
}
|
|
|
|
AddHeader("ui-options-header-shuttle");
|
|
AddButton(ContentKeyFunctions.ShuttleStrafeUp);
|
|
AddButton(ContentKeyFunctions.ShuttleStrafeRight);
|
|
AddButton(ContentKeyFunctions.ShuttleStrafeLeft);
|
|
AddButton(ContentKeyFunctions.ShuttleStrafeDown);
|
|
AddButton(ContentKeyFunctions.ShuttleRotateLeft);
|
|
AddButton(ContentKeyFunctions.ShuttleRotateRight);
|
|
AddButton(ContentKeyFunctions.ShuttleBrake);
|
|
|
|
AddHeader("ui-options-header-map-editor");
|
|
AddButton(EngineKeyFunctions.EditorPlaceObject);
|
|
AddButton(EngineKeyFunctions.EditorCancelPlace);
|
|
AddButton(EngineKeyFunctions.EditorGridPlace);
|
|
AddButton(EngineKeyFunctions.EditorLinePlace);
|
|
AddButton(EngineKeyFunctions.EditorRotateObject);
|
|
AddButton(ContentKeyFunctions.EditorFlipObject);
|
|
AddButton(ContentKeyFunctions.EditorCopyObject);
|
|
|
|
AddHeader("ui-options-header-dev");
|
|
AddButton(EngineKeyFunctions.ShowDebugConsole);
|
|
AddButton(EngineKeyFunctions.ShowDebugMonitors);
|
|
AddButton(EngineKeyFunctions.HideUI);
|
|
AddButton(ContentKeyFunctions.InspectEntity);
|
|
|
|
AddHeader("ui-options-header-text-cursor");
|
|
AddButton(EngineKeyFunctions.TextCursorLeft);
|
|
AddButton(EngineKeyFunctions.TextCursorRight);
|
|
AddButton(EngineKeyFunctions.TextCursorUp);
|
|
AddButton(EngineKeyFunctions.TextCursorDown);
|
|
AddButton(EngineKeyFunctions.TextCursorWordLeft);
|
|
AddButton(EngineKeyFunctions.TextCursorWordRight);
|
|
AddButton(EngineKeyFunctions.TextCursorBegin);
|
|
AddButton(EngineKeyFunctions.TextCursorEnd);
|
|
|
|
AddHeader("ui-options-header-text-cursor-select");
|
|
AddButton(EngineKeyFunctions.TextCursorSelect);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectLeft);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectRight);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectUp);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectDown);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectWordLeft);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectWordRight);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectBegin);
|
|
AddButton(EngineKeyFunctions.TextCursorSelectEnd);
|
|
|
|
AddHeader("ui-options-header-text-edit");
|
|
AddButton(EngineKeyFunctions.TextBackspace);
|
|
AddButton(EngineKeyFunctions.TextDelete);
|
|
AddButton(EngineKeyFunctions.TextWordBackspace);
|
|
AddButton(EngineKeyFunctions.TextWordDelete);
|
|
AddButton(EngineKeyFunctions.TextNewline);
|
|
AddButton(EngineKeyFunctions.TextSubmit);
|
|
AddButton(EngineKeyFunctions.MultilineTextSubmit);
|
|
AddButton(EngineKeyFunctions.TextSelectAll);
|
|
AddButton(EngineKeyFunctions.TextCopy);
|
|
AddButton(EngineKeyFunctions.TextCut);
|
|
AddButton(EngineKeyFunctions.TextPaste);
|
|
|
|
AddHeader("ui-options-header-text-chat");
|
|
AddButton(EngineKeyFunctions.TextHistoryPrev);
|
|
AddButton(EngineKeyFunctions.TextHistoryNext);
|
|
AddButton(EngineKeyFunctions.TextReleaseFocus);
|
|
AddButton(EngineKeyFunctions.TextScrollToBottom);
|
|
|
|
AddHeader("ui-options-header-text-other");
|
|
AddButton(EngineKeyFunctions.TextTabComplete);
|
|
AddButton(EngineKeyFunctions.TextCompleteNext);
|
|
AddButton(EngineKeyFunctions.TextCompletePrev);
|
|
|
|
foreach (var control in _keyControls.Values)
|
|
{
|
|
UpdateKeyControl(control);
|
|
}
|
|
}
|
|
|
|
private void UpdateKeyControl(KeyControl control)
|
|
{
|
|
var activeBinds = _inputManager.GetKeyBindings(control.Function);
|
|
|
|
IKeyBinding? bind1 = null;
|
|
IKeyBinding? bind2 = null;
|
|
|
|
if (activeBinds.Count > 0)
|
|
{
|
|
bind1 = activeBinds[0];
|
|
|
|
if (activeBinds.Count > 1)
|
|
{
|
|
bind2 = activeBinds[1];
|
|
}
|
|
}
|
|
|
|
control.BindButton1.Binding = bind1;
|
|
control.BindButton1.UpdateText();
|
|
|
|
control.BindButton2.Binding = bind2;
|
|
control.BindButton2.UpdateText();
|
|
|
|
control.BindButton2.Button.Disabled = activeBinds.Count == 0;
|
|
control.ResetButton.Disabled = !_inputManager.IsKeyFunctionModified(control.Function);
|
|
}
|
|
|
|
protected override void EnteredTree()
|
|
{
|
|
base.EnteredTree();
|
|
|
|
_inputManager.FirstChanceOnKeyEvent += InputManagerOnFirstChanceOnKeyEvent;
|
|
_inputManager.OnKeyBindingAdded += OnKeyBindAdded;
|
|
_inputManager.OnKeyBindingRemoved += OnKeyBindRemoved;
|
|
}
|
|
|
|
protected override void ExitedTree()
|
|
{
|
|
base.ExitedTree();
|
|
|
|
_inputManager.FirstChanceOnKeyEvent -= InputManagerOnFirstChanceOnKeyEvent;
|
|
_inputManager.OnKeyBindingAdded -= OnKeyBindAdded;
|
|
_inputManager.OnKeyBindingRemoved -= OnKeyBindRemoved;
|
|
}
|
|
|
|
private void OnKeyBindRemoved(IKeyBinding obj)
|
|
{
|
|
OnKeyBindModified(obj, true);
|
|
}
|
|
|
|
private void OnKeyBindAdded(IKeyBinding obj)
|
|
{
|
|
OnKeyBindModified(obj, false);
|
|
}
|
|
|
|
private void OnKeyBindModified(IKeyBinding bind, bool removal)
|
|
{
|
|
if (!_keyControls.TryGetValue(bind.Function, out var keyControl))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (removal && _currentlyRebinding?.KeyControl == keyControl)
|
|
{
|
|
// Don't do update if the removal was from initiating a rebind.
|
|
return;
|
|
}
|
|
|
|
UpdateKeyControl(keyControl);
|
|
|
|
if (_currentlyRebinding == keyControl.BindButton1 || _currentlyRebinding == keyControl.BindButton2)
|
|
{
|
|
_currentlyRebinding = null;
|
|
}
|
|
}
|
|
|
|
private void InputManagerOnFirstChanceOnKeyEvent(KeyEventArgs keyEvent, KeyEventType type)
|
|
{
|
|
DebugTools.Assert(IsInsideTree);
|
|
|
|
if (_currentlyRebinding == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
keyEvent.Handle();
|
|
|
|
if (type != KeyEventType.Up)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var key = keyEvent.Key;
|
|
|
|
// Figure out modifiers based on key event.
|
|
// TODO: this won't allow for combinations with keys other than the standard modifier keys,
|
|
// even though the input system totally supports it.
|
|
var mods = new Keyboard.Key[3];
|
|
var i = 0;
|
|
if (keyEvent.Control && key != Keyboard.Key.Control)
|
|
{
|
|
mods[i] = Keyboard.Key.Control;
|
|
i += 1;
|
|
}
|
|
|
|
if (keyEvent.Shift && key != Keyboard.Key.Shift)
|
|
{
|
|
mods[i] = Keyboard.Key.Shift;
|
|
i += 1;
|
|
}
|
|
|
|
if (keyEvent.Alt && key != Keyboard.Key.Alt)
|
|
{
|
|
mods[i] = Keyboard.Key.Alt;
|
|
i += 1;
|
|
}
|
|
|
|
// The input system can only handle 3 modifier keys so if you hold all 4 of the modifier keys
|
|
// then system gets the shaft, I guess.
|
|
if (keyEvent.System && i != 3 && key != Keyboard.Key.LSystem && key != Keyboard.Key.RSystem)
|
|
{
|
|
mods[i] = Keyboard.Key.LSystem;
|
|
}
|
|
|
|
var function = _currentlyRebinding.KeyControl.Function;
|
|
var bindType = KeyBindingType.State;
|
|
if (ToggleFunctions.Contains(function))
|
|
{
|
|
bindType = KeyBindingType.Toggle;
|
|
}
|
|
|
|
var registration = new KeyBindingRegistration
|
|
{
|
|
Function = function,
|
|
BaseKey = key,
|
|
Mod1 = mods[0],
|
|
Mod2 = mods[1],
|
|
Mod3 = mods[2],
|
|
Priority = _currentlyRebinding.Binding?.Priority ?? 0,
|
|
Type = bindType,
|
|
CanFocus = key == Keyboard.Key.MouseLeft
|
|
|| key == Keyboard.Key.MouseRight
|
|
|| key == Keyboard.Key.MouseMiddle,
|
|
CanRepeat = false
|
|
};
|
|
|
|
_inputManager.RegisterBinding(registration);
|
|
// OnKeyBindModified will cause _currentlyRebinding to be reset and the UI to update.
|
|
_inputManager.SaveToUserData();
|
|
}
|
|
|
|
private void RebindButtonPressed(BindButton button)
|
|
{
|
|
if (_currentlyRebinding != null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_currentlyRebinding = button;
|
|
_currentlyRebinding.Button.Text = Loc.GetString("ui-options-key-prompt");
|
|
|
|
if (button.Binding != null)
|
|
{
|
|
_deferCommands.Add(() =>
|
|
{
|
|
// Have to do defer this or else there will be an exception in InputManager.
|
|
// Because this IS fired from an input event.
|
|
_inputManager.RemoveBinding(button.Binding);
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
if (_deferCommands.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var command in _deferCommands)
|
|
{
|
|
command();
|
|
}
|
|
|
|
_deferCommands.Clear();
|
|
}
|
|
|
|
private sealed class KeyControl : Control
|
|
{
|
|
public readonly BoundKeyFunction Function;
|
|
public readonly BindButton BindButton1;
|
|
public readonly BindButton BindButton2;
|
|
public readonly Button ResetButton;
|
|
|
|
public KeyControl(KeyRebindTab parent, BoundKeyFunction function)
|
|
{
|
|
Function = function;
|
|
var name = new Label
|
|
{
|
|
Text = Loc.GetString(
|
|
$"ui-options-function-{CaseConversion.PascalToKebab(function.FunctionName)}"),
|
|
HorizontalExpand = true,
|
|
HorizontalAlignment = HAlignment.Left
|
|
};
|
|
|
|
BindButton1 = new BindButton(parent, this, StyleBase.ButtonOpenRight);
|
|
BindButton2 = new BindButton(parent, this, StyleBase.ButtonOpenLeft);
|
|
ResetButton = new Button { Text = Loc.GetString("ui-options-bind-reset"), StyleClasses = { StyleBase.ButtonCaution } };
|
|
|
|
var hBox = new BoxContainer
|
|
{
|
|
Orientation = LayoutOrientation.Horizontal,
|
|
Children =
|
|
{
|
|
new Control {MinSize = new Vector2(5, 0)},
|
|
name,
|
|
BindButton1,
|
|
BindButton2,
|
|
new Control {MinSize = new Vector2(10, 0)},
|
|
ResetButton
|
|
}
|
|
};
|
|
|
|
ResetButton.OnPressed += args =>
|
|
{
|
|
parent._deferCommands.Add(() =>
|
|
{
|
|
parent._inputManager.ResetBindingsFor(function);
|
|
parent._inputManager.SaveToUserData();
|
|
});
|
|
};
|
|
|
|
AddChild(hBox);
|
|
}
|
|
}
|
|
|
|
private sealed class BindButton : Control
|
|
{
|
|
private readonly KeyRebindTab _tab;
|
|
public readonly KeyControl KeyControl;
|
|
public readonly Button Button;
|
|
public IKeyBinding? Binding;
|
|
|
|
public BindButton(KeyRebindTab tab, KeyControl keyControl, string styleClass)
|
|
{
|
|
_tab = tab;
|
|
KeyControl = keyControl;
|
|
Button = new Button { StyleClasses = { styleClass } };
|
|
UpdateText();
|
|
AddChild(Button);
|
|
|
|
Button.OnPressed += args =>
|
|
{
|
|
tab.RebindButtonPressed(this);
|
|
};
|
|
|
|
Button.OnKeyBindDown += ButtonOnOnKeyBindDown;
|
|
|
|
MinSize = new Vector2(200, 0);
|
|
}
|
|
|
|
protected override void EnteredTree()
|
|
{
|
|
base.EnteredTree();
|
|
_tab._inputManager.OnInputModeChanged += UpdateText;
|
|
}
|
|
|
|
protected override void ExitedTree()
|
|
{
|
|
base.ExitedTree();
|
|
_tab._inputManager.OnInputModeChanged -= UpdateText;
|
|
}
|
|
|
|
private void ButtonOnOnKeyBindDown(GUIBoundKeyEventArgs args)
|
|
{
|
|
if (args.Function == EngineKeyFunctions.UIRightClick)
|
|
{
|
|
if (Binding != null)
|
|
{
|
|
_tab._deferCommands.Add(() =>
|
|
{
|
|
_tab._inputManager.RemoveBinding(Binding);
|
|
_tab._inputManager.SaveToUserData();
|
|
});
|
|
}
|
|
|
|
args.Handle();
|
|
}
|
|
}
|
|
|
|
public void UpdateText()
|
|
{
|
|
Button.Text = Binding?.GetKeyString() ?? Loc.GetString("ui-options-unbound");
|
|
}
|
|
}
|
|
}
|
|
}
|