Exemplo n.º 1
0
 private void OpenScriptBtn_Click(object sender, EventArgs e)
 {
     if (m_loadedCard != 0)
     {
         string file = "script\\c" + m_loadedCard + ".lua";
         if (File.Exists(file))
         {
             Process.Start(file);
         }
         else
         {
             if (!(Directory.Exists("script")))
             {
                 Directory.CreateDirectory("script");
             }
             if (CardManager.ContainsCard(m_loadedCard))
             {
                 CardInfos card  = CardManager.GetCard(m_loadedCard);
                 string[]  lines = { "--" + card.Name, "function c" + m_loadedCard + ".initial_effect(c)", string.Empty, "end" };
                 File.WriteAllLines(file, lines);
                 Process.Start(file);
             }
         }
     }
 }
        private void List_DrawItem(object sender, DrawItemEventArgs e)
        {
            var list = (ListBox)sender;

            e.DrawBackground();

            bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);

            int index = e.Index;

            if (index >= 0 && index < list.Items.Count)
            {
                string   text = list.Items[index].ToString();
                Graphics g    = e.Graphics;

                CardInfos card = null;

                if (CardManager.ContainsCard(Int32.Parse(text)))
                {
                    card = CardManager.GetCard(Int32.Parse(text));
                }

                g.FillRectangle((selected) ? new SolidBrush(Color.Blue) : new SolidBrush(Color.White), e.Bounds);

                // Print text
                g.DrawString((card == null ? text : card.Name), e.Font,
                             (selected) ? Brushes.White : Brushes.Black,
                             list.GetItemRectangle(index).Location);
            }

            e.DrawFocusRectangle();
        }
Exemplo n.º 3
0
        private void List_DrawItem(object sender, DrawItemEventArgs e)
        {
            var list = (ListBox)sender;

            e.DrawBackground();

            bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);

            int index = e.Index;

            if (index >= 0 && index < list.Items.Count)
            {
                string   text = list.Items[index].ToString();
                Graphics g    = e.Graphics;
                if (!Program.CardData.ContainsKey(Int32.Parse(text)))
                {
                    list.Items.Remove(text);
                }
                else
                {
                    CardInfos card = Program.CardData[Int32.Parse(text)];

                    g.FillRectangle((selected) ? new SolidBrush(Color.Blue) : new SolidBrush(Color.White), e.Bounds);

                    // Print text
                    g.DrawString((card.Name == "" ? card.Id.ToString(CultureInfo.InvariantCulture) : card.Name), e.Font,
                                 (selected) ? Brushes.White : Brushes.Black,
                                 list.GetItemRectangle(index).Location);
                }
            }

            e.DrawFocusRectangle();
        }
Exemplo n.º 4
0
        private bool LoadCard(int cardid)
        {
            if (!Program.CardData.ContainsKey(cardid))
            {
                return(false);
            }

            Clearbtn_Click(null, EventArgs.Empty);
            CardInfos info = Program.CardData[cardid];

            CardID.Text = info.Id.ToString(CultureInfo.InvariantCulture);
            Alias.Text  = info.AliasId.ToString(CultureInfo.InvariantCulture);
            for (int i = 0; i < m_formats.Count; i++)
            {
                if (m_formats[i] == info.Ot)
                {
                    CardFormats.SelectedIndex = i;
                    break;
                }
            }
            Level.SelectedIndex = info.Level - 1;
            for (int i = 0; i < m_cardRaces.Count; i++)
            {
                if (m_cardRaces[i] == info.Race)
                {
                    Race.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < m_cardAttributes.Count; i++)
            {
                if (m_cardAttributes[i] == info.Attribute)
                {
                    CardAttribute.SelectedIndex = i;
                    break;
                }
            }
            ATK.Text             = info.Atk.ToString(CultureInfo.InvariantCulture);
            DEF.Text             = info.Def.ToString(CultureInfo.InvariantCulture);
            CardName.Text        = info.Name;
            CardDescription.Text = info.Description;
            foreach (string effect in info.EffectStrings)
            {
                EffectList.Items.Add(effect);
            }
            SetCardTypes(info.GetCardTypes());

            int index = m_setCodes.IndexOf(info.SetCode & 0xffff);

            SetCodeLst.SelectedIndex = index;
            index = m_setCodes.IndexOf(info.SetCode >> 0x10);
            OtherSetCodeLst.SelectedIndex = index;

            SetCategoryCheckBoxs(info.Category);

            m_loadedCard = info.Id;

            return(true);
        }
Exemplo n.º 5
0
        public static bool SaveCard(CardInfos card, SQLiteConnection connection, int loadedid, bool overwrite)
        {
            try
            {
                SQLiteCommand command;
                if (overwrite)
                {
                    command = DatabaseHelper.CreateCommand("UPDATE datas" +
                                                           " SET id= @id, ot = @ot, alias= @alias, setcode= @setcode, type= @type, atk= @atk, def= @def, level= @level, race= @race, attribute= @attribute, category= @category WHERE id = @loadedid", connection);
                }
                else
                {
                    command = DatabaseHelper.CreateCommand("INSERT INTO datas (id,ot,alias,setcode,type,atk,def,level,race,attribute,category)" +
                                                           " VALUES (@id, @ot, @alias, @setcode, @type, @atk, @def, @level, @race, @attribute, @category)", connection);
                }

                command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                command.Parameters.Add(new SQLiteParameter("@ot", card.Ot));
                command.Parameters.Add(new SQLiteParameter("@alias", card.AliasId));
                command.Parameters.Add(new SQLiteParameter("@setcode", card.SetCode));
                command.Parameters.Add(new SQLiteParameter("@type", card.Type));
                command.Parameters.Add(new SQLiteParameter("@atk", card.Atk));
                command.Parameters.Add(new SQLiteParameter("@def", card.Def));
                command.Parameters.Add(new SQLiteParameter("@level", card.GetLevelCode()));
                command.Parameters.Add(new SQLiteParameter("@race", card.Race));
                command.Parameters.Add(new SQLiteParameter("@attribute", card.Attribute));
                command.Parameters.Add(new SQLiteParameter("@category", card.Category));
                DatabaseHelper.ExecuteNonCommand(command);

                if (overwrite)
                {
                    command = DatabaseHelper.CreateCommand("UPDATE texts" +
                                                           " SET id= @id,name= @name,desc= @des,str1= @str1,str2= @str2,str3= @str3,str4= @str4,str5= @str5,str6= @str6,str7= @str7,str8= @str8,str9= @str9,str10= @str10,str11= @str11,str12= @str12,str13= @str13,str14= @str14,str15= @str15,str16= @str16 WHERE id= @loadedid", connection);
                }
                else
                {
                    command = DatabaseHelper.CreateCommand("INSERT INTO texts (id,name,desc,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16)" +
                                                           " VALUES (@id,@name,@des,@str1,@str2,@str3,@str4,@str5,@str6,@str7,@str8,@str9,@str10,@str11,@str12,@str13,@str14,@str15,@str16)", connection);
                }
                command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                command.Parameters.Add(new SQLiteParameter("@name", card.Name));
                command.Parameters.Add(new SQLiteParameter("@des", card.Description));
                var parameters = new List <SQLiteParameter>();
                for (int i = 0; i < 16; i++)
                {
                    parameters.Add(new SQLiteParameter("@str" + (i + 1), (i < card.EffectStrings.Length ? card.EffectStrings[i].ToString() : string.Empty)));
                }
                command.Parameters.AddRange(parameters.ToArray());
                return(DatabaseHelper.ExecuteNonCommand(command));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK);
                return(false);
            }
        }
