Sfoglia il codice sorgente

Keep SampleSelector from exiting when esc is pressed, event now gets fired same frame

Josh Engebretson 8 anni fa
parent
commit
eb60833ad5

+ 11 - 7
FeatureExamples/CPlusPlus/Source/SampleSelector.cpp

@@ -22,6 +22,7 @@
 //
 //
 
 
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/Log.h>
+#include <Atomic/Graphics/Renderer.h>
 
 
 #include <Atomic/UI/UI.h>
 #include <Atomic/UI/UI.h>
 #include <Atomic/UI/UIEvents.h>
 #include <Atomic/UI/UIEvents.h>
@@ -60,6 +61,9 @@
 SampleSelector::SampleSelector(Context* context) :
 SampleSelector::SampleSelector(Context* context) :
     Object(context)
     Object(context)
 {
 {
+
+    constructionFrame_ = GetSubsystem<Renderer>()->GetFrameInfo().frameNumber_;
+
     UIView* view = FeatureExamples::GetUIView();
     UIView* view = FeatureExamples::GetUIView();
 
 
     UILayout* rootLayout = new UILayout(context_);
     UILayout* rootLayout = new UILayout(context_);
@@ -107,20 +111,20 @@ SampleSelector::SampleSelector(Context* context) :
     input->SetMouseVisible(true);
     input->SetMouseVisible(true);
     input->SetMouseMode(MM_FREE);
     input->SetMouseMode(MM_FREE);
 
 
-    // Subscribe key up event
-    SubscribeToEvent(E_KEYUP, ATOMIC_HANDLER(SampleSelector, HandleKeyUp));
+    // Subscribe key down event
+    SubscribeToEvent(E_KEYDOWN, ATOMIC_HANDLER(SampleSelector, HandleKeyDown));
 
 
     context->RegisterSubsystem(this);
     context->RegisterSubsystem(this);
 }
 }
 
 
-void SampleSelector::HandleKeyUp(StringHash eventType, VariantMap& eventData)
+void SampleSelector::HandleKeyDown(StringHash eventType, VariantMap& eventData)
 {
 {
-    using namespace KeyUp;
+    using namespace KeyDown;
 
 
     int key = eventData[P_KEY].GetInt();
     int key = eventData[P_KEY].GetInt();
 
 
-    // Close console (if open) or exit when ESC is pressed
-    if (key == KEY_ESCAPE)
+    // Close console (if open) or exit when ESC is pressed, and not same frame as construction
+    if (key == KEY_ESCAPE && ( constructionFrame_ != GetSubsystem<Renderer>()->GetFrameInfo().frameNumber_ ) )
     {
     {
         GetSubsystem<Engine>()->Exit();
         GetSubsystem<Engine>()->Exit();
     }
     }
@@ -238,7 +242,7 @@ void SampleSelector::HandleWidgetEvent(StringHash eventType, VariantMap& eventDa
 
 
         if (currentSample_.NotNull())
         if (currentSample_.NotNull())
         {
         {
-            UnsubscribeFromEvent(E_KEYUP);
+            UnsubscribeFromEvent(E_KEYDOWN);
             currentSample_->Start();
             currentSample_->Start();
         }
         }
 
 

+ 5 - 2
FeatureExamples/CPlusPlus/Source/SampleSelector.h

@@ -52,11 +52,14 @@ protected:
 
 
 private:
 private:
 
 
-    /// Handle key up event to process key controls common to all samples.
-    void HandleKeyUp(StringHash eventType, VariantMap& eventData);
+    /// Handle key down event to process key controls common to all samples.
+    void HandleKeyDown(StringHash eventType, VariantMap& eventData);
 
 
     void HandleWidgetEvent(StringHash eventType, VariantMap& eventData);
     void HandleWidgetEvent(StringHash eventType, VariantMap& eventData);
 
 
     SharedPtr<Sample> currentSample_;
     SharedPtr<Sample> currentSample_;
 
 
+    /// the Renderer subsystem frame the selector was created on
+    unsigned constructionFrame_;
+
 };
 };