Пример #1
0
 /// <summary>
 /// 取一个变量作右值
 /// </summary>
 /// <param name="varName">变量名</param>
 /// <param name="vsm">关于哪个调用堆栈做动作</param>
 /// <returns>变量的引用</returns>
 public object Fetch(string varName, StackMachine vsm)
 {
     // 处理局部变量
     if (varName.StartsWith("$"))
     {
         // 非函数调用
         if (this.GameState(vsm) != StackMachineState.FunctionCalling)
         {
             return(this.Symbols.SceneCtxDao.Fetch(ResourceManager.GetInstance().GetScene(vsm.EBP.ScriptName), varName.Replace("$", String.Empty)));
         }
         // 函数调用
         var funFrame = vsm.ESP.BindingFunction;
         return(funFrame.Symbols[varName.Replace("$", String.Empty)]);
     }
     // 处理全局变量
     if (varName.StartsWith("&"))
     {
         return(this.Symbols.GlobalCtxDao.GlobalFetch(varName.Replace("&", String.Empty)));
     }
     // 处理持久化变量
     if (varName.StartsWith("%"))
     {
         return(PersistContextDAO.Fetch(varName.Replace("%", String.Empty)));
     }
     return(null);
 }
Пример #2
0
 /// <summary>
 /// 初始化游戏设置并载入持久化数据
 /// </summary>
 private void InitConfig()
 {
     try
     {
         // 读取游戏设置
         ConfigParser.ConfigParse();
         // 第一次打开游戏就创建持久性上下文
         if (System.IO.File.Exists(GlobalConfigContext.PersistenceFileName) == false)
         {
             PersistContextDAO.Assign("___YURIRI@ACCDURATION___", 0);
             PersistContextDAO.Assign("___YURIRI@FIRSTPLAYTIMESTAMP___", DateTime.Now.ToString());
             PersistContextDAO.SaveToSteadyMemory();
         }
         // 非第一次打开游戏就读取持久性上下文
         else
         {
             PersistContextDAO.LoadFromSteadyMemory();
             Director.LastGameTimeAcc = TimeSpan.Parse(PersistContextDAO.Exist("___YURIRI@ACCDURATION___") ?
                                                       PersistContextDAO.Fetch("___YURIRI@ACCDURATION___").ToString() : "0");
         }
         Director.StartupTimeStamp = DateTime.Now;
     }
     catch (Exception ex)
     {
         LogUtils.LogLine("No config file is detected, use defualt value." + ex, "Director", LogLevel.Error);
     }
 }
Пример #3
0
 /// <summary>
 /// 左值运算一个变量
 /// </summary>
 /// <param name="varname">变量名</param>
 /// <param name="valuePolish">右值逆波兰式</param>
 /// <param name="vsm">关于哪个调用堆栈做动作</param>
 public void Assignment(string varname, string valuePolish, StackMachine vsm)
 {
     // 处理局部变量
     if (varname.StartsWith("$"))
     {
         // 非函数调用
         if (this.GameState(vsm) != StackMachineState.FunctionCalling)
         {
             this.Symbols.SceneCtxDao.Assign(vsm.EBP.ScriptName, varname.Replace("$", String.Empty), PolishEvaluator.Evaluate(valuePolish, vsm));
         }
         // 函数调用
         else
         {
             var functionFrame = vsm.ESP.BindingFunction;
             functionFrame.Symbols[varname.Replace("$", String.Empty)] = PolishEvaluator.Evaluate(valuePolish, vsm);
         }
     }
     // 处理全局变量
     else if (varname.StartsWith("&"))
     {
         this.Symbols.GlobalCtxDao.GlobalAssign(varname.Replace("&", String.Empty), PolishEvaluator.Evaluate(valuePolish, vsm));
     }
     // 处理持久化变量
     else if (varname.StartsWith("%"))
     {
         PersistContextDAO.Assign(varname.Replace("%", String.Empty), PolishEvaluator.Evaluate(valuePolish, vsm));
     }
 }
Пример #4
0
        /// <summary>
        /// 在游戏即将结束时释放所有资源
        /// </summary>
        public static void CollapseWorld()
        {
            Director.IsCollapsing = true;
            var collaTimeStamp = DateTime.Now;

            LogUtils.LogLine("Yuri world began to collapse at " + collaTimeStamp, "Director", LogLevel.Important);
            PersistContextDAO.Assign("___YURIRI@LASTPLAYTIMESTAMP___", collaTimeStamp.ToString());
            PersistContextDAO.Assign("___YURIRI@ACCDURATION___", Director.LastGameTimeAcc + (collaTimeStamp - Director.StartupTimeStamp));
            PersistContextDAO.SaveToSteadyMemory();
            LogUtils.LogLine("Save persistence context OK", "Director", LogLevel.Important);
            if (GlobalConfigContext.UseBassEngine == false)
            {
                MusicianRouterHandler.TerminalFlag = true;
                Musician.GetInstance().Dispose();
            }
            LogUtils.LogLine("Dispose resource OK, program will shutdown soon", "Director", LogLevel.Important);
            var ct = DateTime.Now;

            GC.Collect();
            if (GlobalConfigContext.UseBassEngine == false)
            {
                while ((DateTime.Now - ct).TotalSeconds < 2 && !MusicianRouterHandler.IsCollapsed)
                {
                    System.Threading.Thread.Sleep(10);
                }
            }
            Environment.Exit(0);
        }
Пример #5
0
        private void Chara_VOICE_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            bool?judger = null;
            var  name   = ((Image)sender).Name;

            switch (name)
            {
            case "Chara_VOICE_XW":
                voice_xw = !voice_xw;
                judger   = voice_xw;
                PersistContextDAO.Assign("system_config_audio_voice_xw", judger.ToString().ToLower());
                break;

            case "Chara_VOICE_QL":
                voice_ql = !voice_ql;
                judger   = voice_ql;
                PersistContextDAO.Assign("system_config_audio_voice_ql", judger.ToString().ToLower());
                break;
            }

            var sourcePath = ((Image)sender).Source.ToString();

            if (judger == true && sourcePath.EndsWith("On.png") || judger == false && sourcePath.EndsWith("Off.png"))
            {
                return;
            }
            else if (judger == true)
            {
                sourcePath = sourcePath.Replace("Off.png", "On.png");
            }
            else if (judger == false)
            {
                sourcePath = sourcePath.Replace("On.png", "Off.png");
            }

            BitmapImage rotating;

            if (this.cachingButtons.ContainsKey(sourcePath))
            {
                rotating = this.cachingButtons[sourcePath];
            }
            else
            {
                rotating = new BitmapImage();
                rotating.BeginInit();
                rotating.UriSource = new Uri(sourcePath);
                rotating.EndInit();
                this.cachingButtons[sourcePath] = rotating;
            }
            ((Image)sender).Source = rotating;
        }
