Browse Source

fix mouse invisibility when gui dialogs are open

Kolja Strohm 2 years ago
parent
commit
0a83c6d444
5 changed files with 30 additions and 4 deletions
  1. 1 1
      FactoryCraft/Block.cpp
  2. 13 0
      FactoryCraft/Game.cpp
  3. 1 0
      FactoryCraft/Game.h
  4. 14 3
      FactoryCraft/PlayerKam.cpp
  5. 1 0
      FactoryCraft/PlayerKam.h

+ 1 - 1
FactoryCraft/Block.cpp

@@ -11,7 +11,7 @@ Block::Block(const BlockType* zType, Framework::Vec3<int> pos, Model3DData* mode
 	maxHP((float)maxHP)
 {
 	transparent = 0;
-	hp = maxHP;
+	hp = (float)maxHP;
 	memset(sideVisible, 1, 6);
 	Model3D::setPosition((Framework::Vec3<float>)pos + Framework::Vec3<float>{0.5f, 0.5f, 0.5f});
 	setModelDaten(model);

+ 13 - 0
FactoryCraft/Game.cpp

@@ -104,6 +104,7 @@ void Game::api(char* data)
 								{
 									dialogs.remove(index);
 									window->zBildschirm()->removeMember(d);
+									currentGame->zKamera()->setControlEnabled(dialogs.getEintragAnzahl() == 0);
 									break;
 								}
 								index++;
@@ -111,6 +112,7 @@ void Game::api(char* data)
 						});
 				});
 			dialogs.add(dialog);
+			currentGame->zKamera()->setControlEnabled(0);
 			window->zBildschirm()->addMember(dialog);
 			delete[]uiml;
 		}
@@ -143,4 +145,15 @@ void Game::api(char* data)
 		delete[] uiml;
 	}
 	}
+}
+
+void Game::closeCurrentDialog()
+{
+	if (dialogs.getEintragAnzahl() > 0)
+	{
+		UIMLDialog* d = dialogs.get(dialogs.getEintragAnzahl() - 1);
+		window->zBildschirm()->removeMember(d);
+		dialogs.remove(dialogs.getEintragAnzahl() - 1);
+		currentGame->zKamera()->setControlEnabled(dialogs.getEintragAnzahl() == 0);
+	}
 }

+ 1 - 0
FactoryCraft/Game.h

@@ -23,4 +23,5 @@ public:
 
 	void updatePosition(Vec3<float> position, bool target, Vec3<int> targetPos);
 	void api(char* data);
+	void closeCurrentDialog();
 };

+ 14 - 3
FactoryCraft/PlayerKam.cpp

@@ -1,7 +1,9 @@
+#include <Globals.h>
 #include "PlayerKam.h"
 #include "Globals.h"
 #include "Game.h"
 
+
 PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
 	: Kam3D()
 {
@@ -123,8 +125,11 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
 		}
 		if (te.taste == T_Esc)
 		{
+			bool oldControl = kameraControll;
 			kameraControll = 0;
-			ShowCursor(true);
+			setShowCursor(true);
+			if(!oldControl)
+				((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog();
 		}
 		if (te.taste == T_Tab)
 		{
@@ -139,7 +144,7 @@ void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
 	if (me.verarbeitet)
 	{
 		kameraControll = 0;
-		ShowCursor(true);
+		setShowCursor(true);
 	}
 	else
 	{
@@ -172,7 +177,7 @@ void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
 					*(float*)(action + 9) = direction.z;
 					network->zFactoryClient()->sendPlayerAction(action, 13);
 					SetCursorPos(lastMousePos.x + window->getPosition().x, lastMousePos.y + window->getPosition().y);
-					ShowCursor(false);
+					setShowCursor(false);
 				}
 				if (me.id == ME_PLinks)
 				{
@@ -230,4 +235,10 @@ bool PlayerKam::tick(double time)
 void PlayerKam::setEntityId(int id)
 {
 	entityId = id;
+}
+
+void PlayerKam::setControlEnabled(bool enabled)
+{
+	kameraControll = enabled;
+	setShowCursor(!kameraControll);
 }

+ 1 - 0
FactoryCraft/PlayerKam.h

@@ -17,4 +17,5 @@ public:
 	void doMausEreignis(Framework::MausEreignis& me) override;
 	bool tick(double time) override;
 	void setEntityId(int id);
+	void setControlEnabled(bool enabled);
 };