Skip to content

Commit 3b25432

Browse files
committed
Added areyousure check on pressing esc (game exit)
1 parent edf2f62 commit 3b25432

File tree

9 files changed

+114
-36
lines changed

9 files changed

+114
-36
lines changed

AreYouSure/AreYouSure.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ namespace AreYouSure
1010
{
1111
class AreYouSure : MonoBehaviour
1212
{
13-
private Window window;
13+
private ReplayWindow replayWindow;
14+
private ExitWindow exitWindow;
1415
public void Start() {
15-
window = this.gameObject.AddComponent<Window>();
16-
ReplayState_OnUpdate_Patch.window = window;
16+
replayWindow = this.gameObject.AddComponent<ReplayWindow>();
17+
ReplayState_OnUpdate_Patch.window = replayWindow;
18+
19+
exitWindow = this.gameObject.AddComponent<ExitWindow>();
20+
GameStateMachine_Update_Patch.window = exitWindow;
1721
}
1822
}
1923
}

AreYouSure/AreYouSure.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@
6363
</ItemGroup>
6464
<ItemGroup>
6565
<Compile Include="AreYouSure.cs" />
66+
<Compile Include="ReplayWindow.cs" />
6667
<Compile Include="Logger.cs" />
6768
<Compile Include="Main.cs" />
69+
<Compile Include="Patches\GameStateMachine.cs" />
6870
<Compile Include="Properties\AssemblyInfo.cs" />
69-
<Compile Include="Patches\ReplayStatePatches.cs" />
71+
<Compile Include="Patches\ReplayState.cs" />
72+
<Compile Include="ExitWindow.cs" />
7073
<Compile Include="Window.cs" />
7174
</ItemGroup>
7275
<ItemGroup>

