/// <summary> /// 构造器 /// </summary> public MainWindow() { InitializeComponent(); ViewManager.SetWindowReference(this); this.Title = GlobalConfigContext.GAME_TITLE_NAME; this.Width = GlobalConfigContext.GAME_VIEWPORT_WIDTH; this.Height = GlobalConfigContext.GAME_VIEWPORT_ACTUALHEIGHT; this.mainCanvas.Width = GlobalConfigContext.GAME_WINDOW_WIDTH; this.mainCanvas.Height = GlobalConfigContext.GAME_WINDOW_HEIGHT; this.ResizeMode = GlobalConfigContext.GAME_WINDOW_RESIZEABLE ? ResizeMode.CanResize : ResizeMode.NoResize; // 加载主页面 this.mainFrame.Width = GlobalConfigContext.GAME_WINDOW_WIDTH; this.mainFrame.Height = GlobalConfigContext.GAME_WINDOW_HEIGHT; ViewPageManager.RegisterPage("SplashPage", new SplashPage()); ViewPageManager.RegisterPage("LHPage", new LHPage()); ViewPageManager.RegisterPage("LHStartPage", new LHStartPage()); this.maskFrame.Width = GlobalConfigContext.GAME_WINDOW_WIDTH; this.maskFrame.Height = GlobalConfigContext.GAME_WINDOW_HEIGHT; this.uiFrame.Width = GlobalConfigContext.GAME_WINDOW_WIDTH; this.uiFrame.Height = GlobalConfigContext.GAME_WINDOW_HEIGHT; ViewManager.MaskFrameRef = this.maskFrame; InputMethod.SetIsInputMethodEnabled(this, false); this.mainFrame.Content = ViewPageManager.RetrievePage("SplashPage"); if (GlobalConfigContext.GAME_WINDOW_FULLSCREEN) { Director.IsFullScreen = true; this.FullScreenTransform(); } logger.Info("main window loaded"); }
public void PrepareClose() { this.Frame_SaveLoad.IsHitTestVisible = false; this.WarpedPageSprite.DisplayBinding.Visibility = Visibility.Hidden; if (this.isLoading == false && callbackTarget != String.Empty) { var callbackNtr = new Interrupt() { Detail = "LHRCCallbackNTR", InterruptSA = null, Type = InterruptType.ButtonJump, ReturnTarget = callbackTarget, ExitWait = true }; // 提交返回主舞台的中断到主调用堆栈 Director.RunMana.CallStack.Submit(callbackNtr); // 重置回调 callbackTarget = String.Empty; Director.RunMana.Symbols.GlobalCtxDao.GlobalSymbolTable.Assign("tracing_callback", String.Empty); } if (this.cloudSb != null) { this.cloudSb.SkipToFill(); this.cloudSb = null; } ViewPageManager.CollapseUIPage(); }
// DEBUG private void button1_Click(object sender, RoutedEventArgs e) { //this.core.GetMainRender().Load("mysave"); SLPage p = (SLPage)ViewPageManager.RetrievePage("LoadPage"); p.ReLoadFileInfo(); NavigationService.GetNavigationService(this)?.Navigate(p); }
// DEBUG private void button_Click(object sender, RoutedEventArgs e) { //this.core.GetMainRender().Save("mysave"); ViewManager.RenderFrameworkElementToJPEG(this.BO_MainGrid, GlobalConfigContext.GAME_SAVE_DIR + "\\tempSnapshot.jpg"); SLPage p = (SLPage)ViewPageManager.RetrievePage("SavePage"); p.ReLoadFileInfo(); NavigationService.GetNavigationService(this)?.Navigate(p); }
/// <summary> /// 事件:窗体关闭 /// </summary> private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (!ViewPageManager.IsAtMainStage()) { SplashPage.LoadingExitFlag = true; Director.CollapseWorld(); return; } if (SemaphoreDispatcher.CountBinding("System_PreviewShutdown") > 0) { e.Cancel = true; SemaphoreDispatcher.Activate("System_PreviewShutdown"); } else { Director.CollapseWorld(); } }
/// <summary> /// 强制跳转到主舞台 /// </summary> public void GoToMainStage() { if (MainWindow.initFlag == false) { if (GlobalConfigContext.GAME_IS3D) { this.world.SetStagePageReference(new Stage3D()); } else { this.world.SetStagePageReference(new Stage2D()); } // 预注册保存和读取页面 //ViewPageManager.RegisterPage("SavePage", new SLPage(isSave: true)); //ViewPageManager.RegisterPage("LoadPage", new SLPage(isSave: false)); MainWindow.initFlag = true; } this.mainFrame.Content = ViewPageManager.RetrievePage(GlobalConfigContext.FirstViewPage); Director.ResumeUpdateContext(); }
/// <summary> /// 设置主舞台页面的引用 /// </summary> /// <param name="sp">主舞台对象</param> public void SetStagePageReference(Page sp) { ViewPageManager.RegisterPage(GlobalConfigContext.FirstViewPage, sp); ViewPageManager.InitFirstPage(sp); }
/// <summary> /// 处理消息循环 /// </summary> private void UpdateContext(object sender, EventArgs e) { bool resumeFlag = true; this.timer.Stop(); 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) { 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; } 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; } 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); 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; } } if (resumeFlag) { this.timer.Start(); } }
private void Music_Image_Back_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ViewPageManager.CollapseUIPage(); this.Music_Label_SongAuthor.Content = this.Music_Label_SongDisc.Content = this.Music_Label_SongName.Content = String.Empty; }
public void PrepareClose() { ViewPageManager.CollapseUIPage(); }
private void buttonNext_Click(object sender, RoutedEventArgs e) { ViewManager.RenderFrameworkElementToJPEG(this.BO_MainGrid, GlobalConfigContext.GAME_SAVE_DIR + "\\tempSnapshot.jpg"); NavigationService.GetNavigationService(this).Navigate(ViewPageManager.RetrievePage("SavePage")); }
private void Atr_Image_Back_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ViewPageManager.CollapseUIPage(); }
/// <summary> /// 按钮:保存或读取存档文件 /// </summary> /// <remarks> /// 存档的文件名形如: /// save-1-2017-03-17-21-38-44-484.dat /// 其中save是存档前缀,1是存档位编码(对应存档位0),后面是时间戳和文件后缀 /// 这个存档将绑定截图文件名形如: /// ssnap-1-2017-03-17-21-38-44-484.jpg /// 如果存档存在描述子,那还将生成描述子文件,名字形如: /// sdesc-1-2017-03-17-21-38-44-484.md /// 描述子文件以UTF-8编码,储存单行内容 /// </remarks> private void SL_Button_SorL_MouseDown(object sender, MouseButtonEventArgs e) { // 存档 if (this.isSave) { // 是否覆盖 if (this.saveList[this.lastPointed] != null) { if (MessageBox.Show(String.Format("要覆盖这个存档吗?{0}该动作不能回滚。", Environment.NewLine), "提示", MessageBoxButton.YesNo, MessageBoxImage.None, MessageBoxResult.No) == MessageBoxResult.No) { return; } // 移除原来的文件 try { // 处理过时存档 File.Delete(this.saveList[this.lastPointed].FullName); // 处理过时描述子 var descName = GlobalConfigContext.GAME_SAVE_DIR + @"\" + GlobalConfigContext.GAME_SAVE_DESCRIPTOR_PREFIX + saveList[this.lastPointed].Name.Substring(GlobalConfigContext.GAME_SAVE_PREFIX.Length).Replace(GlobalConfigContext.GAME_SAVE_POSTFIX, GlobalConfigContext.GAME_SAVE_DESCRIPTOR_POSTFIX); File.Delete(IOUtils.ParseURItoURL(descName)); } catch (Exception ex) { LogUtils.LogLine("覆盖存档时,在移除过时文件过程出现异常" + Environment.NewLine + ex, "SLPage", LogLevel.Error); } } // 获得存档时间戳 var timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"); var timeItems = timeStamp.Split('-'); var saveIdentity = String.Format("-{0}-{1}", this.lastPointed + 1, timeStamp); // 不可容忍的错误段 try { // 构造存档文件名(不需要后缀,UR的Save方法已经封装了) var fname = String.Format("{0}{1}", GlobalConfigContext.GAME_SAVE_PREFIX, saveIdentity); // 保存游戏信息 this.core.GetMainRender().ActualSave(fname); // 更新页面的信息 this.saveList[this.lastPointed] = new FileInfo(IOUtils.ParseURItoURL(GlobalConfigContext.GAME_SAVE_DIR + @"\" + fname + GlobalConfigContext.GAME_SAVE_POSTFIX)); this.slotButtonList[this.lastPointed].Content = String.Format("存档{0}:{1}/{2} {3}:{4}", this.lastPointed + 1, timeItems[1], timeItems[2], timeItems[3], timeItems[4]); } catch (Exception ex) { MessageBox.Show("保存文件失败!在SLPage(in CLR)触发了:" + Environment.NewLine + ex); return; } // 可容忍的错误段 try { // 保存截图文件 if (File.Exists(IOUtils.ParseURItoURL(GlobalConfigContext.GAME_SAVE_DIR + "\\tempSnapshot.jpg"))) { File.Move(IOUtils.ParseURItoURL(GlobalConfigContext.GAME_SAVE_DIR + "\\tempSnapshot.jpg"), IOUtils.ParseURItoURL(String.Format("{0}\\{1}{2}{3}", GlobalConfigContext.GAME_SAVE_DIR, GlobalConfigContext.GAME_SAVE_SNAPSHOT_PREFIX, saveIdentity, GlobalConfigContext.GAME_SAVE_SNAPSHOT_POSTFIX))); } // 保存描述子 var descFname = String.Format("{0}\\{1}{2}{3}", GlobalConfigContext.GAME_SAVE_DIR, GlobalConfigContext.GAME_SAVE_DESCRIPTOR_PREFIX, saveIdentity, GlobalConfigContext.GAME_SAVE_DESCRIPTOR_POSTFIX); FileStream fs = new FileStream(IOUtils.ParseURItoURL(descFname), FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(Director.RunMana.PerformingChapter.Trim()); sw.WriteLine(this.SL_Descriptor_TextBox.Text.Trim()); sw.Close(); fs.Close(); } catch (Exception ex) { LogUtils.LogLine("保存存档的辅助文件出现异常" + Environment.NewLine + ex, "SLPage", LogLevel.Warning); } // 保存完毕强制刷新页面 this.button_MouseEnter(this.lastPointed, null); } // 读档 else { // 读取文件 try { this.core.GetMainRender().ActualLoad(this.saveList[this.lastPointed].Name.Replace(GlobalConfigContext.GAME_SAVE_POSTFIX, String.Empty)); // 返回主舞台 ViewPageManager.GoBack(); } catch (Exception ex) { var exStr = "读取存档文件失败,存档是损坏的?" + Environment.NewLine + ex; LogUtils.LogLine(exStr, "SLPage", LogLevel.Error); MessageBox.Show(exStr); } } }
/// <summary> /// 按钮:返回 /// </summary> private void SL_Button_Back_MouseDown(object sender, MouseButtonEventArgs e) { ViewPageManager.GoBack(); }