OwnedHousePanel.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var ItemType = require("ItemType");
  2. var OwnedHousePanel = cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. ownedPre:cc.Prefab,
  6. ownedParent:cc.Node,
  7. tipLbl:cc.Label,
  8. },
  9. ShowPanel:function () {
  10. this.tipLbl.string = "";
  11. if(this.JudeHasAny() == false)
  12. {
  13. this.tipLbl.string = "居无定所,不是您的所想,去房产市场购买一套房产吧";
  14. //return;
  15. }
  16. var houseList = cc.Mgr.UserDataMgr.getOwnDataListByType(ItemType.House);
  17. if(this.ownedParent.children.length != 0)
  18. {
  19. //cc.log("不用再实例化,已经有了");
  20. var children = this.ownedParent.children;
  21. for (var i = children.length - 1; i >= 0; i--) {
  22. var sc = children[i].getComponent("BelongItem");
  23. if(sc != null)
  24. {
  25. for (var j = 0; j < houseList.length; j++) {
  26. if(houseList[j].Id == sc.Id)
  27. {
  28. sc.Refresh(houseList[j]);
  29. if(houseList[j].ownNum > 0)
  30. children[i].active = true;
  31. else
  32. children[i].active = false;
  33. }
  34. }
  35. }
  36. }
  37. }
  38. else
  39. {
  40. for (var i = houseList.length - 1; i >= 0; i--) {
  41. //cc.log("实例化房子");
  42. var obj = cc.instantiate(this.ownedPre);
  43. obj.parent = this.ownedParent;
  44. obj.getComponent("BelongItem").init(houseList[i], ItemType.House);
  45. if(houseList[i].ownNum > 0)
  46. {
  47. obj.active = true;
  48. }
  49. else
  50. {
  51. obj.active = false;
  52. }
  53. }
  54. }
  55. },
  56. JudeHasAny:function(){
  57. var mateList = cc.Mgr.UserDataMgr.getOwnDataListByType(ItemType.House);
  58. var hasAny = false;
  59. for (var i = 0; i < mateList.length; i++) {
  60. if(mateList[i].ownNum > 0)
  61. {
  62. hasAny = true;
  63. return true;
  64. }
  65. }
  66. return hasAny;
  67. },
  68. });
  69. module.exports = OwnedHousePanel;