Jelajahi Sumber

4/10更新

2025/4/10	如果创建的狗不是第一只狗,就要收费(待后端开发完成后测试)
Kenny Chen 1 bulan lalu
induk
melakukan
ef30276150

TEMPAT SAMPAH
.DS_Store


+ 0 - 4
.gitignore

@@ -7,7 +7,3 @@
 /.vscode/
 /.utmp/
 /.vsconfig
-/.Assembly-CSharp.csproj
-/.Assembly-CSharp-Editor.csproj
-/PuppyLocal.sln
-*.csproj

TEMPAT SAMPAH
Assets/.DS_Store


+ 2 - 2
Assets/Resources/Data/dogDB.json

@@ -15,7 +15,7 @@
             },
             "createDate": "2025/2/8",
             "lastDpdate": "2025/2/8",
-            "cost": 0,
+            "cost": 1000,
             "prefab": "shibaInu",
             "skin": [
                 "amber",
@@ -36,7 +36,7 @@
             },
             "createDate": "2025/3/8",
             "lastDpdate": "2025/3/8",
-            "cost": 0,
+            "cost": 1500,
             "prefab": "husky",
             "skin": [
                 "amber",

+ 10 - 2
Assets/Resources/Data/languages.json

@@ -170,9 +170,13 @@
             "en": "<<dog_name>> is your good friend now.",
             "zh-cn": "现在<<dog_name>>是你的好伙伴了。"
         },
+        "dog_create_fail_no_enough_coin": {
+            "en": "You don't have enough coins.",
+            "zh-cn": "你没有足够的金币。"
+        },
         "cannot_add_dog": {
-            "en": "You can't have any more dogs. Unless you foster some dogs.",
-            "zh-cn": "你不能再拥有更多的狗了。除非你把一些狗寄养了。"
+            "en": "You can't have any more dogs.",
+            "zh-cn": "你不能再拥有更多的狗了。"
         },
         "reg_reminder": {
             "en": "Please register user information. It can help to retrieve game data in the future.",
@@ -662,6 +666,10 @@
             "create or adopt msg": {
                 "en": "Create a new dog to start game, or adopt one from your friend?",
                 "zh-cn": "从新开始创造自己的狗,还是从朋友哪里领养一只?"
+            },
+            "price":{
+                "en": "Price:",
+                "zh-cn": "价格:"
             }
         }
     },

+ 4 - 0
Assets/Scenes/Login/InitDogUI.uxml

@@ -6,6 +6,10 @@
             <ui:TextField label="Dog name:" max-length="16" hide-placeholder-on-focus="false" name="name" class="TextField textField" style="height: auto; -unity-text-align: middle-left; -unity-font-definition: url(&quot;project://database/Assets/Font/MaoKenZhuYuanTi-MaokenZhuyuanTi-2.ttf?fileID=12800000&amp;guid=50a63638b44907e46a3fa871d63b7d39&amp;type=3#MaoKenZhuYuanTi-MaokenZhuyuanTi-2&quot;); margin-top: 0;" />
             <ui:DropdownField label="Breed" name="breed" class="dropdownField" />
             <ui:DropdownField label="Sex" name="sex" choices="Male,Female" class="dropdownField" />
+            <ui:VisualElement style="flex-grow: 1; flex-direction: row; justify-content: space-between;">
+                <ui:VisualElement name="VisualElement" style="flex-grow: initial; background-image: url(&quot;project://database/Assets/Packages/2D%20Casual%20UI/Sprite/GUI.png?fileID=21300042&amp;guid=1eaee135ce037439d925cee5e41ce026&amp;type=3#GUI_21&quot;); width: 30px; height: 30px; flex-shrink: initial; max-width: 100%; max-height: 100%; margin-left: 49px; margin-bottom: 2px;" />
+                <ui:Label name="price" style="margin-right: 120px;" />
+            </ui:VisualElement>
             <ui:Label text="* error message&#10;* message 2" name="error_msg" class="err_msg" style="border-top-left-radius: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; border-bottom-left-radius: 0; display: none;" />
         </ui:VisualElement>
         <ui:VisualElement name="arrowArea" style="flex-grow: 1; height: auto; min-height: auto; flex-direction: row; justify-content: space-between; align-self: auto; align-content: flex-start; align-items: center;">