Пример #6
0
        private void Image_Btn_SetFont_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            var fontDialog = new System.Windows.Forms.FontDialog
            {
                AllowVerticalFonts = false,
                AllowScriptChange  = false,
                MinSize            = 8,
                ShowEffects        = false,
                ShowColor          = false,
                ShowHelp           = false,
                ShowApply          = false,
                FontMustExist      = true
            };

            var dr = fontDialog.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            var newFontName = fontDialog.Font.Name;
            var newFontSize = fontDialog.Font.Size;

            try
            {
                this.Label_FontName.Content    = newFontName;
                this.Label_FontName.FontSize   = newFontSize;
                this.Label_FontName.FontFamily = new FontFamily(newFontName);
            }
            catch (Exception fe)
            {
                LogUtils.LogLine("cannot load user custom font: " + fe.ToString(), nameof(LHSettingsPage), LogLevel.Error);
                GlobalConfigContext.GAME_FONT_NAME     = this.startupDefaultFontName;
                GlobalConfigContext.GAME_FONT_FONTSIZE = this.startupDefaultFontSize;
                Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontname", this.startupDefaultFontName);
                Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontsize", this.startupDefaultFontSize.ToString());
                return;
            }

            Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontname", newFontName);
            Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontsize", newFontSize.ToString());

            PersistContextDAO.Assign("system_config_userfont_name", newFontName);
            PersistContextDAO.Assign("system_config_userfont_size", newFontSize);

            GlobalConfigContext.GAME_FONT_NAME     = newFontName;
            GlobalConfigContext.GAME_FONT_FONTSIZE = Convert.ToInt32(newFontSize);
        }
Пример #7
0
 private void Image_Btn_DefaultFont_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (e.RightButton == MouseButtonState.Pressed)
     {
         return;
     }
     GlobalConfigContext.GAME_FONT_NAME     = "default";
     GlobalConfigContext.GAME_FONT_FONTSIZE = 32;
     Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontname", "default");
     Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontsize", "32");
     PersistContextDAO.Assign("system_config_userfont_name", "default");
     PersistContextDAO.Assign("system_config_userfont_size", "32");
     this.Label_FontName.Content    = "(默认)Source Han Serif";
     this.Label_FontName.FontSize   = 32;
     this.Label_FontName.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "Resources/#Source Han Serif CN SemiBold");
 }
Пример #8
0
        private void LabelRadio_Grahpic_Typing_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            var name = ((Label)sender).Name;
            var id   = Convert.ToInt32(name.Replace("LabelRadio_Grahpic_Typing_", ""));

            for (int i = 1; i <= 5; i++)
            {
                var cl = (Label)this.FindName("LabelRadio_Grahpic_Typing_" + i);
                if (i != id)
                {
                    cl.Foreground = new SolidColorBrush(Colors.Black);
                }
                else
                {
                    cl.Foreground = new SolidColorBrush(this.xichengBlue);
                }
            }
            PersistContextDAO.Assign("system_config_typespeed", id.ToString());
            switch (id)
            {
            case 1:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 120;
                break;

            case 2:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 90;
                break;

            case 3:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 30;
                break;

            case 4:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 10;
                break;

            case 5:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 0;
                break;
            }
        }
Пример #9
0
        private void LabelRadio_Others_Performance_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            switch (((Label)sender).Name)
            {
            case "LabelRadio_Others_Performance_Enable":
                PersistContextDAO.Assign("system_config_performance_set", "Enable");
                this.LabelRadio_Others_Performance_Enable.Foreground  = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Performance_Disable.Foreground = new SolidColorBrush(Colors.Black);
                break;

            case "LabelRadio_Others_Performance_Disable":
                PersistContextDAO.Assign("system_config_performance_set", "Disable");
                this.LabelRadio_Others_Performance_Disable.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Performance_Enable.Foreground  = new SolidColorBrush(Colors.Black);
                break;
            }
        }
Пример #10
0
        private void LabelRadio_Others_Title_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            switch (((Label)sender).Name)
            {
            case "LabelRadio_Others_Title_Timing":
                PersistContextDAO.Assign("system_config_title_type", "Timing");
                this.LabelRadio_Others_Title_Timing.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Title_Dusk.Foreground   = new SolidColorBrush(Colors.Black);
                break;

            case "LabelRadio_Others_Title_Dusk":
                PersistContextDAO.Assign("system_config_title_type", "Dusk");
                this.LabelRadio_Others_Title_Dusk.Foreground   = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Title_Timing.Foreground = new SolidColorBrush(Colors.Black);
                break;
            }
        }
Пример #11
0
        private void LabelRadio_Others_Rollback_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            var name = ((Label)sender).Name;

            if (name.Contains("Enable"))
            {
                this.LabelRadio_Others_Rollback_Enable.Foreground  = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Rollback_Disable.Foreground = new SolidColorBrush(Colors.Black);
                Director.IsAllowRollback = true;
                PersistContextDAO.Assign("system_config_rollback_enable", "true");
            }
            else if (name.Contains("Disable"))
            {
                this.LabelRadio_Others_Rollback_Disable.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Rollback_Enable.Foreground  = new SolidColorBrush(Colors.Black);
                Director.IsAllowRollback = false;
                PersistContextDAO.Assign("system_config_rollback_enable", "false");
            }
        }
