mainwindow.html

<Window x:Class="PrimalEditor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:PrimalEditor.Editors"
        xmlns:editors="clr-namespace:PrimalEditor.Editors"
        mc:Ignorable="d" WindowStartupLocation="CenterScreen"
        Title="Primal Editor" Height="1080" Width="1920">
    <Grid>
        <editors:WorldEditorView />
    </Grid>
</Window>

mainwindow.html.cs

using PrimalEditor.GameProject;
using System.ComponentModel;
using System.IO;
using System.Windows;
using Path = System.IO.Path;

namespace PrimalEditor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static string PrimalPath { get; private set; } = @"..\Primal1\Primal\";

        public MainWindow()
        {
            InitializeComponent();

            Loaded += OnMainWindowLoaded;

            Closing += OnMainWindowClosing;
        }


        private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
        {

            Loaded -= OnMainWindowLoaded;
            GetEnginePath();
            OpenProjectBrowserDialog();

        }

        private void GetEnginePath()
        {
            var primalPath = Environment.GetEnvironmentVariable("PRIMAL_ENGINE", EnvironmentVariableTarget.User);

            if (primalPath == null || !Directory.Exists(Path.Combine(primalPath, @"Engine\EngineAPI")))
            {

                var dlg = new EnginePathDialog();

                if (dlg.ShowDialog() == true)
                {
                    PrimalPath = dlg.PrimalPath;
                    Environment.SetEnvironmentVariable("PRIMAL_ENGINE", PrimalPath.ToUpper(), EnvironmentVariableTarget.User);


                }
                else
                {
                    Application.Current.Shutdown();


                }


            }
            else
            {
                PrimalPath = primalPath;

            }

        }

        private void OnMainWindowClosing(object sender, CancelEventArgs e)
        {


            Closing -= OnMainWindowClosing;

            Project.Current?.Unload();


        }

        private void OpenProjectBrowserDialog()
        {

            var projectBrowser = new ProjectBrowserDialog();
            if (projectBrowser.ShowDialog() == false || projectBrowser.DataContext == null)
            {

                Application.Current.Shutdown();

            }
            else
            {

                Project.Current?.Unload();

                DataContext = projectBrowser.DataContext;


            }

        }


    }
}

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