Esempio n. 1
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);
        }
Esempio n. 2
0
        private void ProgressTimer_Tick(object sender, EventArgs e)
        {
            if (this.IsPlaying == false)
            {
                this.progressTimer.Stop();
                return;
            }
            var ms = Musician.GetInstance();

            if (ms.IsBgmPlaying == false)
            {
                return;
            }
            var padSpace = GlobalConfigContext.GAME_WINDOW_WIDTH * (1 - ms.BgmPosition.TotalMilliseconds / ms.BgmDuration.TotalMilliseconds);

            if (Double.IsNaN(padSpace))
            {
                return;
            }
            this.Music_TimeStamp.Content = String.Format("{0:00}:{1:00} / {2:00}:{3:00}",
                                                         ms.BgmPosition.Minutes, ms.BgmPosition.Seconds, ms.BgmDuration.Minutes, ms.BgmDuration.Seconds);
            this.Music_ProgressBar.Margin = new Thickness(0, GlobalConfigContext.GAME_WINDOW_HEIGHT - 10, padSpace, 0);
        }
Esempio n. 3
0
        /// <summary>
        /// 按钮:停止
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.isMusicMana)
            {
                switch (this.tabControl1.SelectedTab.Text)
                {
                case "BGM":
                    Musician.GetInstance().StopAndReleaseBGM();
                    break;

                case "BGS":
                    Musician.GetInstance().StopBGS();
                    break;

                case "Vocal":
                    Musician.GetInstance().StopAndReleaseVocal();
                    break;
                }
            }
            else
            {
                this.Close();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 设置运行时环境管理器,用于读取保存的信息
        /// </summary>
        /// <param name="rm">反序列化后的RM实例</param>
        public static void ResumeFromSaveData(RuntimeManager rm)
        {
            // 停止消息循环
            Director.PauseUpdateContext();
            // 清空回滚器
            RollbackManager.Clear();
            // 清空画面
            ViewManager.GetInstance().RemoveView(ResourceType.Unknown);
            // 检查是否需要回滚当前的并行处理
            Director.RunMana.StopAllParallel();
            // 变更运行时环境
            Director.RunMana = rm;
            Director.RunMana.ParallelHandler = Director.GetInstance().ParallelUpdateContext;
            SymbolTable.ResetSynObject(Director.RunMana.Symbols);
            LogUtils.LogLine("RuntimeManager is replaced", "Director", LogLevel.Important);
            // 缓存指令指针
            var irname = rm.CallStack.ESP.IR;
            var isname = rm.CallStack.ESP.BindingSceneName;

            rm.CallStack.ESP.MircoStep(Director.GetInstance().resMana.GetScene(isname).YuriDict[irname]);
            // 变更屏幕管理器
            ScreenManager.ResetSynObject(Director.RunMana.Screen);
            LogUtils.LogLine("ScreenManager is replaced", "Director", LogLevel.Important);
            // 重绘整个画面
            ViewManager.GetInstance().ReDraw();
            // 重新绑定渲染器的作用堆栈
            UpdateRender render = Director.GetInstance().updateRender;

            render.VsmReference = Director.RunMana.CallStack;
            // 恢复背景音乐
            if (GlobalConfigContext.UseBassEngine)
            {
                MusicianBass.GetInstance().RePerform(Director.RunMana.Musics);
            }
            else
            {
                Musician.GetInstance().RePerform(Director.RunMana.Musics);
            }
            // 清空字符串缓冲
            render.dialogPreStr = String.Empty;
            render.pendingDialogQueue.Clear();
            // 关闭自动播放
            Director.RunMana.IsAutoplaying = false;
            // 弹空全部等待,复现保存最后一个动作
            Director.RunMana.ExitUserWait();
            Interrupt reactionNtr = new Interrupt()
            {
                Type              = InterruptType.LoadReaction,
                Detail            = "Reaction for load data",
                InterruptSA       = Director.RunMana.DashingPureSa,
                InterruptFuncSign = String.Empty,
                ReturnTarget      = null,
                PureInterrupt     = true
            };

            // 提交中断
            Director.RunMana.CallStack.Submit(reactionNtr);
            // 重启并行调度系统
            var sc = ResourceManager.GetInstance().GetScene(Director.RunMana.CallStack.EBP.BindingSceneName);

            Director.RunMana.ParallelExecutorStack = new Stack <List <ParallelExecutor> >();
            Director.RunMana.ConstructParallel(sc);
            Director.RunMana.RestartParallel();
            Director.RunMana.LastScenario = sc.Scenario;
            // 重启信号分发系统
            SemaphoreDispatcher.ReBinding(sc, Director.RunMana.SemaphoreBindings);
            // 重启主调用堆栈上的消息循环
            Director.ResumeUpdateContext();
        }
Esempio n. 5
0
        /// <summary>
        /// 按钮:播放
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.isMusicMana)
            {
                switch (this.tabControl1.SelectedTab.Text)
                {
                case "BGM":
                    if (this.listBoxBGM.SelectedIndex != -1)
                    {
                        Musician.GetInstance().PlayBGM(this.listBoxBGM.SelectedItem.ToString(), this.BGMVec[this.listBoxBGM.SelectedIndex], this.volTrackBar.Value);
                    }
                    break;

                case "BGS":
                    if (this.listBoxBGS.SelectedIndex != -1)
                    {
                        Musician.GetInstance().PlayBGS(this.BGSVec[this.listBoxBGS.SelectedIndex], this.volTrackBar.Value);
                    }
                    break;

                case "SE":
                    if (this.listBoxSE.SelectedIndex != -1)
                    {
                        Musician.GetInstance().PlaySE(this.SEVec[this.listBoxSE.SelectedIndex], this.volTrackBar.Value);
                    }
                    break;

                case "Vocal":
                    if (this.listBoxVocal.SelectedIndex != -1)
                    {
                        Musician.GetInstance().PlayVocal(this.VocalVec[this.listBoxVocal.SelectedIndex], this.volTrackBar.Value);
                    }
                    break;
                }
            }
            else
            {
                switch (this.tabControl1.SelectedTab.Text)
                {
                case "BGM":
                    if (this.listBoxBGM.SelectedIndex != -1)
                    {
                        if (this.isEditing)
                        {
                            Halation.GetInstance().DashEditPlayBGM(
                                this.listBoxBGM.SelectedItem.ToString(), this.volTrackBar.Value.ToString());
                        }
                        else
                        {
                            Halation.GetInstance().DashPlayBGM(
                                this.listBoxBGM.SelectedItem.ToString(), this.volTrackBar.Value.ToString());
                        }
                    }
                    break;

                case "BGS":
                    if (this.listBoxBGS.SelectedIndex != -1)
                    {
                        Halation.GetInstance().DashPlayBGS(this.listBoxBGS.SelectedItem.ToString(), this.volTrackBar.Value.ToString());
                    }
                    break;

                case "SE":
                    if (this.listBoxSE.SelectedIndex != -1)
                    {
                        Halation.GetInstance().DashPlaySE(this.listBoxSE.SelectedItem.ToString(), this.volTrackBar.Value.ToString());
                    }
                    break;
                }
                this.Close();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 将系统跳转到指定的稳定状态
        /// </summary>
        /// <param name="ssp">要演绎的状态包装</param>
        public static void GotoSteadyState(RollbackableSnapshot ssp)
        {
            // 停止消息循环
            Director.PauseUpdateContext();
            // 结束全部动画
            SpriteAnimation.ClearAnimateWaitingDict();
            // 检查是否需要回滚当前的并行处理和信号绑定
            bool needRepara = false;

            if (ssp.VMRef.ESP.BindingSceneName != Director.RunMana.CallStack.SAVEP.BindingSceneName)
            {
                Director.RunMana.PauseParallel();
                needRepara = true;
            }
            // 退到SSP所描述的状态
            SymbolTable.GetInstance().SetDAO(ssp.sceneDao.Fork() as SceneContextDAO, ssp.globalDao.Fork() as GlobalContextDAO);
            ScreenManager.ResetSynObject(ssp.ScreenStateRef.Fork() as ScreenManager);
            Director.RunMana.ResetCallstackObject(ssp.VMRef.Fork() as StackMachine);
            Director.RunMana.Backlogs          = ForkableState.DeepCopyBySerialization(ssp.BacklogRef);
            Director.RunMana.Musics            = ForkableState.DeepCopyBySerialization(ssp.MusicRef);
            Director.RunMana.DashingPureSa     = ssp.ReactionRef.Clone(true);
            Director.RunMana.SemaphoreBindings = ForkableState.DeepCopyBySerialization(ssp.SemaphoreDict);
            Director.RunMana.EnableRClick      = ssp.EnableRClickRef;
            Director.RunMana.PerformingChapter = ssp.PerformingChapterRef;
            Director.ScrMana = ScreenManager.GetInstance();
            // 刷新主渲染器上的堆栈绑定
            Director.GetInstance().RefreshMainRenderVMReference();
            Director.GetInstance().GetMainRender().IsBranching = ssp.IsBranchingRefer;
            // 重绘整个画面
            ViewManager.GetInstance().ReDraw(true);
            // 恢复音效
            UpdateRender render = Director.GetInstance().GetMainRender();

            if (GlobalConfigContext.UseBassEngine)
            {
                MusicianBass.GetInstance().RePerform(Director.RunMana.Musics);
            }
            else
            {
                Musician.GetInstance().RePerform(Director.RunMana.Musics);
            }
            // 清空字符串缓冲
            render.dialogPreStr = String.Empty;
            render.pendingDialogQueue.Clear();
            // 关闭自动播放
            Director.RunMana.IsAutoplaying = false;
            // 弹空全部等待,复现保存最后一个动作
            Director.RunMana.ExitUserWait();
            Interrupt reactionNtr = new Interrupt()
            {
                Type              = InterruptType.LoadReaction,
                Detail            = "Reaction for rollback",
                InterruptSA       = ssp.ReactionRef,
                InterruptFuncSign = String.Empty,
                ReturnTarget      = null,
                PureInterrupt     = true
            };

            // 提交中断到主调用堆栈
            Director.RunMana.CallStack.Submit(reactionNtr);
            // 重启并行处理和信号系统
            if (needRepara)
            {
                var sc = ResourceManager.GetInstance().GetScene(ssp.VMRef.EBP.BindingSceneName);
                Director.RunMana.ConstructParallelForRollingBack(sc);
                Director.RunMana.BackTraceParallel();
                Director.RunMana.LastSceneName = sc.Scenario;
                SemaphoreDispatcher.ReBinding(sc, Director.RunMana.SemaphoreBindings);
            }
            // 重启消息循环
            Director.ResumeUpdateContext();
        }
Esempio n. 7
0
        public void StoryBookForwardNextSteady()
        {
            // 如果在看背景就先切回故事模式
            if (this.ShowingBackground)
            {
                DecorateSprite.Descriptor.ToOpacity = 1;
                DialogueSprite.Descriptor.ToOpacity = 1;
                SpriteAnimation.OpacityToAnimation(DecorateSprite, TimeSpan.FromMilliseconds(100), 1);
                SpriteAnimation.OpacityToAnimation(DialogueSprite, TimeSpan.FromMilliseconds(100), 1);
                //SpriteAnimation.BlurMutexAnimation(MainFrameSprite, TimeSpan.FromMilliseconds(100), 0, 30);
                this.ShowingBackground = false;
                return;
            }
            // 选择项就忽略
            if (this.IsStoryBranching)
            {
                return;
            }
            // 打字动画中就跳过
            if (MsgStoryboard != null)
            {
                lock (MsgStoryboard)
                {
                    if (MsgStoryboard != null)
                    {
                        MsgStoryboard.SkipToFill();
                        return;
                    }
                }
            }
            // 瞄下队列头,是否是空队列,是的话说明要换页
            if (CurrentMessageQueue.Count == 0)
            {
                // 全部都结束啦
                if (PendingMessageQueue.Count == 0)
                {
                    this.PrepareClose();
                    return;
                }
                this.StackPanel_DialogList.Children.Clear();
                CurrentMessageQueue = PendingMessageQueue.Dequeue();
                if (IntentBacklog != null)
                {
                    BacklogStack.Push(IntentBacklog);
                }
                IntentBacklog = ForkableState.DeepCopyBySerialization(CurrentMessageQueue);
            }
            // 取下一条要显示的内容
            var currentRun = CurrentMessageQueue.Dequeue();

            // 选择支:SELECT@分支1@分支2@...
            if (currentRun.StartsWith("SELECT@"))
            {
                var selectionItem = currentRun.Split('@');
                var insertBlock   = new TextBlock
                {
                    Opacity      = 1,
                    Margin       = new Thickness(10, 16, 10, 50),
                    TextWrapping = TextWrapping.Wrap,
                    Foreground   = new SolidColorBrush(Colors.White),
                    FontSize     = 30,
                    FontFamily   = new FontFamily(new Uri("pack://application:,,,/"), "Resources/#Source Han Serif CN SemiBold"),
                    Text         = selectionItem[1]
                };
                this.StackPanel_DialogList.Children.Add(insertBlock);
                for (var i = 2; i < selectionItem.Length; i++)
                {
                    var selectionLable = new Label
                    {
                        Background = new SolidColorBrush(Color.FromArgb(70, 0, 0, 0)),
                        Margin     = new Thickness(10, 80, 10, 0),
                        Foreground = new SolidColorBrush(Colors.White),
                        Height     = 60,
                        FontSize   = 30,
                        FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "Resources/#Source Han Serif CN SemiBold"),
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        Content = selectionItem[i],
                        Tag     = i.ToString()
                    };
                    selectionLable.MouseEnter        += this.Selection_OnMouseEnter;
                    selectionLable.MouseLeave        += this.Selection_OnMouseLeave;
                    selectionLable.MouseLeftButtonUp += this.Selection_OnMouseLeftButtonUp;
                    this.StackPanel_DialogList.Children.Add(selectionLable);
                }
                this.IsStoryBranching = true;
            }
            // 背景:BG@变换时间@图片资源名
            else if (currentRun.StartsWith("BG@"))
            {
                var selectionItem   = currentRun.Split('@');
                var bgTransformTime = Convert.ToInt32(selectionItem[1]);
                var bgResourceName  = selectionItem[2];
                if (bgResourceName != String.Empty)
                {
                    // backlay
                    if (this.Image_StoryBook_BgTransitor.Source == null)
                    {
                        this.Grid_StoryBook.Background = new SolidColorBrush(Colors.Transparent);
                    }
                    else
                    {
                        this.Grid_StoryBook.Background = new ImageBrush(this.Image_StoryBook_BgTransitor.Source);
                    }
                    BgTransitorSprite.Descriptor.Opacity     = 0;
                    BgTransitorSprite.DisplayBinding.Opacity = 0;
                    this.Image_StoryBook_BgTransitor.Source  = resMana.GetPicture(bgResourceName, ResourceManager.FullImageRect).SpriteBitmapImage;
                    BgTransitorSprite.Descriptor.ToOpacity   = 1;
                    SpriteAnimation.OpacityToAnimation(BgTransitorSprite, TimeSpan.FromMilliseconds(bgTransformTime), 1);
                }
                else
                {
                    this.Grid_StoryBook.Background         = new SolidColorBrush(Colors.Transparent);
                    BgTransitorSprite.Descriptor.ToOpacity = 0;
                    SpriteAnimation.OpacityToAnimation(BgTransitorSprite, TimeSpan.FromMilliseconds(bgTransformTime), 0);
                }
                this.StoryBookForwardNextSteady();
            }
            // 声效:SE@音量@SE资源名
            else if (currentRun.StartsWith("SE@"))
            {
                var selectionItem = currentRun.Split('@');
                var volume        = Convert.ToDouble(selectionItem[1]);
                Musician.GetInstance().PlaySE(resMana.GetSE(selectionItem[2]), (float)volume);
                this.StoryBookForwardNextSteady();
            }
            else
            {
                var dialogItem = currentRun.Split('@');
                var fgColor    = Colors.White;
                if (dialogItem.Length > 1)
                {
                    if (CharacterColorDict.ContainsKey(dialogItem[0]))
                    {
                        fgColor = CharacterColorDict[dialogItem[0]];
                    }

                    currentRun = dialogItem[1];
                }
                var insertBlock = new TextBlock
                {
                    Opacity      = 1,
                    Margin       = new Thickness(10, 16, 10, 10),
                    TextWrapping = TextWrapping.Wrap,
                    Foreground   = new SolidColorBrush(fgColor),
                    FontSize     = 30,
                    FontFamily   = new FontFamily(new Uri("pack://application:,,,/"), "Resources/#Source Han Serif CN SemiBold"),
                    Text         = String.Empty
                };
                // 把前一条内容透明化
                if (this.StackPanel_DialogList.Children.Count > 0)
                {
                    var lastMsgBlock      = this.StackPanel_DialogList.Children[this.StackPanel_DialogList.Children.Count - 1] as TextBlock;
                    var OpacingDescriptor = new YuriSprite()
                    {
                        DisplayBinding   = lastMsgBlock,
                        AnimationElement = lastMsgBlock,
                        Descriptor       = new SpriteDescriptor()
                    };
                    OpacingDescriptor.Descriptor.ToOpacity = 0.4;
                    SpriteAnimation.OpacityToAnimation(OpacingDescriptor, TimeSpan.FromMilliseconds(500), 0.4);
                }
                this.StackPanel_DialogList.Children.Add(insertBlock);
                this.TypeWriter(String.Empty, currentRun, insertBlock, GlobalConfigContext.GAME_MSG_TYPING_DELAY);
            }
        }
Esempio n. 8
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);
                    }
                }
            }
        }
Esempio n. 9
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());
            }
        }