Пример #12
0
        private void refreshGalleryInto(string type)
        {
            lock (this)
            {
                if (this.isGalleryAnimating)
                {
                    return;
                }
                this.isGalleryAnimating = true;
            }
            this.Canvas_Gallery_ButtonsWarp.IsHitTestVisible = false;
            foreach (var wrapper in this.Canvas_Gallery_ContentWarp.Children)
            {
                if (wrapper is Canvas)
                {
                    var wrapperCanvas = (Canvas)wrapper;
                    if (wrapperCanvas.Name.EndsWith("_Wrapper"))
                    {
                        if (wrapperCanvas.Name == ("Canvas_Gallery_" + type + "_Wrapper"))
                        {
                            wrapperCanvas.Visibility = Visibility.Visible;
                            wrapperCanvas.Opacity    = 1;
                        }
                        else
                        {
                            wrapperCanvas.Visibility = Visibility.Hidden;
                            wrapperCanvas.Opacity    = 0;
                        }
                    }
                }
            }
            foreach (var btn in this.Canvas_Gallery_ButtonsWarp.Children)
            {
                if (btn is Image)
                {
                    if (((Image)btn).Name.StartsWith("Warp_Gallery_Btn_") && ((Image)btn).Name != ("Warp_Gallery_Btn_" + type))
                    {
                        ((Image)btn).Opacity = 0.3;
                    }
                }
            }

            // 进入刷新的具体逻辑
            switch (type)
            {
            case "EDCard":
                var loopEndFool = (double)PersistContextDAO.Fetch("loop_end_fool") > 0;
                if (loopEndFool)
                {
                    var endPath = this.Image_Gallery_EDCard_FoolEnd.Source.ToString();
                    if (endPath.EndsWith("NoOpen.png"))
                    {
                        endPath = endPath.Replace("NoOpen.png", "FoolEnd.png");
                        BitmapImage endRotating;
                        endRotating = new BitmapImage();
                        endRotating.BeginInit();
                        endRotating.UriSource = new Uri(endPath);
                        endRotating.EndInit();
                        this.Image_Gallery_EDCard_FoolEnd.Source = endRotating;
                    }
                }
                var loopBadBad = (double)PersistContextDAO.Fetch("loop_end_bad") > 0;
                if (loopBadBad)
                {
                    var endPath = this.Image_Gallery_EDCard_BadEnd.Source.ToString();
                    if (endPath.EndsWith("NoOpen.png"))
                    {
                        endPath = endPath.Replace("NoOpen.png", "BadEnd.png");
                        BitmapImage endRotating;
                        endRotating = new BitmapImage();
                        endRotating.BeginInit();
                        endRotating.UriSource = new Uri(endPath);
                        endRotating.EndInit();
                        this.Image_Gallery_EDCard_BadEnd.Source = endRotating;
                    }
                }
                var loopEndNormal = (double)PersistContextDAO.Fetch("loop_end_normal") > 0;
                if (loopEndNormal)
                {
                    var endPath = this.Image_Gallery_EDCard_NormalEnd.Source.ToString();
                    if (endPath.EndsWith("NoOpen.png"))
                    {
                        endPath = endPath.Replace("NoOpen.png", "NormalEnd.png");
                        BitmapImage endRotating;
                        endRotating = new BitmapImage();
                        endRotating.BeginInit();
                        endRotating.UriSource = new Uri(endPath);
                        endRotating.EndInit();
                        this.Image_Gallery_EDCard_NormalEnd.Source = endRotating;
                    }
                }
                var loopEndTrue = (double)PersistContextDAO.Fetch("loop_end_true") > 0;
                if (loopEndTrue)
                {
                    var endPath = this.Image_Gallery_EDCard_TrueEnd.Source.ToString();
                    if (endPath.EndsWith("NoOpen.png"))
                    {
                        endPath = endPath.Replace("NoOpen.png", "TrueEnd.png");
                        BitmapImage endRotating;
                        endRotating = new BitmapImage();
                        endRotating.BeginInit();
                        endRotating.UriSource = new Uri(endPath);
                        endRotating.EndInit();
                        this.Image_Gallery_EDCard_TrueEnd.Source = endRotating;
                    }
                }
                string loopTimesStr;
                try
                {
                    var loopTimes   = PersistContextDAO.Fetch("Game_LoopTime");
                    int loopTimeRaw = Convert.ToInt32(loopTimes);
                    if (loopTimeRaw >= 100)
                    {
                        loopTimesStr = "99+";
                    }
                    else
                    {
                        loopTimesStr = loopTimeRaw.ToString();
                    }
                } catch (Exception e)
                {
                    loopTimesStr = "N/A";
                }
                this.Label_Gallery_EDCard_LoopTime_Hint.Content = $"通关次数:{loopTimesStr}";
                string accTimesStr;
                try
                {
                    TimeSpan accTimes = (TimeSpan)PersistContextDAO.Fetch("___YURIRI@ACCDURATION___");
                    accTimesStr = "";
                    if (accTimes.Days != 0)
                    {
                        accTimesStr += accTimes.Days + "天";
                    }
                    if (accTimes.Hours != 0)
                    {
                        accTimesStr += accTimes.Hours + "小时";
                    }
                    accTimesStr += accTimes.Minutes + "分钟";
                }
                catch (Exception e)
                {
                    accTimesStr = "N/A";
                }
                this.Label_Gallery_EDCard_AccTime_Hint.Content = $"累计时长:{accTimesStr}";
                break;

            case "Music":
                this.RefreshMusicPlayingStatus();
                break;

            case "Bonus":
                try
                {
                    ((LongStoryPage)this.Frame_BonusStory.Content).PrepareOpen();
                }
                catch (Exception e)
                {
                    LogUtils.LogLine("cannot open bonus long story page, " + e.ToString(), nameof(LHStartPage), LogLevel.Error);
                }
                break;

            default:
                break;
            }

            this.GalleryContentWarpSprite.DisplayBinding.Visibility       = Visibility.Visible;
            this.GalleryContentWarpSprite.DisplayBinding.IsHitTestVisible = false;
            this.GalleryContentWarpSprite.Descriptor.ToOpacity            = 1;
            SpriteAnimation.OpacityToAnimation(this.GalleryContentWarpSprite, new Duration(TimeSpan.FromMilliseconds(300)), 1, 0,
                                               cb: (_, __) =>
            {
                this.GalleryContentWarpSprite.DisplayBinding.IsHitTestVisible = true;
                this.currentGalleryStage = type;
                this.isGalleryAnimating  = false;
            });
        }
