Procházet zdrojové kódy

Online "working", nedgraderar till unity 2019.2

Axel Nordh před 6 roky
rodič
revize
2372cd298e

+ 4 - 4
Assets/MainMenu.unity

@@ -2658,7 +2658,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 1, y: 1}
-  m_AnchoredPosition: {x: -0.000045776367, y: 8.757653}
+  m_AnchoredPosition: {x: -0.000045776367, y: 0.0007863349}
   m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 1}
 --- !u!114 &321314050
@@ -5679,7 +5679,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 1, y: 1}
-  m_AnchoredPosition: {x: -0.000015258789, y: 8.757653}
+  m_AnchoredPosition: {x: -0.000015258789, y: 0.0007863349}
   m_SizeDelta: {x: 0, y: 0}
   m_Pivot: {x: 0.5, y: 1}
 --- !u!114 &777178507
@@ -7378,7 +7378,7 @@ MonoBehaviour:
   m_HandleRect: {fileID: 761483706}
   m_Direction: 2
   m_Value: 0
-  m_Size: 0.94679534
+  m_Size: 1
   m_NumberOfSteps: 0
   m_OnValueChanged:
     m_PersistentCalls:
@@ -10953,7 +10953,7 @@ MonoBehaviour:
   m_HandleRect: {fileID: 359479519}
   m_Direction: 2
   m_Value: 0
-  m_Size: 0.94679534
+  m_Size: 1
   m_NumberOfSteps: 0
   m_OnValueChanged:
     m_PersistentCalls:

+ 1 - 1
Assets/Scripts/Database/Database.cs