+ 1 - 2
Assets/Scripts/Develop Script/TestSetup.cs

@@ -80,9 +80,8 @@ public class TestSetup : MonoBehaviour
             //DateTime now = DateTime.Now;
             //DateTime oneHourAgo = now.AddHours(-1);
             //PlayerPrefs.SetString("LoginTokenTime", oneHourAgo.ToString());
-
             PlayerPrefs.DeleteAll();
-            EnviromentSetting.languageCode = "en";
+            // EnviromentSetting.languageCode = "en";
         }
 
         //Debug.Log("Login token" + PlayerPrefs.GetString("LoginToken"));

+ 12 - 0
Assets/Scripts/GameControllers/GameTool.cs

@@ -68,4 +68,16 @@ public static class GameTool
 
         return result > thresHold;
     }
+
+    // 检测新的狗名是否符合重名
+    public static bool NewDogNameAllowed(string newDogName){
+        bool dogNameAllowed = true;
+        foreach (var dog in UserProperty.dogs)
+        {
+            if (newDogName == dog.dog_name){
+                dogNameAllowed = false;
+            }
+        }
+        return dogNameAllowed;
+    }
 }

+ 68 - 41
Assets/Scripts/Login/InitDogUIController.cs

@@ -15,13 +15,14 @@ using UnityEngine.UIElements;
 public class InitDogUIController : MonoBehaviour
 {
     private TextField dogNameTextField;
+    private Label priceLabel;
     private Label leftArrow, rightArrow;
     private DropdownField breedDropdownField, sexDropdownField;
     private Button confirmBtn, cancelBtn;
     private DogBreed dogBreed;      // 狗品种的具体设定数据
     private string femaleText, maleText;
     private int dogSkinIndex = 0;      // 显示狗的皮肤颜色
-    private DogProperty dogProperty = new();        // 用于暂存生成狗的属性配置
+    private DogProperty InitDogProperty = new();        // 用于暂存生成狗的属性配置
 
     private string displayDogName = "createdDog";
     // Start is called once before the first execution of Update after the MonoBehaviour is created
@@ -42,6 +43,7 @@ public class InitDogUIController : MonoBehaviour
         cancelBtn = root.Q<VisualElement>("confirmArea").Q<Button>("cancel");
         leftArrow = root.Q<Label>("leftArrow");
         rightArrow = root.Q<Label>("rightArrow");
+        priceLabel = root.Q<Label>("price");
 
         InitSetting();
         cancelBtn.clicked += CancelClick;
@@ -70,20 +72,21 @@ public class InitDogUIController : MonoBehaviour
         }
 
         dogBreed = EnviromentSetting.dogBreeds[breedDropdownField.index];
-        
-        dogProperty.breed = dogBreed.breed;
-        dogProperty.skin = dogBreed.skin[dogSkinIndex];
-        var location = new Vector3(19.5f, 0, 15); 
+        priceLabel.text = dogBreed.cost.ToString();
+
+        InitDogProperty.breed = dogBreed.breed;
+        InitDogProperty.skin = dogBreed.skin[dogSkinIndex];
+        var location = new Vector3(19.5f, 0, 15);
         var rotation = new Vector3(0f, -135f, 0f);
         var scale = new Vector3(2f, 2f, 2f);
 
