Aded business menu
This commit is contained in:
@@ -19,6 +19,8 @@ const ItemsCollection = NativeUI.ItemsCollection;
|
|||||||
const Color = NativeUI.Color;
|
const Color = NativeUI.Color;
|
||||||
const ListItem = NativeUI.ListItem;
|
const ListItem = NativeUI.ListItem;
|
||||||
|
|
||||||
|
const InputHelper = require("inputhelper");
|
||||||
|
|
||||||
mp.events.add('business_showHelp', (bizName, bizMoney) => {
|
mp.events.add('business_showHelp', (bizName, bizMoney) => {
|
||||||
mp.game.ui.setTextComponentFormat('STRING');
|
mp.game.ui.setTextComponentFormat('STRING');
|
||||||
mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um dein Business zu verwalten');
|
mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um dein Business zu verwalten');
|
||||||
@@ -47,6 +49,10 @@ mp.events.add('business_removeHelp', (unbind) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mp.events.add('business_updateMoney', (newMoney) => {
|
||||||
|
businessMoney = newMoney;
|
||||||
|
});
|
||||||
|
|
||||||
function keyPressHandler() {
|
function keyPressHandler() {
|
||||||
mp.events.call('business_removeHelp', false);
|
mp.events.call('business_removeHelp', false);
|
||||||
mp.gui.chat.show(false);
|
mp.gui.chat.show(false);
|
||||||
@@ -65,9 +71,9 @@ function keyPressHandler() {
|
|||||||
bankAccountItem.SetRightLabel("~g~~h~" + businessMoney);
|
bankAccountItem.SetRightLabel("~g~~h~" + businessMoney);
|
||||||
mainMenu.AddItem(bankAccountItem);
|
mainMenu.AddItem(bankAccountItem);
|
||||||
|
|
||||||
var partnerItem = new UIMenuItem("Inteilhaber", "Verwalte den Inteilhaber");
|
//var partnerItem = new UIMenuItem("Inteilhaber", "Verwalte den Inteilhaber");
|
||||||
partnerItem.SetRightLabel("Niemand");
|
//partnerItem.SetRightLabel("Niemand");
|
||||||
mainMenu.AddItem(partnerItem);
|
//mainMenu.AddItem(partnerItem);
|
||||||
|
|
||||||
mainMenu.Open();
|
mainMenu.Open();
|
||||||
|
|
||||||
@@ -87,6 +93,34 @@ function keyPressHandler() {
|
|||||||
var withdrawItem = new UIMenuItem("Auszahlen", "Zahle Geld von der Businesskasse aus");
|
var withdrawItem = new UIMenuItem("Auszahlen", "Zahle Geld von der Businesskasse aus");
|
||||||
bankMenu.AddItem(withdrawItem);
|
bankMenu.AddItem(withdrawItem);
|
||||||
|
|
||||||
|
bankMenu.ItemSelect.on((item, index) => {
|
||||||
|
if (item === depositItem) {
|
||||||
|
var depositInput = new InputHelper("Wie viel Geld möchtest du auf deine Businesskasse einzahlen?");
|
||||||
|
depositInput.show();
|
||||||
|
depositInput.getValue((data) => {
|
||||||
|
var amount = parseInt(data);
|
||||||
|
if (isNaN(amount)) {
|
||||||
|
mp.game.graphics.notify('~r~Du musst eine Nummer eingeben!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.events.callRemote('Business_DepositMoney', amount);
|
||||||
|
});
|
||||||
|
} else if (item === withdrawItem) {
|
||||||
|
var withdrawInput = new InputHelper("Wie viel Geld möchtest du von deiner Businesskasse abheben?");
|
||||||
|
withdrawInput.show();
|
||||||
|
withdrawInput.getValue((data) => {
|
||||||
|
var amount = parseInt(data);
|
||||||
|
if (isNaN(amount)) {
|
||||||
|
mp.game.graphics.notify('~r~Du musst eine Nummer eingeben!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.events.callRemote('Business_WithdrawMoney', amount);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bankMenu.MenuClose.on(() => {
|
bankMenu.MenuClose.on(() => {
|
||||||
if (closeMenu) {
|
if (closeMenu) {
|
||||||
closeMenu = false;
|
closeMenu = false;
|
||||||
|
|||||||
66
Client/inputhelper/index.js
Normal file
66
Client/inputhelper/index.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
class InputHelper {
|
||||||
|
constructor(title) {
|
||||||
|
this.title = title;
|
||||||
|
|
||||||
|
this.cefTitleCall = this.cefTitleCall.bind(this);
|
||||||
|
mp.events.add('cef_request_title', this.cefTitleCall);
|
||||||
|
|
||||||
|
this.cefCallback = this.cefCallback.bind(this);
|
||||||
|
mp.events.add('cef_inputhelper_sendvalue', this.cefCallback);
|
||||||
|
|
||||||
|
this.finish = this.finish.bind(this);
|
||||||
|
this.show = this.show.bind(this);
|
||||||
|
this.valueGetter = this.valueGetter.bind(this);
|
||||||
|
this.getValue = this.getValue.bind(this);
|
||||||
|
|
||||||
|
this.value = undefined;
|
||||||
|
|
||||||
|
mp.events.add('render', this.disableControls);
|
||||||
|
}
|
||||||
|
|
||||||
|
disableControls() {
|
||||||
|
for (var i = 0; i <= 33; i++) {
|
||||||
|
mp.game.controls.disableAllControlActions(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
show() {
|
||||||
|
if (this.created) return;
|
||||||
|
this.created = true;
|
||||||
|
this.browser = mp.browsers.new('package://inputhelper/web/inputhelper.html');
|
||||||
|
}
|
||||||
|
|
||||||
|
finish() {
|
||||||
|
if (this.browser) {
|
||||||
|
mp.events.remove('cef_inputhelper_sendvalue');
|
||||||
|
mp.events.remove('cef_request_title');
|
||||||
|
mp.events.remove('render', this.disableControls);
|
||||||
|
this.browser.destroy();
|
||||||
|
this.created = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cefTitleCall() {
|
||||||
|
this.browser.execute(`setTitle('${this.title}')`);
|
||||||
|
}
|
||||||
|
|
||||||
|
cefCallback(val) {
|
||||||
|
this.value = val;
|
||||||
|
this.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
valueGetter() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setInterval(() => {
|
||||||
|
if (this.value !== undefined) resolve(this.value);
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getValue(callback) {
|
||||||
|
var getVal = await this.valueGetter();
|
||||||
|
callback(getVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exports = InputHelper;
|
||||||
50
Client/inputhelper/web/inputhelper.css
Normal file
50
Client/inputhelper/web/inputhelper.css
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#black {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
z-index: -1;
|
||||||
|
background-color: rgba(0, 0, 0, .3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-main {
|
||||||
|
display: block;
|
||||||
|
width: 70%;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
|
||||||
|
background-color: rgba(0, 0, 0, .8);
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-main h1 {
|
||||||
|
color: white;
|
||||||
|
font-size: 24px;
|
||||||
|
font-family: "Arial";
|
||||||
|
font-weight: lighter;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-main input {
|
||||||
|
width: 100%;
|
||||||
|
background-color: black;
|
||||||
|
outline: 0;
|
||||||
|
border: grey 1px solid;
|
||||||
|
color: white;
|
||||||
|
padding: 5px;
|
||||||
|
font-size: 20px;
|
||||||
|
font-family: "Arial";
|
||||||
|
font-weight: lighter;
|
||||||
|
}
|
||||||
|
|
||||||
32
Client/inputhelper/web/inputhelper.html
Normal file
32
Client/inputhelper/web/inputhelper.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="stylesheet" href="inputhelper.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="black"></div>
|
||||||
|
<div class="input-main">
|
||||||
|
<h1></h1>
|
||||||
|
<input id="input-value" autofocus>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript" src="package://Dependences/jquery-3.3.1.min.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function () {
|
||||||
|
mp.trigger('cef_request_title');
|
||||||
|
|
||||||
|
$('#input-value').keydown(function (e) {
|
||||||
|
if (e.keyCode != 13) return;
|
||||||
|
var currentValue = $('#input-value').val();
|
||||||
|
if (currentValue) {
|
||||||
|
mp.trigger('cef_inputhelper_sendvalue', currentValue);
|
||||||
|
console.log("triggered event: " + currentValue);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function setTitle(title) {
|
||||||
|
$('.input-main h1').text(title);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user