|
| 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; |
| 8 | + |
| 9 | +namespace StarMap.SimpleExampleMod |
| 10 | +{ |
| 11 | + public class SimpleMod : IStarMapMod |
| 12 | + { |
| 13 | + public bool ImmediateUnload => false; |
| 14 | + |
| 15 | + public void OnFullyLoaded() |
| 16 | + { |
| 17 | + Patcher.Patch(); |
| 18 | + SimpleWindow.Create(); |
| 19 | + |
| 20 | + } |
| 21 | + |
| 22 | + public void OnImmediatLoad() |
| 23 | + { |
| 24 | + } |
| 25 | + |
| 26 | + public void Unload() |
| 27 | + { |
| 28 | + Patcher.Unload(); |
| 29 | + } |
| 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 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments