コード例 #1
0
        private void pictureBox27_Click(object sender, EventArgs e)
        {
            this.Hide();
            english f = new english(s);

            f.Show();
        }
コード例 #2
0
ファイル: player.cs プロジェクト: shironthanda/JJ-Editor
        private void itemBox_TextChanged_1(object sender, EventArgs e)
        {
            english englishItems = JsonConvert.DeserializeObject <english>(englishJson);

            itemList.BeginUpdate();
            itemList.Items.Clear();
            if (itemBox.Text != null)
            {
                for (int i = 1; i < englishItems.treasures.Count; i++)
                {
                    if (englishNames[i].ToString().Contains(itemBox.Text))
                    {
                        itemList.Items.Add(englishNames[i].ToString());
                        if (orderOption == true)
                        {
                            itemList.Sorted = true;
                        }
                    }
                }
                itemList.EndUpdate();
            }
            else
            {
                itemList.Items.Clear();
            }
        }
コード例 #3
0
        public static english TranslateEnglishWordModel(EnglishWordModel model)
        {
            english english = new english();

            english.id         = model.Id;
            english.word       = model.Word;
            english.commentary = model.Commentary;

            return(english);
        }
コード例 #4
0
        /// <summary>
        /// 将english 转换成 EnglishWordModel
        /// </summary>
        /// <param name="english"></param>
        /// <returns></returns>
        public static EnglishWordModel TranslateEnglish(english english)
        {
            if (english == null)
            {
                return(null);
            }

            EnglishWordModel model = new EnglishWordModel();

            model.Id             = english.id;
            model.Word           = english.word;
            model.Commentary     = english.commentary;
            model.Sentence       = english.sentence;
            model.ReviewTurn     = (ReviewTurn)english.review_turn; // 复习轮数
            model.CreateTime     = english.create_time;
            model.LastReviewTime = english.last_review_time;
            model.NextReviewTime = english.next_review_time;
            model.English        = english; // 元数据

            return(model);
        }
