Aded business menu
This commit is contained in:
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