// Edit or Create public override void DrawEditor(Rect box, bool newItem) { if (!linkedTablesLoaded) { LoadDialogueList(); LoadQuestList(); LoadFactionList(); actionOptions = ServerOptionChoices.LoadAtavismChoiceOptions("Dialogue Action", false); linkedTablesLoaded = true; } // Setup the layout Rect pos = box; pos.x += ImagePack.innerMargin; pos.y += ImagePack.innerMargin; pos.width -= ImagePack.innerMargin; pos.height = ImagePack.fieldHeight; // Draw the content database info if (newItem) { ImagePack.DrawLabel (pos.x, pos.y, "Create a new Dialogue"); pos.y += ImagePack.fieldHeight; } // Draw a button to go back to the previous dialogue if (editingDisplay.previousDialogueID != -1) { DialogueData dd = (DialogueData) dataRegister[editingDisplay.previousDialogueID]; pos.width = pos.width * 2; if (ImagePack.DrawButton (pos.x, pos.y, "Go back to " + dd.id + "." + dd.name)) { //editingDisplay = GetDialogue(editingDisplay.previousDialogueID); requestedDisplay = GetPositionOfPreviousDialogue(editingDisplay.previousDialogueID); state = State.Edit; return; } pos.y += ImagePack.fieldHeight; pos.width = pos.width / 2; } editingDisplay.name = ImagePack.DrawField (pos, "Name:", editingDisplay.name, 0.5f); pos.y += ImagePack.fieldHeight; pos.width = pos.width / 2; editingDisplay.openingDialogue = ImagePack.DrawToggleBox(pos, "Opening Dialogue:", editingDisplay.openingDialogue); pos.x += pos.width; editingDisplay.repeatable = ImagePack.DrawToggleBox(pos, "Repeatable:", editingDisplay.repeatable); pos.x -= pos.width; pos.y += ImagePack.fieldHeight; int dialogueID = GetPositionOfDialogue(editingDisplay.prereqDialogue); dialogueID = ImagePack.DrawSelector (pos, "Prereq Dialogue:", dialogueID, dialogueList); editingDisplay.prereqDialogue = dialogueIds[dialogueID]; pos.x += pos.width; int questID = GetPositionOfFaction(editingDisplay.prereqQuest); questID = ImagePack.DrawSelector (pos, "Prereq Quest:", questID, questList); editingDisplay.prereqFaction = factionIds[questID]; pos.x -= pos.width; pos.y += ImagePack.fieldHeight; int factionID = GetPositionOfFaction(editingDisplay.prereqFaction); factionID = ImagePack.DrawSelector (pos, "Prereq Faction:", factionID, factionList); editingDisplay.prereqFaction = factionIds[factionID]; pos.x += pos.width; int factionStance = GetPositionOfStance(editingDisplay.prereqFactionStance); factionStance = ImagePack.DrawSelector (pos, "Prereq Stance:", factionStance, FactionData.stanceOptions); editingDisplay.prereqFactionStance = FactionData.stanceValues[factionStance]; pos.x -= pos.width; pos.y += ImagePack.fieldHeight; pos.width = pos.width * 2; editingDisplay.text = ImagePack.DrawField (pos, "Text:", editingDisplay.text, 0.75f, 60); pos.y += 3f * ImagePack.fieldHeight; // Only show actions if it has been saved due to complications of moving forward/back if (!newItem) { if (editingDisplay.entries.Count == 0) { editingDisplay.entries.Add(new DialogueActionEntry("", actionOptions[0], -1)); } for (int i = 0; i < editingDisplay.maxEntries; i++) { if (editingDisplay.entries.Count > i) { ImagePack.DrawLabel (pos.x, pos.y, "Action " + (i+1)); pos.y += ImagePack.fieldHeight; editingDisplay.entries[i].text = ImagePack.DrawField (pos, "Text:", editingDisplay.entries[i].text, 1.4f); pos.width = pos.width / 2; pos.y += ImagePack.fieldHeight; editingDisplay.entries[i].action = ImagePack.DrawSelector (pos, "Action Type:", editingDisplay.entries[i].action, actionOptions); pos.x += pos.width; if (editingDisplay.entries[i].action == "Dialogue") { // Treat dialogues differently as the developer will be able to click to move onto the next one if (editingDisplay.entries[i].actionID == -1) { // No dialogue yet, click button to create a new one if (ImagePack.DrawButton (pos.x, pos.y, "Create Dialogue")) { // Save dialogue first then lets go create a new one UpdateEntry (); int previousDialogueID = editingDisplay.id; CreateNewData(); editingDisplay.previousDialogueID = previousDialogueID; editingDisplay.previousActionPosition = i; editingDisplay.openingDialogue = false; this.state = State.New; return; } } else { // Show dialogue with option to move forward if (ImagePack.DrawButton (pos.x, pos.y, "Edit Dialogue")) { // Save dialogue first then lets go create a new one UpdateEntry (); dataRegister[editingDisplay.entries[i].actionID].previousDialogueID = editingDisplay.id; requestedDisplay = GetPositionOfDialogue(editingDisplay.entries[i].actionID); state = State.Edit; } } } else { editingDisplay.entries[i].actionID = ImagePack.DrawField (pos, "ActionID:", editingDisplay.entries[i].actionID); } pos.x -= pos.width; pos.y += ImagePack.fieldHeight; pos.width = pos.width * 2; } } if (editingDisplay.entries.Count < editingDisplay.maxEntries) { if (ImagePack.DrawButton (pos.x, pos.y, "Add Action")) { DialogueActionEntry actionEntry = new DialogueActionEntry("", actionOptions[0], -1); editingDisplay.entries.Add(actionEntry); } } } //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")) { if (newItem) InsertEntry (); else UpdateEntry (); state = State.Loaded; } // Delete data if (!newItem) { pos.x += pos.width; if (ImagePack.DrawButton (pos.x, pos.y, "Delete Data")) { DeleteEntry (); newSelectedDisplay = 0; state = State.Loaded; } } // Cancel editing pos.x += pos.width; if (ImagePack.DrawButton (pos.x, pos.y, "Cancel")) { editingDisplay = originalDisplay.Clone(); if (newItem) state = State.New; else state = State.Loaded; } if (resultTimeout != -1 && resultTimeout > Time.realtimeSinceStartup) { pos.y += ImagePack.fieldHeight; ImagePack.DrawText(pos, result); } if (!newItem) EnableScrollBar(pos.y - box.y + ImagePack.fieldHeight + 28); else EnableScrollBar(pos.y - box.y + ImagePack.fieldHeight); }
// Load Database Data public override void Load() { if (!dataLoaded) { // Clean old data dataRegister.Clear (); displayKeys.Clear (); // Read all entries from the table string query = "SELECT * FROM " + tableName; // 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) { //foreach(string key in data.Keys) // Debug.Log("Name[" + key + "]:" + data[key]); //return; DialogueData display = new DialogueData (); display.id = int.Parse (data ["id"]); display.name = data ["name"]; display.openingDialogue = bool.Parse (data ["openingDialogue"]); display.repeatable = bool.Parse (data ["repeatable"]); display.prereqDialogue = int.Parse (data ["prereqDialogue"]); display.prereqQuest = int.Parse (data ["prereqQuest"]); display.prereqFaction = int.Parse (data ["prereqFaction"]); display.prereqFactionStance = int.Parse (data ["prereqFactionStance"]); display.reactionAutoStart = bool.Parse (data ["reactionAutoStart"]); display.text = data ["text"]; for (int i = 1; i <= display.maxEntries; i++) { string text = data ["option" + i + "text"]; if (text != null && text.Length != 0) { string action = data ["option" + i + "action"]; int actionID = int.Parse (data ["option" + i + "actionID"]); DialogueActionEntry entry = new DialogueActionEntry(text, action, actionID); display.entries.Add(entry); } } display.isLoaded = true; //Debug.Log("Name:" + display.name + "=[" + display.id + "]"); dataRegister.Add (display.id, display); displayKeys.Add (display.id); } LoadSelectList(); } dataLoaded = true; } }