BelongItem.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var ItemType = require("ItemType");
  2. var BelongItem = cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. itemType:{
  6. default:ItemType.Car,
  7. type:ItemType,
  8. },
  9. Id:cc.Integer,
  10. ItemName:"",
  11. icon:cc.Sprite,
  12. Atlas:cc.SpriteAtlas,
  13. price:cc.Integer,
  14. nameLbl:cc.Label,
  15. desLbl:cc.Label,
  16. Data:null,
  17. },
  18. init:function (data, itemType) {
  19. this.Id = data.Id;
  20. this.Data = data;
  21. this.itemType = itemType;
  22. this.icon.spriteFrame = this.Atlas.getSpriteFrame(data.icon);
  23. //this.nameLbl.string = data.name;
  24. this.ItemName = data.name;
  25. if(data.price == null)
  26. this.price = 0;
  27. else
  28. this.price = data.price;
  29. if(this.itemType == ItemType.Car || this.itemType == ItemType.House)
  30. {
  31. this.desLbl.string = "x" + data.ownNum;
  32. }
  33. else if(this.itemType == ItemType.Mate)
  34. {
  35. this.desLbl.string = "";
  36. }
  37. },
  38. ClickOpen:function(){
  39. cc.Mgr.AudioMgr.playSFX("click");
  40. if(this.itemType == ItemType.Car || this.itemType == ItemType.House)
  41. {
  42. var param = {};
  43. if(this.itemType == ItemType.Car)
  44. param.name = cc.Mgr.global.getTranslation("car_" + this.Id);
  45. else
  46. param.name = cc.Mgr.global.getTranslation("company_"+this.Id);
  47. param.Id = this.Id;
  48. param.Type = ItemType.House;
  49. if(this.itemType == ItemType.Car)
  50. param.Type = ItemType.Car;
  51. param.price = this.price;
  52. param.icon = this.Data.icon;
  53. param.flag = "Sale";
  54. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonBuy, param);
  55. }
  56. else if(this.itemType == ItemType.Mate)
  57. {
  58. var param = {};
  59. param.name = param.name = cc.Mgr.global.getTranslation("role_"+this.Id);
  60. param.Id = this.Id;
  61. param.Type = ItemType.Mate;
  62. param.price = this.price;
  63. param.flag = "Sale";
  64. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonBuy, param);
  65. }
  66. },
  67. Refresh:function(data){
  68. if(this.itemType == ItemType.Car || this.itemType == ItemType.House)
  69. {
  70. this.desLbl.string = "x" + data.ownNum;
  71. }
  72. },
  73. });
  74. module.exports = BelongItem;