private void lstTables_AfterSelect(object sender, TreeViewEventArgs e) { if (mChangingName) { return; } if (lstTables.SelectedNode == null || lstTables.SelectedNode.Tag == null) { return; } mEditorItem = CraftingTableBase.Get((Guid)lstTables.SelectedNode.Tag); UpdateEditor(); }
private void AssignEditorItem(Guid id) { mEditorItem = CraftingTableBase.Get(id); UpdateEditor(); }
public void InitEditor() { var selectedId = Guid.Empty; var folderNodes = new Dictionary <string, TreeNode>(); if (lstTables.SelectedNode != null && lstTables.SelectedNode.Tag != null) { selectedId = (Guid)lstTables.SelectedNode.Tag; } lstTables.Nodes.Clear(); //Collect folders var mFolders = new List <string>(); foreach (var itm in CraftingTableBase.Lookup) { if (!string.IsNullOrEmpty(((CraftingTableBase)itm.Value).Folder) && !mFolders.Contains(((CraftingTableBase)itm.Value).Folder)) { mFolders.Add(((CraftingTableBase)itm.Value).Folder); if (!mKnownFolders.Contains(((CraftingTableBase)itm.Value).Folder)) { mKnownFolders.Add(((CraftingTableBase)itm.Value).Folder); } } } mFolders.Sort(); mKnownFolders.Sort(); cmbFolder.Items.Clear(); cmbFolder.Items.Add(""); cmbFolder.Items.AddRange(mKnownFolders.ToArray()); lstTables.Sorted = !btnChronological.Checked; if (!btnChronological.Checked && !CustomSearch()) { foreach (var folder in mFolders) { var node = lstTables.Nodes.Add(folder); node.ImageIndex = 0; node.SelectedImageIndex = 0; folderNodes.Add(folder, node); } } foreach (var itm in CraftingTableBase.ItemPairs) { var node = new TreeNode(itm.Value); node.Tag = itm.Key; node.ImageIndex = 1; node.SelectedImageIndex = 1; var folder = CraftingTableBase.Get(itm.Key).Folder; if (!string.IsNullOrEmpty(folder) && !btnChronological.Checked && !CustomSearch()) { var folderNode = folderNodes[folder]; folderNode.Nodes.Add(node); if (itm.Key == selectedId) { folderNode.Expand(); } } else { lstTables.Nodes.Add(node); } if (CustomSearch()) { if (!node.Text.ToLower().Contains(txtSearch.Text.ToLower())) { node.Remove(); } } if (itm.Key == selectedId) { lstTables.SelectedNode = node; } } var selectedNode = lstTables.SelectedNode; if (!btnChronological.Checked) { lstTables.Sort(); } lstTables.SelectedNode = selectedNode; foreach (var node in mExpandedFolders) { if (folderNodes.ContainsKey(node)) { folderNodes[node].Expand(); } } }
//GameObjectPacket private static void HandlePacket(GameObjectPacket packet) { var id = packet.Id; var deleted = packet.Deleted; var json = ""; if (!packet.Deleted) { json = packet.Data; } switch (packet.Type) { case GameObjectType.Animation: if (deleted) { var anim = AnimationBase.Get(id); anim.Delete(); } else { var anim = new AnimationBase(id); anim.Load(json); try { AnimationBase.Lookup.Set(id, anim); } catch (Exception exception) { Log.Error($"Another mystery NPE. [Lookup={AnimationBase.Lookup}]"); if (exception.InnerException != null) { Log.Error(exception.InnerException); } Log.Error(exception); Log.Error($"{nameof(id)}={id},{nameof(anim)}={anim}"); throw; } } break; case GameObjectType.Class: if (deleted) { var cls = ClassBase.Get(id); cls.Delete(); } else { var cls = new ClassBase(id); cls.Load(json); ClassBase.Lookup.Set(id, cls); } break; case GameObjectType.Item: if (deleted) { var itm = ItemBase.Get(id); itm.Delete(); } else { var itm = new ItemBase(id); itm.Load(json); ItemBase.Lookup.Set(id, itm); } break; case GameObjectType.Npc: if (deleted) { var npc = NpcBase.Get(id); npc.Delete(); } else { var npc = new NpcBase(id); npc.Load(json); NpcBase.Lookup.Set(id, npc); } break; case GameObjectType.Projectile: if (deleted) { var proj = ProjectileBase.Get(id); proj.Delete(); } else { var proj = new ProjectileBase(id); proj.Load(json); ProjectileBase.Lookup.Set(id, proj); } break; case GameObjectType.Quest: if (deleted) { var qst = QuestBase.Get(id); qst.Delete(); } else { var qst = new QuestBase(id); qst.Load(json); foreach (var tsk in qst.Tasks) { qst.OriginalTaskEventIds.Add(tsk.Id, tsk.CompletionEventId); } QuestBase.Lookup.Set(id, qst); } break; case GameObjectType.Resource: if (deleted) { var res = ResourceBase.Get(id); res.Delete(); } else { var res = new ResourceBase(id); res.Load(json); ResourceBase.Lookup.Set(id, res); } break; case GameObjectType.Shop: if (deleted) { var shp = ShopBase.Get(id); shp.Delete(); } else { var shp = new ShopBase(id); shp.Load(json); ShopBase.Lookup.Set(id, shp); } break; case GameObjectType.Spell: if (deleted) { var spl = SpellBase.Get(id); spl.Delete(); } else { var spl = new SpellBase(id); spl.Load(json); SpellBase.Lookup.Set(id, spl); } break; case GameObjectType.CraftTables: if (deleted) { var cft = CraftingTableBase.Get(id); cft.Delete(); } else { var cft = new CraftingTableBase(id); cft.Load(json); CraftingTableBase.Lookup.Set(id, cft); } break; case GameObjectType.Crafts: if (deleted) { var cft = CraftBase.Get(id); cft.Delete(); } else { var cft = new CraftBase(id); cft.Load(json); CraftBase.Lookup.Set(id, cft); } break; case GameObjectType.Map: //Handled in a different packet break; case GameObjectType.Event: var wasCommon = false; if (deleted) { var evt = EventBase.Get(id); wasCommon = evt.CommonEvent; evt.Delete(); } else { var evt = new EventBase(id); evt.Load(json); wasCommon = evt.CommonEvent; EventBase.Lookup.Set(id, evt); } if (!wasCommon) { return; } break; case GameObjectType.PlayerVariable: if (deleted) { var pvar = PlayerVariableBase.Get(id); pvar.Delete(); } else { var pvar = new PlayerVariableBase(id); pvar.Load(json); PlayerVariableBase.Lookup.Set(id, pvar); } break; case GameObjectType.ServerVariable: if (deleted) { var svar = ServerVariableBase.Get(id); svar.Delete(); } else { var svar = new ServerVariableBase(id); svar.Load(json); ServerVariableBase.Lookup.Set(id, svar); } break; case GameObjectType.Tileset: var obj = new TilesetBase(id); obj.Load(json); TilesetBase.Lookup.Set(id, obj); if (Globals.HasGameData && !packet.AnotherFollowing) { GameContentManager.LoadTilesets(); } break; default: throw new ArgumentOutOfRangeException(); } GameObjectUpdatedDelegate?.Invoke(packet.Type); }