Пример #13
0
        public void PrepareOpen()
        {
            ((LHSettingsPage)this.Frame_Settings.Content).RefreshSteadyConfig();
            this.currentSubStage             = "root";
            this.titlePlayingBGM             = "2";
            this.isLoading                   = false;
            this.isTrueEndArrival            = (double)PersistContextDAO.Fetch("Game_EndArrival_TE") > 0;
            this.Warp_Btn_Gallery.Visibility = this.isTrueEndArrival ? Visibility.Visible : Visibility.Hidden;


            if (isTrueEndArrival)
            {
                this.Art_Image_Background_Window.Source = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Ground_T2_bg2.png"));
                this.Art_Image_Fore.Source   = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Ground_T2_fore.png"));
                this.Warp_Image_Title.Source = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Logo_2.png"));
            }

            string titleType = PersistContextDAO.Fetch("system_config_title_type")?.ToString();

            if (titleType == "0")
            {
                PersistContextDAO.Assign("system_config_title_type", "Timing");
                titleType = "Timing";
            }

            if (false == isTrueEndArrival)
            {
                String cloudSourcePath;
                if (((DateTime.Now.Hour >= 5 && DateTime.Now.Hour < 17) || titleType != "Timing"))
                {
                    cloudSourcePath = ((Image)this.Art_Image_Background_Cloud_1).Source.ToString();
                    if (cloudSourcePath.EndsWith("_sunset.png"))
                    {
                        cloudSourcePath = cloudSourcePath.Replace("_sunset.png", ".png");
                    }
                }
                else
                {
                    cloudSourcePath = ((Image)this.Art_Image_Background_Cloud_1).Source.ToString();
                    if (!cloudSourcePath.EndsWith("_sunset.png"))
                    {
                        cloudSourcePath = cloudSourcePath.Replace(".png", "_sunset.png");
                    }
                }
                BitmapImage rotating;
                if (this.cachingButtons.ContainsKey(cloudSourcePath))
                {
                    rotating = this.cachingButtons[cloudSourcePath];
                }
                else
                {
                    rotating = new BitmapImage();
                    rotating.BeginInit();
                    rotating.UriSource = new Uri(cloudSourcePath);
                    rotating.EndInit();
                    this.cachingButtons[cloudSourcePath] = rotating;
                }
                ((Image)Art_Image_Background_Cloud_1).Source      = rotating;
                ((Image)Art_Image_Background_Cloud_2).Source      = rotating;
                ((Image)Art_Image_Background_Cloud_Static).Source = null;
            }
            else
            {
                ((Image)Art_Image_Background_Cloud_1).Source      = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Ground_TE_float.png"));
                ((Image)Art_Image_Background_Cloud_2).Source      = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Ground_TE_float.png"));
                ((Image)Art_Image_Background_Cloud_Static).Source = new BitmapImage(new Uri("pack://application:,,,/Yuri;component/Resources/Title_Ground_TE_bg.png"));
            }

            callbackTarget = SymbolTable.GetInstance().GlobalCtxDao.GlobalSymbolTable.Fetch("tracing_callback").ToString();
            this.BackGroundSprite.Descriptor.ToScaleX  = 1.2;
            this.BackGroundSprite.Descriptor.ToScaleY  = 1.2;
            this.BackGroundSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.ScaleToAnimation(this.BackGroundSprite, new Duration(TimeSpan.FromMilliseconds(0)), 1.2, 1.2, 0, 0);
            SpriteAnimation.OpacityToAnimation(this.BackGroundSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);

            this.CloudSpriteA.Descriptor.ToX = 1920 / 2;
            this.CloudSpriteB.Descriptor.ToX = 1920 * 1.5;
            SpriteAnimation.XMoveToAnimation(this.CloudSpriteA, new Duration(TimeSpan.FromSeconds(0)), 1920 / 2, 0);
            SpriteAnimation.XMoveToAnimation(this.CloudSpriteB, new Duration(TimeSpan.FromSeconds(0)), 1920 * 1.5, 0);

            this.RootButtonSprite.Descriptor.ToOpacity = 1;
            SpriteAnimation.OpacityToAnimation(this.RootButtonSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);
            this.UiSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.OpacityToAnimation(this.UiSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);
            this.CloudHolderSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.OpacityToAnimation(this.CloudHolderSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);
            this.MaskSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.OpacityToAnimation(this.MaskSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);
            this.MaskSprite.DisplayBinding.Visibility = Visibility.Hidden;

            this.GalleryWarpSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.OpacityToAnimation(this.GalleryWarpSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);
            this.Canvas_Gallery.Visibility = Visibility.Hidden;

            this.BackGroundSprite.Descriptor.ToScaleX  = 1.0;
            this.BackGroundSprite.Descriptor.ToScaleY  = 1.0;
            this.BackGroundSprite.Descriptor.ToOpacity = 1;
            SpriteAnimation.ScaleToAnimation(this.BackGroundSprite, new Duration(TimeSpan.FromMilliseconds(1000)), 1.0, 1.0, -0.7, -0.7);
            SpriteAnimation.OpacityToAnimation(this.BackGroundSprite, new Duration(TimeSpan.FromMilliseconds(500)), 1, -0.6);

            this.ForeGroundSprite.Descriptor.ToScaleX  = 1.4;
            this.ForeGroundSprite.Descriptor.ToScaleY  = 1.4;
            this.ForeGroundSprite.Descriptor.ToOpacity = 0;
            SpriteAnimation.ScaleToAnimation(this.ForeGroundSprite, new Duration(TimeSpan.FromMilliseconds(0)), 1.4, 1.4, 0, 0);
            SpriteAnimation.OpacityToAnimation(this.ForeGroundSprite, new Duration(TimeSpan.FromMilliseconds(0)), 0, 0);

            this.ForeGroundSprite.Descriptor.ToScaleX  = 1.0;
            this.ForeGroundSprite.Descriptor.ToScaleY  = 1.0;
            this.ForeGroundSprite.Descriptor.ToOpacity = 1;
            SpriteAnimation.ScaleToAnimation(this.ForeGroundSprite, new Duration(TimeSpan.FromMilliseconds(1000)), 1.0, 1.0, -0.7, -0.7, cb: (_, __) =>
            {
                this.UiSprite.Descriptor.ToOpacity = 1;
                SpriteAnimation.OpacityToAnimation(this.UiSprite, new Duration(TimeSpan.FromMilliseconds(500)), 1, -0.6);
                this.Grid_WarpHolder.IsHitTestVisible = true;
            });
            SpriteAnimation.OpacityToAnimation(this.ForeGroundSprite, new Duration(TimeSpan.FromMilliseconds(500)), 1, -0.6);

            this.CloudHolderSprite.Descriptor.ToOpacity = 1;
            SpriteAnimation.OpacityToAnimation(this.CloudHolderSprite, new Duration(TimeSpan.FromMilliseconds(500)), 1, -0.6);

            this.cloudSb = new Storyboard();
            this.CloudSpriteA.Descriptor.ToX = -1920 / 2;
            this.CloudSpriteB.Descriptor.ToX = 1920 / 2;
            SpriteAnimation.XMoveToAnimation(this.CloudSpriteA, new Duration(TimeSpan.FromSeconds(300)), -1920 / 2, 0, null, cloudSb);
            SpriteAnimation.XMoveToAnimation(this.CloudSpriteB, new Duration(TimeSpan.FromSeconds(300)), 1920 / 2, 0, null, cloudSb);
            this.cloudSb.RepeatBehavior = new RepeatBehavior(int.MaxValue);
            this.cloudSb.Begin();
        }
