private void Command_New(object sender, ExecutedRoutedEventArgs e)
        {
            Data = UndertaleData.CreateNew();
            CloseChildFiles();
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Data"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsGMS2"));
            ChangeSelection(Highlighted = new DescriptionView("Welcome to UndertaleModTool!", "New file created, have fun making a game out of nothing\nI TOLD YOU to open data.win, not create a new file! :P"));
            SelectionHistory.Clear();

            CanSave = true;
        }
        // TODO: extract the scripting interface into a separate class

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;

            ChangeSelection(Highlighted = new DescriptionView("Welcome to UndertaleModTool!", "Open data.win file to get started, then double click on the items on the left to view them"));
            SelectionHistory.Clear();

            TitleMain = "UndertaleModTool by krzys_h v" + FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;

            CanSave = false;
        }
    public override void OnInspectorGUI()
    {
        using (new GUILayout.HorizontalScope()) {
            if (GUILayout.Button("GetPrevList"))
            {
                foreach (var p in SelectionHistory.GetPrevList())
                {
                    Debug.Log($"{p.Item1} {p.Item2}");
                }
            }
            if (GUILayout.Button("GetNextList"))
            {
                foreach (var p in SelectionHistory.GetNextList())
                {
                    Debug.Log($"{p.Item1} {p.Item2}");
                }
            }
        }
        //GUILayout.Label( "posision = " + SelectionHistoryParameter.instance.posision );

        for (var i = 0; i < SelectionHistoryParameter.instance.Count; i++)
        {
            var p = SelectionHistoryParameter.instance[i];
            if (p == null)
            {
                continue;
            }
            GUIStyle st = SelectionHistoryParameter.instance.posision - 1 == i ? EditorStyles.boldLabel : EditorStyles.label;
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label($"{i}: {p.name} { p.GetType()}", st);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Select"))
                {
                    SelectionHistory.SetIndex(i);
                }
            }
        }
    }
        private void DeleteItem(UndertaleObject obj)
        {
            TreeViewItem container = GetNearestParent <TreeViewItem>(GetTreeViewItemFor(obj));
            object       source    = container.ItemsSource;
            IList        list      = ((source as ICollectionView)?.SourceCollection as IList) ?? (source as IList);
            bool         isLast    = list.IndexOf(obj) == list.Count - 1;

            if (MessageBox.Show("Delete " + obj.ToString() + "?" + (!isLast ? "\n\nNote that the code often references objects by ID, so this operation is likely to break stuff because other items will shift up!" : ""), "Confirmation", MessageBoxButton.YesNo, isLast ? MessageBoxImage.Question : MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                list.Remove(obj);
                while (SelectionHistory.Remove(obj))
                {
                    ;
                }
                if (Selected == obj)
                {
                    ChangeSelection(null);
                }
                if (Highlighted == obj)
                {
                    Highlighted = null;
                }
            }
        }
        private async Task LoadFile(string filename)
        {
            LoaderDialog dialog = new LoaderDialog("Loading", "Loading, please wait...");

            dialog.Owner = this;
            Task t = Task.Run(() =>
            {
                bool hadWarnings   = false;
                UndertaleData data = null;
                try
                {
                    using (var stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                    {
                        data = UndertaleIO.Read(stream, warning =>
                        {
                            MessageBox.Show(warning, "Loading warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                            hadWarnings = true;
                        });
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occured while trying to load:\n" + e.Message, "Load error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Dispatcher.Invoke(() =>
                {
                    if (data != null)
                    {
                        if (data.UnsupportedBytecodeVersion)
                        {
                            MessageBox.Show("Only bytecode versions 15, 16, and (partially) 17 are supported for now, you are trying to load " + data.GeneralInfo.BytecodeVersion + ". A lot of code is disabled and will likely break something. Saving/exporting is disabled.", "Unsupported bytecode version", MessageBoxButton.OK, MessageBoxImage.Warning);
                            CanSave = false;
                        }
                        else if (hadWarnings)
                        {
                            MessageBox.Show("Warnings occurred during loading. Saving has been disabled.", "Saving disabled", MessageBoxButton.OK, MessageBoxImage.Warning);
                            CanSave = false;
                        }
                        else
                        {
                            CanSave = true;
                        }
                        if (data.Code == null)
                        {
                            MessageBox.Show("This game uses YYC (YoYo Compiler), which means the code is embedded into the game .exe. This configuration is currently not fully supported, continue at your own risk", "YYC", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        if (data.GeneralInfo?.BytecodeVersion == 17)
                        {
                            MessageBox.Show("Bytecode version 17 has been loaded. There may be some problems remaining, as thorough research into the changes are yet to be done.", "Bytecode version 17", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        if (System.IO.Path.GetDirectoryName(FilePath) != System.IO.Path.GetDirectoryName(filename))
                        {
                            CloseChildFiles();
                        }
                        this.Data     = data;
                        this.FilePath = filename;
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Data"));
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("FilePath"));
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsGMS2"));
                        ChangeSelection(Highlighted = new DescriptionView("Welcome to UndertaleModTool!", "Double click on the items on the left to view them!"));
                        SelectionHistory.Clear();
                    }
                    dialog.Hide();
                });
            });

            dialog.ShowDialog();
            await t;
        }
 private void BackButton_Click(object sender, RoutedEventArgs e)
 {
     Selected = SelectionHistory.Last();
     SelectionHistory.RemoveAt(SelectionHistory.Count - 1);
 }
 public void ChangeSelection(object newsel)
 {
     SelectionHistory.Add(Selected);
     Selected = newsel;
 }
Example #8
0
        public async Task OnOpenWizzard(WizardItem item)
        {
            IsLoadedData = false;

            if (item != null)
            {
                SelectedItem = item;

                SelectionHistory.AddLast(item);
            }

            WizardStageResult selections = null;

            if (_wizardId == null)
            {
                var wizardType = item.TypeSource;
                if (wizardType == null || this.HyperStore == null)
                {
                    IsLoadedData = true;
                    return;
                }

                var attr       = wizardType.AsType()?.GetCustomAttributes(true);
                var configAttr = attr?.OfType <ConfigAttribute>().FirstOrDefault();

                if (_pendingConfig == null)
                {
                    var configType = configAttr?.ConfigType;

                    _pendingConfig = configType != null ? (HyperJobConfig)Activator.CreateInstance(configType) : null;
                    if (_pendingConfig != null)
                    {
                        // Show the wizard properties before anything else.
                        ShowPropertyGrid = true;
                        IsLoadedData     = true;

                        SelectionHistory.RemoveLast();                         //

                        return;
                    }
                }

                // Create a new wizard.
                var res = await this.HyperStore.ExecuteAsync(new StartHyperJobArgs(wizardType) { JobConfig = _pendingConfig });

                // Clean it up from the last populate.
                Items.Clear();
                _pendingConfig = null;
                _wizardId      = res.JobId;
            }
            else
            {
                if (_currentStage is WizardListStage)
                {
                    //selections = new WizardStageResult() { Results = Items.Where(it=>it.Selected == true).Select(it => it.Name).ToArray() };
                    selections = new WizardStageResult()
                    {
                        Results = new[] { SelectedItem.Value }
                    };
                }
                else if (_currentStage is WizardDataInputStage)
                {
                    //selections = new WizardStageResult() { Results = new string[] { _lastInputValue } };
                    selections = new WizardStageResult()
                    {
                        Results = new string[] { ConfirmDialogMessage }
                    };
                }
            }

            MessageDescription = "Wizard working...";
            Items.Clear();

            _currentStage = await this.HyperStore.ExecuteAsync(new StepAheadWizardArgs()
            {
                JobId = _wizardId, PreviousStepResult = selections
            });

            if (_currentStage == null || _currentStage.IsFinal)
            {
                if (_wizardId != null)
                {
                    MessageDescription = "Wizard Completed, Hit RESET to start over";
                    Items.Clear();
                    IsWizardFinish = true;
                }
            }
            else
            {
                var listStage  = _currentStage as WizardListStage;
                var inputStage = _currentStage as WizardDataInputStage;

                if (listStage != null)
                {
                    var items = listStage.Entries.Select(it => new WizardItem()
                    {
                        Title = it.Title, Selected = it.PreSelected, Value = it.Value
                    });

                    Items.Clear();
                    Items.AddRange(items);

                    // MultiSelect ?

                    MessageDescription = _currentStage.Title;
                }
                else if (inputStage != null)
                {
                    ShowConfirmDialog = true;

                    ConfirmDialogTitle = inputStage.Title;
                    if (inputStage.DefaultValue != null)
                    {
                        ConfirmDialogMessage = Convert.ToString(inputStage.DefaultValue);
                    }
                }
            }

            IsLoadedData = true;
        }
Example #9
0
        private async Task LoadFile(string filename)
        {
            LoaderDialog dialog = new LoaderDialog("Loading", "Loading, please wait...");

            dialog.Owner = this;
            Task t = Task.Run(() =>
            {
                bool hadWarnings   = false;
                UndertaleData data = null;
                try
                {
                    using (var stream = new FileStream(filename, FileMode.Open))
                    {
                        data = UndertaleIO.Read(stream, warning =>
                        {
                            MessageBox.Show(warning, "Loading warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                            hadWarnings = true;
                        });
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("An error occured while trying to load:\n" + e.Message, "Load error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                Dispatcher.Invoke(() =>
                {
                    if (data != null)
                    {
                        if (data.UnsupportedBytecodeVersion)
                        {
                            MessageBox.Show("Only bytecode versions 15 and 16 are supported for now, you are trying to load " + data.GeneralInfo.BytecodeVersion + ". A lot of code is disabled and will likely break something. Saving/exporting is disabled.", "Unsupported bytecode version", MessageBoxButton.OK, MessageBoxImage.Warning);
                            CanSave = false;
                        }
                        else if (hadWarnings)
                        {
                            MessageBox.Show("Warnings occurred during loading. Saving has been disabled.", "Saving disabled", MessageBoxButton.OK, MessageBoxImage.Warning);
                            CanSave = false;
                        }
                        else
                        {
                            CanSave = true;
                        }
                        if (data.GeneralInfo?.Major >= 2)
                        {
                            MessageBox.Show("Game Maker: Studio 2 game loaded! I just hacked this together quickly for the Nintendo Switch release of Undertale. Most things work, but some editors don't display all the data.", "GMS2 game loaded", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        if (System.IO.Path.GetDirectoryName(FilePath) != System.IO.Path.GetDirectoryName(filename))
                        {
                            CloseChildFiles();
                        }
                        this.Data     = data;
                        this.FilePath = filename;
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Data"));
                        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("IsGMS2"));
                        ChangeSelection(Highlighted = new DescriptionView("Welcome to UndertaleModTool!", "Double click on the items on the left to view them!"));
                        SelectionHistory.Clear();
                    }
                    dialog.Hide();
                });
            });

            dialog.ShowDialog();
            await t;
        }
 public static bool NextCheck()
 {
     return(SelectionHistory.HasNext());
 }
 public static void Next()
 {
     SelectionHistory.Next();
 }
 public static bool PrevCheck()
 {
     return(SelectionHistory.HasPrev());
 }
 public static void Prev()
 {
     SelectionHistory.Prev();
 }