Example #1
0
        public QuestFile(string filePath, bool newFile = false, string mobInfo = "", string itemInfo = "")
        {
            FilePath = filePath;
            IsSaved = true;
            isNewFile = newFile;

            if (!newFile)
            {
                QuestDialog = new SHNFile(Path.Combine(Path.GetDirectoryName(filePath), "QuestDialog.shn"));
                MobInfo = new SHNFile(Path.Combine(Path.GetDirectoryName(filePath), "MobInfo.shn"));

                if (!File.Exists(QuestDialog.FilePath))
                    throw new Exception("QuestDialog.shn cannot be found. Make sure it is in the same directory.");
            }
            else
            {
                MobInfo = new SHNFile(mobInfo);

                QuestDialog = new SHNFile("QuestDialog.shn");
                QuestDialog.CreateFile();
                QuestDialog.Columns.Add(new SHNColumn("ID", -1, SHNType.UInt32, typeof(uint)));
                QuestDialog.Columns.Add(new SHNColumn("Dialog", 50, SHNType.UInt32, typeof(uint)));
            }

            Init();
        }
Example #2
0
        private async void openFile(string fileName)
        {
            try
            {
                dynamic file = null;
                var dgv = new DataGridView();

                // Display the hidden progressbar in the statusbar.
                pbProgress.Visible = true;

                // Determine what file type it is and cast to the appropriate type.
                switch (Path.GetExtension(fileName))
                {
                    case ".shn":
                        if (Path.GetFileNameWithoutExtension(fileName).ToLower() == "questdata")
                        {
                            file = new QuestFile(fileName);
                            Program.LoadedFiles.Add(file);
                            Extensions.FileType = FileType.QuestFile;

                            var mainTab = new TabPage("QuestFile");
                            var qTab = new TabPage("Quests");
                            var dTab = new TabPage("Dialouges");
                            mainTab.BackColor = Color.White;
                            dTab.BackColor = Color.White;
                            qTab.BackColor = Color.White;

                            var tc = new TabControl();
                            tc.Dock = DockStyle.Fill;
                            qTab.Padding = new Padding(0, 5, 0, 0);
                            dTab.Padding = new Padding(0, 5, 0, 0);
                            mainTab.Padding = new Padding(0, 5, 0, 0);

                            tc.TabPages.Add(qTab);
                            tc.TabPages.Add(dTab);

                            mainTab.Controls.Add(tc);

                            var qPanel = new QuestPanel(file);
                            qPanel.Dock = DockStyle.Fill;
                            qTab.BackColor = Color.White;
                            qTab.Controls.Add(qPanel);

                            tcFiles.TabPages.Add(mainTab);
                            tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1;

                            pbProgress.Visible = false;
                            pbProgress.Value = 0;
                            lblStatus.Text = "Ready";
                            updateFileInfo();

                            return;
                        }

                        file = new SHNFile(fileName);
                        Extensions.FileType = FileType.SHNFile;

                        break;

                    case ".txt":
                        file = new ShineFile(fileName);
                        Extensions.FileType = FileType.ShineFile;

                        break;

                    default:
                        throw new Exception("File type not supported");
                }

                lblStatus.Text = "Reading " + Path.GetFileName(fileName);

                // Await the asynchronous Load method and display the reported progress in our progressbar.
                await Task.Run(() => file.Load(new Progress<int>(value =>
                    mainStatusStrip.Invoke(new MethodInvoker(() =>
                    {
                        pbProgress.Value = value;
                    }))
                )));

                Program.LoadedFiles.Add(file);

                if (file.GetType() == typeof(SHNFile))
                {
                    dgv = new DataGridView();
                    dgv.Dock = DockStyle.Fill;
                    dgv.BackgroundColor = Color.WhiteSmoke;
                    dgv.DoubleBuffered(true);
                    dgv.DataSource = file;

                    dgv.CellEnter += File_CellEnter;

                    var tab = new TabPage(file.TableName);
                    file.RowChanged += new DataRowChangeEventHandler(File_RowChanged);
                    tab.Controls.Add(dgv);

                    tcFiles.TabPages.Add(tab);
                    tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1;
                }

                else if (file.GetType() == typeof(ShineFile))
                {
                    var mainTab = new TabPage(file.DataSetName);
                    var tcTables = new TabControl();
                    tcTables.Dock = DockStyle.Fill;

                    tcTables.SelectedIndexChanged += new EventHandler((object s, EventArgs e) =>
                    {
                        file.SelectedIndex = tcTables.SelectedIndex;
                    });

                    mainTab.Controls.Add(tcTables);
                    tcFiles.TabPages.Add(mainTab);
                    mainTab.BackColor = Color.White;

                    tcFiles.SelectedIndex = tcFiles.TabCount - 1;

                    foreach (var table in file.Tables)
                    {
                        dgv = new DataGridView();
                        dgv.Dock = DockStyle.Fill;
                        dgv.BackgroundColor = Color.WhiteSmoke;
                        dgv.DoubleBuffered(true);
                        dgv.DataSource = table;

                        dgv.CellEnter += File_CellEnter;

                        var tab = new TabPage(table.TableName);
                        table.RowChanged += new DataRowChangeEventHandler(File_RowChanged);
                        tab.Controls.Add(dgv);

                        tcTables.TabPages.Add(tab);
                    }
                }


                // Hide and reset the progressbar.
                pbProgress.Visible = false;
                pbProgress.Value = 0;
                lblStatus.Text = "Ready";
                updateFileInfo();
            }
            catch (Exception ex)
            {
                pbProgress.Visible = false;
                pbProgress.Value = 0;
                lblStatus.Text = "Ready";
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }