123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- import { _decorator, Component, Node, SpriteFrame, Sprite, Label, Color, Prefab, instantiate, EditBox } from 'cc';
- import { ClientEvent } from '../clientEvent';
- import { Constant } from '../constant';
- import { GameMng } from '../GameMng';
- import { UIButton } from '../gcommon/UIButton';
- import { chat_text_cell } from './chat_text_cell';
- import { emote } from './emote';
- const { ccclass, property } = _decorator;
- var CHAT_LIST_TEXT = [
- "很高兴认识你,请多多指教。", "你还在吗?请尽快下棋。", "稍等片刻,容我再思考思考。", "棋逢对手,将遇良才,痛快,痛快!",
- "再与我对弈一局?", "呀!大意失荆州!", "宁失一子,不失一先!",
- "哈哈,小卒过河顶大车!", "单车难破士象全呀!", "观棋不语真君子,落子无悔大丈夫!"
- ];
- @ccclass('chat_view')
- export class chat_view extends Component {
- @property(Node)
- btn_emote: Node = null; //
- @property(Node)
- btn_history: Node = null; //
- @property(Node)
- btn_send: Node = null; //
- @property(Node)
- btn_enter: Node = null; //
- @property(Node)
- btn_send_text: Node = null; //
- @property(EditBox)
- text_editBox: EditBox = null; //
- @property(Node)
- emote_scroll: Node = null; //
- @property(Node)
- history_scroll: Node = null; //
- @property(Node)
- chat_scroll: Node = null; //
- // @property(Node)
- // lab_em: Node = null; //
- // @property(Node)
- // lab_r: Node = null; //
- @property(Node)
- content: Node = null; //
- @property(Node)
- content_text: Node = null; //
- @property(Node)
- content_history_text: Node = null; //
- @property(Prefab)
- emote_pf: Node = null; //
- @property(Prefab)
- chat_text_pf: Node = null; //
- @property(SpriteFrame)
- sp_emote_select:SpriteFrame = null;
- @property(SpriteFrame)
- sp_emote_unselect:SpriteFrame = null;
- @property(SpriteFrame)
- sp_lishi_select:SpriteFrame = null;
- @property(SpriteFrame)
- sp_lishi_unselect:SpriteFrame = null;
- _color:Color = new Color;
- start() {
- this.initView()
- }
- initView(){
-
- this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_select;
- //this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
- this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_unselect;
- // this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
- this.emote_scroll.active = true;
- this.history_scroll.active = false;
- UIButton.BindClick(this.btn_emote,()=>{
- this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_select;
- // this.lab_em.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
- this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_unselect;
- // this.lab_r.getComponent(Label).color = this._color.fromHEX("#000000")
- this.emote_scroll.active = true;
- this.history_scroll.active = false;
- },this)
- UIButton.BindClick(this.btn_history,()=>{
- this.btn_emote.getComponent(Sprite).spriteFrame = this.sp_emote_unselect;
- // this.lab_em.getComponent(Label).color = this._color.fromHEX("#000000")
- this.btn_history.getComponent(Sprite).spriteFrame = this.sp_lishi_select;
- //this.lab_r.getComponent(Label).color = this._color.fromHEX("#FFFFFF")
- this.emote_scroll.active = false;
- this.history_scroll.active = true;
- },this)
- UIButton.BindClick(this.btn_send,()=>{
- this.chat_scroll.active = true;
- },this)
- UIButton.BindClick(this.btn_enter,()=>{
- this.chat_scroll.active = true;
- },this)
- UIButton.BindClick(this.btn_send_text,()=>{
- ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_SELF_CHAT,this.text_editBox.string)
- ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_SHOW_RIVAL_CHAT,this.text_editBox.string)
- ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
- },this)
- this.initEmoteList()
- this.initChatTextList()
- this.initChatHisyoryList()
- }
- onEnable(){
- this.emote_scroll.active = true;
- this.history_scroll.active = false;
- this.chat_scroll.active = false;
- this.text_editBox.string="";
- if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
- for (let index = this.content_history_text.children.length-1; index < GameMng._userData.room.chat_history_list.length; index++) {
- const element = GameMng._userData.room.chat_history_list[index];
- this.add_chat_history(element)
- }
- }
-
- }
- closeView(){
- ClientEvent.dispatchEvent(Constant.UI_EVENT.UI_MSG_BTN_HIDE_CHAT)
- }
- add_chat_history(str:string){
- var c = instantiate(this.chat_text_pf)
- this.content_history_text.addChild(c)
- c.getComponent(chat_text_cell).show(str)
- }
- initChatHisyoryList(){
- if(GameMng._userData.room.chat_history_list!=null&&GameMng._userData.room.chat_history_list!=undefined){
- for (let index = 0; index < GameMng._userData.room.chat_history_list.length; index++) {
- const str = GameMng._userData.room.chat_history_list[index];
- this.add_chat_history(str)
- }
- }
- }
- initChatTextList(){
- for (let index = 0; index < CHAT_LIST_TEXT.length; index++) {
- const str = CHAT_LIST_TEXT[index];
- var c = instantiate(this.chat_text_pf)
- this.content_text.addChild(c)
- c.getComponent(chat_text_cell).show(str)
- }
- }
- initEmoteList(){
- for (let index = 0; index < 28; index++) {
- var e = instantiate(this.emote_pf)
- this.content.addChild(e)
- e.getComponent(emote).show(index)
- }
- }
- update(deltaTime: number) {
-
- }
- }
|