Exemplo n.º 6
0
        public static bool SaveCard(CardInfos card, SQLiteConnection connection, int loadedid, bool overwrite)
        {
            try
            {
                SQLiteCommand command;
                if(overwrite)
                {
                    command = DatabaseHelper.CreateCommand("UPDATE datas" +
                  " SET id= @id, ot = @ot, alias= @alias, setcode= @setcode, type= @type, atk= @atk, def= @def, level= @level, race= @race, attribute= @attribute, category= @category WHERE id = @loadedid", connection);
                }
                else
                {
                    command = DatabaseHelper.CreateCommand("INSERT INTO datas (id,ot,alias,setcode,type,atk,def,level,race,attribute,category)" +
                        " VALUES (@id, @ot, @alias, @setcode, @type, @atk, @def, @level, @race, @attribute, @category)", connection);
                }

                command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                command.Parameters.Add(new SQLiteParameter("@ot", card.Ot));
                command.Parameters.Add(new SQLiteParameter("@alias", card.AliasId));
                command.Parameters.Add(new SQLiteParameter("@setcode", card.SetCode));
                command.Parameters.Add(new SQLiteParameter("@type", card.Type));
                command.Parameters.Add(new SQLiteParameter("@atk", card.Atk));
                command.Parameters.Add(new SQLiteParameter("@def", card.Def));
                command.Parameters.Add(new SQLiteParameter("@level", card.GetLevelCode()));
                command.Parameters.Add(new SQLiteParameter("@race", card.Race));
                command.Parameters.Add(new SQLiteParameter("@attribute", card.Attribute));
                command.Parameters.Add(new SQLiteParameter("@category", card.Category));
                DatabaseHelper.ExecuteNonCommand(command);

                if (overwrite)
                {
                    command = DatabaseHelper.CreateCommand("UPDATE texts" +
                    " SET id= @id,name= @name,desc= @des,str1= @str1,str2= @str2,str3= @str3,str4= @str4,str5= @str5,str6= @str6,str7= @str7,str8= @str8,str9= @str9,str10= @str10,str11= @str11,str12= @str12,str13= @str13,str14= @str14,str15= @str15,str16= @str16 WHERE id= @loadedid", connection);
                }
                else
                {
                    command = DatabaseHelper.CreateCommand("INSERT INTO texts (id,name,desc,str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14,str15,str16)" +
                    " VALUES (@id,@name,@des,@str1,@str2,@str3,@str4,@str5,@str6,@str7,@str8,@str9,@str10,@str11,@str12,@str13,@str14,@str15,@str16)", connection);
                }
                command.Parameters.Add(new SQLiteParameter("@loadedid", loadedid));
                command.Parameters.Add(new SQLiteParameter("@id", card.Id));
                command.Parameters.Add(new SQLiteParameter("@name", card.Name));
                command.Parameters.Add(new SQLiteParameter("@des", card.Description));
                var parameters = new List<SQLiteParameter>();
                for (int i = 0; i < 16; i++)
                {
                    parameters.Add(new SQLiteParameter("@str" + (i + 1), (i < card.EffectStrings.Length ? card.EffectStrings[i].ToString() : string.Empty)));
                }
                command.Parameters.AddRange(parameters.ToArray());
                return DatabaseHelper.ExecuteNonCommand(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK);
                return false;
            }
        }
Exemplo n.º 7
0
 public static void UpdateOrAddCard(CardInfos card)
 {
     if (ContainsCard(card.Id))
     {
         CardData[card.Id] = card;
     }
     else
     {
         CardData.Add(card.Id, card);
     }
 }
Exemplo n.º 8
0
        private void List_DragDrop(object sender, DragEventArgs e)
        {
            var list = (ListBox)sender;
            int indexOfItemUnderMouseToDrop = list.IndexFromPoint(list.PointToClient(new Point(e.X, e.Y)));

            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                int         id       = Int32.Parse(e.Data.GetData(DataFormats.Text).ToString());
                CardInfos   cardinfo = Program.CardData[id];
                BanListCard bancard  = new BanListCard()
                {
                    ID = id, Name = cardinfo.Name, Banvalue = (list == BannedList ? 0:list == LimitedList ? 1:2)
                };


                if (GetBanListCard(id) == null)
                {
                    if (indexOfItemUnderMouseToDrop >= 0 && indexOfItemUnderMouseToDrop < list.Items.Count)
                    {
                        list.Items.Insert(indexOfItemUnderMouseToDrop, bancard);
                    }
                    else
                    {
                        list.Items.Add(bancard);
                    }

                    m_banlists[BanList.SelectedItem.ToString()].Add(bancard);
                }
                else
                {
                    BanListCard foundcard = GetBanListCard(id);

                    if (foundcard.Banvalue == 0)
                    {
                        MessageBox.Show(foundcard.Name + " is already contained in the Banned list.");
                    }
                    else if (foundcard.Banvalue == 1)
                    {
                        MessageBox.Show(foundcard.Name + " is already contained in the Limited list.");
                    }
                    else if (foundcard.Banvalue == 2)
                    {
                        MessageBox.Show(foundcard.Name + " is already contained in the SemiLimited list.");
                    }
                }
            }
        }
