Exemplo n.º 1
0
        private void ButtonRegister_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try {
                bool hasError = false;
                if (TextBoxName.Text == null || TextBoxName.Text == "")
                {
                    TextBoxName.Background = pinkBg;
                    hasError = true;
                }
                else
                {
                    TextBoxName.Background = normalBg;
                }
                if (TextBoxDescription.Text == null || TextBoxDescription.Text == "")
                {
                    TextBoxDescription.Background = pinkBg;
                    hasError = true;
                }
                else
                {
                    TextBoxDescription.Background = normalBg;
                }
                if (StickerNewStricker.StickerImage.Source == Sprite.Get("unknown").Source)
                {
                    LabelTip.Foreground = redBg;
                    hasError            = true;
                }
                else
                {
                    LabelTip.Foreground = new SolidColorBrush(Colors.Black);
                }
                if (hasError)
                {
                    return;
                }
                String imgGuid = Guid.NewGuid().ToString();
                File.Copy(dlg.FileName, Path.Combine(Paths.CustomSpritesDirectory, imgGuid));
                Generics.LinkedList <Sprite> spritesMetadata = JsonConvert.DeserializeObject <Generics.LinkedList <Sprite> >(File.ReadAllText(Paths.CustomSpritesMetadata));
                spritesMetadata.Add(new Sprite()
                {
                    ID       = imgGuid,
                    Path     = imgGuid,
                    IsCustom = true
                });
                File.WriteAllText(Paths.CustomSpritesMetadata, JsonConvert.SerializeObject(spritesMetadata, Formatting.Indented));

                Generics.LinkedList <God> customGods = God.GetAll().Where(x => x.IsCustom).ToLinkedList();

                God newCustomGod = new God()
                {
                    Name        = TextBoxName.Text,
                    Description = TextBoxDescription.Text,
                    ID          = Guid.NewGuid().ToString(),
                    SpriteID    = imgGuid,
                    IsCustom    = true
                };

                fatherName_x_id.TryGetValue(ComboBoxFather.Text, out newCustomGod.FatherID);
                motherName_x_id.TryGetValue(ComboBoxMother.Text, out newCustomGod.MotherID);
                rarityOptions.TryGetValue(ComboBoxRarity.Text, out newCustomGod.Rarity);
                genderOptions.TryGetValue(ComboBoxGender.Text, out newCustomGod.Gender);

                customGods.Add(newCustomGod);

                File.WriteAllText(Paths.CustomGodsMetadata, JsonConvert.SerializeObject(customGods, Formatting.Indented));

                Cache.Clear();
                Cache.Load();
                Cache.DumpLog();

                Game.GameMaster.Player.Inventory.Add(new SimpleSticker()
                {
                    ItemID = newCustomGod.ID
                });

                App.ClientWindow.SetCurrentPage(new StickerRegister_Finished(StickerNewStricker));
            } catch (Exception ex) {
                DebugUtils.LogError("Error creating sticker => " + ex.Message);
            }
        }
        private void ButtonRegister_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Console.WriteLine("-- FLAG --");
            bool hasError = false;

            if (TextBoxName.Text == null || TextBoxName.Text == "")
            {
                TextBoxName.Background = pinkBg;
                hasError = true;
            }
            else
            {
                TextBoxName.Background = normalBg;
            }
            if (TextBoxDescription.Text == null || TextBoxDescription.Text == "")
            {
                TextBoxDescription.Background = pinkBg;
                hasError = true;
            }
            else
            {
                TextBoxDescription.Background = normalBg;
            }
            if (StickerNewSticker.StickerImage.Source == Sprite.Get("unknown").Source)
            {
                LabelTip.Foreground = redBg;
                hasError            = true;
            }
            else
            {
                LabelTip.Foreground = new SolidColorBrush(Colors.Black);
            }
            if (TextBoxDangerLevel.Text == null || TextBoxDangerLevel.Text == "")
            {
                TextBoxDangerLevel.Background = pinkBg;
                hasError = true;
            }
            else
            {
                TextBoxDangerLevel.Background = normalBg;
            }
            if (hasError)
            {
                return;
            }

            String imgGuid = Guid.NewGuid().ToString();

            File.Copy(dlg.FileName, Path.Combine(Paths.CustomSpritesDirectory, imgGuid));
            Generics.LinkedList <Sprite> spritesMetadata = JsonConvert.DeserializeObject <Generics.LinkedList <Sprite> >(File.ReadAllText(Paths.CustomSpritesMetadata));
            spritesMetadata.Add(new Sprite()
            {
                ID       = imgGuid,
                Path     = imgGuid,
                IsCustom = true
            });
            File.WriteAllText(Paths.CustomSpritesMetadata, JsonConvert.SerializeObject(spritesMetadata, Formatting.Indented));

            Generics.LinkedList <Creature> customCreatures = Creature.GetAll().Where(x => x.IsCustom).ToLinkedList();

            Creature newCustomCreature = new Creature()
            {
                Name        = TextBoxName.Text,
                Description = TextBoxDescription.Text,
                ID          = Guid.NewGuid().ToString(),
                SpriteID    = imgGuid,
                IsCustom    = true,
                DangerLevel = Int16.Parse(TextBoxDangerLevel.Text)
            };

            rarityOptions.TryGetValue(ComboBoxRarity.Text, out newCustomCreature.Rarity);
            genderOptions.TryGetValue(ComboBoxGender.Text, out newCustomCreature.Gender);

            customCreatures.Add(newCustomCreature);

            File.WriteAllText(Paths.CustomCreaturesMetadata, JsonConvert.SerializeObject(customCreatures, Formatting.Indented));
            Cache.Clear();
            Cache.Load();
            Cache.DumpLog();
            Game.GameMaster.Player.Inventory.Add(new SimpleSticker()
            {
                ItemID = newCustomCreature.ID
            });
            Game.GameMaster.SaveAll();
            App.ClientWindow.SetCurrentPage(new StickerRegister_Finished(StickerNewSticker));
        }