-        GameObject dog = Instantiate(Resources.Load<GameObject>("Dog/Breed/" + dogProperty.breed));
+        GameObject dog = Instantiate(Resources.Load<GameObject>("Dog/Breed/" + InitDogProperty.breed));
         dog.name = displayDogName;
         if (dog != null)
         {
-            GameObject dogL2 = GameObject.Find(dogProperty.breed);
+            GameObject dogL2 = GameObject.Find(InitDogProperty.breed);
             Renderer renderer = dogL2.GetComponent<Renderer>();
-            Material mat = Resources.Load<Material>("Dog/Skin/" + dogProperty.breed + "/" + dogProperty.skin);
+            Material mat = Resources.Load<Material>("Dog/Skin/" + InitDogProperty.breed + "/" + InitDogProperty.skin);
             if (mat != null && renderer != null)
             {
                 renderer.material = mat;
@@ -107,10 +110,10 @@ public class InitDogUIController : MonoBehaviour
         {
             dogSkinIndex = 0;
         }
-        dogProperty.skin = dogBreed.skin[dogSkinIndex];
+        InitDogProperty.skin = dogBreed.skin[dogSkinIndex];
         ChangeDogSkin();
-        Debug.Log("current dog skin index is: " +  dogSkinIndex);
-        Debug.Log("current dog skin name is: " + dogProperty.skin);
+        Debug.Log("current dog skin index is: " + dogSkinIndex);
+        Debug.Log("current dog skin name is: " + InitDogProperty.skin);
     }
 
     void LeftArrowClicked(ClickEvent e)
@@ -120,10 +123,10 @@ public class InitDogUIController : MonoBehaviour
         {
             dogSkinIndex = dogBreed.skin.Length - 1;
         }
-        dogProperty.skin = dogBreed.skin[dogSkinIndex];
+        InitDogProperty.skin = dogBreed.skin[dogSkinIndex];
         ChangeDogSkin();
         Debug.Log("current dog skin index is: " + dogSkinIndex);
-        Debug.Log("current dog skin name is: " + dogProperty.skin);
+        Debug.Log("current dog skin name is: " + InitDogProperty.skin);
     }
 
     // 更换狗的皮肤
@@ -132,9 +135,9 @@ public class InitDogUIController : MonoBehaviour
         var dog = GameObject.Find(displayDogName);
         if (dog != null)
         {
-            GameObject dogL2 = GameObject.Find(dogProperty.breed);
+            GameObject dogL2 = GameObject.Find(InitDogProperty.breed);
             Renderer renderer = dogL2.GetComponent<Renderer>();
-            Material mat = Resources.Load<Material>("Dog/Skin/" + dogProperty.breed + "/" + dogProperty.skin);
+            Material mat = Resources.Load<Material>("Dog/Skin/" + InitDogProperty.breed + "/" + InitDogProperty.skin);
             if (mat != null && renderer != null)
             {
                 renderer.material = mat;
@@ -144,37 +147,48 @@ public class InitDogUIController : MonoBehaviour
     // 绑定点击按键
     void ConfirmClick()
     {
-        dogProperty.dog_name = dogNameTextField.text;
-        bool dogNameAllowed = true;
-        foreach (var dog in UserProperty.dogs)
+        InitDogProperty.dog_name = dogNameTextField.text;
+        // bool dogNameAllowed = true;
+        // foreach (var dog in UserProperty.dogs)
+        // {
+        //     if (InitDogProperty.dog_name == dog.dog_name){
+        //         dogNameAllowed = false;
+        //     }
+        // }
+        if (GameTool.NewDogNameAllowed(InitDogProperty.dog_name))
         {
-            if (dogProperty.dog_name == dog.dog_name){
-                dogNameAllowed = false;
+            if (UserProperty.coin < dogBreed.cost && UserProperty.dogs.Count > 1)
+            {
+                // 当用户狗的数量超过1条的时候,检测用户是否有足够的金币
+                string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "dog_create_fail_no_enough_coin", EnviromentSetting.languageCode });
+                MessageBoxController.ShowMessage(msg);
+                return;
             }
-        }
-        if (dogNameAllowed)
-        {
-            ConfirmClickPost();
+            else
+            {
+                ConfirmClickRequest();
+            }
+
         }
         else
         {
             string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "dog_name_duplicated", EnviromentSetting.languageCode });
-            msg.Replace("<<dog_name>>", dogProperty.dog_name);
+            msg.Replace("<<dog_name>>", InitDogProperty.dog_name);
             MessageBoxController.ShowMessage(msg);
         }
     }
 
     // ConfirmClick点击后第一步POST事件
-    void ConfirmClickPost()
+    void ConfirmClickRequest()
     {
         string url = "/api/initial/dog/";
         Dictionary<string, string> formData = new Dictionary<string, string>();
         WWWForm wwwForm = new WWWForm();
         wwwForm.AddField("user_id", UserProperty.userId);
-        wwwForm.AddField("dog_name", dogProperty.dog_name);
-        wwwForm.AddField("sex", dogProperty.sex);
-        wwwForm.AddField("breed", dogProperty.breed);
-        wwwForm.AddField("skin", dogProperty.skin);
+        wwwForm.AddField("dog_name", InitDogProperty.dog_name);
+        wwwForm.AddField("sex", InitDogProperty.sex);
+        wwwForm.AddField("breed", InitDogProperty.breed);
+        wwwForm.AddField("skin", InitDogProperty.skin);
 
         StartCoroutine(WebController.PostRequest(url, wwwForm, callback: ConfirmClickCallback));
     }
