示例#1
0
 void write_tab_to_json(int tab_id)
 {
     if (tab_id > 0 && tab_id < tab_fld.TabCount - 1)
     {
         DbdCharacter last_char = dbd_char_list[tab_id - 1];
         json_obj["CharacterData"][last_char.EntryNum]["CharacterDataValue"]["inventoryData"] = JToken.FromObject(last_char.GetInventoryData());
         cur_json = Newtonsoft.Json.JsonConvert.SerializeObject(json_obj, Newtonsoft.Json.Formatting.None);
     }
     else if (tab_id == tab_fld.TabCount - 1)
     {
         cur_json = json_text_field.Text;
         json_obj = JObject.Parse(cur_json);
         //Compactify
         cur_json = Newtonsoft.Json.JsonConvert.SerializeObject(json_obj, Newtonsoft.Json.Formatting.None);
     }
 }
示例#2
0
        void fill_tabs()
        {
            if (cur_json.Length == 0)
            {
                return;
            }
            //Parse json
            try {
                json_obj = JObject.Parse(cur_json);

                //Json text
                json_text_field.Text = Newtonsoft.Json.JsonConvert.SerializeObject(json_obj, Newtonsoft.Json.Formatting.Indented);

                dbd_char_list.Clear();;
                main_val_listview.Clear();
                main_val_listview.Items.Clear();
                main_val_listview.Columns.Clear();
                main_val_listview.Columns.Add("Key", -2, HorizontalAlignment.Left);
                main_val_listview.Columns.Add("Value", -2, HorizontalAlignment.Left);
                main_val_listview.View = View.Details;
                foreach (string key in main_keys)
                {
                    var item = new ListViewItem(new[] { key, json_obj.GetValue(key).ToString() });
                    main_val_listview.Items.Add(item);
                }
                main_val_listview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                main_val_listview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

                IList <JToken> results = json_obj["CharacterData"].Children().ToList();
                IList <MainForm.CharacterData> searchResults = new List <MainForm.CharacterData>();
                item_cnt = 0;
                int entry = 0;
                foreach (JToken result in results)
                {
                    MainForm.CharacterData cc = result.ToObject <MainForm.CharacterData>();
                    searchResults.Add(cc);
                    if (cc.CharacterDataID == "-1")
                    {
                        ++entry;
                        continue;
                    }

                    IList <JToken> item_token = cc.CharacterDataValue["inventoryData"].Children().ToList();
                    DbdCharacter   dbd_char   = new DbdCharacter(cc.CharacterDataID, entry);
                    foreach (JToken item in item_token)
                    {
                        MainForm.InventoryData inv_item = item.ToObject <MainForm.InventoryData>();
                        if (!dbd_char.Inventory.ContainsKey(inv_item.name))
                        {
                            dbd_char.Inventory[inv_item.name] = 1;
                        }
                        else
                        {
                            ++dbd_char.Inventory[inv_item.name];
                        }
                        ++item_cnt;
                    }
                    dbd_char_list.Add(dbd_char);
                    ++entry;
                }

                for (int i = 0; i < char_tabs.Count; ++i)
                {
                    char_tabs[i].Dispose();
                }
                char_tabs.Clear();

                int cnum = dbd_char_list.Count;
                foreach (DbdCharacter dbd_char in dbd_char_list.Reverse())
                {
                    CharEditTab gui_tab = new CharEditTab(this, --cnum, dbd_char);
                    char_tabs.Add(gui_tab);
                }
            } catch (Newtonsoft.Json.JsonReaderException) {
                MessageBox.Show("Savegame file is not valid :-(");
            }
        }
