Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 43b7182

Browse files
committed
Add mods menu
1 parent 72f22f4 commit 43b7182

6 files changed

Lines changed: 230 additions & 19 deletions

File tree

ModLoader/Loader.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
using UnityEngine.Events;
1010
using System.IO;
1111
using System.Text.RegularExpressions;
12+
using SFS.UI;
13+
using SFS.Input;
14+
using SFS.Adapter;
15+
using SFS.Translations;
16+
using ModLoader.UI;
1217

1318
namespace ModLoader
1419
{
@@ -83,6 +88,28 @@ private void Start()
8388
}
8489

8590
Debug.Log("Loading finished");
91+
this.postInit();
92+
}
93+
94+
private void postInit()
95+
{
96+
GameObject modsButton = GameObject.Instantiate(GameObject.Find("Exit Button"));
97+
ButtonPC buttonPC = modsButton.GetComponent<ButtonPC>();
98+
TextAdapter textAdapter = modsButton.GetComponentInChildren<TextAdapter>();
99+
Destroy(modsButton.GetComponent<TranslationSelector>());
100+
modsButton.name = "Mods Button";
101+
textAdapter.Text = "MODS";// add text button
102+
103+
//click events
104+
buttonPC.holdEvent = new HoldUnityEvent();
105+
buttonPC.clickEvent = new ClickUnityEvent();
106+
buttonPC.clickEvent.AddListener(delegate (OnInputEndData data) {
107+
ModsMenu.Main.Open();
108+
});
109+
110+
// screen position
111+
modsButton.transform.SetParent(GameObject.Find("Buttons").transform);
112+
buttonPC.transform.localScale = new Vector3(1,1,1);
86113
}
87114

88115
/// <summary>

ModLoader/ModLoader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@
103103
<Compile Include="IO\ConsoleGUI.cs" />
104104
<Compile Include="Helper.cs" />
105105
<Compile Include="Loader.cs" />
106-
<Compile Include="ModsMenu.cs" />
106+
<Compile Include="UI\ModsMenu.cs" />
107107
<Compile Include="Patcher.cs" />
108108
<Compile Include="Properties\AssemblyInfo.cs" />
109109
<Compile Include="SFSMod.cs" />
110+
<Compile Include="UI\ModsMenuGUI.cs" />
110111
</ItemGroup>
111112
<ItemGroup>
112113
<None Include="packages.config" />

ModLoader/ModsMenu.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

ModLoader/Patcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine;
44
using ModLoader.IO;
55
using SFS.Input;
6+
using ModLoader.UI;
67

