Rewrite Inventory-System
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
|
||||
|
||||
body {
|
||||
width: 50%;
|
||||
position: center;
|
||||
margin: 5% auto auto 25%;
|
||||
}
|
||||
|
||||
.inventory-table {
|
||||
background-color: darkgray;
|
||||
position: absolute;
|
||||
padding: 2%;
|
||||
}
|
||||
|
||||
.inventory-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start; /* align items in Main Axis */
|
||||
align-items: flex-start; /* align items in Cross Axis */
|
||||
align-content: flex-start; /* Extra space in Cross Axis */
|
||||
}
|
||||
.inventory-item.axe1 {
|
||||
background-position: -170px -340px;
|
||||
}
|
||||
|
||||
.inventory-cell {
|
||||
width: 160px;
|
||||
height: 160px;
|
||||
background-color: dimgray;
|
||||
border: solid;
|
||||
border-color: darkorange;
|
||||
border-width: 1px;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.inventory-slot {
|
||||
font-family: Pricedown;
|
||||
color: white;
|
||||
background-color: black;
|
||||
padding: 2px;
|
||||
font-size: 25px;
|
||||
vertical-align: top;
|
||||
width: 20%;
|
||||
text-align: center;
|
||||
text-shadow: 2px 2px 3px orange;
|
||||
|
||||
}
|
||||
.inventory-item {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: red;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
|
||||
pointer-events: visible;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="inventory-style.css" />
|
||||
<!--<script src="Inventory/inventory.js"></script>-->
|
||||
<script src="jquery-3.3.1.min.js"></script>
|
||||
<script>
|
||||
function allowDrop(ev) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
function drag(ev) {
|
||||
ev.dataTransfer.setData("text", ev.target.id);
|
||||
}
|
||||
|
||||
function drop(ev) {
|
||||
ev.preventDefault();
|
||||
var data = ev.dataTransfer.getData("text");
|
||||
ev.target.appendChild(document.getElementById(data));
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="inventory-table" id="personal-inventory">
|
||||
<div class="inventory-row">
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot0">
|
||||
<div class="inventory-slot">1</div>
|
||||
<div class="inventory-item" draggable="true" ondragstart="drag(event)" id="item1">Hamburger</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot1">
|
||||
<div class="inventory-slot">2</div>
|
||||
<div class="inventory-item" draggable="true" ondragstart="drag(event)" id="item2" style="background-color:yellow;">Cheeseburger</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot2">
|
||||
<div class="inventory-slot">3</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot3">
|
||||
<div class="inventory-slot">4</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot4">
|
||||
<div class="inventory-slot">5</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inventory-row">
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot5">
|
||||
<div class="inventory-slot">6</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot6">
|
||||
<div class="inventory-slot">7</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot7">
|
||||
<div class="inventory-slot">8</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot8">
|
||||
<div class="inventory-slot">9</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot9">
|
||||
<div class="inventory-slot">10</div>
|
||||
<div class="inventory-item" draggable="true" ondragstart="drag(event)" id="item3" style="background-color:green;">Chickenburger</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inventory-row">
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot10">
|
||||
<div class="inventory-slot">11</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot11">
|
||||
<div class="inventory-slot">12</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot12">
|
||||
<div class="inventory-slot">13</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot13">
|
||||
<div class="inventory-slot">14</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot14">
|
||||
<div class="inventory-slot">15</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inventory-row">
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot15">
|
||||
<div class="inventory-slot">16</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot16">
|
||||
<div class="inventory-slot">17</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot17">
|
||||
<div class="inventory-slot">18</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot18">
|
||||
<div class="inventory-slot">19</div>
|
||||
</div>
|
||||
<div class="inventory-cell" ondrop="drop(event)" ondragover="allowDrop(event)" id="slot19">
|
||||
<div class="inventory-slot">20</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,15 +1,101 @@
|
||||
var inventoryBrowser;
|
||||
var show = false;
|
||||
var trading = false;
|
||||
let screenRes = mp.game.graphics.getScreenResolution(0, 0);
|
||||
let rxC = 0.5;
|
||||
let ryC = 0.5;
|
||||
let rWidth = 0.4;
|
||||
let sX = (screenRes.X * 0.1 / 1000);
|
||||
let sY = (screenRes.Y * 0.1 / 1000);
|
||||
let eX = sX - 0.1;
|
||||
let eY = sY - 0.1;
|
||||
let sizeMul = 0.08;
|
||||
let yMul = 1.8
|
||||
|
||||
mp.events.add("showInventory", (show) => {
|
||||
if (show === true) {
|
||||
inventoryBrowser = mp.browsers.new('package://Gui/Inventory/inventory.html');
|
||||
mp.gui.chat.activate(false);
|
||||
mp.gui.cursor.show(true, true);
|
||||
} else {
|
||||
if (inventoryBrowser) {
|
||||
inventoryBrowser.destroy();
|
||||
mp.gui.chat.activate(true);
|
||||
mp.gui.cursor.show(false, false);
|
||||
var inventoryWeight;
|
||||
var items = [[]];
|
||||
|
||||
var slots = [20];
|
||||
|
||||
for (var s = 1; s <= slots.length; s++) {
|
||||
for (var slY = 0.35; slY <= 0.8; slY += 0.15) {
|
||||
for (var slX = 0.3775; slX <= 0.6655; slX += 0.082) {
|
||||
items[s] = { slX, slY };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
} 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;
|
||||
mp.game.graphics.drawText("~r~X: " + pos[0] + " ~g~Y: " + pos[1], [0.5, 0.01], {
|
||||
font: 2,
|
||||
color: [255, 255, 255, 185],
|
||||
scale: [1, 1],
|
||||
outline: true,
|
||||
});
|
||||
|
||||
mp.game.graphics.drawRect(rxC, ryC, 0.45, 0.7, 255, 255, 255, 200); //Hintergrundbox
|
||||
|
||||
|
||||
|
||||
for (var y = ryC - (rWidth / 2) + 0.005; y < ryC + (rWidth / 2) * yMul + 0.01; y = y + sizeMul * yMul + 0.006) {
|
||||
for (var x = rxC - (rWidth / 2) + 0.0375; x < rxC + (rWidth / 2) + 0.01; x = x + sizeMul + 0.002) {
|
||||
|
||||
|
||||
mp.game.graphics.drawRect(x, y, sizeMul, sizeMul * yMul, 112, 128, 144, 254);
|
||||
mp.game.graphics.drawText(slot, [x - (sizeMul / 2) + 0.006, y - (sizeMul / 2) * yMul], {
|
||||
font: 7,
|
||||
color: [255, 69, 0, 254],
|
||||
scale: [0.3, 0.3],
|
||||
outline: true,
|
||||
});
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
//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();
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
mp.game.graphics.drawSprite("rp", "Mprpsymbol", slot[items[i][4]][0], slot[items[i][4]][1], rWidth - 0.1, rWidth - 0.1, 0, 255, 255, 255, 125);
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
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.");
|
||||
});
|
||||
2
Client/Gui/Inventory/jquery-3.3.1.min.js
vendored
2
Client/Gui/Inventory/jquery-3.3.1.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -52,13 +52,7 @@ mp.keys.bind(0x49, false, function () {
|
||||
|
||||
//J
|
||||
mp.keys.bind(0x4A, false, function () {
|
||||
if (showInventory === false) {
|
||||
mp.events.call("showInventory", true);
|
||||
showInventory = true;
|
||||
} else {
|
||||
mp.events.call("showInventory", false);
|
||||
showInventory = false;
|
||||
}
|
||||
mp.events.callRemote("keyPress:J");
|
||||
});
|
||||
|
||||
//K //Dienstkleidung
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace reallife_gamemode.Server.Entities
|
||||
public int UserId { get; set; }
|
||||
public User User { get; set; }
|
||||
|
||||
public float Amount { get; set; }
|
||||
|
||||
public int Amount { get; set; }
|
||||
public int Slot { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using Newtonsoft.Json;
|
||||
using reallife_gamemode.Model;
|
||||
using reallife_gamemode.Server.Entities;
|
||||
using reallife_gamemode.Server.Extensions;
|
||||
using reallife_gamemode.Server.Inventory.Interfaces;
|
||||
using reallife_gamemode.Server.Managers;
|
||||
using reallife_gamemode.Server.Saves;
|
||||
using reallife_gamemode.Server.Services;
|
||||
@@ -113,6 +114,31 @@ namespace reallife_gamemode.Server.Events
|
||||
}
|
||||
player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers));
|
||||
}
|
||||
[RemoteEvent("keyPress:J")]
|
||||
public void KeyPressJ(Client player)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
var inventoryWeight = 0;
|
||||
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
List<UserItem> userItems = context.UserItems.ToList().FindAll(i => i.UserId == user.Id);
|
||||
string[][] items = new string[userItems.Count][];
|
||||
foreach (var item in userItems)
|
||||
{
|
||||
IItem iItem = InventoryManager.GetItemById(item.ItemId);
|
||||
var currentItemWeight = iItem.Gewicht * item.Amount;
|
||||
inventoryWeight += currentItemWeight;
|
||||
|
||||
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();
|
||||
}
|
||||
player.TriggerEvent("showInventory", inventoryWeight, items);
|
||||
}
|
||||
}
|
||||
[RemoteEvent("keyPress:K")]
|
||||
public void KeyPressK(Client player)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user