Files
reallife-gamemode/Client/Gui/Inventory/inventory.js
2018-12-04 22:09:43 +01:00

183 lines
6.0 KiB
JavaScript

var show = false;
var trading = false;
const { x: screenX, y: screenY } = mp.game.graphics.getScreenActiveResolution(0, 0);
let rxC = 0.5;
let ryC = 0.5;
let rWidth = 0.4;
let sX = (screenX * 0.1 / 1000);
let sY = (screenY * 0.1 / 1000);
let eX = sX - 0.1;
let eY = sY - 0.1;
let sizeMul = 0.08;
let yMul = 1.8;
var hoverItem;
var inventoryWeight;
var items = [[]];
var grid = [];
grid[0] = [0.3375, 0.305]
grid[1] = [0.4195, 0.305]
grid[2] = [0.5015, 0.305]
grid[3] = [0.5835, 0.305]
grid[4] = [0.6655, 0.305]
grid[5] = [0.3375, 0.455]
grid[6] = [0.4195, 0.455]
grid[7] = [0.5015, 0.455]
grid[8] = [0.5835, 0.455]
grid[9] = [0.6655, 0.455]
grid[10] = [0.3375, 0.605]
grid[11] = [0.4195, 0.605]
grid[12] = [0.5015, 0.605]
grid[13] = [0.5835, 0.605]
grid[14] = [0.6655, 0.605]
grid[15] = [0.3375, 0.755]
grid[16] = [0.4195, 0.755]
grid[17] = [0.5015, 0.755]
grid[18] = [0.5835, 0.755]
grid[19] = [0.6655, 0.755]
mp.events.add("showInventory", (invWeight, itemArr) => {
if (show === false) {
mp.gui.chat.activate(false);
mp.gui.cursor.show(true, true);
inventoryWeight = invWeight;
items = itemArr;
show = true;
mp.game.graphics.requestStreamedTextureDict("Mprpsymbol", true);
} else {
mp.gui.chat.activate(true);
mp.gui.cursor.show(false, false);
show = false;
}
});
mp.events.add("render", () => {
if (show === true) {
var pos = mp.gui.cursor.position;
//DEBUG 2D-SCREEN-KOORDINATEN
mp.game.graphics.drawText("~r~X: " + pos[0] + " ~g~Y: " + pos[1] + "~s~ ---~b~" + parseFloat(pos[0] / screenX).toFixed(3) + " ~y~" + parseFloat(pos[1] / screenY).toFixed(3), [pos[0] / screenX, (pos[1] / screenY) - 0.02], {
font: 0,
color: [255, 255, 255, 185],
scale: [0.25, 0.25],
outline: true,
});
//INVENTARHINTERGRUND
mp.game.graphics.drawRect(rxC, ryC, 0.45, 0.7, 255, 255, 255, 200);
//INVENTARÜBERSCHRIFT
mp.game.graphics.drawText("Inventar ~g~(" + inventoryWeight + "/40000g)", [rxC, ryC - (rWidth / 1.20)], {
font: 7,
color: [112, 128, 144, 254],
scale: [0.7, 0.7],
outline: true,
});
//SLOTS [RECHTECKE] [SLOTZAHLEN]
var tempSlot;
for (var slots = 0; slots < grid.length; slots++) {
mp.game.graphics.drawRect(grid[slots][0], grid[slots][1], sizeMul, sizeMul * yMul, 112, 128, 144, 254);
mp.game.graphics.drawText(tempSlot = slots + 1, [grid[slots][0] - (sizeMul / 2) + 0.006, grid[slots][1] - (sizeMul / 2 * yMul)], {
font: 7,
color: [255, 69, 0, 254],
scale: [0.3, 0.3],
outline: true,
});
}
//SPRITES
for (var currentItem = 0; currentItem < items.length; currentItem++) {
mp.game.graphics.drawSprite("Mprpsymbol", "rp", grid[parseInt(items[currentItem][4] - 1)][0], grid[parseInt(items[currentItem][4] - 1)][1], rWidth / 8, rWidth / 5, 0, 255, 255, 255, 255);
}
//isMouseOverItem(pos[0], pos[1]);
//WENN MAUS ÜBER ITEM
if (isMouseOverItem(pos[0], pos[1])) {
mp.game.graphics.drawRect(pos[0] / screenX, pos[1] / screenY + 0.055, 0.16, 0.08, 0, 0, 0, 220);
var hoverItemP = [items[hoverItem][0], items[hoverItem][1], items[hoverItem][2], items[hoverItem][3]];
//NAME
mp.game.graphics.drawText("~g~" + hoverItemP[0], [pos[0] / screenX, pos[1] / screenY + 0.02], {
font: 4,
color: [255, 255, 255, 255],
scale: [0.4, 0.4],
outline: true,
});
//BESCHREIBUNG
mp.game.graphics.drawText("~y~Beschreibung: ~s~" + hoverItemP[1], [pos[0] / screenX, pos[1] / screenY + 0.04], {
font: 4,
color: [255, 255, 255, 255],
scale: [0.35, 0.35],
outline: true,
});
//EINZELGEWICHT
mp.game.graphics.drawText("~y~Einzelgewicht: ~s~" + hoverItemP[2] + "g", [pos[0] / screenX, pos[1] / screenY + 0.06], {
font: 4,
color: [255, 255, 255, 255],
scale: [0.35, 0.35],
outline: true,
});
}
//items[userItems.IndexOf(item)][0] = iItem.Name;
//items[userItems.IndexOf(item)][1] = iItem.Description;
//items[userItems.IndexOf(item)][2] = iItem.Gewicht.ToString();
//items[userItems.IndexOf(item)][3] = item.Amount.ToString();
//items[userItems.IndexOf(item)][4] = item.Slot.ToString();
}
});
function isMouseOverItem(cX, cY) {
var x = cX / screenX;
var y = cY / screenY;
var a;
var b;
var c;
for (var s = 0; s < 20; s++) {
a = grid[s][0] - x;
b = grid[s][1] - y;
c = Math.sqrt(a * a + b * b);
var invSlot = (s + 1);
if (c < sizeMul / 2) {
for (i = 0; i < items.length; i++) {
if (parseInt(items[i][4]) === invSlot) {
hoverItem = i;
return true;
}
}
}
}
}
//items[userItems.IndexOf(item)] = new string[5];
//items[userItems.IndexOf(item)][0] = iItem.Name;
//items[userItems.IndexOf(item)][1] = iItem.Description;
//items[userItems.IndexOf(item)][2] = iItem.Gewicht.ToString();
//items[userItems.IndexOf(item)][3] = item.Amount.ToString();
//items[userItems.IndexOf(item)][4] = item.Slot.ToString();
mp.events.add('click', (x, y, upOrDown, leftOrRight, relativeX, relativeY, worldPosition, hitEntity) => {
//mp.gui.chat.push("Mouse X:" + x + " | Mouse Y:" + y); // Displays mouse position on click.
//if (upOrDown == "up")
// mp.gui.chat.push("Mouse Clicked Up with " + leftOrRight + " button.");
//if (upOrDown == "down")
// mp.gui.chat.push("Mouse Clicked Down with " + leftOrRight + " button.");
});