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
94namespace 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}
0 commit comments