Пример #14
0
        /// <summary>
        /// 处理消息循环
        /// </summary>
        private void UpdateContext(object sender, EventArgs e)
        {
            bool resumeFlag = true;

            this.timer.Stop();
            try
            {
                while (true)
                {
                    // 取得调用堆栈顶部状态
                    StackMachineState stackState = Director.RunMana.GameState(Director.RunMana.CallStack);
                    switch (stackState)
                    {
                    case StackMachineState.Interpreting:
                    case StackMachineState.FunctionCalling:
                        this.curState = GameState.Performing;
                        resumeFlag    = false;
                        break;

                    case StackMachineState.WaitUser:
                        this.curState = GameState.WaitForUserInput;
                        resumeFlag    = true;
                        break;

                    case StackMachineState.WaitAnimation:
                        this.curState = GameState.WaitAni;
                        resumeFlag    = true;
                        break;

                    case StackMachineState.Await:
                        this.curState = GameState.Waiting;
                        resumeFlag    = true;
                        break;

                    case StackMachineState.Interrupt:
                        this.curState = GameState.Interrupt;
                        resumeFlag    = false;
                        break;

                    case StackMachineState.AutoWait:
                        this.curState = GameState.AutoPlay;
                        resumeFlag    = true;
                        break;

                    case StackMachineState.NOP:
                        this.curState = GameState.Exit;
                        resumeFlag    = true;
                        break;
                    }
                    // 根据调用堆栈顶部更新系统
                    switch (this.curState)
                    {
                    // 等待状态
                    case GameState.Waiting:
                        // 计算已经等待的时间
                        if (DateTime.Now - Director.RunMana.CallStack.ESP.TimeStamp >
                            Director.RunMana.CallStack.ESP.Delay)
                        {
                            Director.RunMana.ExitCall(Director.RunMana.CallStack);
                        }
                        break;

                    // 等待动画
                    case GameState.WaitAni:
                        if (SpriteAnimation.IsAnyAnimation == false && SCamera2D.IsAnyAnimation == false &&
                            SCamera3D.IsAnyAnimation == false)
                        {
                            Director.RunMana.ExitCall(Director.RunMana.CallStack);
                        }
                        break;

                    // 自动播放
                    case GameState.AutoPlay:
                        // 等待动画和延时
                        if (DateTime.Now - Director.RunMana.CallStack.ESP.TimeStamp > Director.RunMana.CallStack.ESP.Delay &&
                            SpriteAnimation.IsAnyAnimation == false &&
                            SCamera2D.IsAnyAnimation == false &&
                            SCamera3D.IsAnyAnimation == false &&
                            Director.IsRClicking == false &&
                            Musician.IsVoicePlaying == false &&
                            SemaphoreDispatcher.GetSemaphoreState("System_PreviewShutdown") == false &&
                            ViewPageManager.IsAtMainStage() == true)
                        {
                            this.updateRender.IsShowingDialog = false;
                            this.updateRender.dialogPreStr    = String.Empty;
                            if (this.updateRender.IsContinousDialog == false)
                            {
                                ViewManager.GetInstance().GetMessageLayer(0).Visibility = Visibility.Hidden;
                                this.updateRender.HideMessageTria();
                            }
                            Director.RunMana.ExitCall(Director.RunMana.CallStack);
                        }
                        break;

                    // 等待用户操作
                    case GameState.WaitForUserInput:
                        break;

                    // 中断
                    case GameState.Interrupt:
                        var interruptSa        = Director.RunMana.CallStack.ESP.IP;
                        var interruptExitPoint = Director.RunMana.CallStack.ESP.Tag;
                        // 退出中断
                        var pureInt = Director.RunMana.CallStack.ESP.BindingInterrupt.PureInterrupt;
                        var interruptFuncCalling = Director.RunMana.CallStack.ESP.BindingInterrupt.InterruptFuncSign;
                        var needExitWait         = Director.RunMana.CallStack.ESP.BindingInterrupt.ExitWait;
                        Director.RunMana.ExitCall(Director.RunMana.CallStack);
                        // 处理中断优先动作
                        if (interruptSa != null)
                        {
                            if (interruptSa.Type == SActionType.act_waituser)
                            {
                                Director.RunMana.UserWait("Director", interruptSa.NodeName);
                            }
                            else
                            {
                                var iterSa = interruptSa;
                                while (iterSa != null)
                                {
                                    this.updateRender.Execute(interruptSa);
                                    iterSa = iterSa.Next;
                                }
                            }
                        }
                        // 判断中断是否需要处理后续动作
                        if (pureInt)
                        {
                            break;
                        }
                        // 跳出所有用户等待
                        if (needExitWait || interruptExitPoint != String.Empty)
                        {
                            Director.RunMana.ExitUserWait();
                        }
                        // 处理跳转(与中断调用互斥)
                        if (interruptExitPoint != String.Empty)
                        {
                            RunnableYuriri curRunnable;
                            if (Director.RunMana.CallStack.EBP.BindingFunction == null)
                            {
                                curRunnable = this.resMana.GetScene(Director.RunMana.CallStack.EBP.BindingSceneName);
                            }
                            else
                            {
                                curRunnable = Director.RunMana.CallStack.EBP.BindingFunction;
                            }
                            if (!curRunnable.LabelDictionary.ContainsKey(interruptExitPoint))
                            {
                                LogUtils.LogLine(String.Format("Ignored Interrupt jump Instruction (target not exist): {0}",
                                                               interruptExitPoint), "Director", LogLevel.Error);
                                break;
                            }
                            Director.RunMana.CallStack.EBP.MircoStep(curRunnable.LabelDictionary[interruptExitPoint]);
                        }
                        // 处理中断函数调用
                        else if (interruptFuncCalling != String.Empty)
                        {
                            var ifcItems    = interruptFuncCalling.Split('(');
                            var funPureName = ifcItems[0];
                            var funParas    = "(" + ifcItems[1];
                            this.FunctionCalling(funPureName, funParas, Director.RunMana.CallStack);
                        }
                        break;

                    // 演绎脚本
                    case GameState.Performing:
                        // 取下一动作
                        var nextInstruct = Director.RunMana.MoveNext(Director.RunMana.CallStack);
                        // 如果指令空了就立即迭代本次消息循环
                        if (nextInstruct == null)
                        {
                            this.timer.Start();
                            return;
                        }
                        // 处理影响调用堆栈的动作
                        if (nextInstruct.Type == SActionType.act_wait)
                        {
                            double waitMs = nextInstruct.ArgsDict.ContainsKey("time")
                                    ? (double)PolishEvaluator.Evaluate(nextInstruct.ArgsDict["time"], Director.RunMana.CallStack)
                                    : 0;
                            Director.RunMana.Delay(nextInstruct.NodeName, DateTime.Now,
                                                   TimeSpan.FromMilliseconds(waitMs));
                            break;
                        }
                        else if (nextInstruct.Type == SActionType.act_waitani)
                        {
                            Director.RunMana.AnimateWait(nextInstruct.NodeName);
                            break;
                        }
                        else if (nextInstruct.Type == SActionType.act_waituser)
                        {
                            Director.RunMana.UserWait("Director", nextInstruct.NodeName);
                            break;
                        }
                        else if (nextInstruct.Type == SActionType.act_jump)
                        {
                            try
                            {
                                PersistContextDAO.SaveToSteadyMemory();
                                LogUtils.LogLine("Save persistence context OK when jump", "Director", LogLevel.Important);
                            }
                            catch (Exception se)
                            {
                                LogUtils.LogLine("cannot persist context when jumping, " + se.ToString(), "Director", LogLevel.Error);
                            }

                            var jumpToScene  = nextInstruct.ArgsDict["filename"];
                            var jumpToTarget = nextInstruct.ArgsDict["target"];
                            // 场景内跳转
                            if (jumpToScene == String.Empty)
                            {
                                if (stackState == StackMachineState.Interpreting)
                                {
                                    var currentScene = this.resMana.GetScene(Director.RunMana.CallStack.ESP.BindingSceneName);
                                    if (!currentScene.LabelDictionary.ContainsKey(jumpToTarget))
                                    {
                                        LogUtils.LogLine(
                                            String.Format("Ignored Jump Instruction (target not exist): {0}",
                                                          jumpToTarget),
                                            "Director", LogLevel.Error);
                                        break;
                                    }
                                    RunMana.LastLabelName = jumpToTarget;
                                    Director.RunMana.CallStack.ESP.MircoStep(currentScene.LabelDictionary[jumpToTarget]);
                                }
                                else if (stackState == StackMachineState.FunctionCalling)
                                {
                                    var currentFunc = Director.RunMana.CallStack.ESP.BindingFunction;
                                    if (!currentFunc.LabelDictionary.ContainsKey(jumpToTarget))
                                    {
                                        LogUtils.LogLine(
                                            String.Format("Ignored Jump Instruction (target not exist): {0}",
                                                          jumpToTarget),
                                            "Director", LogLevel.Error);
                                        break;
                                    }
                                    RunMana.LastLabelName = jumpToTarget;
                                    Director.RunMana.CallStack.ESP.MircoStep(currentFunc.LabelDictionary[jumpToTarget]);
                                }
                            }
                            // 跨场景跳转
                            else
                            {
                                var jumpScene = this.resMana.GetScene(jumpToScene);
                                if (jumpScene == null)
                                {
                                    LogUtils.LogLine(
                                        String.Format("Ignored Jump Instruction (scene not exist): {0}", jumpToScene),
                                        "Director", LogLevel.Error);
                                    break;
                                }
                                if (jumpToTarget != String.Empty && !jumpScene.LabelDictionary.ContainsKey(jumpToTarget))
                                {
                                    LogUtils.LogLine(
                                        String.Format("Ignored Jump Instruction (target not exist): {0} -> {1}",
                                                      jumpToScene, jumpToTarget),
                                        "Director", LogLevel.Error);
                                    break;
                                }
                                Director.RunMana.ExitCall(Director.RunMana.CallStack);
                                RunMana.LastSceneName = jumpToScene;
                                RunMana.LastLabelName = jumpToTarget;
                                Director.RunMana.CallScene(jumpScene,
                                                           jumpToTarget == String.Empty ? jumpScene.Ctor : jumpScene.LabelDictionary[jumpToTarget]);
                            }
                            break;
                        }
                        else if (nextInstruct.Type == SActionType.act_call)
                        {
                            var callFunc = nextInstruct.ArgsDict["name"];
                            var signFunc = nextInstruct.ArgsDict["sign"];
                            this.FunctionCalling(callFunc, signFunc, Director.RunMana.CallStack);
                            break;
                        }
                        // 处理常规动作
                        this.updateRender.Execute(nextInstruct);
                        break;

                    // 退出
                    case GameState.Exit:
                        this.updateRender.Shutdown();
                        break;
                    }
                    // 处理IO
                    //this.updateRender.UpdateForMouseState();
                    // 是否恢复消息循环
                    if (resumeFlag)
                    {
                        break;
                    }
                }
            }
            catch (Exception anyEx)
            {
                MessageBox.Show("Fatal Error: " + anyEx.ToString());
                logger.Error("fatal error in main context loop", anyEx);
                throw anyEx;
            }
            finally
            {
                if (resumeFlag)
                {
                    this.timer.Start();
                }
            }
        }