示例#3
0
            public CharEditTab(MainForm parent_form, int char_num, DbdCharacter the_dbd_char)
            {
                parent                 = parent_form;
                this.slasher_tab       = new System.Windows.Forms.TabPage();
                this.add_item_btn      = new System.Windows.Forms.Button();
                this.modify_lvl_btn    = new System.Windows.Forms.Button();
                this.copy_btn          = new System.Windows.Forms.Button();
                this.paste_btn         = new System.Windows.Forms.Button();
                this.modify_amount_btn = new System.Windows.Forms.Button();
                this.slasher_list_view = new System.Windows.Forms.ListView();
                this.slasher_tab.SuspendLayout();
                parent_form.SuspendLayout();

                dbd_char = the_dbd_char;

                this.add_item_btn.Location = new System.Drawing.Point(265, 470);
                this.add_item_btn.Name     = "add_item_btn";
                this.add_item_btn.Size     = new System.Drawing.Size(251, 40);
                this.add_item_btn.Text     = "Add new item";
                this.add_item_btn.UseVisualStyleBackColor = true;
                this.add_item_btn.Click += new System.EventHandler(parent.add_item_btn_Click);

                this.modify_amount_btn.Location = new System.Drawing.Point(5, 470);
                this.modify_amount_btn.Name     = "modify_amount_btn";
                this.modify_amount_btn.Size     = new System.Drawing.Size(251, 40);
                this.modify_amount_btn.Text     = "Modify amount";
                this.modify_amount_btn.UseVisualStyleBackColor = true;
                this.modify_amount_btn.Click += new System.EventHandler(parent.modify_amount_btn_Click);

                this.modify_lvl_btn.Location = new System.Drawing.Point(603, 470);
                this.modify_lvl_btn.Name     = "modify_lvl_btn";
                this.modify_lvl_btn.Size     = new System.Drawing.Size(48, 40);
                this.modify_lvl_btn.Text     = "Level";
                this.modify_lvl_btn.UseVisualStyleBackColor = true;
                this.modify_lvl_btn.Click += new System.EventHandler(parent.set_level_btn_Click);

                this.copy_btn.Location = new System.Drawing.Point(659, 470);
                this.copy_btn.Name     = "copy_btn";
                this.copy_btn.Size     = new System.Drawing.Size(115, 40);
                this.copy_btn.Text     = "Copy";
                this.copy_btn.UseVisualStyleBackColor = true;
                this.copy_btn.Click += new System.EventHandler(parent.copy_items_btn_Click);

                this.paste_btn.Location = new System.Drawing.Point(661 + 115 + 11, 470);
                this.paste_btn.Name     = "paste_btn";
                this.paste_btn.Size     = new System.Drawing.Size(115, 40);
                this.paste_btn.Text     = "Paste";
                this.paste_btn.UseVisualStyleBackColor = true;
                this.paste_btn.Click += new System.EventHandler(parent.paste_items_btn_Click);

                this.slasher_list_view.FullRowSelect = true;
                this.slasher_list_view.Location      = new System.Drawing.Point(5, 6);
                this.slasher_list_view.MultiSelect   = true;
                this.slasher_list_view.Name          = "slasher_list_view_" + char_num;
                this.slasher_list_view.Size          = new System.Drawing.Size(896, 448);
                this.slasher_list_view.UseCompatibleStateImageBehavior = false;
                this.slasher_list_view.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(parent.slasher_tab_MouseDoubleClick);

                this.slasher_tab.Controls.Add(this.modify_lvl_btn);
                this.slasher_tab.Controls.Add(this.copy_btn);
                this.slasher_tab.Controls.Add(this.paste_btn);
                this.slasher_tab.Controls.Add(this.add_item_btn);
                this.slasher_tab.Controls.Add(this.modify_amount_btn);
                this.slasher_tab.Controls.Add(this.slasher_list_view);
                this.slasher_tab.Location = new System.Drawing.Point(4, 22);
                this.slasher_tab.Name     = "tabPage" + char_num;
                this.slasher_tab.Size     = new System.Drawing.Size(908, 507);
                if (dbd_char.IsKiller())
                {
                    this.slasher_name     = replace_name("kill_" + dbd_char.TruncDataId());
                    this.slasher_tab.Text = this.slasher_name;
                }
                else
                {
                    this.slasher_name     = replace_name("surv_" + dbd_char.TruncDataId());
                    this.slasher_tab.Text = this.slasher_name;
                }
                this.has_prestige = check_has_prestige(this.slasher_name);
                this.slasher_tab.UseVisualStyleBackColor = true;
                fill_tab();

                IntPtr h = parent.get_tab_fld().Handle;

                parent.get_tab_fld().TabPages.Insert(1, this.slasher_tab);
                this.slasher_tab.ResumeLayout(false);
                parent_form.ResumeLayout(false);
            }