Exemple #1
0
        private void SetYotogiUsedTimes(object sender, EventArgs e)
        {
            uint       v;
            TextDialog td = new TextDialog(Translation.GetTranslation("GUI_YOTOGI_TIMES_TITLE"),
                                           Translation.GetTranslation("GUI_YOTOGI_TIMES_PROMPT"), "0",
                                           s => uint.TryParse(s, out v), Translation.GetTranslation("OK"),
                                           Translation.GetTranslation("CANCEL"))
            {
                StartPosition = FormStartPosition.CenterParent
            };
            DialogResult dr = td.ShowDialog(this);

            Debugger.WriteLine(LogLevel.Info, $"Prompt result: {EnumHelper.GetName(dr)}, {td.Input}");

            if (dr != DialogResult.OK)
            {
                return;
            }
            v = uint.Parse(td.Input);
            td.Dispose();

            MaidInfo maid = SelectedMaid;

            foreach (var skill in
                     Yotogi.skill_data_list.SelectMany(ee => ee).Where(ss => maid.Maid.Param.status.IsGetSkill(ss.Key)))
            {
                maid.Maid.Param.status_.skill_data[skill.Key].play_count = v;
                maid.UpdateSkillData(skill.Value.id);
            }
        }
Exemple #2
0
        private void SetClassLevel(object sender, EventArgs e)
        {
            Debugger.WriteLine(LogLevel.Info, "Prompting class level set.");
            uint       v;
            TextDialog td = new TextDialog(Translation.GetTranslation("GUI_CLASS_LVL_TITLE"),
                                           Translation.GetTranslation("GUI_CLASS_LVL_PROMPT"), "0",
                                           s => uint.TryParse(s, out v) && (v <= 10), Translation.GetTranslation("OK"),
                                           Translation.GetTranslation("CANCEL"))
            {
                StartPosition = FormStartPosition.CenterParent
            };
            DialogResult dr = td.ShowDialog(this);

            Debugger.WriteLine(LogLevel.Info, $"Prompt result: {EnumHelper.GetName(dr)}, {td.Input}");

            if (dr != DialogResult.OK)
            {
                return;
            }
            v = uint.Parse(td.Input);
            int val = (int)v;

            td.Dispose();

            MaidInfo selected = SelectedMaid;
            Maid     maid     = selected.Maid;

            for (int maidClass = 0; maidClass < EnumHelper.MaxMaidClass; maidClass++)
            {
                SetClassIsHave(maid, "maid_class_data", maidClass, true);
                SetClassLevel(maid, "maid_class_data", maidClass, val);
            }
            selected.UpdateMaidClasses();

            foreach (int yotogiClass in EnumHelper.EnabledYotogiClasses)
            {
                SetClassIsHave(maid, "yotogi_class_data", yotogiClass, true);
                SetClassLevel(maid, "yotogi_class_data", yotogiClass, val);
            }

            selected.UpdateYotogiClasses();
        }
        private void SetClassLevel(object sender, EventArgs e)
        {
            Debugger.WriteLine(LogLevel.Info, "Prompting class level set.");
            uint v;
            TextDialog td = new TextDialog(Translation.GetTranslation("GUI_CLASS_LVL_TITLE"),
                                           Translation.GetTranslation("GUI_CLASS_LVL_PROMPT"), "0",
                                           s => uint.TryParse(s, out v) && (v <= 10), Translation.GetTranslation("OK"),
                                           Translation.GetTranslation("CANCEL"))
            {
                StartPosition = FormStartPosition.CenterParent
            };
            DialogResult dr = td.ShowDialog(this);
            Debugger.WriteLine(LogLevel.Info, $"Prompt result: {EnumHelper.GetName(dr)}, {td.Input}");

            if (dr != DialogResult.OK)
                return;
            v = uint.Parse(td.Input);
            int val = (int) v;
            td.Dispose();

            MaidInfo selected = SelectedMaid;
            Maid maid = selected.Maid;

            for (int maidClass = 0; maidClass < EnumHelper.MaxMaidClass; maidClass++)
            {
                SetClassIsHave(maid, "maid_class_data", maidClass, true);
                SetClassLevel(maid, "maid_class_data", maidClass, val);
            }
            selected.UpdateMaidClasses();

            foreach (int yotogiClass in EnumHelper.EnabledYotogiClasses)
            {
                SetClassIsHave(maid, "yotogi_class_data", yotogiClass, true);
                SetClassLevel(maid, "yotogi_class_data", yotogiClass, val);
            }

            selected.UpdateYotogiClasses();
        }
        private void SetClassLevel(object sender, EventArgs e)
        {
            Debugger.WriteLine(LogLevel.Info, "Prompting class level set.");
            uint v;
            TextDialog td = new TextDialog(
            Resources.GetFieldText("GUI_CLASS_LVL_TITLE"),
            Resources.GetFieldText("GUI_CLASS_LVL_PROMPT"),
            "0",
            s => uint.TryParse(s, out v) && v <= 10,
            Resources.GetFieldText("OK"),
            Resources.GetFieldText("CANCEL")) {StartPosition = FormStartPosition.CenterParent};
            DialogResult dr = td.ShowDialog(this);
            Debugger.WriteLine(LogLevel.Info, $"Prompt result: {EnumHelper.GetName(dr)}, {td.Input}");

            if (dr != DialogResult.OK)
                return;
            v = uint.Parse(td.Input);
            int val = (int) v;
            td.Dispose();

            MaidInfo selected = SelectedMaid;
            Maid maid = selected.Maid;

            for (int maidClass = 0; maidClass < (int) EnumHelper.MaxMaidClass; maidClass++)
            {
                maid.Param.status_.maid_class_data[maidClass].is_have = true;
                maid.Param.status_.maid_class_data[maidClass].exp_system.SetLevel(val);
            }
            selected.UpdateMaidClasses();

            for (int yotogiClass = 0; yotogiClass < (int) EnumHelper.MaxYotogiClass; yotogiClass++)
            {
                maid.Param.status_.yotogi_class_data[yotogiClass].is_have = true;
                maid.Param.status_.yotogi_class_data[yotogiClass].exp_system.SetLevel(val);
            }
            selected.UpdateYotogiClasses();
        }
        private void SetYotogiUsedTimes(object sender, EventArgs e)
        {
            uint v;
            TextDialog td = new TextDialog(
            Resources.GetFieldText("GUI_YOTOGI_TIMES_TITLE"),
            Resources.GetFieldText("GUI_YOTOGI_TIMES_PROMPT"),
            "0",
            s => uint.TryParse(s, out v),
            Resources.GetFieldText("OK"),
            Resources.GetFieldText("CANCEL")) {StartPosition = FormStartPosition.CenterParent};
            DialogResult dr = td.ShowDialog(this);
            Debugger.WriteLine(LogLevel.Info, $"Prompt result: {EnumHelper.GetName(dr)}, {td.Input}");

            if (dr != DialogResult.OK)
                return;
            v = uint.Parse(td.Input);
            td.Dispose();

            MaidInfo maid = SelectedMaid;

            foreach (KeyValuePair<int, Yotogi.SkillData> skill in
            Yotogi.skill_data_list.SelectMany(ee => ee).Where(ss => maid.Maid.Param.status.IsGetSkill(ss.Key)))
            {
                maid.Maid.Param.status_.skill_data[skill.Key].play_count = v;
                maid.UpdateSkillData(skill.Value.id);
            }
        }
        private void OpenTranslationDownloadUrl(object sender, EventArgs e)
        {
            Uri uri = null;
            TextDialog tdURL = new TextDialog(
            Translation.GetTranslation("TL_URL_TITLE"),
            Translation.GetTranslation("TL_URL_TEXT"),
            string.Empty,
            s =>
            {
                try
                {
                    uri = new Uri(s);
                    return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps;
                }
                catch (Exception)
                {
                    return false;
                }
            },
            Translation.GetTranslation("OK"),
            Translation.GetTranslation("CANCEL"));
            DialogResult promptDialog = tdURL.ShowDialog(this);
            tdURL.Dispose();

            if (promptDialog != DialogResult.OK)
                return;

            string translationsPath = Path.Combine(MaidFiddler.DATA_PATH, Translation.TRANSLATIONS_PATH);
            LoadingBarGUI loadingBarGui = new LoadingBarGUI(
            Translation.GetTranslation("LOADING"),
            Translation.GetTranslation("TL_URL_DOWNLOADING"),
            true,
            g =>
            {
                HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create(uri);
                g.Timer.Start();
                Debugger.WriteLine(LogLevel.Info, "Getting translation...");
                webRequest.BeginGetResponse(
                ar =>
                {
                    try
                    {
                        HttpWebResponse response = (HttpWebResponse) webRequest.EndGetResponse(ar);
                        Debugger.WriteLine(LogLevel.Info, "Got response!");
                        Debugger.WriteLine(LogLevel.Info, $"Response: {response.StatusCode}");
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            MessageBox.Show(
                            "Failed to download the translation: File not found",
                            "Boop!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                            g.DialogResult = DialogResult.Abort;
                            g.Timer.Stop();
                            g.Close();
                            return;
                        }
                        Stream s = response.GetResponseStream();
                        Debugger.WriteLine(LogLevel.Info, "Reading response");
                        StringBuilder sb = new StringBuilder();
                        byte[] responseBuffer = new byte[1024];
                        int read;
                        do
                        {
                            read = s.Read(responseBuffer, 0, responseBuffer.Length);
                            sb.Append(Encoding.UTF8.GetString(responseBuffer, 0, read));
                        } while (read > 0);

                        using (TextReader tr = new StringReader(sb.ToString()))
                        {
                            if (!Translation.TagPattern.Match(tr.ReadLine()).Success)
                            {
                                Debugger.WriteLine(LogLevel.Error, "Failed to parse the translation: No tag found!");
                                MessageBox.Show(
                                "The file does not contain the translation tag and thus cannot be recognised as a Maid Fiddler translation file.\nThe file has not been saved.",
                                "Boop!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                                g.DialogResult = DialogResult.Abort;
                                g.Timer.Stop();
                                g.Close();
                                return;
                            }
                        }

                        string tlFileName = Path.GetFileNameWithoutExtension(uri.AbsolutePath);
                        Debugger.WriteLine($"File name: {tlFileName}");

                        if (tlFileName == string.Empty
                            || File.Exists(Path.Combine(translationsPath, $"{tlFileName}.txt")))
                        {
                            char[] invalidChars = Path.GetInvalidFileNameChars();
                            TextDialog tdFileName = new TextDialog(
                            Translation.GetTranslation("TL_NAME_CHANGE_TITLE"),
                            Translation.GetTranslation("TL_NAME_CHANGE"),
                            tlFileName,
                            s1 => !s1.Any(c => invalidChars.Contains(c)),
                            Translation.GetTranslation("OK"),
                            Translation.GetTranslation("CANCEL"));
                            if (tdFileName.ShowDialog(g) == DialogResult.OK)
                                tlFileName = tdFileName.Input;
                            if (tlFileName == string.Empty)
                                tlFileName = FiddlerUtils.GenerateFileName();

                            tdFileName.Dispose();
                        }

                        string path = Path.Combine(translationsPath, $"{tlFileName}.txt");
                        Debugger.WriteLine($"Writing translation to {path}");

                        using (TextWriter tw = File.CreateText(path))
                            tw.Write(sb.ToString());
                        g.DialogResult = DialogResult.OK;
                    }
                    catch (WebException we)
                    {
                        MessageBox.Show(
                        $"Failed to retreive translation.\nResponse: {we.Message}",
                        "Boop!",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                        g.DialogResult = DialogResult.Abort;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                        $"Unknown error occurred.\nInfo: {ex.ToString()}",
                        "Boop!",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                        g.DialogResult = DialogResult.Abort;
                    }
                    finally
                    {
                        g.Timer.Stop();
                        g.Close();
                    }
                },
                null);
            });
            DialogResult result = loadingBarGui.ShowDialog(this);
            loadingBarGui.Dispose();
            if (result != DialogResult.OK)
                return;
            MessageBox.Show(
            Translation.GetTranslation("TL_DOWNLOAD_DONE"),
            Translation.GetTranslation("TL_DOWNLOAD_DONE_TITLE"),
            MessageBoxButtons.OK);
            LoadTranslations(Translation.CurrentTranslationFile);
        }
        private void OpenTranslationDownloadUrl(object sender, EventArgs e)
        {
            Uri        uri   = null;
            TextDialog tdURL = new TextDialog(
                Translation.GetTranslation("TL_URL_TITLE"),
                Translation.GetTranslation("TL_URL_TEXT"),
                string.Empty,
                s =>
            {
                try
                {
                    uri = new Uri(s);
                    return(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);
                }
                catch (Exception)
                {
                    return(false);
                }
            },
                Translation.GetTranslation("OK"),
                Translation.GetTranslation("CANCEL"));
            DialogResult promptDialog = tdURL.ShowDialog(this);

            tdURL.Dispose();

            if (promptDialog != DialogResult.OK)
            {
                return;
            }

            string        translationsPath = Path.Combine(MaidFiddler.DATA_PATH, Translation.TRANSLATIONS_PATH);
            LoadingBarGUI loadingBarGui    = new LoadingBarGUI(
                Translation.GetTranslation("LOADING"),
                Translation.GetTranslation("TL_URL_DOWNLOADING"),
                true,
                g =>
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
                g.Timer.Start();
                Debugger.WriteLine(LogLevel.Info, "Getting translation...");
                webRequest.BeginGetResponse(
                    ar =>
                {
                    try
                    {
                        HttpWebResponse response = (HttpWebResponse)webRequest.EndGetResponse(ar);
                        Debugger.WriteLine(LogLevel.Info, "Got response!");
                        Debugger.WriteLine(LogLevel.Info, $"Response: {response.StatusCode}");
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            MessageBox.Show(
                                "Failed to download the translation: File not found",
                                "Boop!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                            g.DialogResult = DialogResult.Abort;
                            g.Timer.Stop();
                            g.Close();
                            return;
                        }
                        Stream s = response.GetResponseStream();
                        Debugger.WriteLine(LogLevel.Info, "Reading response");
                        List <byte> resultBuffer = new List <byte>();
                        byte[] responseBuffer    = new byte[1024];
                        int read;
                        do
                        {
                            read = s.Read(responseBuffer, 0, responseBuffer.Length);
                            resultBuffer.AddRange(responseBuffer, 0, read);
                        } while (read > 0);
                        string translationString = Encoding.UTF8.GetString(resultBuffer.ToArray());

                        using (TextReader tr = new StringReader(translationString))
                        {
                            if (!Translation.TagPattern.Match(tr.ReadLine()).Success)
                            {
                                Debugger.WriteLine(LogLevel.Error, "Failed to parse the translation: No tag found!");
                                MessageBox.Show(
                                    "The file does not contain the translation tag and thus cannot be recognised as a Maid Fiddler translation file.\nThe file has not been saved.",
                                    "Boop!",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                g.DialogResult = DialogResult.Abort;
                                g.Timer.Stop();
                                g.Close();
                                return;
                            }
                        }

                        string tlFileName = Path.GetFileNameWithoutExtension(uri.AbsolutePath);
                        Debugger.WriteLine($"File name: {tlFileName}");

                        if (tlFileName == string.Empty ||
                            File.Exists(Path.Combine(translationsPath, $"{tlFileName}.txt")))
                        {
                            char[] invalidChars   = Path.GetInvalidFileNameChars();
                            TextDialog tdFileName = new TextDialog(
                                Translation.GetTranslation("TL_NAME_CHANGE_TITLE"),
                                Translation.GetTranslation("TL_NAME_CHANGE"),
                                tlFileName,
                                s1 => !s1.Any(c => invalidChars.Contains(c)),
                                Translation.GetTranslation("OK"),
                                Translation.GetTranslation("CANCEL"));
                            if (tdFileName.ShowDialog(g) == DialogResult.OK)
                            {
                                tlFileName = tdFileName.Input;
                            }
                            if (tlFileName == string.Empty)
                            {
                                tlFileName = FiddlerUtils.GenerateFileName();
                            }

                            tdFileName.Dispose();
                        }

                        string path = Path.Combine(translationsPath, $"{tlFileName}.txt");
                        Debugger.WriteLine($"Writing translation to {path}");

                        using (TextWriter tw = File.CreateText(path))
                            tw.Write(translationString);
                        g.DialogResult = DialogResult.OK;
                    }
                    catch (WebException we)
                    {
                        MessageBox.Show(
                            $"Failed to retreive translation.\nResponse: {we.Message}",
                            "Boop!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        g.DialogResult = DialogResult.Abort;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            $"Unknown error occurred.\nInfo: {ex.ToString()}",
                            "Boop!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        g.DialogResult = DialogResult.Abort;
                    }
                    finally
                    {
                        g.Timer.Stop();
                        g.Close();
                    }
                },
                    null);
            });
            DialogResult result = loadingBarGui.ShowDialog(this);

            loadingBarGui.Dispose();
            if (result != DialogResult.OK)
            {
                return;
            }
            MessageBox.Show(
                Translation.GetTranslation("TL_DOWNLOAD_DONE"),
                Translation.GetTranslation("TL_DOWNLOAD_DONE_TITLE"),
                MessageBoxButtons.OK);
            LoadTranslations(Translation.CurrentTranslationFile);
        }