Пример #15
0
        private void Rec_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.RightButton == MouseButtonState.Pressed)
            {
                return;
            }
            var selectedName  = ((Rectangle)sender).Name;
            var selectedCount = Convert.ToInt32(selectedName.Split('_').Last());
            var selectedTerm  = selectedName.Substring(0, selectedName.LastIndexOf('_') + 1);

            for (int i = 1; i <= selectedCount; i++)
            {
                var curRec = (Rectangle)this.FindName(selectedTerm + i);
                curRec.Fill = new SolidColorBrush(this.xichengBlue);
            }
            for (int i = selectedCount + 1; i <= 20; i++)
            {
                var curRec = (Rectangle)this.FindName(selectedTerm + i);
                curRec.Fill = new SolidColorBrush(Color.FromRgb(222, 222, 222));
            }
            if (selectedTerm.StartsWith("Rec_BGM_"))
            {
                if (selectedCount == 1)
                {
                    Musician.GetInstance().BGMVolumeRatio = 0.0;
                }
                else if (selectedCount == 20)
                {
                    Musician.GetInstance().BGMVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().BGMVolumeRatio = 1.0 / 20 * selectedCount;
                }
                PersistContextDAO.Assign("system_config_audio_bgm", selectedCount.ToString());
                Musician.GetInstance().SetBGMVolume(800);
            }
            else if (selectedTerm.StartsWith("Rec_SE_"))
            {
                if (selectedCount == 1)
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 0.0;
                }
                else if (selectedCount == 20)
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 1.0 / 20 * selectedCount;
                }
                PersistContextDAO.Assign("system_config_audio_se", selectedCount.ToString());
            }
            else if (selectedTerm.StartsWith("Rec_VOICE_"))
            {
                if (selectedCount == 1)
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 0.0;
                }
                else if (selectedCount == 20)
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 1.0 / 20 * selectedCount;
                }
                PersistContextDAO.Assign("system_config_audio_voice", selectedCount.ToString());
            }
        }