@@ -694,7 +694,7 @@ public class Database : MonoBehaviour {
             
             string values = "";
             foreach (int questionId in questionsToSave) {
-                values += "(" + playerNameValue + "," + questionId + "," + gameId + "),";
+                values += "('" + playerNameValue + "'," + questionId + "," + gameId + "),";
             }
             values = values.Substring(0, values.Length - 1);
             string sql = "INSERT OR IGNORE INTO usersLockedQuestions (playerName, questionId, gameId) VALUES " + values;

+ 3 - 3
Assets/Scripts/Database/OnlineDatabase.cs

@@ -425,7 +425,7 @@ public class OnlineDatabase : MonoBehaviour {
             Debug.Log("Something wrong with getting players from game with id: " + gameId);
         }
 
-        response = response = "{\"playerInfoList\" : " + response + " }";
+        response = response = "{\"gamePlayerInfoList\" : " + response + " }";
         GamePlayerInfos gpi = new GamePlayerInfos();
         JsonUtility.FromJsonOverwrite(response, gpi);
 
@@ -508,7 +508,7 @@ public class OnlineDatabase : MonoBehaviour {
         WWWForm form = new WWWForm();
         form.AddField("f", "SavePlayerQuestions");
         form.AddField("gameId", gameId);
-        form.AddField("questionsToSave", questionsToSave.ToString());
+        form.AddField("questionsToSave", String.Join(",",questionsToSave));
         form.AddField("userName", playerNameValue);
 
         string response = CallOnlineDatabaseWithResponse("OnlineGames.php", form);
@@ -538,7 +538,7 @@ public class OnlineDatabase : MonoBehaviour {
 
             qc.SetAnswerText(q.answer);
             qc.SetQuestionText(q.question);
-            qc.idString = q.category;
+            qc.idString = q.id;
 
             Color32 questionCategoryColor = new Color32((byte)q.r, (byte)q.g, (byte)q.b, (byte)q.a);
             qc.SetQuestionCategoryColor(questionCategoryColor);

+ 3 - 1
Assets/Scripts/Login/Login.cs

@@ -117,7 +117,9 @@ public class Login : MonoBehaviour {
         string result = www.downloadHandler.text;
 
         User u = new User();
-        JsonUtility.FromJsonOverwrite(result, u);
+        if (!result.Equals("")) {
+            JsonUtility.FromJsonOverwrite(result, u);
+        }
 
         if (!u.userId.Equals("")) {
             byte[] pwd = Encoding.UTF8.GetBytes(u.salt + Password);

+ 1 - 0
Assets/Scripts/RoundButtonsScript.cs

@@ -31,6 +31,7 @@ public class RoundButtonsScript : MonoBehaviour
     void NextPlayer() {
         svs.SetAllQuestionsLocked(true);
         svs.NextPlayer();
+        svs.CheckActiveUserLoggedIn();
         HidePanel();
     }
 

+ 35 - 16
Assets/Scripts/ScrollViewScript.cs

@@ -58,23 +58,42 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
         return gameMode;
     }
 
-    private void ShowRoundButtons(bool ShowNextPlayer) {
-        RoundButtonsScript rbs = GameObject.Find("NewQuestionButtonPanel").GetComponent<RoundButtonsScript>();
+    private void Awake() {
+        CheckActiveUserLoggedIn();
+    }
 
-        if (ShowNextPlayer) {
-            rbs.ActivateNextPlayer();
-        } else {
-            rbs.DeactivateNextPlayer();
+    public void CheckActiveUserLoggedIn() {
+        if (!Database.Instance.GetSignedInUser().Value.Equals(currentPlayer)) {
+            GameObject.Find("NewQuestionButtonPanel").GetComponent<RoundButtonsScript>().HidePanel();
+            if (nq != null) {
+                CanvasGroup newQuestionCanvasGroup = nq.GetComponent<CanvasGroup>();
+                newQuestionCanvasGroup.interactable = false;
+                newQuestionCanvasGroup.blocksRaycasts = false;
+            }
         }
+    }
 
-        rbs.ShowPanel();
-        
-        if (nq == null) {
-            nq = gameManagerScript.db.GetNewQuestion(GetQuestionIdsInAnswerLine(), currentPlayer, GetGameMode());
+    private void ShowRoundButtons(bool ShowNextPlayer) {
+        if (Database.Instance.GetSignedInUser().Value.Equals(currentPlayer)) {
+            RoundButtonsScript rbs = GameObject.Find("NewQuestionButtonPanel").GetComponent<RoundButtonsScript>();
+
+            if (ShowNextPlayer) {
+                rbs.ActivateNextPlayer();
+            } else {
+                rbs.DeactivateNextPlayer();
+            }
+
+            rbs.ShowPanel();
+
+            if (nq == null) {
+                nq = gameManagerScript.db.GetNewQuestion(GetQuestionIdsInAnswerLine(), currentPlayer, GetGameMode());
+            }
+            nq.GetComponent<CanvasGroup>().alpha = 0;
+            nq.GetComponent<CanvasGroup>().interactable = false;
+            nq.GetComponent<CanvasGroup>().blocksRaycasts = false;
+        } else {
+            CheckActiveUserLoggedIn();
         }
-        nq.GetComponent<CanvasGroup>().alpha = 0;
-        nq.GetComponent<CanvasGroup>().interactable = false;
-        nq.GetComponent<CanvasGroup>().blocksRaycasts = false;
     }
 
     public void HideRoundButtons() {
@@ -108,10 +127,10 @@ public class ScrollViewScript : MonoBehaviour, IDropHandler {
         List<int> saveQuestions = new List<int>();
         for (int i = 0; i < contentPanel.childCount; i++) {
             QuestionCard q = contentPanel.GetChild(i).GetComponent<QuestionCard>();
-            q.SetQuestionSafe();
-            if (needsSave) {
-                Int32.TryParse(q.questionString, out int qId);
+            if (needsSave && !q.IsQuestionSafe()) {
+                Int32.TryParse(q.idString, out int qId);
                 saveQuestions.Add(qId);
+                q.SetQuestionSafe();
             }
         }
         if (saveQuestions.Count > 0) {

binární
Assets/narKampenLocal.db


+ 32 - 32
ProjectSettings/ProjectSettings.asset

@@ -120,7 +120,7 @@ PlayerSettings:
     16:10: 1
     16:9: 1
     Others: 1
-  bundleVersion: 0.3
+  bundleVersion: 0.4
   preloadedAssets: []
   metroInputSource: 0
   wsaTransparentSwapchain: 0
@@ -164,7 +164,7 @@ PlayerSettings:
   applicationIdentifier:
     Android: se.axelnordh.narkampen
   buildNumber: {}
-  AndroidBundleVersionCode: 12
+  AndroidBundleVersionCode: 13
   AndroidMinSdkVersion: 19
   AndroidTargetSdkVersion: 0
   AndroidPreferredInstallLocation: 1
@@ -321,6 +321,36 @@ PlayerSettings:
       m_Height: 36
       m_Kind: 0
       m_SubKind: 
+    - m_Textures: []
+      m_Width: 432
+      m_Height: 432
+      m_Kind: 2
+      m_SubKind: 
+    - m_Textures: []
+      m_Width: 324
+      m_Height: 324
+      m_Kind: 2
+      m_SubKind: 
+    - m_Textures: []
+      m_Width: 216
+      m_Height: 216
+      m_Kind: 2
+      m_SubKind: 
+    - m_Textures: []
+      m_Width: 162
+      m_Height: 162
+      m_Kind: 2
+      m_SubKind: 
+    - m_Textures: []
+      m_Width: 108
+      m_Height: 108
+      m_Kind: 2
+      m_SubKind: 
+    - m_Textures: []
+      m_Width: 81
+      m_Height: 81
+      m_Kind: 2
+      m_SubKind: 
     - m_Textures:
       - {fileID: 0}
       m_Width: 192
@@ -357,36 +387,6 @@ PlayerSettings:
       m_Height: 36
       m_Kind: 1
       m_SubKind: 
-    - m_Textures: []
-      m_Width: 432
-      m_Height: 432
-      m_Kind: 2
-      m_SubKind: 
-    - m_Textures: []
-      m_Width: 324
-      m_Height: 324
-      m_Kind: 2
-      m_SubKind: 
-    - m_Textures: []
-      m_Width: 216
-      m_Height: 216
-      m_Kind: 2
-      m_SubKind: 
-    - m_Textures: []
-      m_Width: 162
-      m_Height: 162
-      m_Kind: 2
-      m_SubKind: 
-    - m_Textures: []
-      m_Width: 108
-      m_Height: 108
-      m_Kind: 2
-      m_SubKind: 
-    - m_Textures: []
-      m_Width: 81
-      m_Height: 81
-      m_Kind: 2
-      m_SubKind: 
   m_BuildTargetBatching: []
   m_BuildTargetGraphicsAPIs: []
   m_BuildTargetVRSettings: []

+ 1 - 1
dbFiles/Login.php

@@ -26,7 +26,7 @@
 		$returnArray = array('userId' => $data['id'], 'pass' => $data['password'], 'salt' => $data['salt']);
 		echo json_encode($returnArray);
 	} else {
-		echo "Error while logging in user " . $conn->error;
+		echo "";
 	}
 	$conn->close();
 	

+ 3 - 0
dbFiles/OnlineGames.php

@@ -189,6 +189,9 @@
 		if (!$result) {
 			echo "ERROR while svaing player questions for game $gameId and player $userName with error " . $conn->error . " from sql $sql";
 		}
+		
+		$sql = "UPDATE gamePlayers SET userLockedQuestions = (SELECT count(*) FROM usersLockedQuestions WHERE gameId = $gameId AND playerName = '$userName') WHERE playerId = (SELECT id FROM users WHERE username = '$userName' AND gameId = $gameId)";
+		$conn->query($sql);
 	}