コード例 #5
0
ファイル: player.cs プロジェクト: shironthanda/JJ-Editor
        void writeToPlayer()
        {
            timer2.Interval = 2000;
            timer2.Tick    += timer2_Tick;
            timer2.Start();
            saveToolStripMenuItem2.Enabled = false;

            main m = (main)this.MdiParent;
            var  s = m.statusLabelPlayer;

            s.Text = "Player file saved!";

            // Write all changed values to file
            using (var bw = new BinaryWriter(File.OpenWrite(playerFile)))
            {
                playerName = nameText.Text;

                // Clear all name characters
                for (int i = 0x57; i <= 0x66; i++)
                {
                    bw.BaseStream.Position = i;
                    bw.Write(0x00);
                }
                // Write player name
                bw.BaseStream.Position = 0x57;
                bw.Write(playerName);

                // Write health
                bw.BaseStream.Position = 0x538;
                if (healthBox.Value == 0xFFFF)
                {
                    byte[] invincible = { 0x00, 0x00, 0xFF, 0xFF };
                    bw.Write(invincible);
                }
                else
                {
                    health = (int)healthBox.Value;
                    float  hFloat      = Convert.ToSingle(health);
                    byte[] healthBytes = BitConverter.GetBytes(hFloat);
                    bw.Write(healthBytes);
                }

                // Write characteristics
                // Hair color
                byte shiftValue = 4;
                bw.BaseStream.Position = 0x74;
                colorValue             = Convert.ToByte((colorBox.SelectedItem as dynamic).Value);
                bw.Write((byte)(colorValue << shiftValue));

                // Gender
                // 0 2 4 6 8 male
                // 1 3 5 6 7 female
                bw.BaseStream.Position = 0x75;

                switch (toneBox.SelectedValue)
                {
                case 1:     // Very Light
                    if (genderBox.SelectedValue == male)
                    {
                        skinID = 0;
                    }
                    else
                    {
                        skinID = 1;
                    }
                    break;

                case 2:     // Light
                    if (genderBox.SelectedValue == male)
                    {
                        skinID = 2;
                    }
                    else
                    {
                        skinID = 3;
                    }
                    break;

                case 3:     // Tan
                    if (genderBox.SelectedValue == male)
                    {
                        skinID = 4;
                    }
                    else
                    {
                        skinID = 5;
                    }
                    break;

                case 4:     // Dark
                    if (genderBox.SelectedValue == male)
                    {
                        skinID = 6;
                    }
                    else
                    {
                        skinID = 7;
                    }
                    break;

                case 5:     // very Dark
                    if (genderBox.SelectedValue == male)
                    {
                        skinID = 8;
                    }
                    else
                    {
                        skinID = 9;
                    }
                    break;
                }

                //bw.Write((byte)(genderValue << shiftValue));

                // Hair style
                bw.BaseStream.Position = 0x75;
                styleValue             = Convert.ToByte((styleBox.SelectedItem as dynamic).Value);
                bw.Write((byte)((skinID << shiftValue)) | (styleValue & 0x0F));

                readHex();

                // Write armor values
                void writeOffset(int start, TextBox textbox = null, NumericUpDown itemAmount = null)
                {
                    int id = 65535;

                    bw.BaseStream.Position = start;

                    english englishItems = JsonConvert.DeserializeObject <english>(englishJson);

                    if (textbox != null)
                    {
                        if (textbox.Text == "")
                        {
                            id = 65535;
                        }
                        else
                        {
                            foreach (var item in englishItems.treasures)
                            {
                                englishID   = item.id;
                                englishName = item.name;

                                if (textbox.Text == englishName)
                                {
                                    id = englishID;
                                    //id = int.Parse(textbox.Text);
                                }
                            }
                        }
                        IDToHex.idToHex(id);
                        bw.Write(id);
                    }
                    else if (textbox == null)
                    {
                        id = int.Parse(numericUpDown1.Value.ToString());
                        IDToHex.idToHex(id);
                        bw.Write(id);
                    }
                    bw.BaseStream.Position = start + 6; // For toggle render
                    bw.Write(0x00);
                }

                writeOffset(helm, helmText);
                writeOffset(chest, chestText);
                writeOffset(legs, legsText);
                writeOffset(feet, feetText);

                // Write treeview values
                if (treeView1.SelectedNode == null)
                {
                    return;
                }
                else
                {
                    if (itemBox.Text == "")
                    {
                        treeView1.SelectedNode.Text = "[Empty]";
                        numericUpDown1.Value        = 0;
                    }
                    else if (itemBox.Text == "0")
                    {
                        treeView1.SelectedNode.Text = "[Empty]";
                        numericUpDown1.Value        = 0;
                    }
                    treeView1.SelectedNode.Text = itemBox.Text;

                    // Invenory items
                    for (var i = 0; i < hots.Length; i++)
                    {
                        int[] tag = { hots[i], hotsAmount[i] };
                        treeView1.Nodes[0].Nodes[i].Tag = tag[0]; //hots[i];
                    }
                    for (var i = 0; i < slots.Length; i++)
                    {
                        int[] tag = { slots[i], slotsAmount[i] };
                        treeView1.Nodes[1].Nodes[i].Tag = tag[0];
                    }

                    int selectedItem = Convert.ToInt32(treeView1.SelectedNode.Tag);
                    writeOffset(selectedItem, itemBox);

                    // Item amounts
                    for (var i = 0; i < hots.Length; i++)
                    {
                        int[] tag = { hots[i], hotsAmount[i] };
                        treeView1.Nodes[0].Nodes[i].Tag = tag[1]; //hots[i];
                    }
                    for (var i = 0; i < slots.Length; i++)
                    {
                        int[] tag = { slots[i], slotsAmount[i] };
                        treeView1.Nodes[1].Nodes[i].Tag = tag[1];
                    }
                    selectedAmount = Convert.ToInt32(treeView1.SelectedNode.Tag);
                    writeOffset(selectedAmount, null, numericUpDown1);
                }
            }

            // Read to itemAmount again
            using (var br = new BinaryReader(File.OpenRead(playerFile)))
            {
                var treeHots = treeView1.Nodes[0];
                for (var i = 0; i < hots.Length; i++)
                {
                    //readOffset(hots[i], hotsEnds[i], hotNames[i], null, treeHots, null, br);
                    readOffset(hotsAmount[i], hotsAmountEnds[i], hotNames[i], null, null, numericUpDown1, br);
                    //treeHots.Tag = hots[i];

                    if (numericUpDown1.Value > numericUpDown1.Maximum)
                    {
                        numericUpDown1.Value = 0xFFFF;
                    }
                    //int[] tag = { hots[i], hotsAmount[i] };
                    treeView1.Nodes[0].Nodes[i].Tag = tags[i];
                }
                tags.Clear();
                var treeSlots = treeView1.Nodes[1];
                for (var i = 0; i < slots.Length; i++)
                {
                    //readOffset(slots[i], slotsEnds[i], slotNames[i], null, treeSlots, null, br);
                    readOffset(slotsAmount[i], slotsAmountEnds[i], null, null, null, numericUpDown1, br);
                    //treeSlots.Tag = slots[i];

                    if (numericUpDown1.Value > numericUpDown1.Maximum)
                    {
                        numericUpDown1.Value = 0xFFFF;
                    }
                    //int[] tag = { slots[i], slotsAmount[i] };
                    treeView1.Nodes[1].Nodes[i].Tag = tags[i];
                }
                tags.Clear();
            }
        }
