public static void ExportNPC(NPCProject save, string directory, bool bundlify = false)
        {
            try
            {
                dir = Path.Combine(directory, $"{save.guid}");

                if (Directory.Exists(dir))
                {
                    Directory.Delete(dir, true);
                }

                if (bundlify)
                {
                    dir = Path.Combine(dir, "Bundles", "NPCs");
                }

                Export_Characters(save.characters);
                Export_Dialogues(save.dialogues);
                Export_Quests(save.quests);
                Export_Vendors(save.vendors);
                Export_Currencies(save.currencies);
                Button button = new Button
                {
                    Content = new TextBlock
                    {
                        Text = LocalizationManager.Current.Notification["Export_Done_Goto"]
                    }
                };
                if (Directory.Exists(dir))
                {
                    button.Click += (sender, e) =>
                    {
                        Process.Start(dir);
                    };
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Done"], buttons: button);
                }
            }
            catch (Exception ex)
            {
                App.Logger.LogException("Unable to export NPC.", ex: ex);
                switch (ex)
                {
                case IOException iOException:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error_IOException"]);
                    break;

                case UnauthorizedAccessException unauthorizedAccessException:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error_UnauthorizedAccessException"]);
                    break;

                default:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error"]);
                    break;
                }
            }
        }
Esempio n. 2
0
        public void SaveAll()
        {
            CharacterTabViewModel.SaveCommand.Execute(null);
            DialogueTabViewModel.SaveCommand.Execute(null);
            VendorTabViewModel.SaveCommand.Execute(null);
            QuestTabViewModel.SaveCommand.Execute(null);

            ProjectData proj = MainWindow.CurrentProject;
            NPCProject  data = proj.data;

            data.lastCharacter = data.characters.IndexOf(CharacterTabViewModel.Character);
            data.lastDialogue  = data.dialogues.IndexOf(DialogueTabViewModel.Dialogue);
            data.lastQuest     = data.quests.IndexOf(QuestTabViewModel.Quest);
            data.lastVendor    = data.vendors.IndexOf(VendorTabViewModel.Vendor);
        }
        public static void ExportNPC(NPCProject save)
        {
            try
            {
                if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + $@"\results\{save.guid}"))
                {
                    Directory.Delete(AppDomain.CurrentDomain.BaseDirectory + $@"\results\{save.guid}", true);
                }

                dir = AppDomain.CurrentDomain.BaseDirectory + $@"\results\{save.guid}\";
                Export_Characters(save.characters);
                Export_Dialogues(save.dialogues);
                Export_Quests(save.quests);
                Export_Vendors(save.vendors);
                Button button = new Button
                {
                    Content = new TextBlock
                    {
                        Text = LocalizationManager.Current.Notification["Export_Done_Goto"]
                    }
                };
                if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + $@"results\{save.guid}"))
                {
                    Action <object, RoutedEventArgs> action = new Action <object, RoutedEventArgs>((sender, e) => { Process.Start(AppDomain.CurrentDomain.BaseDirectory + $@"results\{save.guid}"); });
                    button.Click += new RoutedEventHandler(action);
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Done"], buttons: button);
                }
            }
            catch (Exception ex)
            {
                App.Logger.LogException("Unable to export NPC.", ex: ex);
                switch (ex)
                {
                case IOException iOException:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error_IOException"]);
                    break;

                case UnauthorizedAccessException unauthorizedAccessException:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error_UnauthorizedAccessException"]);
                    break;

                default:
                    App.NotificationManager.Notify(LocalizationManager.Current.Notification["Export_Error"]);
                    break;
                }
            }
        }
