Skip to content

Commit

Permalink
1.5.1 (#17)
Browse files Browse the repository at this point in the history
- Using character profiles for build cockpit

This is to prevent players from thinking they lost all of their
character profiles while trying to use the cockpit build mode (Ctrl-G).

This feature is enabled by default, but will not be in effect if there
is any profiles aready defined for the build cockpit.

To merge your build cockpit profiles into your character profiles open
the `%AppData%\SpaceEngineers\ToolbarManager` directory in `Explorer`
and move all files from the `BuildCockpit` to the `Character` folder.
  • Loading branch information
viktor-ferenczi authored May 1, 2024
1 parent d71054e commit 82829e3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 22 deletions.
6 changes: 6 additions & 0 deletions ToolbarManager/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ namespace ToolbarManager
{
public class PluginConfig
{
// Building from cockpit (Ctrl-G) uses the character profiles
public bool UseCharacterProfilesForBuildCockpit = true;

// Keep the search text between subsequent uses of the Profile dialog
public bool KeepProfileSearchText = false;
public string LatestProfileSearchText = "";

// Keep the search text between subsequent uses of the block search
public bool KeepBlockSearchText = false;
public string LatestBlockSearchText = "";

// Key to start block search
public MyKeys BlockSearchKey = MyKeys.OemPipe;
}

Expand Down
41 changes: 28 additions & 13 deletions ToolbarManager/Gui/PluginConfigDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ public class PluginConfigDialog : MyGuiScreenBase

private MyLayoutTable layoutTable;

private MyGuiControlLabel keepBlockSearchTextLabel;
private MyGuiControlCheckbox keepBlockSearchTextCheckbox;
private MyGuiControlLabel mapBuildCockpitToCharacterLabel;
private MyGuiControlCheckbox mapBuildCockpitToCharacterCheckbox;

private MyGuiControlLabel keepProfileSearchTextLabel;
private MyGuiControlCheckbox keepProfileSearchTextCheckbox;

private MyGuiControlLabel keepBlockSearchTextLabel;
private MyGuiControlCheckbox keepBlockSearchTextCheckbox;

private MyControl blockSearchKeyControl;
private MyGuiControlLabel blockSearchKeyLabel;
private MyGuiControlButton blockSearchKeyButton;

private MyGuiControlButton closeButton;

public PluginConfigDialog() : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, new Vector2(0.5f, 0.5f), false, null, MySandboxGame.Config.UIBkOpacity, MySandboxGame.Config.UIOpacity)
public PluginConfigDialog() : base(new Vector2(0.5f, 0.6f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, new Vector2(0.5f, 0.5f), false, null, MySandboxGame.Config.UIBkOpacity, MySandboxGame.Config.UIOpacity)
{
EnabledBackgroundFade = true;
m_closeOnEsc = true;
Expand Down Expand Up @@ -59,6 +62,14 @@ private void CreateControls()
{
AddCaption(Caption);

CreateCheckbox(
out mapBuildCockpitToCharacterLabel,
out mapBuildCockpitToCharacterCheckbox,
Config.Data.UseCharacterProfilesForBuildCockpit,
value => { Config.Data.UseCharacterProfilesForBuildCockpit = value; },
"Use character profiles for build cockpit",
"Building from cockpit (Ctrl-G) uses the character profiles.");

CreateCheckbox(
out keepProfileSearchTextLabel,
out keepProfileSearchTextCheckbox,
Expand Down Expand Up @@ -159,13 +170,13 @@ private void CreateCheckbox(out MyGuiControlLabel labelControl, out MyGuiControl
labelControl = new MyGuiControlLabel
{
Text = label,
OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP,
OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
Enabled = enabled,
};

checkboxControl = new MyGuiControlCheckbox(toolTip: tooltip)
{
OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP,
OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER,
IsChecked = value,
Enabled = enabled,
CanHaveFocus = enabled
Expand All @@ -182,22 +193,26 @@ private void CreateCheckbox(out MyGuiControlLabel labelControl, out MyGuiControl

private void LayoutControls()
{
layoutTable = new MyLayoutTable(this, new Vector2(-0.2f, -0.25f), new Vector2(0.20f, 0.25f));
layoutTable = new MyLayoutTable(this, new Vector2(-0.2f, -0.3f), new Vector2(0.20f, 0.3f));
layoutTable.SetColumnWidths(500f, 500f);
layoutTable.SetRowHeights(150f, 90f, 90f, 90f, 90f, 180f);
layoutTable.SetRowHeights(180f, 90f, 90f, 90f, 90f, 90f, 180f);

var row = 1;

layoutTable.Add(keepProfileSearchTextLabel, MyAlignH.Left, MyAlignV.Top, row, 0);
layoutTable.Add(keepProfileSearchTextCheckbox, MyAlignH.Left, MyAlignV.Top, row, 1);
layoutTable.Add(mapBuildCockpitToCharacterLabel, MyAlignH.Left, MyAlignV.Center, row, 0);
layoutTable.Add(mapBuildCockpitToCharacterCheckbox, MyAlignH.Left, MyAlignV.Center, row, 1);
row++;

layoutTable.Add(keepProfileSearchTextLabel, MyAlignH.Left, MyAlignV.Center, row, 0);
layoutTable.Add(keepProfileSearchTextCheckbox, MyAlignH.Left, MyAlignV.Center, row, 1);
row++;

layoutTable.Add(keepBlockSearchTextLabel, MyAlignH.Left, MyAlignV.Top, row, 0);
layoutTable.Add(keepBlockSearchTextCheckbox, MyAlignH.Left, MyAlignV.Top, row, 1);
layoutTable.Add(keepBlockSearchTextLabel, MyAlignH.Left, MyAlignV.Center, row, 0);
layoutTable.Add(keepBlockSearchTextCheckbox, MyAlignH.Left, MyAlignV.Center, row, 1);
row++;

layoutTable.Add(blockSearchKeyLabel, MyAlignH.Left, MyAlignV.Top, row, 0);
layoutTable.Add(blockSearchKeyButton, MyAlignH.Left, MyAlignV.Top, row, 1);
layoutTable.Add(blockSearchKeyLabel, MyAlignH.Left, MyAlignV.Center, row, 0);
layoutTable.Add(blockSearchKeyButton, MyAlignH.Left, MyAlignV.Center, row, 1);
row++;

layoutTable.Add(closeButton, MyAlignH.Center, MyAlignV.Center, row, 0, colSpan: 2);
Expand Down
23 changes: 22 additions & 1 deletion ToolbarManager/Logic/ProfileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using LitJson;
using Sandbox.Game.Screens.Helpers;
using ToolbarManager.Extensions;
using VRage.FileSystem;
using VRage.Game;
using VRage.Utils;

namespace ToolbarManager.Logic
Expand All @@ -24,7 +26,26 @@ public ProfileStorage(MyToolbar currentToolbar)
{
this.currentToolbar = currentToolbar;

profileDir = Path.Combine(PluginDataDir, currentToolbar.ToolbarType.ToString());
var toolbarType = currentToolbar.ToolbarType;
profileDir = Path.Combine(PluginDataDir, toolbarType.ToString());

// If there are no BuildCockpit profiles defined, then use the Character profile folder instead.
// This is to prevent players from thinking they lost all of their character profiles while trying
// to use the build cockpit mode (Ctrl-G).
if (Config.Data.UseCharacterProfilesForBuildCockpit &&
toolbarType == MyToolbarType.BuildCockpit)
{
var hasAnyProfiles = Directory.Exists(profileDir) &&
Directory.EnumerateFiles(profileDir)
.Any(path => path.EndsWith(".xml") || path.EndsWith(".json"));

if (!hasAnyProfiles && Config.Data.UseCharacterProfilesForBuildCockpit)
{
toolbarType = MyToolbarType.Character;
profileDir = Path.Combine(PluginDataDir, toolbarType.ToString());
}
}

Directory.CreateDirectory(profileDir);

backupDir = Path.Combine(profileDir, "Backup");
Expand Down
24 changes: 18 additions & 6 deletions ToolbarManager/Patches/MyGuiScreenGamePlayPatch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Diagnostics.CodeAnalysis;
using HarmonyLib;
using Sandbox.Game.Entities.Character;
using Sandbox.Game.Gui;
using Sandbox.Game.Screens.Helpers;
using Sandbox.Game.World;
using Sandbox.Graphics.GUI;
using ToolbarManager.Gui;
using VRage.Game;
using VRage.Input;

namespace ToolbarManager.Patches
Expand All @@ -18,17 +21,26 @@ public static class MyGuiScreenGamePlayPatch
[HarmonyPatch(nameof(MyGuiScreenGamePlay.HandleUnhandledInput))]
public static bool HandleUnhandledInputPrefix()
{
if (MyGuiScreenGamePlay.ActiveGameplayScreen != null || !(MySession.Static.ControlledEntity is MyCharacter))
var myInput = MyInput.Static;
if (!myInput.IsNewKeyPressed(Config.Data.BlockSearchKey))
return true;

var myInput = MyInput.Static;
if (myInput.IsNewKeyPressed(Config.Data.BlockSearchKey))
if (MyGuiScreenGamePlay.ActiveGameplayScreen != null)
return true;

var toolbarType = MyToolbarComponent.CurrentToolbar?.ToolbarType;
switch (toolbarType)
{
OpenCubeBuilder();
return false;
case MyToolbarType.Character:
case MyToolbarType.BuildCockpit:
break;
default:
return true;
}

return true;
OpenCubeBuilder();
return false;

}

private static void OpenCubeBuilder()
Expand Down
4 changes: 2 additions & 2 deletions ToolbarManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyVersion("1.5.1.0")]
[assembly: AssemblyFileVersion("1.5.1.0")]

0 comments on commit 82829e3

Please sign in to comment.