Skip to content

Commit

Permalink
Refactor commands to fit new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Jul 24, 2024
1 parent f624f3d commit 446640e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 150 deletions.
2 changes: 0 additions & 2 deletions HKMP/Game/Client/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ ModSettings modSettings
/// Register the default client commands.
/// </summary>
private void RegisterCommands() {
_commandManager.RegisterCommand(new ConnectCommand(this));
_commandManager.RegisterCommand(new HostCommand(_serverManager));
_commandManager.RegisterCommand(new AddonCommand(_addonManager, _netClient));
}

Expand Down
30 changes: 18 additions & 12 deletions HKMP/Game/Command/Client/AddonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ public void Execute(string[] arguments) {
var action = arguments[1];

if (action == "list") {
var message = "Loaded addons: ";
message += string.Join(
", ",
_addonManager.GetLoadedAddons().Select(addon => {
var msg = $"{addon.GetName()} {addon.GetVersion()}";
if (addon is TogglableClientAddon {Disabled: true }) {
msg += " (disabled)";
}

return msg;
})
);
string message;
var addons = _addonManager.GetLoadedAddons();
if (addons.Count == 0) {
message = "No addons loaded.";
} else {
message = "Loaded addons: ";
message += string.Join(
", ",
addons.Select(addon => {
var msg = $"{addon.GetName()} {addon.GetVersion()}";
if (addon is TogglableClientAddon { Disabled: true }) {
msg += " (disabled)";
}

return msg;
})
);
}

UiManager.InternalChatBox.AddMessage(message);
return;
Expand Down
61 changes: 0 additions & 61 deletions HKMP/Game/Command/Client/ConnectCommand.cs

This file was deleted.

64 changes: 0 additions & 64 deletions HKMP/Game/Command/Client/HostCommand.cs

This file was deleted.

46 changes: 35 additions & 11 deletions HKMP/Ui/Chat/ChatBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Hkmp.Ui.Resources;
using Hkmp.Util;
using UnityEngine;
using Logger = Hkmp.Logging.Logger;
using Object = UnityEngine.Object;

namespace Hkmp.Ui.Chat;
Expand Down Expand Up @@ -171,19 +172,42 @@ private void CheckKeyBinds(ModSettings modSettings) {
}
} else if (Input.GetKeyDown(modSettings.OpenChatKey)) {
var gameManager = GameManager.instance;
if (gameManager == null) {
Logger.Debug("Could not open chat, GM is null");
return;
}

var gameState = gameManager.gameState;
if (gameState != GameState.PLAYING && gameState != GameState.MAIN_MENU) {
Logger.Debug($"Could not open chat, game state is incorrect: {gameState}");
return;
}

var uiManager = UIManager.instance;
if (uiManager == null) {
Logger.Debug("Could not open chat, UIM is null");
return;
}

var uiState = uiManager.uiState;
if (uiState != UIState.PLAYING && uiState != UIState.MAIN_MENU_HOME) {
Logger.Debug($"Could not open chat, UI state is incorrect: {uiState}");
return;
}

var heroController = HeroController.instance;
if (gameManager == null
|| uiManager == null
|| gameManager.gameState != GameState.PLAYING
|| uiManager.uiState != UIState.PLAYING
// If the hero is charging their nail and chat opens, it will cause a flashing effect
|| (heroController != null && heroController.cState.nailCharging)
// If we are in the inventory, opening the chat has side-effects, such as floating
|| IsInventoryOpen()
// If we are in a godhome menu, we will soft-lock opening the chat
|| IsGodHomeMenuOpen()
) {
if (heroController != null && heroController.cState.nailCharging) {
Logger.Debug("Could not open chat, player is charging nail");
return;
}

if (gameState == GameState.PLAYING && IsInventoryOpen()) {
Logger.Debug("Could not open chat, inventory is open");
return;
}

if (IsGodHomeMenuOpen()) {
Logger.Debug("Could not open chat, GodHome menu is open");
return;
}

Expand Down

0 comments on commit 446640e

Please sign in to comment.