AreYouSure/ExitWindow.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using AreYouSure.Patches;
2+
using GameManagement;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using UnityEngine;
7+
using XLShredLib;
8+
9+
namespace AreYouSure
10+
{
11+
public class ExitWindow : Window
12+
{
13+
14+
protected override void RenderWindow(int windowID) {
15+
if (Event.current.type == EventType.Repaint) windowRect.height = 0;
16+
17+
GUI.DragWindow(new Rect(0, 0, 10000, 20));
18+
19+
GUILayout.Label("ARE YOU SURE YOU WANT TO EXIT THE GAME?", labelStyle);
20+
GUILayout.BeginHorizontal();
21+
if (GUILayout.Button("Yes, Exit")) {
22+
Close();
23+
Application.Quit();
24+
}
25+
if (GUILayout.Button("No, Stay HERE")) {
26+
Close();
27+
}
28+
GUILayout.EndHorizontal();
29+
}
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using GameManagement;
2+
using Harmony12;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using UnityEngine;
9+
10+
namespace AreYouSure.Patches
11+
{
12+
[HarmonyPatch(typeof(GameStateMachine), "Update")]
13+
static class GameStateMachine_Update_Patch
14+
{
15+
public static ExitWindow window;
16+
static bool Prefix(GameStateMachine __instance) {
17+
__instance.CurrentState.OnUpdate();
18+
if (Input.GetKeyDown(KeyCode.Escape)) {
19+
window.Open();
20+
}
21+
return false;
22+
}
23+
}
24+
}

AreYouSure/Patches/ReplayStatePatches.cs renamed to AreYouSure/Patches/ReplayState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace AreYouSure.Patches
1515
static class ReplayState_OnUpdate_Patch
1616
{
1717
public static Traverse replayStateTraverse;
18-
public static Window window;
18+
public static ReplayWindow window;
1919
static bool Prefix(ReplayState __instance) {
2020
if (replayStateTraverse == null) {
2121
replayStateTraverse = Traverse.Create(__instance);

AreYouSure/ReplayWindow.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using AreYouSure.Patches;
2+
using GameManagement;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using UnityEngine;
7+
using XLShredLib;
8+
9+
namespace AreYouSure
10+
{
11+
public class ReplayWindow : Window
12+
{
13+
14+
protected override void RenderWindow(int windowID) {
15+
if (Event.current.type == EventType.Repaint) windowRect.height = 0;
16+
17+
GUI.DragWindow(new Rect(0, 0, 10000, 20));
18+
19+
GUILayout.Label("ARE YOU SURE YOU WANT TO EXIT REPLAY EDITOR?", labelStyle);
20+
GUILayout.BeginHorizontal();
21+
if (GUILayout.Button("Yes, Exit")) {
22+
Close();
23+
var traverse = ReplayState_OnUpdate_Patch.replayStateTraverse;
24+
var requestTransitionTo = traverse.Method("RequestTransitionTo", new Type[] { typeof(Type) });
25+
requestTransitionTo.GetValue(typeof(PauseState));
26+
}
27+
if (GUILayout.Button("No, Stay HERE")) {
28+
Close();
29+
}
30+
GUILayout.EndHorizontal();
31+
}
32+
}
33+
}

AreYouSure/Resources/Info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Id": "AreYouSure",
33
"DisplayName": "AreYouSure",
44
"Author": "Babbo Elu",
5-
"Version": "0.0.1",
5+
"Version": "0.0.2",
66
"ManagerVersion": "0.15.0",
77
"Requirements": [ "blendermf.XLShredMenu-0.0.5" ],
88
"AssemblyName": "AreYouSure.dll",

AreYouSure/Window.cs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88

99
namespace AreYouSure
1010
{
11-
public class Window : MonoBehaviour
11+
public abstract class Window : MonoBehaviour
1212
{
1313

1414
#region GUI style
15-
private Rect windowRect = new Rect(Screen.width / 2 - 200f, 200f, 600f, 0f);
16-
private GUIStyle windowStyle;
17-
private GUIStyle labelStyle;
18-
private readonly Color windowColor = new Color(0.8f, 0.8f, 0.8f);
15+
protected Rect windowRect = new Rect(Screen.width / 2 - 200f, 200f, 600f, 0f);
16+
protected GUIStyle windowStyle;
17+
protected GUIStyle labelStyle;
18+
protected readonly Color windowColor = new Color(0.8f, 0.8f, 0.8f);
1919
#endregion
2020

2121
#region GUI status
22-
private bool showUI = false;
23-
private GameObject master;
24-
private bool setUp;
22+
protected bool showUI = false;
23+
protected GameObject master;
24+
protected bool setUp;
2525
#endregion
2626

27-
private void SetUp() {
27+
protected void SetUp() {
2828
if (master == null) {
2929
master = GameObject.Find("New Master Prefab");
3030
if (master != null) {
@@ -46,7 +46,7 @@ public void Open() {
4646
ModMenu.Instance.ShowCursor(Main.modId);
4747
}
4848

49-
private void Close() {
49+
protected void Close() {
5050
showUI = false;
5151
ModMenu.Instance.HideCursor(Main.modId);
5252
}
@@ -64,23 +64,6 @@ public void OnGUI() {
6464
}
6565
}
6666

67-
void RenderWindow(int windowID) {
68-
if (Event.current.type == EventType.Repaint) windowRect.height = 0;
69-
70-
GUI.DragWindow(new Rect(0, 0, 10000, 20));
71-
72-
GUILayout.Label("ARE YOU SURE YOU WANT TO EXIT REPLAY EDITOR?", labelStyle);
73-
GUILayout.BeginHorizontal();
74-
if (GUILayout.Button("Yes, Exit")) {
75-
Close();
76-
var traverse = ReplayState_OnUpdate_Patch.replayStateTraverse;
77-
var requestTransitionTo = traverse.Method("RequestTransitionTo", new Type[] { typeof(Type) });
78-
requestTransitionTo.GetValue(typeof(PauseState));
79-
}
80-
if (GUILayout.Button("No, Stay HERE")) {
81-
Close();
82-
}
83-
GUILayout.EndHorizontal();
84-
}
67+
protected abstract void RenderWindow(int windowID);
8568
}
8669
}

repository.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
},
88
{
99
"Id": "AreYouSure",
10-
"Version": "0.0.1",
11-
"DownloadUrl": "https://github.com/andreamatt/Skater-XL-mods/releases/download/AreYouSure_v0.0.1/AreYouSure-0.0.1.zip"
10+
"Version": "0.0.2",
11+
"DownloadUrl": "https://github.com/andreamatt/Skater-XL-mods/releases/download/AreYouSure_v0.0.2/AreYouSure-0.0.2.zip"
1212
}
1313
]
1414
}

0 commit comments

Comments
 (0)