Exemplo n.º 9
0
 private void BanTCGBtn_Click(object sender, EventArgs e)
 {
     foreach (int id in CardManager.GetKeys())
     {
         CardInfos card = CardManager.GetCard(id);
         if (card.Ot == 2)
         {
             if (GetBanListCard(id) == null)
             {
                 BanListCard bancard = new BanListCard {
                     ID = id, Banvalue = 0, Name = card.Name
                 };
                 BannedList.Items.Add(bancard);
                 m_banlists[BanList.SelectedItem.ToString()].Add(bancard);
             }
         }
     }
 }
Exemplo n.º 10
0
 private void OpenScriptBtn_Click(object sender, EventArgs e)
 {
     if (m_loadedCard != 0)
     {
         string file = "script\\c" + m_loadedCard + ".lua";
         if (File.Exists(file))
         {
             Process.Start(file);
         }
         else
         {
             if (Program.CardData.ContainsKey(m_loadedCard))
             {
                 CardInfos card  = Program.CardData[m_loadedCard];
                 string[]  lines = { "--" + card.Name, "function c" + m_loadedCard + ".initial_effect(c)", string.Empty, "end" };
                 File.WriteAllLines(file, lines);
                 Process.Start(file);
             }
         }
     }
 }
Exemplo n.º 11
0
        private void NewIDList_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);

            int index = e.Index;

            if (index >= 0 && index < UpdateCardsList.Items.Count)
            {
                var      data = (string[])UpdateCardsList.Items[index];
                Graphics g    = e.Graphics;

                CardInfos card = Program.CardData[Int32.Parse(data[0])];

                g.FillRectangle((selected) ? new SolidBrush(Color.Blue) : new SolidBrush(Color.White), e.Bounds);

                // Print text
                g.DrawString((card.Name == "" ? "???" : card.Name) + "   -  " + data[0] + " > " + data[1], e.Font, (selected) ? Brushes.White : Brushes.Black,
                             UpdateCardsList.GetItemRectangle(index).Location);
            }

            e.DrawFocusRectangle();
        }
