Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
3.7.0 inventory (#263)
Browse files Browse the repository at this point in the history
* Init New Inventory Functions

* not inventory stuff, but putting it here because why not

* Additional WebSocket Changes

* Debug Plugin
  • Loading branch information
Stuyk committed Aug 1, 2022
1 parent 229db04 commit 194a2f4
Show file tree
Hide file tree
Showing 22 changed files with 1,081 additions and 225 deletions.
4 changes: 2 additions & 2 deletions scripts/streamer/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class StreamerServer {
}
return Math.sqrt(
Math.pow(vector1.x - vector2.x, 2) +
Math.pow(vector1.y - vector2.y, 2) +
Math.pow(vector1.z - vector2.z, 2),
Math.pow(vector1.y - vector2.y, 2) +
Math.pow(vector1.z - vector2.z, 2),
);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/core/client/rmlui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as alt from 'alt-client';

const fontsToLoad = [
{
path: '/client/rmlui/fonts/arialbd.ttf', // Only supports TTF
name: 'arial',
italic: false,
bold: false,
},
];

for (let i = 0; i < fontsToLoad.length; i++) {
if (!fontsToLoad[i].path.includes('ttf')) {
console.warn(`Could not load Font: ${fontsToLoad[i].path}. TTF only fonts.`);
continue;
}

try {
alt.loadRmlFont(fontsToLoad[i].path, fontsToLoad[i].name, fontsToLoad[i].italic, fontsToLoad[i].bold);
} catch (err) {}
}
53 changes: 53 additions & 0 deletions src/core/client/rmlui/input/index.rml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<rml>
<head>
<title>Quick Input</title>
<style>
html,
body {
padding: 0;
margin: 0;
overflow: hidden;
}

body {
font-family: arial;
font-style: normal;
font-size: 16px;
width: 100vw;
box-sizing: border-box;
padding-left: 25vw;
padding-right: 25vw;
padding-top: 75vh;
}

.text-input {
font-family: arial;
font-style: normal;
font-size: 16px;
width: 100%;
border: 2px rgb(22, 22, 22);
border-radius: 6px;
min-height: 30px;
background: rgba(0, 0, 0, 100);
padding: 12px;
color: white;
box-sizing: border-box;
font-effect: shadow(2px 2px black);
}

.invisible {
font-family: arial;
font-style: normal;
font-size: 16px;
/* height: 0px;
opacity: 0; */
}
</style>
</head>
<body>
<form id="form" onsubmit="submit">
<input class="text-input" id="input" onchange="(e) => console.log(e)" tabindex="0" />
<input class="invisible" type="submit" value="submit">Submit</input>
</form>
</body>
</rml>
93 changes: 93 additions & 0 deletions src/core/client/rmlui/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import alt, { RmlElement } from 'alt-client';
import { SYSTEM_EVENTS } from '../../../shared/enums/system';
import { disableAllControls } from '../../utility/disableControls';

let document: alt.RmlDocument;
let form: alt.RmlElement;
let input: alt.RmlElement;
let callback: (result: string) => void;
let currentValue = '';

class Internal {
static init() {
document = new alt.RmlDocument('/client/rmlui/input/index.rml');
document.hide();
}

static handleKey(key: number) {
if (key === 13) {
}

// Closing
if (key !== 27) {
return;
}

disableAllControls(false);
alt.toggleRmlControls(false);
alt.off('keyup', Internal.handleKey);
input.off('textinput', Internal.handleInput);
callback('');
document.hide();
}

static handleInput(element: alt.RmlElement, text: string) {
console.log('submitted');
console.log(text);

// disableAllControls(false);
// alt.toggleRmlControls(false);
// alt.off('keyup', Internal.handleKey);
// input.off('textinput', Internal.handleInput);
// callback('');
// document.hide();
}
}

export class QuickInput {
static open(_callback: (result: string) => void) {
if (callback) {
alt.logWarning(`Tried to Open Quick Input when Input is Already Open`);
return;
}

callback = _callback;
document.show();
form = document.getElementByID('form');
input = document.getElementByID('input');

input.focus();
alt.on('keyup', Internal.handleKey);
form.on('submit', (e, args) => {
console.log(e);
console.log(args);
});

form.on('onsubmit', (e, args) => {
console.log(e);
console.log(args);
});

form.on('customevent', (e, args) => {
console.log(e);
console.log(args);
});

alt.nextTick(() => {
alt.toggleGameControls(false);
alt.toggleRmlControls(true);
alt.showCursor(true);
disableAllControls(true);
});
}
}

// Internal.init();

// alt.onServer(SYSTEM_EVENTS.TICKS_START, async () => {
// await alt.Utils.wait(2000);

// QuickInput.open((result) => {
// console.log(`Final Text: ${result}`);
// });
// });
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
**/

import alt, { RmlElement } from 'alt-client';
import { SYSTEM_EVENTS } from '../../shared/enums/system';
import { Vector2, Vector3 } from '../../shared/interfaces/vector';
import { distance } from '../../shared/utility/vector';
import { isAnyMenuOpen } from '../utility/menus';
import { UID } from '../utility/uid';
import { SYSTEM_EVENTS } from '../../../shared/enums/system';
import { Vector2, Vector3 } from '../../../shared/interfaces/vector';
import { distance } from '../../../shared/utility/vector';
import { isAnyMenuOpen } from '../../utility/menus';
import { UID } from '../../utility/uid';

const elements: {
[uid: string]: { element: RmlElement; position: Vector2 | Vector3; nextCheck?: number; isOffScreen?: boolean };
Expand Down Expand Up @@ -116,63 +116,63 @@ class InternalFunctions {
}
}

export class ScreenText {
static addText(text: string, position: Vector2 | Vector3, uid: string = null): string {
if (!uid) {
uid = UID.generate();
}

if (elements[uid]) {
ScreenText.removeText(uid);
}

elements[uid] = {
element: document.createElement('div'),
position,
};

elements[uid].element.addClass('text');
elements[uid].element.innerRML = text;
elements[uid].element.setProperty('left', `${position.x}px`);
elements[uid].element.setProperty('top', `${position.y}px`);
elements[uid].element.setProperty('font-size', '70dp');
container.appendChild(elements[uid].element);

return uid;
}

static updateText(uid: string, position: Vector2 | Vector3) {
if (!elements[uid]) {
return;
}

elements[uid].position = position;
}

static hasText(uid: string) {
if (!elements[uid]) {
return false;
}

return true;
}

static removeText(uid: string) {
const elementRef = elements[uid];
if (!elementRef) {
return;
}

const element = elementRef.element;

try {
container.removeChild(element);
delete elements[uid];
} catch (err) {}
}
}

alt.onServer(SYSTEM_EVENTS.TICKS_START, InternalFunctions.init);
// export class ScreenText {
// static addText(text: string, position: Vector2 | Vector3, uid: string = null): string {
// if (!uid) {
// uid = UID.generate();
// }

// if (elements[uid]) {
// ScreenText.removeText(uid);
// }

// elements[uid] = {
// element: document.createElement('div'),
// position,
// };

// elements[uid].element.addClass('text');
// elements[uid].element.innerRML = text;
// elements[uid].element.setProperty('left', `${position.x}px`);
// elements[uid].element.setProperty('top', `${position.y}px`);
// elements[uid].element.setProperty('font-size', '70dp');
// container.appendChild(elements[uid].element);

// return uid;
// }

// static updateText(uid: string, position: Vector2 | Vector3) {
// if (!elements[uid]) {
// return;
// }

// elements[uid].position = position;
// }

// static hasText(uid: string) {
// if (!elements[uid]) {
// return false;
// }

// return true;
// }

// static removeText(uid: string) {
// const elementRef = elements[uid];
// if (!elementRef) {
// return;
// }

// const element = elementRef.element;

// try {
// container.removeChild(element);
// delete elements[uid];
// } catch (err) {}
// }
// }

// alt.onServer(SYSTEM_EVENTS.TICKS_START, InternalFunctions.init);

// alt.onServer(SYSTEM_EVENTS.TICKS_START, () => {
// alt.log('starting...');
Expand Down
3 changes: 2 additions & 1 deletion src/core/client/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import './menus/player';
import './menus/vehicle';

// rmlui
// import './rmlui/screenText';
import './rmlui/index';
import './rmlui/input/index';

// Streamers
import './streamers/item';
Expand Down
39 changes: 0 additions & 39 deletions src/core/client/utility/sandbox.ts
Original file line number Diff line number Diff line change
@@ -1,39 +0,0 @@
import * as alt from 'alt-client';
import * as native from 'natives';
import MinimapHelper from './minimap';
import { drawRectangle2D, drawText2D } from './text';
// TODO: Still in Usage? Can't tell properly, so i'll keep it for now.

// const polygon = new Polygon([
// { x: -1498.1483154296875, y: -677.0752563476562, z: 28.048023223876953 },
// { x: -1491.2274169921875, y: -671.2970581054688, z: 28.943195343017578 },
// { x: -1498.2650146484375, y: -664.248291015625, z: 29.025087356567383 },
// { x: -1463.30908203125, y: -638.9778442382812, z: 29.582916259765625 },
// { x: -1452.80712890625, y: -652.8944091796875, z: 29.582338333129883 },
// { x: -1478.6595458984375, y: -672.8909301757812, z: 29.041839599609375 },
// { x: -1481.732421875, y: -672.94677734375, z: 28.943140029907227 },
// { x: -1493.603271484375, y: -681.1644897460938, z: 27.73985481262207 },
// { x: -1493.603271484375, y: -681.1644897460938, z: 27.73985481262207 },
// ]);

// alt.setInterval(() => {
// if (!polygon) {
// return;
// }

// const lines = polygon.getDrawLines();
// for (let i = 0; i < lines.length; i++) {
// const a = lines[i].a;
// const b = lines[i].b;
// native.drawLine(a.x, a.y, a.z, b.x, b.y, b.z, 255, 0, 0, 255);
// }

// const center = polygon.getCenter();
// native.drawLine(center.x, center.y, center.z, center.x, center.y, center.z + 2, 255, 0, 0, 255);

// if (polygon.isInPolygon(alt.Player.local.pos)) {
// drawText2D('INSIDE', { x: 0.5, y: 0.2 }, 0.4, new alt.RGBA(255, 255, 255, 100));
// } else {
// drawText2D('OUTSIDE', { x: 0.5, y: 0.2 }, 0.4, new alt.RGBA(255, 255, 255, 100));
// }
// }, 0);
13 changes: 13 additions & 0 deletions src/core/plugins/athena-debug/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as alt from 'alt-client';
import { SYSTEM_EVENTS } from '../../../shared/enums/system';
import { ATHENA_DEBUG_EVENTS } from '../shared/events';

alt.onServer(SYSTEM_EVENTS.TICKS_START, () => {
alt.on('keyup', (key: number) => {
if (key !== 112) {
return;
}

alt.emitServer(ATHENA_DEBUG_EVENTS.ClientToServer.FORWARD);
});
});
Empty file.
12 changes: 12 additions & 0 deletions src/core/plugins/athena-debug/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as alt from 'alt-server';
import { PluginSystem } from '../../../server/systems/plugins';
import { Keys } from './system/keys';
import { WebSocketClient } from './system/ws';

const PLUGIN_NAME = 'Athena Debug';

PluginSystem.registerPlugin(PLUGIN_NAME, () => {
WebSocketClient.init();
Keys.init();
alt.log(`~lg~CORE ==> ${PLUGIN_NAME} was Loaded`);
});
Loading

0 comments on commit 194a2f4

Please sign in to comment.