chat_view.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import { _decorator, Component, Node, SpriteFrame, Sprite, Label, Color, Prefab, instantiate, EditBox } from 'cc';
  2. import { ClientEvent } from '../clientEvent';
  3. import { Constant } from '../constant';
  4. import { GameMng } from '../GameMng';
  5. import { UIButton } from '../gcommon/UIButton';
  6. import { chat_text_cell } from './chat_text_cell';
  7. import { emote } from './emote';
  8. const { ccclass, property } = _decorator;
  9. var CHAT_LIST_TEXT = [
  10. "很高兴认识你,请多多指教。", "你还在吗?请尽快下棋。", "稍等片刻,容我再思考思考。", "棋逢对手,将遇良才,痛快,痛快!",
  11. "再与我对弈一局?", "呀!大意失荆州!", "宁失一子,不失一先!",
  12. "哈哈,小卒过河顶大车!", "单车难破士象全呀!", "观棋不语真君子,落子无悔大丈夫!"
  13. ];
  14. @ccclass('chat_view')
  15. export class chat_view extends Component {
  16. @property(Node)
  17. btn_emote: Node = null; //
  18. @property(Node)
  19. btn_history: Node = null; //
  20. @property(Node)
  21. btn_send: Node = null; //
  22. @property(Node)
  23. btn_enter: Node = null; //
  24. @property(Node)
  25. btn_send_text: Node = null; //
  26. @property(EditBox)
  27. text_editBox: EditBox = null; //
  28. @property(Node)
  29. emote_scroll: Node = null; //
  30. @property(Node)
  31. history_scroll: Node = null; //
  32. @property(Node)
  33. chat_scroll: Node = null; //
  34. // @property(Node)
  35. // lab_em: Node = null; //
  36. // @property(Node)
  37. // lab_r: Node = null; //
  38. @property(Node)
  39. content: Node = null; //
  40. @property(Node)
  41. content_text: Node = null; //
  42. @property(Node)
  43. content_history_text: Node = null; //
  44. @property(Prefab)
  45. emote_pf: Node = null; //
  46. @property(Prefab)
  47. chat_text_pf: Node = null; //
  48. @property(SpriteFrame)
  49. sp_emote_select:SpriteFrame = null;
  50. @property(SpriteFrame)
  51. sp_emote_unselect:SpriteFrame = null;
  52. @property(SpriteFrame)
  53. sp_lishi_select:SpriteFrame = null;
  54. @property(SpriteFrame)
  55. sp_lishi_unselect:SpriteFrame = null;
  56. _color:Color = new Color;
  57. start() {
  58. this.initView()
  59. }
  60. initView(){
  61. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_select;
  62. //this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  63. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_unselect;
  64. // this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
  65. this.emote_scroll.active = true;
  66. this.history_scroll.active = false;
  67. UIButton.BindClick(this.btn_emote,()=>{
  68. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_select;
  69. // this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  70. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_unselect;
  71. // this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
  72. this.emote_scroll.active = true;
  73. this.history_scroll.active = false;
  74. },this)
  75. UIButton.BindClick(this.btn_history,()=>{
  76. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_unselect;
  77. // this.lab_em.getComponent(Label).color = this._color.fromHEX("#000000")
  78. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_select;
  79. //this.lab_r.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  80. this.emote_scroll.active = false;
  81. this.history_scroll.active = true;
  82. },this)
  83. UIButton.BindClick(this.btn_send,()=>{
  84. this.chat_scroll.active = true;
  85. },this)
  86. UIButton.BindClick(this.btn_enter,()=>{
  87. this.chat_scroll.active = true;
  88. },this)
  89. UIButton.BindClick(this.btn_send_text,()=>{
  90. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.text_editBox.string)
  91. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.text_editBox.string)
  92. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
  93. },this)
  94. this.initEmoteList()
  95. this.initChatTextList()
  96. this.initChatHisyoryList()
  97. }
  98. onEnable(){
  99. this.emote_scroll.active = true;
  100. this.history_scroll.active = false;
  101. this.chat_scroll.active = false;
  102. this.text_editBox.string="";
  103. if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
  104. for (let index = this.content_history_text.children.length-1; index < GameMng._userData.room.chat_history_list.length; index++) {
  105. const element = GameMng._userData.room.chat_history_list[index];
  106. this.add_chat_history(element)
  107. }
  108. }
  109. }
  110. closeView(){
  111. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
  112. }
  113. add_chat_history(str:string){
  114. var c = instantiate(this.chat_text_pf)
  115. this.content_history_text.addChild(c)
  116. c.getComponent(chat_text_cell).show(str)
  117. }
  118. initChatHisyoryList(){
  119. if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
  120. for (let index = 0; index < GameMng._userData.room.chat_history_list.length; index++) {
  121. const str = GameMng._userData.room.chat_history_list[index];
  122. this.add_chat_history(str)
  123. }
  124. }
  125. }
  126. initChatTextList(){
  127. for (let index = 0; index < CHAT_LIST_TEXT.length; index++) {
  128. const str = CHAT_LIST_TEXT[index];
  129. var c = instantiate(this.chat_text_pf)
  130. this.content_text.addChild(c)
  131. c.getComponent(chat_text_cell).show(str)
  132. }
  133. }
  134. initEmoteList(){
  135. for (let index = 0; index < 28; index++) {
  136. var e = instantiate(this.emote_pf)
  137. this.content.addChild(e)
  138. e.getComponent(emote).show(index)
  139. }
  140. }
  141. update(deltaTime: number) {
  142. }
  143. }