Browse Source

Reverted the addition of IsTouchEnabled() as on some platforms it is set dynamically on receiving the first touch.

Lasse Öörni 12 years ago
parent
commit
5ad269e68c

+ 28 - 25
Bin/Data/Scripts/NinjaSnowWar.as

@@ -87,12 +87,8 @@ void Start()
     SubscribeToEvent("Points", "HandlePoints");
     SubscribeToEvent("Kill", "HandleKill");
     SubscribeToEvent("ScreenMode", "HandleScreenMode");
-
-    if (touchEnabled)
-    {
-        SubscribeToEvent("TouchBegin", "HandleTouchBegin");
-        SubscribeToEvent("TouchEnd", "HandleTouchEnd");
-    }
+    SubscribeToEvent("TouchBegin", "HandleTouchBegin");
+    SubscribeToEvent("TouchEnd", "HandleTouchEnd");
 
     if (singlePlayer)
     {
@@ -191,6 +187,26 @@ void InitNetworking()
     }
 }
 
+void InitTouchInput()
+{
+    touchEnabled = true;
+
+    moveButton = BorderImage();
+    moveButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
+    moveButton.imageRect = IntRect(0, 0, 96, 96);
+    moveButton.SetPosition(touchButtonBorder, graphics.height - touchButtonSize - touchButtonBorder);
+    moveButton.SetSize(touchButtonSize, touchButtonSize);
+    ui.root.AddChild(moveButton);
+
+    fireButton = BorderImage();
+    fireButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
+    fireButton.imageRect = IntRect(96, 0, 192, 96);
+    fireButton.SetPosition(graphics.width - touchButtonSize - touchButtonBorder, graphics.height - touchButtonSize -
+        touchButtonBorder);
+    fireButton.SetSize(touchButtonSize, touchButtonSize);
+    ui.root.AddChild(fireButton);
+}
+
 void CreateCamera()
 {
     // Note: the camera is not in the scene
@@ -261,25 +277,8 @@ void CreateOverlays()
     healthBar.SetSize(116, 16);
     healthBorder.AddChild(healthBar);
 
-    if (input.touchEnabled)
-    {
-        touchEnabled = true;
-
-        moveButton = BorderImage();
-        moveButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
-        moveButton.imageRect = IntRect(0, 0, 96, 96);
-        moveButton.SetPosition(touchButtonBorder, graphics.height - touchButtonSize - touchButtonBorder);
-        moveButton.SetSize(touchButtonSize, touchButtonSize);
-        ui.root.AddChild(moveButton);
-
-        fireButton = BorderImage();
-        fireButton.texture = cache.GetResource("Texture2D", "Textures/TouchInput.png");
-        fireButton.imageRect = IntRect(96, 0, 192, 96);
-        fireButton.SetPosition(graphics.width - touchButtonSize - touchButtonBorder, graphics.height - touchButtonSize -
-            touchButtonBorder);
-        fireButton.SetSize(touchButtonSize, touchButtonSize);
-        ui.root.AddChild(fireButton);
-    }
+    if (GetPlatform() == "Android" || GetPlatform() == "iOS")
+        InitTouchInput();
 }
 
 void SetMessage(const String&in message)
@@ -457,6 +456,10 @@ void HandlePostRenderUpdate()
 
 void HandleTouchBegin(StringHash eventType, VariantMap& eventData)
 {
+    // On some platforms like Windows the presence of touch input can only be detected dynamically
+    if (!touchEnabled)
+        InitTouchInput();
+
     int touchID = eventData["TouchID"].GetInt();
     IntVector2 pos(eventData["X"].GetInt(), eventData["Y"].GetInt());
     UIElement@ element = ui.GetElementAt(pos, false);

+ 0 - 1
Docs/ScriptAPI.dox

@@ -3148,7 +3148,6 @@ Properties:<br>
 - int mouseMoveX (readonly)
 - int mouseMoveY (readonly)
 - int mouseMoveWheel (readonly)
-- bool touchEnabled (readonly)
 - uint numTouches (readonly)
 - TouchState@[] touches (readonly)
 - uint numJoysticks (readonly)

+ 0 - 5
Engine/Input/Input.cpp

@@ -332,11 +332,6 @@ IntVector2 Input::GetMousePosition() const
     return ret;
 }
 
-bool Input::IsTouchEnabled() const
-{
-    return SDL_GetNumTouchDevices() > 0;
-}
-
 TouchState* Input::GetTouch(unsigned index) const
 {
     if (index >= touches_.Size())

+ 0 - 2
Engine/Input/Input.h

@@ -161,8 +161,6 @@ public:
     int GetMouseMoveY() const { return mouseMove_.y_; }
     /// Return mouse wheel movement since last frame.
     int GetMouseMoveWheel() const { return mouseMoveWheel_; }
-    /// Return if has touch input.
-    bool IsTouchEnabled() const;
     /// Return number of active finger touches.
     unsigned GetNumTouches() const { return touches_.Size(); }
     /// Return active finger touch by index.

+ 0 - 1
Engine/Script/InputAPI.cpp

@@ -162,7 +162,6 @@ static void RegisterInput(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Input", "int get_mouseMoveX() const", asMETHOD(Input, GetMouseMoveX), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "int get_mouseMoveY() const", asMETHOD(Input, GetMouseMoveY), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "int get_mouseMoveWheel() const", asMETHOD(Input, GetMouseMoveWheel), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Input", "bool get_touchEnabled() const", asMETHOD(Input, IsTouchEnabled), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "uint get_numTouches() const", asMETHOD(Input, GetNumTouches), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "TouchState@+ get_touches(uint) const", asMETHOD(Input, GetTouch), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "uint get_numJoysticks() const", asMETHOD(Input, GetNumJoysticks), asCALL_THISCALL);

+ 0 - 2
Extras/LuaScript/pkgs/Input/Input.pkg

@@ -99,8 +99,6 @@ public:
     int GetMouseMoveY() const { return mouseMove_.y_; }
     /// Return mouse wheel movement since last frame.
     int GetMouseMoveWheel() const { return mouseMoveWheel_; }
-    /// Return if has touch input.
-    bool IsTouchEnabled() const;
     /// Return number of active finger touches.
     unsigned GetNumTouches() const { return touches_.Size(); }
     /// Return active finger touch by index.