chat_view.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. sp_select:SpriteFrame = null;
  49. sp_unselect:SpriteFrame = null;
  50. _color:Color = new Color;
  51. start() {
  52. this.initView()
  53. }
  54. initView(){
  55. if(this.sp_select===null){
  56. this.sp_select = this.btn_history.getComponent(Sprite).spriteFrame;
  57. this.sp_unselect = this.btn_emote.getComponent(Sprite).spriteFrame;
  58. }
  59. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_select;
  60. this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  61. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_unselect;
  62. this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
  63. this.emote_scroll.active = true;
  64. this.history_scroll.active = false;
  65. UIButton.BindClick(this.btn_emote,()=>{
  66. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_select;
  67. this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  68. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_unselect;
  69. this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
  70. this.emote_scroll.active = true;
  71. this.history_scroll.active = false;
  72. },this)
  73. UIButton.BindClick(this.btn_history,()=>{
  74. this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_unselect;
  75. this.lab_em.getComponent(Label).color = this._color.fromHEX("#000000")
  76. this.btn_history.getComponent(Sprite).spriteFrame = this.sp_select;
  77. this.lab_r.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
  78. this.emote_scroll.active = false;
  79. this.history_scroll.active = true;
  80. },this)
  81. UIButton.BindClick(this.btn_send,()=>{
  82. this.chat_scroll.active = true;
  83. },this)
  84. UIButton.BindClick(this.btn_enter,()=>{
  85. this.chat_scroll.active = true;
  86. },this)
  87. UIButton.BindClick(this.btn_send_text,()=>{
  88. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.text_editBox.string)
  89. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.text_editBox.string)
  90. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
  91. },this)
  92. this.initEmoteList()
  93. this.initChatTextList()
  94. this.initChatHisyoryList()
  95. }
  96. onEnable(){
  97. this.emote_scroll.active = true;
  98. this.history_scroll.active = false;
  99. this.chat_scroll.active = false;
  100. this.text_editBox.string="";
  101. if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
  102. for (let index = this.content_history_text.children.length-1; index < GameMng._userData.room.chat_history_list.length; index++) {
  103. const element = GameMng._userData.room.chat_history_list[index];
  104. this.add_chat_history(element)
  105. }
  106. }
  107. }
  108. closeView(){
  109. ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
  110. }
  111. add_chat_history(str:string){
  112. var c = instantiate(this.chat_text_pf)
  113. this.content_history_text.addChild(c)
  114. c.getComponent(chat_text_cell).show(str)
  115. }
  116. initChatHisyoryList(){
  117. if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
  118. for (let index = 0; index < GameMng._userData.room.chat_history_list.length; index++) {
  119. const str = GameMng._userData.room.chat_history_list[index];
  120. this.add_chat_history(str)
  121. }
  122. }
  123. }
  124. initChatTextList(){
  125. for (let index = 0; index < CHAT_LIST_TEXT.length; index++) {
  126. const str = CHAT_LIST_TEXT[index];
  127. var c = instantiate(this.chat_text_pf)
  128. this.content_text.addChild(c)
  129. c.getComponent(chat_text_cell).show(str)
  130. }
  131. }
  132. initEmoteList(){
  133. for (let index = 0; index < 28; index++) {
  134. var e = instantiate(this.emote_pf)
  135. this.content.addChild(e)
  136. e.getComponent(emote).show(index)
  137. }
  138. }
  139. update(deltaTime: number) {
  140. }
  141. }