public void init(string id) { taskId = id; if (taskId == "random") { Dictionary <string, TaskItem> requireDic = BattleFormation.getRanTaskFishList(); foreach (string key in requireDic.Keys) { TaskItem item = requireDic[key]; requireList.Add(item.item_id, item); } } else { TaskItemSpec spec = getTaskSpec(); List <OwnedItem> specrequireList = spec.getRequireList(); foreach (OwnedItem item in specrequireList) { TaskItem item1 = new TaskItem(); item1.item_id = item.item_id; item1.finished = 0; item1.total = item.count; requireList.Add(item.item_id, item1); } } creatRewards(); setSaveData(); }
public void finishTask(string id) { if (CurrentScene == LOGINSCENE) { LoginController.GetInstance().initTreasure(); } if (id == "random") { PlayerData.setCurTask(null); } else { string nextId = (int.Parse(id) + 1).ToString(); TaskItemSpec nextSpec = SpecController.getItemById(nextId) as TaskItemSpec; if (nextSpec != null) { addTask(nextId); } else { PlayerData.setCurTask(null); creatMyShip(); if (id == "70003") { creatMyShip(); if (CurrentScene == LOGINSCENE) { LoginController.GetInstance().initShipButton(); } } } } }
public Dictionary <string, TaskItem> getRequireList() { if (requireList.Count == 0) { requireList = new Dictionary <string, TaskItem> (); if (conditions != null) { requireList = JsonMapper.ToObject <Dictionary <string, TaskItem> > (conditions); /* string[] arr = conditions.Split (new char[1]{ '|' }); * foreach (string str in arr) { * string[] arr1 = str.Split (new char[1]{ ':' }); * TaskItem item = new TaskItem (); * item.item_id = arr1 [0]; * item.finished = int.Parse(arr1 [1]); * item.total = int.Parse(arr1 [2]); * requireList.Add (arr1 [0], item); * }*/ } else { TaskItemSpec spec = getTaskSpec(); List <OwnedItem> specrequireList = spec.getRequireList(); foreach (OwnedItem item in specrequireList) { TaskItem item1 = new TaskItem(); item1.item_id = item.item_id; item1.finished = 0; item1.total = item.count; requireList.Add(item.item_id, item1); } } } return(requireList); }
void configTask() { if (taskdata.taskId == "random") { transform.Find("TaskName").GetComponent <Text> ().text = LanController.getString("randomTask").ToUpper(); } else { TaskItemSpec taskspec = taskdata.getTaskSpec(); transform.Find("TaskName").GetComponent <Text> ().text = LanController.getString(taskspec.name).ToUpper(); } for (int i = 0; i < requireGrid.transform.childCount; i++) { GameObject go = requireGrid.transform.GetChild(i).gameObject; Destroy(go); } for (int i = 0; i < rewardGrid.transform.childCount; i++) { GameObject to = rewardGrid.transform.GetChild(i).gameObject; Destroy(to); } requireList = taskdata.getRequireList(); rewardList = taskdata.getRewardList(); hasFinished = true; foreach (string id in requireList.Keys) { GameObject bt = Instantiate(requireRender); bt.GetComponent <RectTransform>().SetParent(requireGrid.GetComponent <RectTransform>()); bt.GetComponent <RectTransform>().localScale = Vector3.one; //调整大小 bt.GetComponent <RectTransform>().localPosition = Vector3.zero; //调整位置 bt.SetActive(true); TaskItem taskItem = requireList [id]; GameObject completeIcon = bt.transform.Find("CompletIcon").gameObject; int completeC = Mathf.Min(taskItem.finished, taskItem.total); bt.transform.Find("CompleteText").GetComponent <Text> ().text = completeC.ToString(); bt.transform.Find("TotalText").GetComponent <Text> ().text = "/" + taskItem.total.ToString(); if (taskItem.beFinished()) { completeIcon.SetActive(true); } else { completeIcon.SetActive(false); hasFinished = false; } ItemSpec spec = SpecController.getItemById(id); bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + spec.name + "Icon"); } int t = (requireList.Count % 2) == 0 ? (requireList.Count / 2) : ((requireList.Count / 2) + 1); float h = t * 120 + (t - 1) * 10 + 20; requireGrid.GetComponent <RectTransform>().sizeDelta = new Vector2(requireGrid.GetComponent <RectTransform>().sizeDelta.x, h); requireGrid.transform.Translate(new Vector3(0, -h / 2, 0)); foreach (string key in rewardList.Keys) { GameObject bt = Instantiate(rewardRender); bt.GetComponent <RectTransform>().SetParent(rewardGrid.GetComponent <RectTransform>()); bt.GetComponent <RectTransform>().localScale = Vector3.one; //调整大小 bt.GetComponent <RectTransform>().localPosition = Vector3.zero; //调整位置 bt.SetActive(true); bt.transform.Find("Text").GetComponent <Text> ().text = "×" + rewardList[key].ToString(); if (key == "gem") { bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + "gemIcon"); } else if (key == "coin") { bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + "CoinIcon"); } else if (key == "bullet") { bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + "BulletShopIcon"); } else if (key == "exp") { bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + "ExpIcon"); } else if (key == "ship") { bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + "PirateBoat"); } else { ItemSpec spec = SpecController.getItemById(key); bt.transform.Find("Icon").GetComponent <Image>().sprite = GameController.GetInstance().getSpByName("Pic/ui/" + spec.name + "Icon"); } } if (hasFinished) { confirmButText.text = LanController.getString("complete").ToUpper(); } else { confirmButText.text = LanController.getString("confirm").ToUpper(); } }