select_area_item.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
  2. import { base_ui } from '../../fw/base_ui';
  3. import { area_item_data } from '../../data';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('select_area_item')
  6. export class select_area_item extends base_ui {
  7. @property(SpriteFrame) sf_unselected:SpriteFrame = null
  8. @property(SpriteFrame) sf_selected:SpriteFrame = null
  9. @property(Node) lab_name:Node = null
  10. private m_data:area_item_data = null
  11. private m_callback = null
  12. private m_index:number = 0
  13. private m_is_selected:boolean = false
  14. protected start(): void {
  15. this.onButtonListen(this.node, ()=>{
  16. if(this.m_callback!=null) {
  17. this.m_callback(this)
  18. }
  19. })
  20. }
  21. initView(data:area_item_data,index,call) {
  22. this.m_data = data
  23. this.m_callback = call
  24. this.m_index = index
  25. this.lab_name.getComponent(Label).string = data.name
  26. }
  27. public getData():area_item_data {
  28. return this.m_data
  29. }
  30. public getIndex():number {
  31. return this.m_index
  32. }
  33. public setSelectStatus() {
  34. this.m_is_selected = true
  35. this.node.getComponent(Sprite).spriteFrame = this.sf_selected
  36. }
  37. public setUnselectStatus() {
  38. this.m_is_selected = false
  39. this.node.getComponent(Sprite).spriteFrame = this.sf_unselected
  40. }
  41. public getIsSelected():boolean {
  42. return this.m_is_selected
  43. }
  44. }