334 lines
11 KiB
TypeScript
334 lines
11 KiB
TypeScript
//GANGZONE EDITOR
|
|
var gzEdit = false;
|
|
var editVisualHelpX = 0.5;
|
|
var editVisualHelpY = 0.8;
|
|
var pointCounter = -1;
|
|
var editorState = 0;
|
|
var gangZoneMidHeight;
|
|
var helpScale = 0.1;
|
|
var editPoint = null;
|
|
|
|
var colorG = [0, 255, 0, 255];
|
|
var colorR = [255, 0, 0, 255];
|
|
var colorW = [255, 255, 255, 255];
|
|
var colorY = [245, 229, 27, 255];
|
|
var pointColors = <any>[colorW, colorR, colorR, colorR];
|
|
|
|
var gPoints; //Eckpunkte
|
|
var gZoneBorders;
|
|
|
|
/*
|
|
class gPoint {
|
|
constructor(id: number, x: number, y: number) { }
|
|
id: number;
|
|
x: number;
|
|
y: number;
|
|
}*/
|
|
|
|
mp.events.add("SERVER:Load_Gangzone_Editor", () => {
|
|
/*if (gzEdit == false) {
|
|
|
|
}*/
|
|
reloadGangZoneEditor();
|
|
});
|
|
|
|
function reloadGangZoneEditor() {
|
|
gzEdit = true;
|
|
pointCounter = -1;
|
|
gangZoneMidHeight = new mp.Vector3(0, 0, 0);
|
|
pointColors = [colorW, colorR, colorR, colorR];
|
|
gPoints = new Array<Vector3Mp>();
|
|
editorState = 0;
|
|
editPoint = null;
|
|
gZoneBorders = new Array<number>();
|
|
}
|
|
|
|
//TASTE NUM5
|
|
mp.keys.bind(0x65, false, function () {
|
|
if (gzEdit) {
|
|
switch (editorState) {
|
|
case 0:
|
|
if (pointCounter < 0) { //Map-Höhe definieren
|
|
gangZoneMidHeight = mp.players.local.position;
|
|
} else { //Eckpunkte abspeichern
|
|
var newPoint = mp.players.local.position;
|
|
newPoint.z = gangZoneMidHeight.z;
|
|
gPoints.push(newPoint);
|
|
pointColors[pointCounter] = colorG;
|
|
pointColors[pointCounter + 1] = colorW;
|
|
}
|
|
pointCounter++;
|
|
if (pointCounter == 4) { //Alle Eckpunkte abgespeichert
|
|
editorState = 1;
|
|
}
|
|
break;
|
|
case 1: //Bearbeiteten Punkt abspeichern
|
|
var newPoint = mp.players.local.position;
|
|
newPoint.z = gangZoneMidHeight.z;
|
|
gPoints[editPoint - 1] = newPoint;
|
|
pointColors[editPoint - 1] = colorG;
|
|
editPoint = null;
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
//NUM0
|
|
mp.keys.bind(0x60, false, function () {
|
|
if (gzEdit && editorState == 1 && editPoint == null) {
|
|
editorState = 2;
|
|
squarItUp();
|
|
}
|
|
});
|
|
|
|
|
|
//NUM1
|
|
mp.keys.bind(0x61, false, function () {
|
|
if (gzEdit && editorState == 1) {
|
|
editPoint = 1;
|
|
pointColors[0] = colorY;
|
|
}
|
|
});
|
|
|
|
//NUM2
|
|
mp.keys.bind(0x62, false, function () {
|
|
if (gzEdit && editorState == 1) {
|
|
editPoint = 2;
|
|
pointColors[1] = colorY;
|
|
}
|
|
});
|
|
|
|
//NUM3
|
|
mp.keys.bind(0x63, false, function () {
|
|
if (gzEdit && editorState == 1) {
|
|
editPoint = 3;
|
|
pointColors[2] = colorY;
|
|
}
|
|
});
|
|
|
|
//NUM4
|
|
mp.keys.bind(0x64, false, function () {
|
|
if (gzEdit && editorState == 1) {
|
|
editPoint = 4;
|
|
pointColors[3] = colorY;
|
|
}
|
|
});
|
|
|
|
//NUM7
|
|
mp.keys.bind(0x67, false, function () {
|
|
if (gzEdit && editorState == 2) {
|
|
|
|
}
|
|
});
|
|
|
|
|
|
//NUM9
|
|
mp.keys.bind(0x69, false, function () {
|
|
if (gzEdit && editorState == 2) {
|
|
|
|
}
|
|
});
|
|
|
|
|
|
function squarItUp() {
|
|
|
|
/* A B
|
|
*
|
|
* D C
|
|
*/
|
|
|
|
var A = gPoints[0];
|
|
var B = gPoints[1];
|
|
var C = gPoints[2];
|
|
var D = gPoints[3];
|
|
|
|
var distAB = A - B;
|
|
var distBC = B - C;
|
|
var distCD = C - D;
|
|
var distDA = D - A;
|
|
|
|
|
|
}
|
|
|
|
mp.events.add("render", () => {
|
|
if (gzEdit) {
|
|
if (pointCounter >= 0) { //Wenn Y-Spielhöhe definiert wurde
|
|
renderVisualHelp(); //Onscreen Texte
|
|
renderVisualWorld(); //RealWorld Geometrie
|
|
} else { //Ansonsten Spielhöhe definieren
|
|
renderGangzonePreSetup();
|
|
}
|
|
}
|
|
|
|
/*mp.game.graphics.drawText("GW-Edit DEBUG\n" +
|
|
"editorState: " + editorState + "\n" +
|
|
"pointCounter: " + pointCounter + "\n"
|
|
, [editVisualHelpX, 0.1],
|
|
{
|
|
font: 0,
|
|
color: [255, 255, 255, 255],
|
|
scale: [0.3, 0.3],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
*/
|
|
});
|
|
|
|
function renderVisualHelp() {
|
|
if (gzEdit == true) {
|
|
if (editorState == 0) {
|
|
//Visualisierungshilfe zum erstelln von Gangzonen
|
|
mp.game.graphics.drawText("Speicher bitte Punkt ~y~" + (pointCounter + 1) + "~s~ ab. Taste ~g~NUM-5", [editVisualHelpX, editVisualHelpY],
|
|
{
|
|
font: 0,
|
|
color: [255, 255, 255, 255],
|
|
scale: [0.3, 0.3],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawRect(editVisualHelpX, editVisualHelpY, helpScale * 2, helpScale * 2, 255, 255, 255, 150);
|
|
mp.game.graphics.drawText("1", [editVisualHelpX - helpScale, editVisualHelpY - helpScale - 0.025],
|
|
{
|
|
font: 0,
|
|
color: pointColors[0],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("2", [editVisualHelpX + helpScale, editVisualHelpY - helpScale - 0.025],
|
|
{
|
|
font: 0,
|
|
color: pointColors[1],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("3", [editVisualHelpX + helpScale, editVisualHelpY + helpScale],
|
|
{
|
|
font: 0,
|
|
color: pointColors[2],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("4", [editVisualHelpX - helpScale, editVisualHelpY + helpScale],
|
|
{
|
|
font: 0,
|
|
color: pointColors[3],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
} else if (editorState == 1) {
|
|
if (editPoint != null) {
|
|
mp.game.graphics.drawText("Welchen Eckpunkt möchtest du bearbeiten? Drücke ~g~NUM1-4\n"+
|
|
"~s~Oder drücke ~g~NUM-0 ~s~ für die Finalisierung", [editVisualHelpX, editVisualHelpY],
|
|
{
|
|
font: 0,
|
|
color: [255, 255, 255, 255],
|
|
scale: [0.3, 0.3],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
mp.game.graphics.drawRect(editVisualHelpX, editVisualHelpY, helpScale * 2, helpScale * 2, 255, 255, 255, 150);
|
|
mp.game.graphics.drawText("1", [editVisualHelpX - helpScale, editVisualHelpY - helpScale - 0.025],
|
|
{
|
|
font: 0,
|
|
color: pointColors[0],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("2", [editVisualHelpX + helpScale, editVisualHelpY - helpScale - 0.025],
|
|
{
|
|
font: 0,
|
|
color: pointColors[1],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("3", [editVisualHelpX + helpScale, editVisualHelpY + helpScale],
|
|
{
|
|
font: 0,
|
|
color: pointColors[2],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
|
|
mp.game.graphics.drawText("4", [editVisualHelpX - helpScale, editVisualHelpY + helpScale],
|
|
{
|
|
font: 0,
|
|
color: pointColors[3],
|
|
scale: [0.4, 0.4],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
} else {
|
|
mp.game.graphics.drawText("Du bearbeitest Eckpunkt ~y~" + editPoint + "~s~. Zum Speichern ~g~NUM-5", [editVisualHelpX, editVisualHelpY],
|
|
{
|
|
font: 0,
|
|
color: [255, 255, 255, 255],
|
|
scale: [0.3, 0.3],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function renderVisualWorld() {
|
|
var playerPosition = mp.players.local.position;
|
|
|
|
if (pointCounter >= 1 && pointCounter < 4) {
|
|
mp.game.graphics.drawLine(gPoints[pointCounter - 1].x, gPoints[pointCounter - 1].y, gangZoneMidHeight.z, playerPosition.x, playerPosition.y, playerPosition.z, 255, 0, 0, 200);
|
|
}
|
|
|
|
if (pointCounter > 1) mp.game.graphics.drawLine(gPoints[0].x, gPoints[0].y, gangZoneMidHeight.z, gPoints[1].x, gPoints[1].y, gangZoneMidHeight.z, 0, 255, 0, 200);
|
|
if (pointCounter > 2) mp.game.graphics.drawLine(gPoints[1].x, gPoints[1].y, gangZoneMidHeight.z, gPoints[2].x, gPoints[2].y, gangZoneMidHeight.z, 0, 255, 0, 200);
|
|
if (pointCounter > 3) {
|
|
mp.game.graphics.drawLine(gPoints[2].x, gPoints[2].y, gangZoneMidHeight.z, gPoints[3].x, gPoints[3].y, gangZoneMidHeight.z, 0, 255, 0, 200);
|
|
mp.game.graphics.drawLine(gPoints[3].x, gPoints[3].y, gangZoneMidHeight.z, gPoints[0].x, gPoints[0].y, gangZoneMidHeight.z, 0, 255, 0, 200);
|
|
}
|
|
|
|
if (editorState == 1 && editPoint != null) {
|
|
mp.game.graphics.drawLine(gPoints[editPoint - 1].x, gPoints[editPoint - 1].y, gangZoneMidHeight.z, playerPosition.x, playerPosition.y, playerPosition.z, 255, 0, 0, 200);
|
|
}
|
|
|
|
//QUADER
|
|
/*
|
|
if (pointCounter > 3) {
|
|
for (var x = 0; x < 4; x++) {
|
|
var newPoint = gPoints[0];
|
|
newPoint.z += 5.0;
|
|
gPoints.push(newPoint);
|
|
}
|
|
|
|
for (var v = 4; v < 8; v++) { //Verdrahtung horizontal
|
|
if (v < 7) {
|
|
mp.game.graphics.drawLine(gPoints[v].x, gPoints[v].y, gPoints[v].z, gPoints[v + 1].x, gPoints[v + 1].y, gPoints[v + 1].z, 0, 255, 0, 200);
|
|
} else {
|
|
mp.game.graphics.drawLine(gPoints[v].x, gPoints[v].y, gPoints[v].z, gPoints[4].x, gPoints[4].y, gPoints[4].z, 0, 255, 0, 200);
|
|
}
|
|
mp.game.graphics.drawLine(gPoints[v].x, gPoints[v].y, gPoints[v].z, gPoints[v-4].x, gPoints[v-4].y, gPoints[v-4].z, 0, 255, 0, 200); //Verdrahtung Vertikal
|
|
}
|
|
}*/
|
|
}
|
|
|
|
function renderGangzonePreSetup() {
|
|
mp.game.graphics.drawText("Stelle dich ungefähr in die Mitte der Gangzone um die Z-Koordinatenhöhe zu berechnen und drücke ~y~NUM5", [editVisualHelpX, editVisualHelpY - 0.05],
|
|
{
|
|
font: 0,
|
|
color: [255,255,255,255],
|
|
scale: [0.3, 0.3],
|
|
outline: true,
|
|
centre: false
|
|
});
|
|
} |