68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
|
import { tgxUIAlert, tgxUIController, tgxUIWaiting, tgx_class } from "../../core_tgx/tgx";
|
||
|
import { GameUILayers } from "../../scripts/GameUILayers";
|
||
|
import { ModuleDef } from "../../scripts/ModuleDef";
|
||
|
import { SubGameMgr } from "../../module_basic/scripts/SubGameMgr";
|
||
|
import { UserMgr } from "../../module_basic/scripts/UserMgr";
|
||
|
import { Layout_UICreateRoom } from "./Layout_UICreateRoom";
|
||
|
|
||
|
@tgx_class(ModuleDef.BASIC)
|
||
|
export class UICreateRoom extends tgxUIController {
|
||
|
constructor() {
|
||
|
super('ui_create_room/ui_create_room', GameUILayers.POPUP, Layout_UICreateRoom);
|
||
|
}
|
||
|
|
||
|
protected onCreated(): void {
|
||
|
let layout = this.layout as Layout_UICreateRoom;
|
||
|
this.onButtonEvent(layout.btnClose, () => {
|
||
|
this.close();
|
||
|
});
|
||
|
|
||
|
this.onButtonEvent(layout.btnCreate, this.onBtnCreateClicked, this);
|
||
|
|
||
|
layout.edtName.string = this.getDefaultRoomName();
|
||
|
}
|
||
|
|
||
|
private getDefaultRoomName() {
|
||
|
return UserMgr.inst.name + '的好友局';
|
||
|
}
|
||
|
|
||
|
async onBtnCreateClicked() {
|
||
|
let layout = this.layout as Layout_UICreateRoom;
|
||
|
if (!layout.edtName.string) {
|
||
|
layout.edtName.string = this.getDefaultRoomName();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (layout.edtName.string.length > 14) {
|
||
|
tgxUIAlert.show('名称最多 14 个汉字');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (layout.edtPassword.string.length > 16) {
|
||
|
tgxUIAlert.show('密码最多16个字符');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
tgxUIWaiting.show();
|
||
|
|
||
|
let ret = await UserMgr.inst.rpc_CreateRoom(SubGameMgr.current.id, layout.edtName.string, layout.edtPassword.string);
|
||
|
|
||
|
tgxUIWaiting.hide();
|
||
|
|
||
|
if (ret.isSucc) {
|
||
|
let password = layout.edtPassword.string;
|
||
|
if (ret.isSucc) {
|
||
|
let params = ret.res.enterRoomParams;
|
||
|
return await SubGameMgr.inst.enterSubGame(params,UserMgr.inst.uid);
|
||
|
}
|
||
|
else {
|
||
|
tgxUIAlert.show('创建失败');
|
||
|
}
|
||
|
|
||
|
this.close();
|
||
|
}
|
||
|
else {
|
||
|
tgxUIAlert.show(ret.err.message);
|
||
|
}
|
||
|
}
|
||
|
}
|