Exemplo n.º 12
0
        private bool SaveCardtoCDB(string cdbpath)
        {
            int cardid;
            int cardalias;
            int atk;
            int def;
            int ot = (CardFormats.SelectedItem == null ? 0 : GetCardFormat());
            if(chkPre.Checked)
                ot |= 0x4;

            if (!Int32.TryParse(CardID.Text, out cardid))
            {
                MessageBox.Show("Invalid card id");
                return false;
            }

            int updatecard = m_loadedCard == 0 ? cardid : m_loadedCard;

            if (!Int32.TryParse(Alias.Text, out cardalias))
            {
                cardalias = 0;
            }
            if (!Int32.TryParse(ATK.Text, out atk))
            {
                MessageBox.Show("Invalid atk value");
                return false;
            }
            if (!Int32.TryParse(DEF.Text, out def))
            {
                MessageBox.Show("Invalid def value");
                return false;
            }
            if (CDBSelect.Items.Count == 0)
            {
                MessageBox.Show("No loaded database");
                return false;
            }

            CardInfos newCardInfo = new CardInfos(new[] { cardid.ToString(CultureInfo.InvariantCulture), (ot.ToString(CultureInfo.InvariantCulture)),cardalias.ToString(CultureInfo.InvariantCulture),GetSetCode().ToString(CultureInfo.InvariantCulture),GetTypeCode().ToString(CultureInfo.InvariantCulture),
                GetLevelCode().ToString(), (Race.SelectedItem == null ? "0" : (Race.SelectedItem == null ? "0" : m_cardRaces[Race.SelectedIndex].ToString(CultureInfo.InvariantCulture))),
                (CardAttribute.SelectedItem == null ? "0" : (CardAttribute.SelectedItem == null ? "0" : m_cardAttributes[CardAttribute.SelectedIndex].ToString(CultureInfo.InvariantCulture))),atk.ToString(CultureInfo.InvariantCulture),def.ToString(CultureInfo.InvariantCulture),GetCategoryNumber().ToString(CultureInfo.InvariantCulture)}
            , CDBSelect.SelectedIndex + 1);

            var cardtextarray = new List<string> { cardid.ToString(CultureInfo.InvariantCulture), CardName.Text, CardDescription.Text };

            for (var i = 0; i < 17; i++)
            {
                cardtextarray.Add((i < EffectList.Items.Count ? EffectList.Items[i].ToString() : string.Empty));
            }

            newCardInfo.SetCardText(cardtextarray.ToArray());

            //check source DB

            if (CardManager.ContainsCard(cardid))
            {
                if (CardManager.GetCard(cardid).source != newCardInfo.source)
                {
                    if(MessageBox.Show("Copy to new database?","",MessageBoxButtons.YesNo) != DialogResult.Yes)
                        return false;
                }
            }

            //save/update card
            var connection = new SQLiteConnection("Data Source=" + CardManager.GetDatabaseDir(newCardInfo.source));
            connection.Open();
            //check if card id exsists
            bool overwrite = SQLiteCommands.ContainsCard(updatecard, connection);

            if (overwrite)
            {
                if (MessageBox.Show("Overwrite current card?", "Found", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    connection.Close();
                    return false;
                }
            }

            SQLiteCommands.SaveCard(newCardInfo, connection, updatecard, overwrite);

            connection.Close();

            if (cardid != updatecard)
                CardManager.RenameKey(updatecard, cardid);

            CardManager.UpdateOrAddCard(newCardInfo);

            MessageBox.Show("Card Saved");
            return true;
        }
Exemplo n.º 13
0
        private bool LoadCard(int cardid)
        {
            if (!Program.CardData.ContainsKey(cardid))
            {
                return(false);
            }

            Clearbtn_Click(null, EventArgs.Empty);
            CardInfos info = Program.CardData[cardid];

            CardID.Text = info.Id.ToString(CultureInfo.InvariantCulture);
            Alias.Text  = info.AliasId.ToString(CultureInfo.InvariantCulture);
            for (int i = 0; i < m_formats.Count; i++)
            {
                if (m_formats[i] == info.Ot)
                {
                    CardFormats.SelectedIndex = i;
                    break;
                }
            }
            Level.SelectedIndex  = (int)info.Level - 1;
            RScale.SelectedIndex = (int)info.RScale;
            LScale.SelectedIndex = (int)info.LScale;
            for (int i = 0; i < m_cardRaces.Count; i++)
            {
                if (m_cardRaces[i] == info.Race)
                {
                    Race.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < m_cardAttributes.Count; i++)
            {
                if (m_cardAttributes[i] == info.Attribute)
                {
                    CardAttribute.SelectedIndex = i;
                    break;
                }
            }
            ATK.Text             = info.Atk.ToString(CultureInfo.InvariantCulture);
            DEF.Text             = info.Def.ToString(CultureInfo.InvariantCulture);
            CardName.Text        = info.Name;
            CardDescription.Text = info.Description;
            foreach (string effect in info.EffectStrings)
            {
                EffectList.Items.Add(effect);
            }
            SetCardTypes(info.GetCardTypes());

            long setcode = info.SetCode & 0xffff;

            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeOne.SelectedItem = m_setCodes[(int)setcode];
            }
            else
            {
                SetCodeOne.SelectedItem = m_setCodes[0];
            }
            setcode = info.SetCode >> 16 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeTwo.SelectedItem = m_setCodes[(int)setcode];
            }
            else
            {
                SetCodeTwo.SelectedItem = m_setCodes[0];
            }
            setcode = info.SetCode >> 32 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeThree.SelectedItem = m_setCodes[(int)setcode];
            }
            else
            {
                SetCodeThree.SelectedItem = m_setCodes[0];
            }
            setcode = info.SetCode >> 48 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeFour.SelectedItem = m_setCodes[(int)setcode];
            }
            else
            {
                SetCodeFour.SelectedItem = m_setCodes[0];
            }
            SetCategoryCheckBoxs(info.Category);

            m_loadedCard = info.Id;

            return(true);
        }