@@ -186,9 +200,18 @@ public class InitDogUIController : MonoBehaviour
         if (data != null && data["status"].ToString() == "success")
         {
             string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "dog_create_success", EnviromentSetting.languageCode });
-            msg=msg.Replace("<<dog_name>>", dogProperty.dog_name);
+            msg = msg.Replace("<<dog_name>>", InitDogProperty.dog_name);
             MessageBoxController.ShowMessage(msg, FreshUserData);
         }
+        else if (data != null && data["status"].ToString() == "fail")
+        {
+            string msg = GameTool.GetValueAtPath(EnviromentSetting.languageData, new string[] { "game_message", "dog_create_fail_no_enough_coin", EnviromentSetting.languageCode });
+            MessageBoxController.ShowMessage(msg);
+        }
+        else
+        {
+            Debug.Log(data["message"]);
+        }
     }
 
     // 刷新用户狗的数据
@@ -207,15 +230,19 @@ public class InitDogUIController : MonoBehaviour
         var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
         if (data != null && data["status"].ToString() == "success")
         {
-            UserProperty.dogs.Clear();
+            // 刷新用户所有数据
+            var user_info = data["user_info"].ToString();
+            UserProperty.FreshUserInfo(user_info);
 
             // 保存狗的数据
-            DogProperty[] dogProperties = JsonConvert.DeserializeObject<DogProperty[]>(data["dogs"].ToString());
-            foreach (var dog in dogProperties)
-            {
-                UserProperty.dogs.Add(dog);
-            }
-            SceneManager.LoadScene("Home");
+            string dogsJson = data["dogs"].ToString();
+            UserProperty.FreshDogInfo(dogsJson);
+
+            // 保存道具数据
+            UserProperty.FreshUserItems(data["props"].ToString());
+
+            // SceneManager.LoadScene("Home");
+            MaskTransitions.TransitionManager.Instance.LoadLevel("Home");
         }
         else
         {
@@ -262,7 +289,7 @@ public class InitDogUIController : MonoBehaviour
             cancelBtn.style.display = DisplayStyle.None;
         }
 
-        foreach(var item in EnviromentSetting.dogBreeds)
+        foreach (var item in EnviromentSetting.dogBreeds)
         {
             breedDropdownField.choices.Add(item.name[EnviromentSetting.languageCode]);
         }
@@ -281,7 +308,7 @@ public class InitDogUIController : MonoBehaviour
         {
             confirmBtn.SetEnabled(true);
         }
-        else {  confirmBtn.SetEnabled(false); }
+        else { confirmBtn.SetEnabled(false); }
     }
 
     // 根据品种加载狗的动画
@@ -296,7 +323,7 @@ public class InitDogUIController : MonoBehaviour
         Animator animator = dog.GetComponent<Animator>();
         RuntimeAnimatorController animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/CreateDogAnimController");
         //AnimatorController animatorController = new AnimatorController();
-        if (dogProperty.breed == "shibaInu") { animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/CreateDogAnimController"); }
+        if (InitDogProperty.breed == "shibaInu") { animatorController = Resources.Load<RuntimeAnimatorController>("Dog/AnimatorController/shibaInu/CreateDogAnimController"); }
 
         animator.runtimeAnimatorController = animatorController;
     }

+ 0 - 5
Assets/Scripts/Login/LoginController.cs

@@ -171,11 +171,6 @@ public class LoginController : MonoBehaviour
             // 保存狗的数据
             string dogsJson = data["dogs"].ToString();
             UserProperty.FreshDogInfo(dogsJson);
-            //DogProperty[] dogProperties = JsonConvert.DeserializeObject<DogProperty[]>(data["dogs"].ToString());
-            //foreach (var dog in dogProperties)
-            //{
-            //    UserProperty.dogs.Add(dog);
-            //}
 
             // 保存道具数据
             UserProperty.FreshUserItems(data["props"].ToString());