2024-11-15 19:06:44 +03:00
using System.Numerics ;
2025-10-05 18:17:18 +03:00
using System.Text ;
2024-11-15 19:06:44 +03:00
using ImGuiNET ;
using Microsoft.Extensions.DependencyInjection ;
using NResUI.Abstractions ;
using NResUI.Models ;
using Silk.NET.Input ;
using Silk.NET.OpenGL ;
using Silk.NET.Windowing ;
namespace NResUI ;
public class App
{
2026-05-09 20:36:43 +03:00
public GL GL { get ; set ; } = null !;
public IInputContext Input { get ; set ; } = null !;
2024-11-15 19:06:44 +03:00
2026-05-09 20:36:43 +03:00
public static App Instance = null !;
2024-11-15 19:06:44 +03:00
private static bool _dockspaceOpen = true ;
private static bool _optFullscreenPersistant = true ;
private static bool _optFullscreen = _optFullscreenPersistant ;
private static ImGuiDockNodeFlags _dockspaceFlags = ImGuiDockNodeFlags . None ;
public ImFontPtr OpenSansFont ;
2026-05-09 20:36:43 +03:00
private List < IImGuiPanel > _imGuiPanels = [];
2026-06-07 00:41:16 +03:00
private Later _later = new ();
2024-11-15 19:06:44 +03:00
public App ()
{
Instance = this ;
}
public void Init ( IWindow window , GL openGl , ImFontPtr openSansFont )
{
2025-10-05 18:17:18 +03:00
// Call this once at program startup
Encoding . RegisterProvider ( CodePagesEncodingProvider . Instance );
2024-11-15 19:06:44 +03:00
ImGui . StyleColorsLight ();
IServiceCollection serviceCollection = new ServiceCollection ();
2026-06-07 00:41:16 +03:00
serviceCollection . AddSingleton < ILater >( _later );
serviceCollection . AddSingleton < IConfigProvider >( new ConfigProvider ( new ConfigJson ()));
2024-11-15 19:06:44 +03:00
foreach ( var type in Utils . GetAssignableTypes < IService >())
{
serviceCollection . AddSingleton ( type );
}
foreach ( var type in Utils . GetAssignableTypes < IImGuiPanel >())
{
serviceCollection . AddSingleton ( type );
}
2026-06-07 00:41:16 +03:00
foreach ( var type in Utils . GetAssignableTypes < ILaunchReceiver >())
{
serviceCollection . AddSingleton ( type );
}
2024-11-19 02:13:14 +03:00
serviceCollection . AddSingleton ( openGl );
serviceCollection . AddSingleton ( window );
2024-11-18 23:48:42 +03:00
serviceCollection . AddSingleton ( new NResExplorerViewModel ());
serviceCollection . AddSingleton ( new TexmExplorerViewModel ());
2024-11-26 04:05:25 +03:00
serviceCollection . AddSingleton ( new MissionTmaViewModel ());
2025-02-26 04:27:16 +03:00
serviceCollection . AddSingleton ( new BinaryExplorerViewModel ());
serviceCollection . AddSingleton ( new ScrViewModel ());
2025-03-01 23:03:13 +03:00
serviceCollection . AddSingleton ( new VarsetViewModel ());
2025-09-04 02:45:26 +03:00
serviceCollection . AddSingleton ( new CpDatSchemeViewModel ());
2025-12-04 03:50:29 +03:00
serviceCollection . AddSingleton ( new MaterialViewModel ());
2026-02-15 23:44:20 +03:00
serviceCollection . AddSingleton ( new ResearchTreeViewModel ());
2024-11-15 19:06:44 +03:00
var serviceProvider = serviceCollection . BuildServiceProvider ();
_imGuiPanels = Utils . GetAssignableTypes < IImGuiPanel >()
. Select ( t => ( serviceProvider . GetService ( t ) as IImGuiPanel )!)
. ToList ();
2026-06-07 00:41:16 +03:00
foreach ( var type in Utils . GetAssignableTypes < ILaunchReceiver >())
{
var launchReceiver = serviceProvider . GetService ( type ) as ILaunchReceiver ;
launchReceiver ?. OnLaunch ();
}
2024-11-15 19:06:44 +03:00
}
public void OnImGuiRender ()
{
ImGui . PushFont ( OpenSansFont );
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others.
var windowFlags = ImGuiWindowFlags . MenuBar | ImGuiWindowFlags . NoDocking ;
if ( _optFullscreen )
{
var viewport = ImGui . GetMainViewport ();
ImGui . SetNextWindowPos ( viewport . Pos );
ImGui . SetNextWindowSize ( viewport . Size );
ImGui . SetNextWindowViewport ( viewport . ID );
ImGui . PushStyleVar ( ImGuiStyleVar . WindowRounding , 0.0f );
ImGui . PushStyleVar ( ImGuiStyleVar . WindowBorderSize , 0.0f );
windowFlags |= ImGuiWindowFlags . NoTitleBar | ImGuiWindowFlags . NoCollapse | ImGuiWindowFlags . NoResize |
ImGuiWindowFlags . NoMove ;
windowFlags |= ImGuiWindowFlags . NoBringToFrontOnFocus | ImGuiWindowFlags . NoNavFocus ;
}
// When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background.
if (( _dockspaceFlags & ImGuiDockNodeFlags . PassthruCentralNode ) != 0 )
windowFlags |= ImGuiWindowFlags . NoBackground ;
// Important: note that we proceed even if Begin() returns false (aka window is collapsed).
// This is because we want to keep our DockSpace() active. If a DockSpace() is inactive,
// all active windows docked into it will lose their parent and become undocked.
// We cannot preserve the docking relationship between an active window and an inactive docking, otherwise
// any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
ImGui . PushStyleVar ( ImGuiStyleVar . WindowPadding , new Vector2 ( 0.0f , 0.0f ));
ImGui . Begin ( "DockSpace Demo" , ref _dockspaceOpen , windowFlags );
ImGui . PopStyleVar ();
if ( _optFullscreen )
ImGui . PopStyleVar ( 2 );
// DockSpace
var io = ImGui . GetIO ();
var style = ImGui . GetStyle ();
var minWinSizeX = style . WindowMinSize . X ;
style . WindowMinSize . X = 370.0f ;
if (( io . ConfigFlags & ImGuiConfigFlags . DockingEnable ) != 0 )
{
var dockspaceId = ImGui . GetID ( "MyDockSpace" );
ImGui . DockSpace ( dockspaceId , new Vector2 ( 0.0f , 0.0f ), _dockspaceFlags );
}
style . WindowMinSize . X = minWinSizeX ;
foreach ( var imGuiPanel in _imGuiPanels )
{
imGuiPanel . OnImGuiRender ();
}
2026-06-07 00:41:16 +03:00
foreach ( var action in _later . Enumerate ())
{
action ();
}
2024-11-15 19:06:44 +03:00
2024-11-18 18:49:39 +03:00
// ImGui.ShowMetricsWindow();
// ImGui.ShowDemoWindow();
2024-11-15 19:06:44 +03:00
ImGui . PopFont ();
ImGui . End ();
}
public void Exit ()
{
}
public void Update ( double delta )
{
}
public void OnKeyPressed ( Key key )
{
}
public void OnKeyDown ( Key key )
{
}
public void OnKeyReleased ( Key key )
{
}
2026-05-09 20:36:43 +03:00
}