Esempio n. 4
0
        public MainWindowViewModel(MainWindow mainWindow)
        {
            MainWindow = mainWindow;
            RoutedCommand saveHotkey = new RoutedCommand();

            saveHotkey.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(saveHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                SaveProjectCommand.Execute(null);
            })));
            RoutedCommand loadHotkey = new RoutedCommand();

            loadHotkey.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(loadHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                LoadProjectCommand.Execute(null);
            })));
            RoutedCommand exportHotkey = new RoutedCommand();

            exportHotkey.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(exportHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                ExportProjectCommand.Execute(null);
            })));
            RoutedCommand newFileHotkey = new RoutedCommand();

            newFileHotkey.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(newFileHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                NewProjectCommand.Execute(null);
            })));
            RoutedCommand logWindow = new RoutedCommand();

            logWindow.InputGestures.Add(new KeyGesture(Key.F1, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(logWindow,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                if (ConsoleLogger.IsOpened)
                {
                    ConsoleLogger.HideConsoleWindow();
                }
                else
                {
                    ConsoleLogger.ShowConsoleWindow();
                }
            })));
            RoutedCommand pasteCommand = new RoutedCommand();

            pasteCommand.InputGestures.Add(new KeyGesture(Key.V, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(pasteCommand,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                switch (MainWindow.mainTabControl.SelectedIndex)
                {
                case 0 when CharacterTabViewModel.Character != null:         // character (condition)
                    {
                        if (ClipboardManager.TryGetObject(ClipboardManager.ConditionFormat, out var obj) && obj is Condition cond)
                        {
                            CharacterTabViewModel.Character.visibilityConditions.Add(cond);
                        }
                    }
                    break;

                case 1 when DialogueTabViewModel.Dialogue != null:         // dialogue (nothing at this moment)
                    {
                    }
                    break;

                case 2 when VendorTabViewModel.Vendor != null:         // vendor (vendor item)
                    {
                        if (ClipboardManager.TryGetObject(ClipboardManager.VendorItemFormat, out var obj) && obj is VendorItem item)
                        {
                            if (item.isBuy)
                            {
                                VendorTabViewModel.AddItemBuy(item);
                            }
                            else
                            {
                                VendorTabViewModel.AddItemSell(item);
                            }
                        }
                    }
                    break;

                case 3 when QuestTabViewModel.Quest != null:         // quest (condition, reward)
                    {
                        if (ClipboardManager.TryGetObject(ClipboardManager.ConditionFormat, out var obj) && obj is Condition cond)
                        {
                            QuestTabViewModel.AddCondition(new Controls.Universal_ItemList(cond, true));
                        }
                        else if (ClipboardManager.TryGetObject(ClipboardManager.RewardFormat, out obj) && obj is Reward rew)
                        {
                            QuestTabViewModel.AddReward(new Controls.Universal_ItemList(rew, true));
                        }
                    }
                    break;
                }
            })));
            CharacterTabViewModel = new CharacterTabViewModel();
            DialogueTabViewModel  = new DialogueTabViewModel();
            VendorTabViewModel    = new VendorTabViewModel();
            QuestTabViewModel     = new QuestTabViewModel();
            CurrencyTabViewModel  = new CurrencyTabViewModel();
            MainWindow.mainTabControl.SelectionChanged += TabControl_SelectionChanged;

            MainWindow.CurrentProject.OnDataLoaded += () =>
            {
                ResetAll();

                ProjectData proj = MainWindow.CurrentProject;
                NPCProject  data = proj.data;

                if (data.lastCharacter > -1 && data.lastCharacter < data.characters.Count)
                {
                    CharacterTabViewModel.Character = data.characters[data.lastCharacter];
                }

                if (data.lastDialogue > -1 && data.lastDialogue < data.dialogues.Count)
                {
                    DialogueTabViewModel.Dialogue = data.dialogues[data.lastDialogue];
                }

                if (data.lastVendor > -1 && data.lastVendor < data.vendors.Count)
                {
                    VendorTabViewModel.Vendor = data.vendors[data.lastVendor];
                }

                if (data.lastQuest > -1 && data.lastQuest < data.quests.Count)
                {
                    QuestTabViewModel.Quest = data.quests[data.lastQuest];
                }

                if (data.lastCurrency > -1 && data.lastCurrency < data.currencies.Count)
                {
                    CurrencyTabViewModel.Currency = data.currencies[data.lastCurrency];
                }

                UpdateAllTabs();
            };
        }
Esempio n. 5
0
        public MainWindowViewModel(MainWindow mainWindow)
        {
            MainWindow = mainWindow;
            RoutedCommand saveHotkey = new RoutedCommand();

            saveHotkey.InputGestures.Add(new KeyGesture(Key.S, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(saveHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                SaveProjectCommand.Execute(null);
            })));
            RoutedCommand loadHotkey = new RoutedCommand();

            loadHotkey.InputGestures.Add(new KeyGesture(Key.O, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(loadHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                LoadProjectCommand.Execute(null);
            })));
            RoutedCommand exportHotkey = new RoutedCommand();

            exportHotkey.InputGestures.Add(new KeyGesture(Key.E, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(exportHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                ExportProjectCommand.Execute(null);
            })));
            RoutedCommand newFileHotkey = new RoutedCommand();

            newFileHotkey.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(newFileHotkey,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                NewProjectCommand.Execute(null);
            })));
            RoutedCommand logWindow = new RoutedCommand();

            logWindow.InputGestures.Add(new KeyGesture(Key.F1, ModifierKeys.Control));
            MainWindow.CommandBindings.Add(new CommandBinding(logWindow,
                                                              new ExecutedRoutedEventHandler((object sender, ExecutedRoutedEventArgs e) =>
            {
                if (ConsoleLogger.IsOpened)
                {
                    ConsoleLogger.HideConsoleWindow();
                }
                else
                {
                    ConsoleLogger.ShowConsoleWindow();
                }
            })));
            CharacterTabViewModel = new CharacterTabViewModel();
            DialogueTabViewModel  = new DialogueTabViewModel();
            VendorTabViewModel    = new VendorTabViewModel();
            QuestTabViewModel     = new QuestTabViewModel();
            MainWindow.mainTabControl.SelectionChanged += TabControl_SelectionChanged;

            MainWindow.CurrentProject.OnDataLoaded += () =>
            {
                ResetAll();

                ProjectData proj = MainWindow.CurrentProject;
                NPCProject  data = proj.data;

                if (data.lastCharacter > -1)
                {
                    CharacterTabViewModel.Character = data.characters[data.lastCharacter];
                }

                if (data.lastDialogue > -1)
                {
                    DialogueTabViewModel.Dialogue = data.dialogues[data.lastDialogue];
                }

                if (data.lastVendor > -1)
                {
                    VendorTabViewModel.Vendor = data.vendors[data.lastVendor];
                }

                if (data.lastQuest > -1)
                {
                    QuestTabViewModel.Quest = data.quests[data.lastQuest];
                }
            };
        }