Continue script abstraction

This commit is contained in:
hydrant
2020-03-01 13:15:50 +01:00
parent 37f499a446
commit d7a76caf2a
14 changed files with 531 additions and 8 deletions

View File

@@ -0,0 +1,73 @@
import { IUi, IBrowser } from "../../game";
import { Menu } from "../../libs/NativeUI/index";
export default class RageUi implements IUi {
private _inMenu: boolean = false;
private _activeMenu: Menu = null;
inChat: boolean = false;
get activeMenu(): Menu {
return this._activeMenu;
}
set activeMenu(value: Menu) {
if (this.activeMenu && this.activeMenu.Visible) {
this.activeMenu.Close(true);
}
this._activeMenu = value;
if (this.activeMenu) {
this.activeMenu.Open();
}
this.inMenu = this.activeMenu != null;
}
get inMenu() {
return this._inMenu;
}
set inMenu(value: boolean) {
this._inMenu = value;
this.toggleChat(!value);
}
toggleChat(toggle: boolean) {
mp.gui.chat.show(toggle);
}
openBrower(path: string): IBrowser {
return new RageBrowser(path);
}
sendChatMessage(message: string) {
mp.gui.chat.push(message);
}
setCursor(freeze: boolean, show: boolean): void {
mp.gui.cursor.show(freeze, show);
}
}
export class RageBrowser implements IBrowser {
private rageBrowser: BrowserMp;
constructor(path: string) {
this.rageBrowser = mp.browsers.new(path);
}
close(): void {
if (this.rageBrowser) {
this.rageBrowser.destroy();
this.rageBrowser = null;
}
}
executeJs(script: string) {
if (this.rageBrowser) {
this.rageBrowser.execute(script);
}
}
}