Skip to content

Commit 231ae22

Browse files
committed
Implement IStarMapOnUi and added instructions on how to build SimpleMod
1 parent 452851d commit 231ae22

File tree

4 files changed

+72
-52
lines changed

4 files changed

+72
-52
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ enabled = true
3232
```
3333

3434
- When now loading the game via `StarMap.exe` or `StarMapLoader.exe`, the mod should be loaded and run
35+
36+
## How to build simple example mod
37+
38+
- Add a folder on the same level as the solution folder called "Import"
39+
- Add the KSA binaries there
40+
- (Also possible to alter this location in the .csproj)
41+
- Build the project, it should output the needed files
42+
- Copy over the mod.toml. SimpleMod.dll and SimpleMod.Deps.json to KSA, this should load

StarMap.SimpleMod/Patcher.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using Brutal.GlfwApi;
2-
using Brutal.ImGuiApi;
3-
using Brutal.Numerics;
4-
using HarmonyLib;
5-
using KSA;
6-
using System.Reflection;
1+
using HarmonyLib;
72

83
namespace StarMap.SimpleExampleMod
94
{
@@ -14,6 +9,7 @@ internal static class Patcher
149

1510
public static void Patch()
1611
{
12+
Console.WriteLine("Patching SimpleMod...");
1713
_harmony?.PatchAll();
1814
}
1915

StarMap.SimpleMod/SimpleMod.cs

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,74 @@
1-
using KSA;
2-
using Brutal.ImGuiApi;
3-
using StarMap.Types;
4-
using Brutal.ImGuiApi.Extensions;
5-
using System;
6-
using Brutal.Numerics;
7-
using Brutal.GlfwApi;
1+
using Brutal.ImGuiApi;
2+
using StarMap.API;
83

94
namespace StarMap.SimpleExampleMod
105
{
11-
public class SimpleMod : IStarMapMod
6+
public class SimpleMod : IStarMapMod, IStarMapOnUi
127
{
138
public bool ImmediateUnload => false;
149

10+
public void OnAfterUi(double dt)
11+
{
12+
ImGuiWindowFlags flags = ImGuiWindowFlags.MenuBar;
13+
14+
ImGui.Begin("MyWindow", flags);
15+
if (ImGui.BeginMenuBar())
16+
{
17+
if (ImGui.BeginMenu("SimpleMod"))
18+
{
19+
if (ImGui.MenuItem("Show Message"))
20+
{
21+
Console.WriteLine("Hello from SimpleMod!");
22+
}
23+
ImGui.EndMenu();
24+
}
25+
ImGui.EndMenuBar();
26+
}
27+
ImGui.Text("Hello from SimpleMod!");
28+
ImGui.End();
29+
30+
ImGui.Begin("MyWindow", flags);
31+
if (ImGui.BeginMenuBar())
32+
{
33+
if (ImGui.BeginMenu("SimpleMod 2"))
34+
{
35+
if (ImGui.MenuItem("Show Message 2"))
36+
{
37+
Console.WriteLine("Hello from SimpleMod 2!");
38+
}
39+
ImGui.EndMenu();
40+
}
41+
ImGui.EndMenuBar();
42+
}
43+
ImGui.Text("Hello from SimpleMod 2!");
44+
ImGui.End();
45+
46+
flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.MenuBar;
47+
48+
ImGui.Begin((ImString)"Menu Bar", flags);
49+
if (ImGui.BeginMenuBar())
50+
{
51+
if (ImGui.BeginMenu((ImString)"SimpleMod 2"))
52+
{
53+
if (ImGui.MenuItem("Show Message 2"))
54+
{
55+
Console.WriteLine("Hello from SimpleMod 2!");
56+
}
57+
ImGui.EndMenu();
58+
}
59+
ImGui.EndMenuBar();
60+
}
61+
ImGui.Text("Hello from SimpleMod 2!");
62+
ImGui.End();
63+
}
64+
65+
public void OnBeforeUi(double dt)
66+
{
67+
}
68+
1569
public void OnFullyLoaded()
1670
{
1771
Patcher.Patch();
18-
SimpleWindow.Create();
1972

2073
}
2174

@@ -27,41 +80,5 @@ public void Unload()
2780
{
2881
Patcher.Unload();
2982
}
30-
internal class SimpleWindow : Popup
31-
{
32-
private float _width;
33-
private readonly IPopupWidget<SimpleWindow>[] _widgetMatrix;
34-
private readonly PopupToken[] _textList;
35-
36-
private string _text = "Hello world!";
37-
38-
public SimpleWindow()
39-
{
40-
this._widgetMatrix = new IPopupWidget<SimpleWindow>[]
41-
{
42-
Popup.PopupButtonOkay,
43-
};
44-
this._textList = StringTokenParser.Parse(this._text).ToArray();
45-
}
46-
47-
public static SimpleWindow Create() { return new SimpleWindow(); }
48-
49-
protected override void OnDrawUi()
50-
{
51-
ImGui.OpenPopup("SimpleMod", ImGuiPopupFlags.None);
52-
ImGui.BeginPopupModal("SimpleMod", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.Popup | ImGuiWindowFlags.Modal);
53-
GlfwWindow window = Program.GetWindow();
54-
int2 size = window.Size;
55-
float2 @float = Brutal.Numerics.float2.Unpack(size, Unpack.Float.Cast);
56-
this._width = float.Clamp(@float.X * 0.85f, 600f * GameSettings.GetInterfaceScale(), 2048f * GameSettings.GetInterfaceScale());
57-
float2 float2 = new float2(this._width, -1f);
58-
ImGui.SetWindowSize(float2, ImGuiCond.None);
59-
ImGuiHelper.SetCurrentWindowToCenter(ImGuiCond.Always);
60-
PopupToken.Draw(this._textList);
61-
ImGui.Separator();
62-
Popup.DrawUi<SimpleWindow>(this, this._widgetMatrix);
63-
ImGui.EndPopup();
64-
}
65-
}
6683
}
6784
}

StarMap.SimpleMod/StarMap.SimpleMod.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Lib.Harmony" Version="2.4.1" />
12-
<PackageReference Include="StarMap.API" Version="0.0.2" />
1312
</ItemGroup>
1413

1514
<ItemGroup>

0 commit comments

Comments
 (0)