-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added restart prompt to Mods dialog - Added automatic restart setting - Mod load order changes are now detected and will also prompt for a restart - Added "Files" menu to log window: open log file, browse save and mods directories - Added hotkeys for opening the log file and restarting the game (define to use) - "already detoured" error will now properly report on the existing destination - Fixed ModSettingsPack mod name accessibility
- Loading branch information
UnlimitedHugs
committed
Jan 31, 2017
1 parent
bec28c6
commit 517165d
Showing
21 changed files
with
357 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<VersionData> | ||
<overrideVersion>2.3.3</overrideVersion> | ||
<overrideVersion>2.4.0</overrideVersion> | ||
<gitHubRepository>UnlimitedHugs/RimworldHugsLib</gitHubRepository> | ||
</VersionData> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using HugsLib.Restarter; | ||
using HugsLib.Shell; | ||
using HugsLib.Utils; | ||
using UnityEngine; | ||
|
||
namespace HugsLib.Core { | ||
/** | ||
* Handles the key presses for key bindings added by HugsLib | ||
*/ | ||
internal static class KeyBindingHandler { | ||
public static void OnGUI() { | ||
if (Event.current.type != EventType.KeyDown) return; | ||
if (HugsLibKeyBingings.PublishLogs.JustPressed && HugsLibUtility.ControlIsHeld) { | ||
HugsLibController.Instance.LogUploader.ShowPublishPrompt(); | ||
} | ||
if (HugsLibKeyBingings.OpenLogFile.JustPressed) { | ||
ShellOpenLog.Execute(); | ||
} | ||
if (HugsLibKeyBingings.RestartRimworld.JustPressed) { | ||
AutoRestarter.PerformRestart(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using HugsLib.GuiInject; | ||
using HugsLib.Settings; | ||
using HugsLib.Shell; | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace HugsLib.Restarter { | ||
/** | ||
* Makes the the Close button in the Mods dialog prompt the player to restart the game if the mod configuration has changed. | ||
* Will restart the game automatically if the autoRestart setting is active. | ||
* Unlike in vanilla, changes in mod order are also detected and will require a restart. | ||
*/ | ||
internal class AutoRestarter { | ||
private static readonly Vector2 CloseButSize = new Vector2(120f, 40f); | ||
|
||
private static int lastSeenWindowHash; | ||
private static int lastModListHash; | ||
|
||
public SettingHandle<bool> AutoRestartSetting { get; private set; } | ||
|
||
public static void PerformRestart() { | ||
LongEventHandler.QueueLongEvent(() => { | ||
ShellRestartRimWorld.Execute(); | ||
}, "HugsLib_restart_restarting", true, null); | ||
} | ||
|
||
[WindowInjection(typeof (Page_ModsConfig), Mode = WindowInjectionManager.InjectMode.AfterContents)] | ||
private static void DrawLogWindowButtons(Window window, Rect inRect) { | ||
// update mod list hash | ||
if (window.GetHashCode() != lastSeenWindowHash) { | ||
lastSeenWindowHash = window.GetHashCode(); | ||
lastModListHash = GetModListHash(); | ||
} | ||
// replace close button, handle keys | ||
Text.Font = GameFont.Small; | ||
window.doCloseButton = false; | ||
window.closeOnEscapeKey = false; | ||
var closeBtnRect = new Rect(inRect.width / 2f - CloseButSize.x / 2f, inRect.height - CloseButSize.y, CloseButSize.x, CloseButSize.y); | ||
var keyUsed = Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.Escape); | ||
if (Widgets.ButtonText(closeBtnRect, "CloseButton".Translate()) || keyUsed) { | ||
CloseAction(window); | ||
if(keyUsed) Event.current.Use(); | ||
} | ||
} | ||
|
||
// TODO: on update, verify that this still does the same thing as Page_ModsConfig.PostClose | ||
private static void CloseAction(Window window) { | ||
ModsConfig.Save(); | ||
if (lastModListHash != GetModListHash()) { | ||
if (HugsLibController.Instance.AutoRestarter.AutoRestartSetting) { | ||
PerformRestart(); | ||
} else { | ||
Find.WindowStack.Add(new Dialog_RestartGame()); | ||
} | ||
} else { | ||
window.Close(); | ||
} | ||
} | ||
|
||
// an alternative way to detect changes to the mod list that takes mod order into account | ||
private static int GetModListHash() { | ||
int hash = 42; | ||
foreach (var modMetaData in ModsConfig.ActiveModsInLoadOrder) { | ||
if (modMetaData.enabled){ | ||
unchecked { | ||
hash <<= 1; | ||
hash += hash + modMetaData.GetHashCode(); | ||
} | ||
} | ||
} | ||
return hash; | ||
|
||
} | ||
|
||
public void CreateSettingsHandles(ModSettingsPack pack) { | ||
AutoRestartSetting = pack.GetHandle("autoRestart", "HugsLib_setting_autoRestart_label".Translate(), "HugsLib_setting_autoRestart_desc".Translate(), false); | ||
} | ||
} | ||
} |
Oops, something went wrong.