78
namespace ModLoader
89
{
@@ -24,7 +25,7 @@ public static void Postfix(BaseAssigner __instance)
2425
modConsole.SetActive(true);
2526
loader.AddComponent<Loader>();
2627
modConsole.AddComponent<Helper>();
27-
//modConsole.AddComponent<ModsMenu>();
28+
modConsole.AddComponent<ModsMenu>();
2829

2930
UnityEngine.Object.DontDestroyOnLoad(modConsole);
3031
UnityEngine.Object.DontDestroyOnLoad(loader);

ModLoader/UI/ModsMenu.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+

2+
3+
using SFS.Input;
4+
using SFS.UI;
5+
using System.Collections.Generic;
6+
using UnityEngine;
7+
8+
namespace ModLoader.UI
9+
{
10+
/// <summary>
11+
/// This class is not used at the moment, because it is better to use it to display mod information and not UI for
12+
/// all mod interactions. Is necesary rework
13+
/// </summary>
14+
public class ModsMenu : BasicMenu
15+
{
16+
public static ModsMenu Main;
17+
18+
private void Awake()
19+
{
20+
Main = this;
21+
base.menuHolder = new GameObject();
22+
base.menuHolder.SetActive(false);
23+
base.menuHolder.AddComponent<ModsMenuGUI>();
24+
}
25+
26+
27+
/*public void OpenMenu()
28+
{
29+
List<MenuElement> list = new List<MenuElement>();
30+
list.Add(TextBuilder.CreateText().Text(() => "Mods Installed"));
31+
32+
SizeSyncerBuilder.Carrier sizeSync;
33+
list.Add(new SizeSyncerBuilder(out sizeSync).VerticalMode(SizeMode.MaxChildSize));
34+
35+
36+
foreach (SFSMod mod in Loader.main.getMods())
37+
{
38+
foreach (SFSMod mod2 in Loader.main.getMods())
39+
{
40+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod2.Name} {mod2.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
41+
}
42+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod.Name} {mod.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
43+
}
44+
45+
foreach (SFSMod mod in Loader.main.getMods())
46+
{
47+
foreach (SFSMod mod2 in Loader.main.getMods())
48+
{
49+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod2.Name} {mod2.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
50+
}
51+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod.Name} {mod.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
52+
}
53+
54+
foreach (SFSMod mod in Loader.main.getMods())
55+
{
56+
foreach (SFSMod mod2 in Loader.main.getMods())
57+
{
58+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod2.Name} {mod2.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
59+
}
60+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod.Name} {mod.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
61+
}
62+
63+
foreach (SFSMod mod in Loader.main.getMods())
64+
{
65+
foreach (SFSMod mod2 in Loader.main.getMods())
66+
{
67+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod2.Name} {mod2.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
68+
}
69+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod.Name} {mod.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
70+
}
71+
foreach (SFSMod mod in Loader.main.getMods())
72+
{
73+
foreach (SFSMod mod2 in Loader.main.getMods())
74+
{
75+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod2.Name} {mod2.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
76+
}
77+
list.Add(ButtonBuilder.CreateButton(sizeSync, () => $"{mod.Name} {mod.Version}", () => { Debug.Log("Open COnfig"); }, CloseMode.None));
78+
}
79+
MenuGenerator.OpenMenu(CancelButton.Close, CloseMode.Current, list.ToArray());
80+
}*/
81+
82+
}
83+
84+
85+
86+
}

ModLoader/UI/ModsMenuGUI.cs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+

2+
using SFS.Translations;
3+
using UnityEngine;
4+
5+
namespace ModLoader.UI
6+
{
7+
class ModsMenuGUI : MonoBehaviour
8+
{
9+
10+
private Vector2 _scroll;
11+
12+
private GUIStyle _windowStyle;
13+
private GUIStyle _modInformationStyle;
14+
private GUIStyle _titleStyle;
15+
private GUIStyle _modInformationTextStyle;
16+
17+
private Rect _windowsPosition;
18+
private const float _margin = 0.2f;
19+
20+
private void Awake()
21+
{
22+
this._scroll = Vector2.zero;
23+
24+
this._windowStyle = new GUIStyle();
25+
this._modInformationStyle = new GUIStyle();
26+
this._titleStyle = new GUIStyle();
27+
this._modInformationTextStyle = new GUIStyle();
28+
29+
}
30+
31+
private void Start()
32+
{
33+
this._windowStyle.normal.background = this.makeTexture(new Color32(14, 17,27,230));
34+
35+
this._modInformationStyle.normal.background = this.makeTexture(new Color32(27, 32, 50, 240));
36+
this._modInformationStyle.padding = new RectOffset(10,10,10,10);
37+
this._modInformationStyle.margin.top = 10;
38+
39+
this._modInformationTextStyle.fontSize = 20;
40+
this._modInformationTextStyle.normal.textColor = Color.white;
41+
42+
this._titleStyle.fontSize = 30;
43+
this._titleStyle.fontStyle = FontStyle.Bold;
44+
this._titleStyle.normal.textColor = Color.white;
45+
this._titleStyle.alignment = TextAnchor.MiddleCenter;
46+
47+
}
48+
49+
/// <sumary>
50+
/// Create solid color texture
51+
///</sumary>
52+
private Texture2D makeTexture(Color col)
53+
{
54+
Color[] pix = new Color[1];
55+
for (int i = 0; i < pix.Length; ++i)
56+
{
57+
pix[i] = col;
58+
}
59+
Texture2D result = new Texture2D(1, 1);
60+
result.SetPixels(pix);
61+
result.Apply();
62+
return result;
63+
}
64+
65+
private void OnEnable()
66+
{
67+
68+
float windowsHeigth = Screen.height * (1 - _margin - _margin);
69+
float windowsWidth = Screen.width * (1 - _margin - _margin);
70+
float windowsX = Screen.width * _margin;
71+
float windowsY = Screen.height * _margin;
72+
73+
this._windowsPosition = new Rect(windowsX, windowsY, windowsWidth,windowsHeigth);
74+
}
75+
76+
77+
private void OnGUI()
78+
{
79+
GUI.BeginGroup(this._windowsPosition, this._windowStyle);
80+
GUILayout.Label("Installed Mods",this._titleStyle);
81+
this._scroll = GUILayout.BeginScrollView(this._scroll, GUILayout.Width(this._windowsPosition.width),GUILayout.Height(this._windowsPosition.height - 70));
82+
83+
foreach(SFSMod mod in Loader.main.getMods())
84+
{
85+
this.modInformation(mod);
86+
}
87+
88+
GUILayout.EndScrollView();
89+
bool click = GUILayout.Button(Loc.main.Close);
90+
GUI.EndGroup();
91+
if (click)
92+
{
93+
ModsMenu.Main.Close();
94+
ModsMenu.Main.OnClose();
95+
}
96+
}
97+
98+
public void modInformation(SFSMod mod)
99+
{
100+
101+
GUILayout.BeginVertical(this._modInformationStyle,GUILayout.Width(this._windowsPosition.width-20));
102+
103+
GUILayout.BeginHorizontal();
104+
GUILayout.Label($"Mod: {mod.Name}",this._modInformationTextStyle);
105+
GUILayout.Label($"Version: {mod.Version}", this._modInformationTextStyle);
106+
GUILayout.Label($"Author: {mod.Author}", this._modInformationTextStyle);
107+
GUILayout.EndHorizontal();
108+
GUILayout.Label($"Description:\n{mod.Description}", this._modInformationTextStyle);
109+
//bool click = GUILayout.Button("Config");
110+
GUILayout.EndVertical();
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)