コード例 #6
0
ファイル: player.cs プロジェクト: shironthanda/JJ-Editor
        // Reads offsets for items
        void readOffset(int start, int end, string offset, TextBox textbox = null, TreeNode treeView = null, NumericUpDown itemAmount = null, BinaryReader br = null)
        {
            char[] characters = null;
            for (int i = start; i <= end; i++)
            {
                br.BaseStream.Position = i;
                offset += br.ReadByte().ToString("X2");
            }

            characters = offset.ToCharArray();
            HexToID.hexToID(characters);
            string hexID = new string(characters);

            bool isEmpty = false;

            if (hexID == "FFFF")
            {
                isEmpty = true;
            }
            else if (hexID.EndsWith("0"))
            {
                hexID = hexID.Substring(0, hexID.Length - 1);
            }

            int itemID = Convert.ToInt32(hexID, 16);

            english englishItems = JsonConvert.DeserializeObject <english>(englishJson);

            foreach (var item in englishItems.treasures)
            {
                englishIDs.Add(item.id);
                englishNames.Add(item.name);
                //itemNames.Add(item.name);
            }

            if (textbox != null && isEmpty)
            {
                textbox.Text = null;
            }

            treeView1.BeginUpdate();
            if (treeView != null && isEmpty)
            {
                treeView.Nodes.Add("[Empty]");
            }

            for (int i = 0; i < englishItems.treasures.Count; i++)
            {
                englishIDs.Add(englishItems.treasures[i].id);
                englishNames.Add(englishItems.treasures[i].name);

                if ((textbox != null))
                {
                    int eID = Convert.ToInt32(englishIDs[i]);
                    if (itemID == eID)
                    {
                        textbox.Text = englishNames[i].ToString();
                    }
                }

                if ((treeView != null))
                {
                    int eID = Convert.ToInt32(englishIDs[i]);
                    if (itemID == eID)
                    {
                        treeView.Nodes.Add(englishNames[i].ToString());
                    }
                }
                treeView1.EndUpdate();
            }
            if (itemAmount != null)
            {
                //itemAmount.Tag = itemID;
                tags.Add(itemID);
            }
        }
