OSDN Git Service

Boost.MSMでメニュー部分を実装
[shooting3/shootinggame.git] / ShootingGame / MainPage.xaml.cpp
1 //
2 // MainPage.xaml.cpp
3 // Implementation of the MainPage class.
4 //
5
6 #include "pch.h"
7 #include "GameMain.h"
8 #include "MainPage.xaml.h"
9 #include "SoundEditorPage.xaml.h"
10
11 using namespace Platform;
12 using namespace Windows::Foundation;
13 using namespace Windows::Foundation::Collections;
14 using namespace Windows::UI::Xaml;
15 using namespace Windows::UI::Xaml::Controls;
16 using namespace Windows::UI::Xaml::Controls::Primitives;
17 using namespace Windows::UI::Xaml::Data;
18 using namespace Windows::UI::Xaml::Input;
19 using namespace Windows::UI::Xaml::Media;
20 using namespace Windows::UI::Xaml::Interop;
21 using namespace Windows::UI::Xaml::Navigation;
22
23 // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
24 namespace ShootingGame
25 {
26
27
28 MainPage::MainPage(GameMain^ g) : gameMain_(g)
29 {
30   InitializeComponent();
31   //std::function<void (Windows::UI::Xaml::Controls::Page^ )> f(std::bind(&MainPage::Subframe,this,std::placeholders::_1));
32   gameMain_->SetSubFrameFunc(ref new GameMain::SubFrameFuncDelegate(this,&MainPage::Subframe));
33   gameMain_->SetIsBackButtonEnabledDelgate( ref new GameMain::IsBackButtonEnabledDelgate
34   (
35     [this](bool v)
36     {
37       backButton->IsEnabled = v;
38     }
39   )
40   );
41 }
42
43 void MainPage::Subframe(Windows::UI::Xaml::Controls::Page^ p)
44 {
45   if(p != nullptr)
46   {
47    // hiddenFrame_->
48      UIElement^ content = p->Content; 
49      p->Content = nullptr;
50      SubContent->Content = content;
51   } else {
52      SubContent->Content = nullptr;
53   }
54 }
55
56 //UIElement^ MainPage::NavigateSubframe(Windows::UI::Xaml::Interop::TypeName typeName)
57 //{
58 //  if(!hiddenFrame_->Navigate(typeName,this))
59 //  {
60 //    throw ref new FailureException(ref new String(L"切り替えできませんでした。"));
61 //  };
62 //
63 //  Page^ hiddenPage = safe_cast<Page^>(hiddenFrame_->Content);
64 //  UIElement^ content = hiddenPage->Content;
65 //  hiddenPage->Content = nullptr;
66 //  SubContent->Content =  content;
67 //  return  content;
68 //;
69 //}
70
71
72 /// <summary>
73 /// Invoked when this page is about to be displayed in a Frame.
74 /// </summary>
75 /// <param name="e">Event data that describes how this page was reached.  The Parameter
76 /// property is typically used to configure the page.</param>
77 void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
78 {
79   (void) e;     // Unused parameter
80 }
81
82 void MainPage::UpdateProcessTime(float delta)
83 {
84   processTime->Text = ref new String((boost::wformat(L"%1.4f") % delta).str().c_str());
85 }
86
87 void MainPage::UpdateFrameTime(float delta,float max,float min,float avg)
88 {
89   frameTime->Text = ref new String((boost::wformat(L"%1.4f") % delta).str().c_str());
90   frameTimeMax->Text = ref new String((boost::wformat(L"%1.4f") % max).str().c_str());
91   frameTimeMin->Text = ref new String((boost::wformat(L"%1.4f") % min).str().c_str());
92   frameTimeAvg->Text = ref new String((boost::wformat(L"%1.4f") % avg).str().c_str());
93 }
94
95
96 //void ShootingGame::MainPage::Button_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
97 //{
98 //  //TypeName t = {ref new String(L"ShootingGame.SoundEditorPage"),TypeKind::Custom};
99 //  // if(!hiddenFrame_->Navigate(t,this))
100 //  // {
101 //  //   throw ref new FailureException(ref new String(L"サウンドエディタに切り替えできませんでした。"));
102 //  // };
103 //
104 //  //  Page^ hiddenPage = safe_cast<Page^>(hiddenFrame_->Content);
105 //  //  UIElement^ content = hiddenPage->Content;
106 //  //  hiddenPage->Content = nullptr;
107 //  //  SubContent->Content =  content;
108 //
109 //  //Grid^ grid = safe_cast<Grid^>(hiddenPage->FindName(L"LayoutRoot"));
110 //  //if(grid != nullptr){
111 //  //// Get each element.
112 //  //UIElement^ c = safe_cast<UIElement^>(grid->FindName(L"Editor"));
113 //  //UIElementCollection^ collection = grid->Children;
114 //  //unsigned int  index;
115 //  //collection->IndexOf(c, &index);
116 //  //collection->RemoveAt(index);
117 //  //SubContent->Content =  c;
118 //  //}
119 //
120 //} 
121
122 //void MainPage::GameMain(ShootingGame::GameMain^  p){gameMain_ = p;}
123 //
124 //ShootingGame::GameMain^ MainPage::GameMain(){return gameMain_; }
125 //
126 void ShootingGame::MainPage::backButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
127 {
128    gameMain_->GameStateMachine().ProcessEvent(Event::Back());
129 }
130 }