FDialogAttr.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import i18n from "../../../../i18n/i18n";
  2. /**
  3. * 对话中的属性选择
  4. */
  5. const {ccclass, property} = cc._decorator;
  6. /**
  7. * 对话属性内容
  8. */
  9. export interface DialogAttrContent{
  10. name:string,
  11. about:string,
  12. icon:string,
  13. vaule:number,
  14. type:number,//添加属性类型
  15. }
  16. @ccclass
  17. export default class FDialogAttr extends cc.Component {
  18. @property(cc.Label)
  19. mName: cc.Label = null;
  20. @property(cc.Label)
  21. mAbout: cc.Label = null;
  22. @property(cc.Label)
  23. mVaule: cc.Label = null;
  24. @property(cc.Sprite)
  25. mIcon: cc.Sprite = null;
  26. public attr:DialogAttrContent;
  27. private callback:(attr:FDialogAttr)=>void;
  28. public onclick(){
  29. if(this.callback){
  30. this.callback(this);
  31. }
  32. }
  33. public setCallback(callback:(attr:FDialogAttr)=>void){
  34. this.callback = callback;
  35. }
  36. public setVaule(attr:DialogAttrContent){
  37. this.attr = attr;
  38. this.mName.string = i18n.t(attr.name)
  39. this.mAbout.string = i18n.t(attr.about)
  40. this.mVaule.string = attr.vaule + '%';
  41. cc.resources.load('icon/attr/'+attr.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  42. if(err){
  43. cc.error(err);
  44. }else{
  45. this.mIcon.spriteFrame = spriteFrame;
  46. }
  47. } );
  48. }
  49. }