コード例 #1
0
        //プリセット用INIファイル読み書き
        public static bool SaveIni_UserCfg(string inifn, UserConfig uc)
        {
#if COM3D2
            string saveDirPath = Path.Combine(getPlginDir(), @"Config\");
            //ファイル名
            string fileIni = saveDirPath + @"XtMasterSlave\User_SaveData\" + inifn;
#else
            string fullpath    = Path.GetFullPath(".\\");
            string saveDirPath = Path.Combine(fullpath, @"Sybaris\Plugins\UnityInjector\Config\");
            //ファイル名
            //string fileIni = @"UnityInjector\Config\XtMsterSlave\User_SaveData\" + inifn;
            string fileIni = saveDirPath + @"XtMsterSlave\User_SaveData\" + inifn;
#endif
            string xfn       = extpath(fileIni);
            bool   isSuccess = false;
            string strfn_d   = null;
            try
            {
                if (File.Exists(fileIni))
                {
                    var msgo = "上書きしますか?\r\nファイル名: " + inifn;
                    var reto = NUty.WinMessageBox(NUty.GetWindowHandle(), msgo, "( ! )", NUty.MSGBOX.MB_OKCANCEL | NUty.MSGBOX.MB_ICONQUESTION);
                    if (reto != (int)System.Windows.Forms.DialogResult.OK)
                    {
                        msgo = "保存はキャンセルされました";
                        NUty.WinMessageBox(NUty.GetWindowHandle(), msgo, "( ! )", NUty.MSGBOX.MB_OK);
                        return(false);
                    }
                    else
                    {
                        strfn_d = fileIni + ".bak";
                        File.Move(fileIni, strfn_d);
                    }
                }

                if (!File.Exists(fileIni))
                {
                    Console.WriteLine("ユーザーセーブini設定書き込み :" + xfn);

                    uc.cfg_h.Memo = uc.cfg_h.Memo.Replace("\n", "<改行>");
                    uc.cfg_h.Memo = uc.cfg_h.Memo.Replace("\r", "");
                    SharedConfig.SaveConfig("Config", xfn, uc.cfg_h);

                    for (int i = 0; i < XtMasterSlave.MAX_PAGENUM; i++)
                    {
                        //前後のスペースがトリムされるようなので""でエスケープする
                        uc.cfgs_p[i].Master_Name = uc.cfgs_p[i].Master_Name.dq_();
                        uc.cfgs_p[i].Slave_Name  = uc.cfgs_p[i].Slave_Name.dq_();

                        SharedConfig.SaveConfig("Page-" + (i + 1).ToString(), xfn, uc.cfgs_p[i]);
                    }

                    for (int i = 0; i < uc.cfgs_ms.Length; i++)
                    {
                        SharedConfig.SaveConfig("Config-" + (i + 1).ToString(), xfn, uc.cfgs_ms[i]);
                    }
                }
                if (strfn_d != null && File.Exists(strfn_d))
                {
                    File.Delete(strfn_d);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log("api+INI SaveError:" + e);

                var msg = "ファイル保存に失敗しました\r\nファイル名:" + inifn + "\r\n" + e.Message;
                NUty.WinMessageBox(NUty.GetWindowHandle(), msg, "( ! )", NUty.MSGBOX.MB_OK | NUty.MSGBOX.MB_ICONERROR);
            }
            return(isSuccess);
        }
コード例 #2
0
        public static void SaveWindowCallback_proc(int id, XtMasterSlave XtMS, ref int showWndMode, ref int _pageNum, XtMasterSlave.MsLinks[] p_MSlinks, XtMasterSlave.MsLinkConfig[] cfgs, XtMasterSlave.v3Offsets[] v3ofs, out string _WinprocPhase)
        {
            //XtMasterSlave.MsLinks ms_ = p_MSlinks[_pageNum];
            //bool boChrCng = false;

            _WinprocPhase = "[init]";
            GUIStyle gsLabel = new GUIStyle("label");

            gsLabel.fontSize  = 12;
            gsLabel.alignment = TextAnchor.MiddleLeft;

            GUIStyle gsButton = new GUIStyle("button");

            gsButton.fontSize  = 12;
            gsButton.alignment = TextAnchor.MiddleCenter;

            GUIStyle gsToggle = new GUIStyle("toggle");

            gsToggle.fontSize  = 12;
            gsToggle.alignment = TextAnchor.MiddleLeft;

            GUIStyle gsText = new GUIStyle("textfield");

            gsText.fontSize  = 12;
            gsText.alignment = TextAnchor.UpperLeft;

            GUIStyle gsTextAr = new GUIStyle("textArea");

            gsTextAr.fontSize  = 12;
            gsTextAr.alignment = TextAnchor.UpperLeft;
            gsTextAr.wordWrap  = true;

            GUIStyle gsCombo = new GUIStyle("button");

            gsCombo.fontSize           = 12;
            gsCombo.alignment          = TextAnchor.MiddleLeft;
            gsCombo.hover.textColor    = Color.cyan;
            gsCombo.onHover.textColor  = Color.cyan;
            gsCombo.onActive.textColor = Color.cyan;

            //GUIStyle gsScView = new GUIStyle("scrollView");
            _WinprocPhase = "[ctrl-1]";

            //GUI.enabled = false; //セーブ画面では閉じない
            if (GUI.Button(new Rect(240, 0, 20, 20), "x", gsButton))
            {
                //GizmoVisible(false);
                //GizmoHsVisible(false);
                //GuiFlag = false;
                boShow = false;
            }
            GUI.enabled = true;

            if (showWndMode == 1)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(new Rect(240 - 70, 0, 20, 20), "-", gsButton))
            {
                showWndMode = 1;
            }
            GUI.enabled = true;
            if (showWndMode == 2)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(new Rect(240 - 50, 0, 20, 20), "=", gsButton))
            {
                showWndMode = 2;
            }
            GUI.enabled = true;
            if (showWndMode == 0)
            {
                GUI.enabled = false;
            }
            if (GUI.Button(new Rect(240 - 30, 0, 20, 20), "□", gsButton))
            {
                showWndMode = 0;
            }
            GUI.enabled = true;

            EditScroll_cfg = GUI.BeginScrollView(new Rect(0, 20, XtMasterSlave.GUI_WIDTH, XtMasterSlave.GUI_HIGHT - 30), EditScroll_cfg,
                                                 new Rect(0, 0, XtMasterSlave.GUI_WIDTH - 16, EditScroll_cfg_sizeY));
            try
            {
                //XtMasterSlave.MsLinkConfig p_mscfg = cfgs[_pageNum];
                //XtMasterSlave.v3Offsets p_v3of = v3ofs[_pageNum];
                int pos_y = 0;

                GUI.Label(new Rect(ItemX, pos_y, 200, ItemHeight), "【設定保存・読込】", gsLabel);
                pos_y += ItemHeight;
                if (GUI.Button(new Rect(ItemX, pos_y, ItemWidth, ItemHeight), "戻る", gsButton))
                {
                    boShow = false;
                    Init();
                }
                pos_y += ItemHeight;
                pos_y += ItemHeight / 2;

                GUI.Label(new Rect(ItemX, pos_y, 200, ItemHeight), "【デフォルト&一般設定】", gsLabel);

                if (GUI.Button(new Rect(ItemX, pos_y += ItemHeight, ItemWidth / 2, ItemHeight), "保存", gsButton))
                {
                    // Iniファイル書き出し
                    XtMS.SaveMyConfigs();
                }
                if (GUI.Button(new Rect(ItemX + ItemWidth / 2, pos_y, ItemWidth / 2, ItemHeight), "読込", gsButton))
                {
                    // Iniファイル読み出し
                    XtMS.LoadMyConfigs();
                }

                /*
                 * GUI.Label(new Rect(5 + ItemWidth - 25 - 35 - 35, pos_y, 25, ItemHeight), "設定", gsLabel);
                 *
                 * if (GUI.Button(new Rect(5 + ItemWidth - 35 - 35, pos_y, 35, 20), "保存", gsButton))
                 * {
                 *  // Iniファイル書き出し
                 *  XtMS.SaveMyConfigs();
                 * }
                 * if (GUI.Button(new Rect(5 + ItemWidth - 35, pos_y, 35, 20), "読込", gsButton))
                 * {
                 *  // Iniファイル読み出し
                 *  XtMS.LoadMyConfigs();
                 * }*/

                pos_y += ItemHeight;
                pos_y += ItemHeight / 2;
                // 男0でもプリセ保存できてもいいかな?v0025 if (XtMasterSlave._MensList.Count <= 0)
                //    GUI.enabled = false;
                try
                {
                    GUI.Label(new Rect(ItemX, pos_y, 200, ItemHeight), "【プリセットの保存】", gsLabel);
                    pos_y += ItemHeight;

                    GUI.Label(new Rect(ItemX, pos_y, ItemWidth - 110, ItemHeight), "ファイル名(Save)", gsLabel);
                    if (GUI.Button(new Rect(ItemWidth - 110, pos_y, 110, ItemHeight), "日時で付ける", gsButton))
                    {
                        _memo      = string.Empty;
                        _EditIniFN = "XtMS-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".ini";
                    }
                    _EditIniFN = GUI.TextField(new Rect(5, pos_y += ItemHeight, ItemWidth, ItemHeight), _EditIniFN, gsText);

                    if (GUI.Button(new Rect(ItemX, pos_y += ItemHeight, ItemWidth, ItemHeight), "保存", gsButton))
                    {
                        // Iniファイル書き出し
                        _WinprocPhase = "[save-uIni]";

                        if (string.IsNullOrEmpty(_EditIniFN))
                        {
                            NUty.WinMessageBox(NUty.GetWindowHandle(), "ファイル名を入力して下さい", "( ! )", NUty.MSGBOX.MB_OK | NUty.MSGBOX.MB_ICONERROR);
                        }
                        else
                        {
                            if (Path.GetExtension(_EditIniFN) != ".ini")
                            {
                                _EditIniFN = _EditIniFN + ".ini";
                            }
                            UserConfig ucfg    = new UserConfig();
                            string     strmemo = "";


                            for (int i = 0; i < cfgs.Length; i++)
                            {
                                XtMasterSlave.v3OffsetsToIniCfgs(ref cfgs[i], v3ofs[i]);
                            }

                            for (int i = 0; i < XtMasterSlave.MAX_PAGENUM; i++)
                            {
                                var ms = p_MSlinks[i];

                                ucfg.cfgs_ms[i] = cfgs[i];
                                ucfg.cfgs_p[i]  = new UserConfigPage(ms.doMasterSlave, ms.Scc1_MasterMaid, ms);

                                /*ucfg.cfgs_p[i] = new UserConfigPage(ms.doMasterSlave, ms.Scc1_MasterMaid,
                                 *  new XtMasterSlave.ManInfo(ms.mdMasters[ms.mdMaster_No].mem, ms.mdMaster_No),
                                 *  new XtMasterSlave.ManInfo(ms.mdSlaves[ms.mdSlave_No].mem, ms.mdSlave_No));
                                 */
                                if (ms.doMasterSlave)
                                {
                                    strmemo = strmemo + i + "Master" + ": [" + maidorman(ms.mdMasters[0].mem) + ms.mdMaster_No + "]   " + XtMasterSlave.GetMaidName(ms.mdMasters[ms.mdMaster_No]) + "  [M⇔S]\r\n";
                                    strmemo = strmemo + "  Slave" + ": [" + maidorman(ms.mdSlaves[0].mem) + ms.mdSlave_No + "]   " + XtMasterSlave.GetMaidName(ms.mdSlaves[ms.mdSlave_No]) + "  [M⇔S]\r\n";
                                }
                                else if (XtMasterSlave._MensList.Count <= 0)
                                {
                                    // メイドのみモード
                                    strmemo = strmemo + i + "Master" + ": 不在" + "\r\n";

                                    if (ms.mdSlave_No < 0)
                                    {
                                        strmemo = strmemo + "  Slave" + ": [" + maidorman(ms.mdSlaves[0].mem) + "_]   " + "未選択" + "\r\n";
                                    }
                                    else
                                    {
                                        strmemo = strmemo + "  Slave" + ": [" + maidorman(ms.mdSlaves[0].mem) + ms.mdSlave_No + "]   " + XtMasterSlave.GetMaidName(ms.mdSlaves[ms.mdSlave_No]) + "\r\n";
                                    }
                                }
                                else
                                {
                                    if (ms.mdMaster_No < 0)
                                    {
                                        strmemo = strmemo + i + "Master" + ": [" + maidorman(ms.mdMasters[0].mem) + "_]   " + "未選択" + "\r\n";
                                    }
                                    else
                                    {
                                        strmemo = strmemo + i + "Master" + ": [" + maidorman(ms.mdMasters[0].mem) + ms.mdMaster_No + "]   " + XtMasterSlave.GetMaidName(ms.mdMasters[ms.mdMaster_No]) + "\r\n";
                                    }

                                    if (ms.mdSlave_No < 0)
                                    {
                                        strmemo = strmemo + "  Slave" + ": [" + maidorman(ms.mdSlaves[0].mem) + "_]   " + "未選択" + "\r\n";
                                    }
                                    else
                                    {
                                        strmemo = strmemo + "  Slave" + ": [" + maidorman(ms.mdSlaves[0].mem) + ms.mdSlave_No + "]   " + XtMasterSlave.GetMaidName(ms.mdSlaves[ms.mdSlave_No]) + "\r\n";
                                    }
                                }
                            }
                            if (strmemo.Length > 0)
                            {
                                //strmemo = "保存時のリンク状態\r\n" + strmemo;
                            }

                            _WinprocPhase         = "[save-uIni2]";
                            ucfg.cfg_h.CurPageNum = _pageNum;
                            ucfg.cfg_h.Memo       = strmemo;
                            // ジッサイに保存
                            SaveIni_UserCfg(_EditIniFN, ucfg);
                            GetUsersConfigs();
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    GUI.enabled = true;
                }

                pos_y += ItemHeight;
                pos_y += ItemHeight;
                GUI.Label(new Rect(ItemX, pos_y, 200, ItemHeight), "【プリセットの読込】", gsLabel);
                pos_y += ItemHeight;

                List <string> slist   = _UserIniFN;
                Rect          boxrect = new Rect(ItemX, pos_y, ItemWidth, ItemHeight * 5);
                pos_y += ItemHeight * 5;
                GUI.Box(boxrect, "");
                EditScroll_fn       = GUI.BeginScrollView(boxrect, EditScroll_fn, new Rect(0, 0, EditScroll_fn_sizeX, (ItemHeight * slist.Count())), false, true);
                EditScroll_fn_sizeX = (int)boxrect.width - 16;
                try
                {
                    int pos_sy = 0;
                    foreach (string str in slist)
                    {
                        bool chk    = (_LoadIniFN == str);
                        int  pos_sx = 2;

                        //ファイル名
                        Vector2 v2Toggle = gsToggle.CalcSize(new GUIContent(str));
                        v2Toggle.x += pos_sx + 10;
                        if (EditScroll_fn_sizeX < v2Toggle.x)
                        {
                            EditScroll_fn_sizeX = (int)v2Toggle.x;
                        }
                        bool chk2 = GUI.Toggle(new Rect(pos_sx, pos_sy, /*boxrect.width*/ v2Toggle.x, ItemHeight), chk, str, gsToggle);
                        if (chk != chk2)
                        {
                            if (chk2)
                            {
                                _LoadIniFN = str;
                                _UserCfg   = LoadIni_UserCfg(str);
                                _memo      = _UserCfg.cfg_h.Memo;
                            }/*
                              * else
                              * {
                              * _LoadIniFN = string.Empty;
                              * }*/
                        }
                        pos_sy += ItemHeight;
                    }
                }
                catch (Exception)
                {
                    _WinprocPhase = "スクロール1";
                    throw;
                }
                finally
                {
                    GUI.EndScrollView();
                }

                //pos_y += ItemHeight / 2;

                //ファイル名
                GUI.Label(new Rect(ItemX, pos_y, 200, ItemHeight), "ファイル名(Load)", gsLabel);
                GUI.TextField(new Rect(5, pos_y += ItemHeight, ItemWidth, ItemHeight), _LoadIniFN, gsText);

                GUI.Label(new Rect(ItemX, pos_y    += ItemHeight, ItemWidth, ItemHeight), "保存時の情報", gsLabel);
                GUI.TextArea(new Rect(ItemX, pos_y += ItemHeight, ItemWidth, ItemHeight * 8), _memo, gsTextAr);
                pos_y += ItemHeight * 8;
                //pos_y += ItemHeight / 2;

                if (GUI.Button(new Rect(ItemX, pos_y, ItemWidth, ItemHeight), "読込", gsButton))
                {
                    // 元のカーソルを保持
                    System.Windows.Forms.Cursor preCursor = System.Windows.Forms.Cursor.Current;
                    // カーソルを待機カーソルに変更
                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                    try {
                        // Iniファイル読み出し
                        _UserCfg = LoadIni_UserCfg(_LoadIniFN);

                        //ページ選択の復元
                        _pageNum = _UserCfg.cfg_h.CurPageNum;

                        //プリセットデータの反映を行う
                        procUserCfg(p_MSlinks, cfgs, v3ofs);
                    }
                    catch
                    {
                        _WinprocPhase = "[load-uIni2]";
                        throw;
                    }
                    finally
                    {
                        // カーソルを元に戻す
                        System.Windows.Forms.Cursor.Current = preCursor;
                    }

                    //画面を閉じる
                    boShow = false;
                    Init();
                }//ボタン

                pos_y += ItemHeight;
                XtMasterSlave.cfg.boNameSelectAndLoad = GUI.Toggle(new Rect(ItemX, pos_y, ItemWidth, ItemHeight), XtMasterSlave.cfg.boNameSelectAndLoad, "キャラ名指定&呼び出し有効", gsToggle);
                pos_y += ItemHeight;

                GUI.Label(new Rect(ItemX, pos_y, ItemWidth, ItemHeight), "注:呼び出す人数が多いと時間が掛かります", gsLabel);
                pos_y += ItemHeight;
                GUI.Label(new Rect(ItemX, pos_y, ItemWidth, ItemHeight), "(※OFF時は表示キャラ順の番号指定)", gsLabel);
                pos_y += ItemHeight;

                pos_y += ItemHeight / 2;
                pos_y += ItemHeight * 2;
                EditScroll_cfg_sizeY = pos_y;
            }
            catch
            {
                throw;
            }
            finally
            {
                GUI.EndScrollView();
            }
        }