Exemplo n.º 14
0
        private bool SaveCardtoCDB(string cdbpath)
        {
            int cardid;
            int cardalias;
            int atk;
            int def;
            int ot = (CardFormats.SelectedItem == null ? 0 : GetCardFormat());

            if (chkPre.Checked)
            {
                ot |= 0x4;
            }

            if (!Int32.TryParse(CardID.Text, out cardid))
            {
                MessageBox.Show("Invalid card id");
                return(false);
            }

            int updatecard = m_loadedCard == 0 ? cardid : m_loadedCard;

            if (!Int32.TryParse(Alias.Text, out cardalias))
            {
                cardalias = 0;
            }
            if (!Int32.TryParse(ATK.Text, out atk))
            {
                MessageBox.Show("Invalid atk value");
                return(false);
            }
            if (!Int32.TryParse(DEF.Text, out def))
            {
                MessageBox.Show("Invalid def value");
                return(false);
            }
            if (CDBSelect.Items.Count == 0)
            {
                MessageBox.Show("No loaded database");
                return(false);
            }

            CardInfos newCardInfo = new CardInfos(new[] { cardid.ToString(CultureInfo.InvariantCulture), (ot.ToString(CultureInfo.InvariantCulture)), cardalias.ToString(CultureInfo.InvariantCulture), GetSetCode().ToString(CultureInfo.InvariantCulture), GetTypeCode().ToString(CultureInfo.InvariantCulture),
                                                          GetLevelCode().ToString(), (Race.SelectedItem == null ? "0" : (Race.SelectedItem == null ? "0" : m_cardRaces[Race.SelectedIndex].ToString(CultureInfo.InvariantCulture))),
                                                          (CardAttribute.SelectedItem == null ? "0" : (CardAttribute.SelectedItem == null ? "0" : m_cardAttributes[CardAttribute.SelectedIndex].ToString(CultureInfo.InvariantCulture))), atk.ToString(CultureInfo.InvariantCulture), def.ToString(CultureInfo.InvariantCulture), GetCategoryNumber().ToString(CultureInfo.InvariantCulture) }
                                                  , CDBSelect.SelectedIndex + 1);

            var cardtextarray = new List <string> {
                cardid.ToString(CultureInfo.InvariantCulture), CardName.Text, CardDescription.Text
            };

            for (var i = 0; i < 17; i++)
            {
                cardtextarray.Add((i < EffectList.Items.Count ? EffectList.Items[i].ToString() : string.Empty));
            }

            newCardInfo.SetCardText(cardtextarray.ToArray());

            if (CardTypeList.CheckedItems.Contains("Link"))
            {
                newCardInfo.Def = GetLinkMarkers();
            }

            //check source DB

            if (CardManager.ContainsCard(cardid))
            {
                if (CardManager.GetCard(cardid).source != newCardInfo.source)
                {
                    if (MessageBox.Show("Copy to new database?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return(false);
                    }
                }
            }


            //save/update card
            var connection = new SQLiteConnection("Data Source=" + CardManager.GetDatabaseDir(newCardInfo.source));

            connection.Open();
            //check if card id exsists
            bool overwrite = SQLiteCommands.ContainsCard(updatecard, connection);

            if (overwrite)
            {
                if (MessageBox.Show("Overwrite current card?", "Found", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    connection.Close();
                    return(false);
                }
            }

            SQLiteCommands.SaveCard(newCardInfo, connection, updatecard, overwrite);

            connection.Close();

            if (cardid != updatecard)
            {
                CardManager.RenameKey(updatecard, cardid);
            }

            CardManager.UpdateOrAddCard(newCardInfo);

            MessageBox.Show("Card Saved");
            return(true);
        }
Exemplo n.º 15
0
        private bool LoadCard(int cardid)
        {
            if (!CardManager.ContainsCard(cardid))
            {
                return(false);
            }

            Clearbtn_Click(null, EventArgs.Empty);
            CardInfos info = CardManager.GetCard(cardid);

            CardID.Text = info.Id.ToString(CultureInfo.InvariantCulture);
            Alias.Text  = info.AliasId.ToString(CultureInfo.InvariantCulture);
            for (int i = 0; i < m_formats.Count; i++)
            {
                if (m_formats[i] == (info.Ot & 0x3))
                {
                    CardFormats.SelectedIndex = i;
                    break;
                }
            }
            Level.SelectedIndex  = (int)info.Level - 1;
            RScale.SelectedIndex = (int)info.RScale;
            LScale.SelectedIndex = (int)info.LScale;
            for (int i = 0; i < m_cardRaces.Count; i++)
            {
                if (m_cardRaces[i] == info.Race)
                {
                    Race.SelectedIndex = i;
                    break;
                }
            }
            for (int i = 0; i < m_cardAttributes.Count; i++)
            {
                if (m_cardAttributes[i] == info.Attribute)
                {
                    CardAttribute.SelectedIndex = i;
                    break;
                }
            }
            ATK.Text       = info.Atk.ToString(CultureInfo.InvariantCulture);
            DEF.Text       = info.Def.ToString(CultureInfo.InvariantCulture);
            chkPre.Checked = (info.Ot & 0x4) > 0;

            CardName.Text        = info.Name;
            CardDescription.Text = info.Description;
            foreach (string effect in info.EffectStrings)
            {
                EffectList.Items.Add(effect);
            }
            SetCardTypes(info.GetCardTypes());
            if (CardTypeList.CheckedItems.Contains("Link"))
            {
                SetCardMarkers(info.GetLinkMarkers());
                linkMarkerPanel.Enabled = true;
            }

            long setcode = info.SetCode & 0xffff;

            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeOne.SelectedItem = (int)setcode;
            }
            else
            {
                SetCodeOne.SelectedItem = m_setCodes[0];
            }
            setcode = info.SetCode >> 16 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeTwo.SelectedItem = (int)setcode;
            }
            else
            {
                SetCodeTwo.SelectedItem = m_setCodes[0];
            }
            setcode = info.SetCode >> 32 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeThree.SelectedItem = (int)setcode;
            }
            else
            {
                SetCodeThree.SelectedItem = 0;
            }
            setcode = info.SetCode >> 48 & 0xffff;
            if (m_setCodes.ContainsKey((int)setcode))
            {
                SetCodeFour.SelectedItem = (int)setcode;
            }
            else
            {
                SetCodeFour.SelectedItem = m_setCodes[0];
            }
            SetCategoryCheckBoxs(info.Category);

            m_loadedCard = info.Id;

            CDBSelect.SelectedIndex = info.source - 1;

            return(true);
        }