Пример #16
0
        public void RefreshSteadyConfig()
        {
            string rawRollback = PersistContextDAO.Fetch("system_config_rollback_enable")?.ToString();

            if (rawRollback == "0")
            {
                PersistContextDAO.Assign("system_config_rollback_enable", "true");
                rawRollback = "true";
            }
            Director.IsAllowRollback = rawRollback == "true";
            if (Director.IsAllowRollback)
            {
                this.LabelRadio_Others_Rollback_Enable.Foreground  = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Rollback_Disable.Foreground = new SolidColorBrush(Colors.Black);
            }
            else
            {
                this.LabelRadio_Others_Rollback_Disable.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Rollback_Enable.Foreground  = new SolidColorBrush(Colors.Black);
            }

            string titleType = PersistContextDAO.Fetch("system_config_title_type")?.ToString();

            if (titleType == "0")
            {
                PersistContextDAO.Assign("system_config_title_type", "Timing");
                titleType = "Timing";
            }
            if (titleType == "Timing")
            {
                this.LabelRadio_Others_Title_Timing.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Title_Dusk.Foreground   = new SolidColorBrush(Colors.Black);
            }
            else
            {
                this.LabelRadio_Others_Title_Dusk.Foreground   = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Title_Timing.Foreground = new SolidColorBrush(Colors.Black);
            }

            string performanceType = PersistContextDAO.Fetch("system_config_performance_set")?.ToString();

            if (performanceType == "0")
            {
                PersistContextDAO.Assign("system_config_performance_set", "Enable");
                performanceType = "Enable";
            }
            if (performanceType == "Enable")
            {
                this.LabelRadio_Others_Performance_Enable.Foreground  = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Performance_Disable.Foreground = new SolidColorBrush(Colors.Black);
            }
            else
            {
                this.LabelRadio_Others_Performance_Disable.Foreground = new SolidColorBrush(this.xichengBlue);
                this.LabelRadio_Others_Performance_Enable.Foreground  = new SolidColorBrush(Colors.Black);
            }

            string autoSpeedRaw = PersistContextDAO.Fetch("system_config_autospeed")?.ToString();

            if (autoSpeedRaw == "0")
            {
                PersistContextDAO.Assign("system_config_autospeed", "3");
                autoSpeedRaw = "3";
            }
            var autoSpeed = Convert.ToInt32(autoSpeedRaw);

            for (int i = 1; i <= 5; i++)
            {
                var cl = (Label)this.FindName("LabelRadio_Grahpic_Auto_" + i);
                if (i != autoSpeed)
                {
                    cl.Foreground = new SolidColorBrush(Colors.Black);
                }
                else
                {
                    cl.Foreground = new SolidColorBrush(this.xichengBlue);
                }
            }
            switch (autoSpeed)
            {
            case 1:
                GlobalConfigContext.GAME_MSG_AUTOPLAY_DELAY = 7000;
                break;

            case 2:
                GlobalConfigContext.GAME_MSG_AUTOPLAY_DELAY = 3500;
                break;

            case 3:
                GlobalConfigContext.GAME_MSG_AUTOPLAY_DELAY = 2000;
                break;

            case 4:
                GlobalConfigContext.GAME_MSG_AUTOPLAY_DELAY = 1500;
                break;

            case 5:
                GlobalConfigContext.GAME_MSG_AUTOPLAY_DELAY = 600;
                break;
            }

            string typeSpeedRaw = PersistContextDAO.Fetch("system_config_typespeed")?.ToString();

            if (typeSpeedRaw == "0")
            {
                PersistContextDAO.Assign("system_config_typespeed", "3");
                typeSpeedRaw = "3";
            }
            var typeSpeed = Convert.ToInt32(typeSpeedRaw);

            for (int i = 1; i <= 5; i++)
            {
                var cl = (Label)this.FindName("LabelRadio_Grahpic_Typing_" + i);
                if (i != typeSpeed)
                {
                    cl.Foreground = new SolidColorBrush(Colors.Black);
                }
                else
                {
                    cl.Foreground = new SolidColorBrush(this.xichengBlue);
                }
            }
            switch (typeSpeed)
            {
            case 1:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 120;
                break;

            case 2:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 90;
                break;

            case 3:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 30;
                break;

            case 4:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 10;
                break;

            case 5:
                GlobalConfigContext.GAME_MSG_TYPING_DELAY = 0;
                break;
            }

            string bgmRaw = PersistContextDAO.Fetch("system_config_audio_bgm")?.ToString();

            if (bgmRaw == "0")
            {
                PersistContextDAO.Assign("system_config_audio_bgm", "18");
                bgmRaw = "18";
            }
            var bgmRatio = Convert.ToInt32(bgmRaw);

            for (int i = 1; i <= bgmRatio; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_BGM_" + i);
                curRec.Fill = new SolidColorBrush(this.xichengBlue);
            }
            for (int i = bgmRatio + 1; i <= 20; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_BGM_" + i);
                curRec.Fill = new SolidColorBrush(Color.FromRgb(222, 222, 222));
            }
            if (!musicianInit)
            {
                if (bgmRatio == 1)
                {
                    Musician.GetInstance().BGMVolumeRatio = 0.0;
                }
                else if (bgmRatio == 20)
                {
                    Musician.GetInstance().BGMVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().BGMVolumeRatio = 1.0 / 20 * bgmRatio;
                }
                Musician.GetInstance().SetBGMVolume(800);
            }

            string seRaw = PersistContextDAO.Fetch("system_config_audio_se")?.ToString();

            if (seRaw == "0")
            {
                PersistContextDAO.Assign("system_config_audio_se", "18");
                seRaw = "18";
            }
            var seRatio = Convert.ToInt32(seRaw);

            for (int i = 1; i <= seRatio; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_SE_" + i);
                curRec.Fill = new SolidColorBrush(this.xichengBlue);
            }
            for (int i = seRatio + 1; i <= 20; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_SE_" + i);
                curRec.Fill = new SolidColorBrush(Color.FromRgb(222, 222, 222));
            }
            if (!musicianInit)
            {
                if (seRatio == 1)
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 0.0;
                }
                else if (seRatio == 20)
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().SEDefaultVolumeRatio = 1.0 / 20 * seRatio;
                }
            }

            string voiceRaw = PersistContextDAO.Fetch("system_config_audio_voice")?.ToString();

            if (voiceRaw == "0")
            {
                PersistContextDAO.Assign("system_config_audio_voice", "20");
                voiceRaw = "20";
            }
            var voiceRatio = Convert.ToInt32(voiceRaw);

            for (int i = 1; i <= voiceRatio; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_VOICE_" + i);
                curRec.Fill = new SolidColorBrush(this.xichengBlue);
            }
            for (int i = voiceRatio + 1; i <= 20; i++)
            {
                var curRec = (Rectangle)this.FindName("Rec_VOICE_" + i);
                curRec.Fill = new SolidColorBrush(Color.FromRgb(222, 222, 222));
            }
            if (!musicianInit)
            {
                if (voiceRatio == 1)
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 0.0;
                }
                else if (voiceRatio == 20)
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 1.0;
                }
                else
                {
                    Musician.GetInstance().VocalDefaultVolumeRatio = 1.0 / 20 * voiceRatio;
                }
            }

            musicianInit = true;

            string xwVoiceRaw = PersistContextDAO.Fetch("system_config_audio_voice_xw")?.ToString();

            if (xwVoiceRaw == "0")
            {
                PersistContextDAO.Assign("system_config_audio_voice_xw", "true");
                xwVoiceRaw = "true";
            }
            voice_xw = xwVoiceRaw == "true";
            var xwVoiceSourcePath = this.Chara_VOICE_XW.Source.ToString();

            if (voice_xw == true && xwVoiceSourcePath.EndsWith("On.png") || voice_xw == false && xwVoiceSourcePath.EndsWith("Off.png"))
            {
                // nothing
            }
            else if (voice_xw == true)
            {
                xwVoiceSourcePath = xwVoiceSourcePath.Replace("Off.png", "On.png");
            }
            else if (voice_xw == false)
            {
                xwVoiceSourcePath = xwVoiceSourcePath.Replace("On.png", "Off.png");
            }

            BitmapImage voiceXWRotating;

            if (this.cachingButtons.ContainsKey(xwVoiceSourcePath))
            {
                voiceXWRotating = this.cachingButtons[xwVoiceSourcePath];
            }
            else
            {
                voiceXWRotating = new BitmapImage();
                voiceXWRotating.BeginInit();
                voiceXWRotating.UriSource = new Uri(xwVoiceSourcePath);
                voiceXWRotating.EndInit();
                this.cachingButtons[xwVoiceSourcePath] = voiceXWRotating;
            }
            this.Chara_VOICE_XW.Source = voiceXWRotating;

            string qlVoiceRaw = PersistContextDAO.Fetch("system_config_audio_voice_ql")?.ToString();

            if (qlVoiceRaw == "0")
            {
                PersistContextDAO.Assign("system_config_audio_voice_ql", "true");
                qlVoiceRaw = "true";
            }
            voice_ql = qlVoiceRaw == "true";
            var qlVoiceSourcePath = this.Chara_VOICE_QL.Source.ToString();

            if (voice_ql == true && qlVoiceSourcePath.EndsWith("On.png") || voice_ql == false && qlVoiceSourcePath.EndsWith("Off.png"))
            {
                // nothing
            }
            else if (voice_ql == true)
            {
                qlVoiceSourcePath = qlVoiceSourcePath.Replace("Off.png", "On.png");
            }
            else if (voice_ql == false)
            {
                qlVoiceSourcePath = qlVoiceSourcePath.Replace("On.png", "Off.png");
            }

            BitmapImage voiceQLRotating;

            if (this.cachingButtons.ContainsKey(qlVoiceSourcePath))
            {
                voiceQLRotating = this.cachingButtons[qlVoiceSourcePath];
            }
            else
            {
                voiceQLRotating = new BitmapImage();
                voiceQLRotating.BeginInit();
                voiceQLRotating.UriSource = new Uri(qlVoiceSourcePath);
                voiceQLRotating.EndInit();
                this.cachingButtons[qlVoiceSourcePath] = voiceQLRotating;
            }
            this.Chara_VOICE_QL.Source = voiceQLRotating;

            string userFontName = PersistContextDAO.Fetch("system_config_userfont_name")?.ToString();

            if (userFontName == "0")
            {
                PersistContextDAO.Assign("system_config_userfont_name", "default");
                userFontName = "default";
            }
            string userFontSize = PersistContextDAO.Fetch("system_config_userfont_size")?.ToString();

            if (userFontSize == "0")
            {
                PersistContextDAO.Assign("system_config_userfont_size", GlobalConfigContext.GAME_FONT_FONTSIZE.ToString());
                userFontSize = GlobalConfigContext.GAME_FONT_FONTSIZE.ToString();
            }
            lock (LHSettingsPage.syncObj)
            {
                if (fontInit == false)
                {
                    try
                    {
                        this.startupDefaultFontName    = GlobalConfigContext.GAME_FONT_NAME;
                        this.startupDefaultFontSize    = GlobalConfigContext.GAME_FONT_FONTSIZE;
                        this.Label_FontName.Content    = userFontName;
                        this.Label_FontName.FontSize   = Convert.ToDouble(userFontSize);
                        this.Label_FontName.FontFamily = new FontFamily(userFontName);

                        Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontname", userFontName);
                        Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontsize", userFontSize);
                        GlobalConfigContext.GAME_FONT_NAME     = userFontName;
                        GlobalConfigContext.GAME_FONT_FONTSIZE = int.Parse(userFontSize);
                    }
                    catch (Exception fe)
                    {
                        LogUtils.LogLine("cannot load user custom font: " + fe.ToString(), nameof(LHSettingsPage), LogLevel.Error);
                        Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontname", this.startupDefaultFontName);
                        Director.GetInstance().GetMainRender().MsgLayerOpt(0, "fontsize", this.startupDefaultFontSize.ToString());
                        GlobalConfigContext.GAME_FONT_NAME     = this.startupDefaultFontName;
                        GlobalConfigContext.GAME_FONT_FONTSIZE = this.startupDefaultFontSize;
                    }
                    fontInit = true;
                }
                else
                {
                    if (userFontName == "default")
                    {
                        this.Label_FontName.Content    = "(默认)Source Han Serif";
                        this.Label_FontName.FontSize   = 32;
                        this.Label_FontName.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "Resources/#Source Han Serif CN SemiBold");
                    }
                    else
                    {
                        this.Label_FontName.Content    = userFontName;
                        this.Label_FontName.FontSize   = Convert.ToDouble(userFontSize);
                        this.Label_FontName.FontFamily = new FontFamily(userFontName);
                    }
                }
            }
        }