コード例 #7
0
        private void AddWords(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            List <english> englishes = new List <english>();

            try
            {
                string[] lines = text.Split("\n".ToCharArray());

                string   regexStr = @"(\d{0,4})\s*年\s*(\d{0,2})\s*月\s*(\d{0,2})\s*日"; // 正则表达式
                DateTime date     = DateTime.Now.Date;

                foreach (var line in lines)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }
                    Regex regex = new Regex(regexStr);
                    var   match = regex.Match(line);

                    // 如果时候时间行
                    if (match.Success)
                    {
                        var groups = match.Groups;

                        if (groups.Count == 4)
                        {
                            string year  = groups[1].Value;
                            string month = groups[2].Value;
                            string day   = groups[3].Value;

                            string datestr = $"{year}/{month}/{day}";

                            DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();

                            dtFormat.ShortDatePattern = "yyyy/MM/dd";

                            date = Convert.ToDateTime(datestr, dtFormat); // 修改时间
                        }
                    }
                    // 如果是单词行
                    else
                    {
                        // hello 你好 --- Hello, how are you today?
                        try
                        {
                            string[] words     = line.Split(new string[] { "---" }, StringSplitOptions.RemoveEmptyEntries);
                            string   firstword = words[0].Substring(1).Trim();
                            int      index     = firstword.IndexOf(" ");
                            string   word      = firstword.Substring(0, index).Trim();
                            string   comment   = firstword.Substring(index + 1).Trim();
                            string   sentence  = words[1].Trim();

                            english english = new english()
                            {
                                word             = word,
                                commentary       = comment,
                                sentence         = sentence,
                                create_time      = date,
                                last_review_time = date, // 默认一天后开始复习
                                next_review_time = date.AddDays(1),
                                review_turn      = 0,
                                delete_flag      = 0,
                            };

                            englishes.Add(english);
                        }
                        catch (System.Exception ex)
                        {
                            Logger.Info(ex.Message);
                        }
                    }
                }


                if (englishes.Count > 0)
                {
                    using (MyContext context = new MyContext())
                    {
                        var ret = context.Englishes;
                        ret.AddRange(englishes);
                        context.SaveChanges();
                    }
                }
            }
            catch (System.Exception e)
            {
                Logger.Info(e.Message);
            }
        }
コード例 #8
0
        private void Dispose()
        {
            // 保存
            var englishModels = ViewModel.EnglishWords;
            var changedModels = from model in englishModels where model.IsReviewed select model;

            foreach (var model in changedModels)
            {
                english english = model.English;
                if (english == null)
                {
                    continue;
                }
                // 改变时间
                english.last_review_time = DateTime.Today;
                int      addDays  = 0;
                int      nextTurn = (int)model.ReviewTurn;
                DateTime time     = DateTime.Today;
                switch (model.ReviewTurn)
                {
                case ReviewTurn.FIRST:
                    time = time.AddDays(2);
                    break;

                case ReviewTurn.SECOND:
                    time = time.AddDays(4);
                    break;

                case ReviewTurn.THIRD:
                    time = time.AddDays(7);
                    break;

                case ReviewTurn.FOURTH:
                    time = time.AddDays(7);
                    break;

                case ReviewTurn.FIFTH:
                    time = time.AddDays(39);
                    break;

                case ReviewTurn.SIXTH:
                    time = time.AddDays(300);
                    break;

                case ReviewTurn.SEVENTH:
                    time = time.AddDays(365);
                    break;

                case ReviewTurn.OVER:
                    break;

                default:
                    break;
                }

                nextTurn++;
                if (nextTurn > (int)ReviewTurn.OVER)
                {
                    nextTurn = (int)ReviewTurn.OVER;
                }

                english.review_turn      = nextTurn;
                english.next_review_time = time;
            }

            var context = ServiceLocator.Current.GetInstance <MyContext>();

            context.SaveChanges();
        }