bag_list_page_item.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { bag_list_item_data } from '../../data';
  4. import { tools } from '../../tools';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('bag_list_page_item')
  7. export class bag_list_page_item extends base_ui {
  8. @property(Node) icon_bg:Node = null
  9. @property(Node) img_icon:Node = null
  10. @property(Node) lab_count:Node = null
  11. @property(Node) lab_name:Node = null
  12. @property(SpriteFrame) sf_icon_bg_selected:SpriteFrame = null
  13. @property(SpriteFrame) sf_icon_bg_unSelected:SpriteFrame = null
  14. private m_data:bag_list_item_data = null
  15. private m_click_cb = null
  16. start() {
  17. this.onButtonListen(this.node, ()=>{
  18. if(this.m_click_cb) {
  19. this.m_click_cb(this)
  20. }
  21. })
  22. }
  23. initView(data:bag_list_item_data, click_cb) {
  24. this.m_click_cb = click_cb
  25. this.setData(data)
  26. }
  27. public setData(data:bag_list_item_data) {
  28. this.m_data = data
  29. tools.loadRemoteImg(this.m_data.icon, (r)=>{
  30. this.img_icon.getComponent(Sprite).spriteFrame = r.sf
  31. })
  32. this.lab_name.getComponent(Label).string = data.name
  33. this.lab_count.getComponent(Label).string = data.quantity + ''
  34. }
  35. public setSelectedStatus() {
  36. this.icon_bg.getComponent(Sprite).spriteFrame = this.sf_icon_bg_selected
  37. }
  38. public setUnselectedStatus() {
  39. this.icon_bg.getComponent(Sprite).spriteFrame = this.sf_icon_bg_unSelected
  40. }
  41. public getData():bag_list_item_data {
  42. return this.m_data
  43. }
  44. }