Пример #17
0
        /// <summary>
        /// 初始化精灵对象,它只能被执行一次
        /// </summary>
        /// <param name="resName">资源名称</param>
        /// <param name="resType">资源类型</param>
        /// <param name="ms">材质的内存流</param>
        /// <param name="cutrect">材质切割矩形</param>
        public void Init(string resName, ResourceType resType, MemoryStream ms, Int32Rect?cutrect = null)
        {
            this.memoryStreamRef = ms;
            if (!this.IsInit)
            {
                this.ResourceName = resName;
                this.ResourceType = resType;
                var highPerformanceFlag = PersistContextDAO.Fetch("system_config_performance_set")?.ToString() == "Disable";
                if (highPerformanceFlag || resType != ResourceType.Stand || resName.StartsWith("@") || !resName.Contains("_@"))
                {
                    this.SpriteBitmapImage = new BitmapImage();
                    this.SpriteBitmapImage.BeginInit();
                    this.SpriteBitmapImage.StreamSource = ms;
                    if (cutrect != null)
                    {
                        this.CutRect = (Int32Rect)cutrect;
                        this.SpriteBitmapImage.SourceRect = this.CutRect;
                    }
                    this.SpriteBitmapImage.EndInit();
                    this.IsInit = true;
                    // 加载Mask
                    var rm       = ResourceManager.GetInstance();
                    var maskPath = GlobalConfigContext.PictureMaskPrefix + resName;
                    this.IsMaskTriggerable = rm.IsResourceExist(maskPath, ResourceType.Pictures);
                    if (this.IsMaskTriggerable)
                    {
                        this.MaskSprite = rm.GetPicture(maskPath, ResourceManager.FullImageRect);
                    }
                    this.IsAutoAnimateable = false;
                }
                // 如果是立绘,就看是否需要加载帧动画
                else
                {
                    this.IsAutoAnimateable = true;
                    var splitor = resName.LastIndexOf(".");
                    var prefix  = resName.Substring(0, splitor);
                    var postfix = resName.Substring(splitor, resName.Length - splitor);
                    this.AutoAnimationCount = 4;
                    this.animationImageList = new List <BitmapImage>();
                    var rm = ResourceManager.GetInstance();
                    for (int i = 1; i <= this.AutoAnimationCount; i++)
                    {
                        var actualName = $"@{prefix}@{i}{postfix}";
                        var tSprite    = rm.GetCharacterStand(actualName, ResourceManager.FullImageRect);
                        this.animationImageList.Add(tSprite.SpriteBitmapImage);
                    }
                    this.autoAnimationTimer = new System.Windows.Forms.Timer
                    {
                        Interval = 5000
                    };
                    this.autoAnimationTimer.Tick += AutoAnimationTimer_Tick;
                    this.autoAnimationTimer.Start();
                    this.SpriteBitmapImage = this.animationImageList[0];
                    this.IsInit            = true;

                    // fast wink when loaded
                    try
                    {
                        this.AutoAnimationTimer_Tick(null, null);
                    } catch (Exception e)
                    {
                        LogUtils.LogLine("fast wink failed: " + e.ToString(), "YuriSprite", LogLevel.Warning);
                    }
                }
            }
            else
            {
                LogUtils.LogLine($"Sprite Init again: {resName}", "MySprite", LogLevel.Error);
            }
        }