Skip to content

Commit

Permalink
Added option to mass change mod settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Byte-Nova committed Dec 29, 2024
1 parent 6135fb2 commit 4660558
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Source/Client/Dialogs/RT_Dialog_1Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using RimWorld;
using UnityEngine;
using Verse;
using static GameClient.Managers.DialogManagerHelper;
using static GameClient.Managers.DialogManagerH;

namespace GameClient.Dialogs
{
Expand Down
33 changes: 27 additions & 6 deletions Source/Client/Dialogs/RT_Dialog_ListingWithTuple.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using GameClient.Managers;
using RimWorld;
using UnityEngine;
using Verse;
using static GameClient.Managers.DialogManagerHelper;
using static GameClient.Managers.DialogManagerH;

namespace GameClient.Dialogs
{
public class RT_Dialog_ListingWithTuple : Window
{
public override Vector2 InitialSize => new Vector2(400f, 400f);
public override Vector2 InitialSize => new Vector2(500f, 400f);

public readonly string title;

Expand All @@ -24,6 +25,8 @@ public class RT_Dialog_ListingWithTuple : Window

private readonly Vector2 selectButton = new Vector2(100f, 25f);

private readonly Vector2 smallButton = new Vector2(25f, 25f);

private Vector2 scrollPosition = Vector2.zero;

public string[] valueString;
Expand Down Expand Up @@ -74,6 +77,9 @@ public override void DoWindowContents(Rect rect)
FillMainRect(new Rect(0f, descriptionLineDif2 + 10f, rect.width, rect.height - defaultButtonSize.y - 85f));

Text.Font = GameFont.Small;

if (Widgets.ButtonText(GetRectForLocation(rect, smallButton, RectLocation.TopRight), "▶")) ShowFloatMenu(-1, true);

if (Widgets.ButtonText(GetRectForLocation(rect, defaultButtonSize, RectLocation.BottomCenter), "Accept"))
{
DialogManager.dialogTupleListingResultString = keys;
Expand Down Expand Up @@ -118,20 +124,35 @@ private void DrawCustomRow(Rect rect, string element, int index)
string buttonLabel = valueString[index];
if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - selectButton.x, rect.yMax - selectButton.y), selectButton), buttonLabel))
{
ShowFloatMenu(index);
ShowFloatMenu(index, false);
}
}

private void ShowFloatMenu(int index)
private void ShowFloatMenu(int index, bool globalChange)
{
List<FloatMenuOption> list = new List<FloatMenuOption>();

foreach (string str in values)
{
list.Add(new FloatMenuOption(str, delegate
Action changeSingleValue = delegate
{
valueString[index] = str;
valueInt[index] = GetValueFromString(str);
};

Action changeAllValues = delegate
{
for (int i = 0; i < valueString.Length; i++)
{
valueString[i] = str;
valueInt[i] = GetValueFromString(valueString[i]);
}
};

list.Add(new FloatMenuOption(str, delegate
{
if (globalChange) changeAllValues();
else changeSingleValue();
}));
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Managers/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void PushNewDialog(Window window)
public static void PopWaitDialog() { dialogWait?.Close(); }
}

public static class DialogManagerHelper
public static class DialogManagerH
{
public enum RectLocation { TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight }

Expand Down
46 changes: 1 addition & 45 deletions Source/Server/Commands/ServerCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ public static class ConsoleCommands
"will use UPnP to portforward the server",
PortForwardCommandAction);

public static readonly BaseServerCommand setGameSpeedCommand = new BaseServerCommand("setgamespeed", 1,
"Changes the enforced game speed for all players",
SetGameSpeedCommandAction);

public static readonly BaseServerCommand resetWorldCommand = new BaseServerCommand("resetworld", 0,
"Resets all the world related data and stores a backup of it",
ResetWorldCommandAction);
Expand All @@ -151,10 +147,6 @@ public static class ConsoleCommands
"Clears the console output",
ClearCommandAction);

public static readonly BaseServerCommand showModManagerCommand = new BaseServerCommand("showmodmanager", 1,
"Allows a player to change mod configuration for the server",
ShowModManagerCommandAction);

public static List<BaseServerCommand> commands = new List<BaseServerCommand>
{
backupCommand,
Expand All @@ -168,7 +160,6 @@ public static class ConsoleCommands
doSiteRewards,
eventAllCommand,
eventCommand,
setGameSpeedCommand,
eventListCommand,
forceQuitCommand,
forceSaveCommand,
Expand All @@ -186,8 +177,7 @@ public static class ConsoleCommands
serverMessageCommand,
whitelistAddCommand,
whitelistCommand,
whitelistRemoveCommand,
showModManagerCommand
whitelistRemoveCommand
};
}

Expand Down Expand Up @@ -371,19 +361,6 @@ public static void ModListCommandAction()
Printer.Title("----------------------------------------");
}

public static void SetGameSpeedCommandAction()
{
int desiredSpeed = int.Parse(ConsoleManager.commandParameters[0]);
if (desiredSpeed < 0 || desiredSpeed > 4) Printer.Error("Tried to set invalid game speed, specify 0-4");
else
{
Master.actionConfigs.EnforcedGameSpeed = int.Parse(ConsoleManager.commandParameters[0]);
Main_.SaveValueFile(ServerFileMode.Actions);

Printer.Warning($"Enforced game speed to '{Master.actionConfigs.EnforcedGameSpeed}'");
}
}

public static void DoSiteRewardsCommandAction()
{
Printer.Title($"Forced site rewards");
Expand Down Expand Up @@ -624,26 +601,5 @@ public static void ClearCommandAction()

Printer.Title("[Cleared console]");
}

public static void ShowModManagerCommandAction()
{
ServerClient toFind = NetworkHelper.GetConnectedClientFromUid(ConsoleManager.commandParameters[0]);
if (toFind == null) Printer.Error($"Player '{ConsoleManager.commandParameters[0]}' was not found");
else
{
if (!toFind.userFile.IsAdmin) Printer.Error($"Player '{ConsoleManager.commandParameters[0]}' needs to be an operator");
else
{
ModConfigData data = new ModConfigData();
data._stepMode = ModConfigStepMode.Ask;
data._configFile = Master.modConfig;

Packet packet = Packet.CreatePacketFromObject(nameof(ModManager), data);
toFind.listener.EnqueuePacket(packet);

Printer.Warning("Command sent sucessfully");
}
}
}
}
}

0 comments on commit 4660558

Please sign in to comment.