コード例 #1
0
ファイル: DialogueScreen.cs プロジェクト: pquinn/time-sink
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see> in the database.</param>
 public DialogueScreen(Guid id)
     : base()
 {
     this.scale = 0.75f;
     this.prompt = EngineGame.Instance.Database.FindPrompt(id);
     this.responses = new List<Response>();
     IsPopup = false;
     InitializeActions();
 }
コード例 #2
0
ファイル: DialogueEdit.xaml.cs プロジェクト: pquinn/time-sink
        public void InitGrid(NPCPrompt entity)
        {
            dynamic.Children.Clear();

            int i = 0;
            foreach (var prop in entity.GetType().GetProperties())
            {
                var attr = prop.GetCustomAttributes(typeof(EditableFieldAttribute), false);
                if (attr.Any())
                {
                    dynamic.RowDefinitions.Add(new RowDefinition());

                    var val = prop.GetValue(entity, null) ?? string.Empty;
                    var textBlock = new TextBlock() { Text = ((EditableFieldAttribute)attr[0]).Display };
                    UIElement elementToAdd = null;
                    dynamic.Children.Add(textBlock);
                    Grid.SetRow(textBlock, i);
                    Grid.SetColumn(textBlock, 0);

                    var type = prop.PropertyType;

                    if (type.Equals(typeof(bool)))
                    {
                        elementToAdd = new CheckBox() { IsChecked = (bool)val };
                    }
                    else
                    {
                        if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
                        {
                            var builder = new StringBuilder();
                            var j = 0;
                            foreach (var v in (IEnumerable)val)
                            {
                                if (j > 0)
                                    builder.Append(";\n");
                                builder.Append(CreateString(v, type.GetGenericArguments()[0]));
                                j++;
                            }

                            elementToAdd = new TextBox()
                            {
                                AcceptsReturn = true,
                                TextWrapping = TextWrapping.Wrap,
                                Height = double.NaN,
                                Text = builder.ToString()
                            };
                        }
                        else
                        {
                            elementToAdd = new TextBox() { Text = CreateString(val,type) };
                        }
                    }

                    dynamic.Children.Add(elementToAdd);
                    Grid.SetRow(elementToAdd, i);
                    Grid.SetColumn(elementToAdd, 1);

                    i++;
                }
            }
        }
コード例 #3
0
ファイル: DialogueEdit.xaml.cs プロジェクト: pquinn/time-sink
 public void UpdatePromptInDB(NPCPrompt prompt)
 {
     Dictionary<string, string> data = new Dictionary<string, string>();
     //data.Add("ID", Id.ToString());
     data.Add("speaker", prompt.Speaker);
     data.Add("entry", prompt.Body);
     data.Add("animation", "null");
     data.Add("sound", "null");
     data.Add("quest", "null");
     data.Add("response_required", SQLiteDatabase.BooleanToDBValue(prompt.ResponseRequired));
     string where = String.Format("ID = '{0}'", prompt.Id.ToString());
     //var temp = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
     Game.Database.Update(NPCPrompt.TABLE_NAME, data, where);
 }
コード例 #4
0
ファイル: DialogueEdit.xaml.cs プロジェクト: pquinn/time-sink
        public void UpdatePrompt(NPCPrompt prompt)
        {
            int i = 0;
            foreach (var prop in prompt.GetType().GetProperties())
            {
                var attr = prop.GetCustomAttributes(typeof(EditableFieldAttribute), false);
                if (attr.Any())
                {
                    var element = dynamic.Children
                      .Cast<UIElement>()
                      .First(e => Grid.GetRow(e) == i && Grid.GetColumn(e) == 1);
                    var type = prop.PropertyType;

                    if (type.Equals(typeof(bool)))
                        prop.SetValue(prompt, ((CheckBox)element).IsChecked, null);
                    else
                    {
                        var text = ((TextBox)element).Text;
                        if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
                        {
                            var vals = text
                                .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                                .Select(x => x.Trim()).ToList();

                            vals.Select(x => ParseVal(x, type.GetGenericArguments()[0]));
                            prop.SetValue(prompt, vals, null);
                        }
                        else
                        {
                            prop.SetValue(prompt, ParseVal(text, type), null);
                        }
                    }

                    i++;
                }
            }
            UpdatePromptInDB(prompt);
        }
コード例 #5
0
ファイル: SQLiteDatabase.cs プロジェクト: pquinn/time-sink
        public NPCPrompt FindPrompt(Guid id)
        {
            List<IDialogueAction> promptActions = new List<IDialogueAction>();
            try
            {
                DataTable entry;
                String query = "select speaker \"speaker\", entry \"entry\", ";
                query += "animation \"animation\", sound \"sound\", quest \"quest\", ";
                query += "response_required \"response\" ";
                query += "from Prompt where id = \"" + id.ToString() + "\";";
                entry = GetDataTable(query);
                // only take the first result (there should only be one anyway)
                DataRow result = entry.Rows[0];
                String speaker = (String)result["speaker"];
                String body = (String)result["entry"];

                if (!DBNull.Value.Equals(result["animation"]))
                {
                    promptActions.Add(new AnimationAction((String)result["animation"]));
                }

                if (!DBNull.Value.Equals(result["sound"]))
                {
                    promptActions.Add(new SoundAction((String)result["sound"]));
                }

                if (!DBNull.Value.Equals(result["quest"]))
                {
                    promptActions.Add(new QuestAction((String)result["quest"]));
                }

                Boolean responseRequired = (Boolean)result["response"];

                NPCPrompt prompt = new NPCPrompt(id, speaker, body, promptActions, responseRequired);

                if (responseRequired)
                {
                    prompt.Responses = FindResponses(id);
                }
                return prompt;

            }
            catch (Exception e)
            {
                String error = "The following error has occurred:\n";
                error += e.Message.ToString() + "\n";
                Console.WriteLine(error);
                return new NPCPrompt(id, "error", error, promptActions, false);
            }
        }