void DrawMobLootEditor(Rect box) { // First check if the selected mob has been changed if (mobLoot.Count > 0 && editingDisplay.id != mobLoot[0].mobTemplate) { LoadMobLoot (); } // Setup the layout Rect pos = box; pos.x += ImagePack.innerMargin; pos.y += ImagePack.innerMargin; pos.width -= ImagePack.innerMargin; pos.height = ImagePack.fieldHeight; ImagePack.DrawLabel (pos.x, pos.y, "Set mob loot tables for mob: " + editingDisplay.name); pos.y += ImagePack.fieldHeight; pos.width = pos.width / 2; for (int i = 0; i < maxLootTables; i++) { if (mobLoot.Count > i) { int selectedItem = GetPositionOfTable(mobLoot[i].tableId); selectedItem = ImagePack.DrawSelector (pos, "Loot Table:", selectedItem, tablesList); mobLoot[i].tableId = tableIds[selectedItem]; //mobLoot[i].tableId = ImagePack.DrawField (pos, "Loot Table:", mobLoot[i].tableId); //pos.y += ImagePack.fieldHeight; pos.x += pos.width; mobLoot[i].chance = ImagePack.DrawField (pos, "Drop Chance:", mobLoot[i].chance); pos.y += ImagePack.fieldHeight; if (ImagePack.DrawButton (pos.x, pos.y, "Delete Entry")) { if (mobLoot[i].id > 0) mobLootToBeDeleted.Add(mobLoot[i].id); mobLoot.RemoveAt(i); } pos.x -= pos.width; pos.y += ImagePack.fieldHeight; } } if (mobLoot.Count < maxLootTables) { if (ImagePack.DrawButton (pos.x, pos.y, "Add Loot Table")) { MobLoot lootEntry = new MobLoot(); lootEntry.mobTemplate = editingDisplay.id; mobLoot.Add(lootEntry); } } pos.width = pos.width * 2; // Save data //pos.x -= ImagePack.innerMargin; pos.y += 1.4f * ImagePack.fieldHeight; pos.width /= 3; if (ImagePack.DrawButton (pos.x, pos.y, "Save Data")) { SaveChanges(); } // Cancel editing pos.x += pos.width; if (ImagePack.DrawButton (pos.x, pos.y, "Back")) { editingLoot = false; } if (resultTimeout != -1 && resultTimeout > Time.realtimeSinceStartup) { pos.y += ImagePack.fieldHeight; ImagePack.DrawText(pos, result); } }
public void LoadMobLoot() { mobLoot.Clear(); string tableName = "mob_loot"; // Read all entries from the table string query = "SELECT * FROM " + tableName + " where mobTemplate = " + editingDisplay.id; // If there is a row, clear it. if (rows != null) rows.Clear (); // Load data rows = DatabasePack.LoadData (DatabasePack.contentDatabasePrefix, query); //Debug.Log("#Rows:"+rows.Count); // Read all the data if ((rows!=null) && (rows.Count > 0)) { foreach (Dictionary<string,string> data in rows) { MobLoot lootEntry = new MobLoot(); lootEntry.id = int.Parse (data ["id"]); lootEntry.category = int.Parse (data ["category"]); lootEntry.tableId = int.Parse (data ["lootTable"]); lootEntry.chance = int.Parse (data ["dropChance"]); lootEntry.mobTemplate = editingDisplay.id; mobLoot.Add(lootEntry); } } }