SamsaraGame/assets/Script/ts/game/role/ChangeNameAlert.ts
2025-04-24 17:03:28 +08:00

63 lines
1.9 KiB
TypeScript

import GameModel from "../../core/GameModel";
import FGHUD from "../../gear_2.3.4/fgui/FGHUD";
import FGUtil from "../../gear_2.3.4/fgui/FGUtil";
import SKDataUtil from "../../gear_2.3.4/util/SKDataUtil";
import MsgAlert from "../msg/MsgAlert";
export default class ChangeNameAlert {
static shared: ChangeNameAlert = new ChangeNameAlert();
main: fgui.GComponent;
name_ti: fgui.GTextInput;
mId: string = "";
mTag: number = 1;
show(id: string, tag: number,name: string) {
this.mId = id;
this.mTag = tag;
this.loadUI(name);
}
hide() {
FGUtil.dispose(this.main);
this.main = null;
}
loadUI(name) {
FGUtil.dispose(this.main);
this.main = fgui.UIPackage.createObject("main_ui", "change_name_main").asCom;
FGUtil.root().addChild(this.main);
FGUtil.fitScreen(this.main);
FGUtil.getButton(this.main, "alert/close_btn").onClick(this.hide, this);
this.name_ti = FGUtil.getTextInput(this.main, "alert/name_ti");
this.name_ti.text = name;
this.name_ti.on(fgui.Event.Submit, this.onSubmit, this);
FGUtil.getButton(this.main, "alert/sure_btn").onClick(this.clickSure, this);
FGUtil.getButton(this.main, "alert/cancel_btn").onClick(this.hide, this);
}
onSubmit(event: fgui.Event) {
}
clickSure(event: fgui.Event) {
let name = this.name_ti.text;
let valid = SKDataUtil.checkSymbol(name, 2, 12, "不能有特殊字符!");
if (valid.length > 0) {
MsgAlert.addMsg(`角色名${valid}`);
return;
}
FGHUD.showLoading();
if(this.mTag == 0){
GameModel.send('c2s_update_pet_name', {
petId: this.mId,
name: name
});
}else{
GameModel.send('c2s_changename', {
roleid: this.mId,
name: name
});
}
}
}