Exemplo n.º 16
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            ConvertButton.Enabled = false;
            bool            updateCdb    = cdbchk.Checked;
            bool            updateScript = patchchk.Checked;
            bool            updateImage  = imagechk.Checked;
            List <string[]> updateCards  = UpdateCardsList.Items.OfType <string[]>().ToList();

            if (patchchk.Checked)
            {
                if (!Directory.Exists("DevPatch"))
                {
                    Directory.CreateDirectory("DevPatch");
                }
                if (!Directory.Exists("DevPatch\\script"))
                {
                    Directory.CreateDirectory("DevPatch\\script");
                }
                if (!Directory.Exists("DevPatch\\pics"))
                {
                    Directory.CreateDirectory("DevPatch\\pics");
                }
                if (!Directory.Exists("DevPatch\\pics\\thumbnail"))
                {
                    Directory.CreateDirectory("DevPatch\\pics\\thumbnail");
                }
            }

            string str = "cards.cdb";

            foreach (var updateCard in updateCards)
            {
                if (updateCdb)
                {
                    if (!File.Exists(str))
                    {
                        MessageBox.Show("cards.cdb not found.");
                        return;
                    }

                    int cardid = Int32.Parse(updateCard[0]);
                    int newid  = Int32.Parse(updateCard[1]);
                    CardManager.RenameKey(cardid, newid);

                    CardInfos card = CardManager.GetCard(newid);
                    card.Id = newid;
                    if (chkremovepre.Checked)
                    {
                        card.Ot = card.Ot & 0x03;
                    }

                    CardManager.UpdateOrAddCard(card);

                    var connection = new SQLiteConnection("Data Source=" + str);
                    connection.Open();

                    SQLiteCommands.UpdateCardId(updateCard[0], updateCard[1], connection);
                    if (chkremovepre.Checked)
                    {
                        SQLiteCommands.UpdateCardOt(updateCard[1], card.Ot.ToString(), connection);
                    }

                    connection.Close();
                }

                if (updateImage)
                {
                    string       mainDir            = Directory.GetCurrentDirectory();;
                    const string picFolderName      = "pics";
                    const string tumbnailFolderName = "pics\\thumbnail";
                    string       picName            = updateCard[0] + ".png";
                    string       newPicName         = updateCard[1] + ".png";

                    string imagePath             = Path.Combine(mainDir, picFolderName, picName);
                    string newImagePath          = Path.Combine(mainDir, picFolderName, newPicName);
                    string thumbnailImagePath    = Path.Combine(mainDir, tumbnailFolderName, picName);
                    string newthumbnailImagePath = Path.Combine(mainDir, tumbnailFolderName, newPicName);

                    if (File.Exists(imagePath) && !File.Exists(newImagePath))
                    {
                        File.Move(imagePath, newImagePath);
                    }
                    if (File.Exists(thumbnailImagePath) && !File.Exists(newthumbnailImagePath))
                    {
                        File.Move(thumbnailImagePath, newthumbnailImagePath);
                    }
                    if (patchchk.Checked)
                    {
                        if (File.Exists(newImagePath))
                        {
                            File.Copy(newImagePath, Path.Combine("DevPatch\\pics", newPicName), true);
                        }
                        if (File.Exists(newthumbnailImagePath))
                        {
                            File.Copy(newthumbnailImagePath, Path.Combine("DevPatch\\pics\\thumbnail", newPicName), true);
                        }
                    }
                }

                if (updateScript)
                {
                    string       mainDir          = Directory.GetCurrentDirectory();;
                    const string scriptFolderName = "script";
                    string       scriptName       = "c" + updateCard[0] + ".lua";
                    string       newScriptName    = "c" + updateCard[1] + ".lua";

                    string scriptPath    = Path.Combine(mainDir, scriptFolderName, scriptName);
                    string newScriptPath = Path.Combine(mainDir, scriptFolderName, newScriptName);

                    if (File.Exists(scriptPath))
                    {
                        File.Move(scriptPath, newScriptPath);

                        //needs testing id replacing
                        string scriptFile = File.ReadAllText(newScriptPath);
                        scriptFile = scriptFile.Replace(updateCard[0], updateCard[1]);
                        File.WriteAllText(newScriptPath, scriptFile);

                        if (patchchk.Checked)
                        {
                            if (File.Exists(newScriptPath))
                            {
                                File.Copy(newScriptPath, Path.Combine("DevPatch\\script", newScriptName), true);
                            }
                        }
                    }
                }
            }
            if (patchchk.Checked)
            {
                File.Copy(str, "DevPatch\\cards.cdb", true);
            }
            UpdateCardsList.Items.Clear();
            MessageBox.Show("Complete.");
            ConvertButton.Enabled = true;
        }