Skip to content

Commit

Permalink
Many fixes and additions, see description
Browse files Browse the repository at this point in the history
-Inventory system almost done
-Market for buying randomly generated houses
-Refined jobs system
-Refined factions system in preparation for adding factions such as police
-Started working on item shops
  • Loading branch information
Samuli Lehtonen committed Jan 5, 2018
1 parent d3066c9 commit 299e774
Show file tree
Hide file tree
Showing 32 changed files with 1,294 additions and 1,049 deletions.
64 changes: 54 additions & 10 deletions Client/HUDManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class House {
}
}

class Item {
constructor(id, name, amount, description) {
this.id = id;
this.name = name;
this.amount = amount;
this.description = description;
}
}

class HUDManager
{
constructor() {
Expand Down Expand Up @@ -69,6 +78,9 @@ class HUDManager
this.ownedHouseIds = null;
this.houses = [];

// Item menu values
this.items = [];

// help values
this.screenResolution = null;
this.selectedTextMessageIndex = null;
Expand All @@ -94,7 +106,7 @@ class HUDManager
switch (eventName)
{
case 'EVENT_INIT_HUD':
this.initHUD(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19]);
this.initHUD(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15], args[16], args[17], args[18], args[19], args[20], args[21], args[22], args[23]);
break;

case 'EVENT_UPDATE_MONEY':
Expand Down Expand Up @@ -140,6 +152,10 @@ class HUDManager
case 'EVENT_UPDATE_JOB':
this.setEmployment(args[0], args[1], args[2], args[3]);
break;

case 'EVENT_CREATE_TIMER_BAR':
this.createTimerBar(args[0], args[1]);
break;
}
}

Expand All @@ -160,6 +176,10 @@ class HUDManager

}

createTimerBar(text, time) {
var myBar = API.createBarTimerBar("test");
}

receivePhoneCall(number) {
this.createPhoneCallMenu(number, false);
}
Expand Down Expand Up @@ -218,6 +238,12 @@ class HUDManager
}
}

initItems(ids, names, counts, descriptions) {
for (var i = 0; i < names.Count; i++) {
this.items.push(new Item(ids[i], names[i], counts[i], descriptions[i]));
}
}

initVehicles(ids, licensePlates, spawneds)
{
for (var i = 0; i < ids.Count; i++) {
Expand All @@ -227,12 +253,13 @@ class HUDManager

initHouses(ids, names)
{
this.houses = [];
for (var i = 0; i < ids.Count; i++) {
this.houses.push(new House(ids[i], names[i]));
}
}

initHUD(employment, r1, g1, b1, faction, r2, g2, b2, money, name, phoneNumber, textMessageIds, textMessageSenders, textMessageTimes, textMessages, contactNames, contactNumbers, vehicleIds, licensePlates, vehicleSpawneds)
initHUD(employment, r1, g1, b1, faction, r2, g2, b2, money, name, phoneNumber, textMessageIds, textMessageSenders, textMessageTimes, textMessages, contactNames, contactNumbers, vehicleIds, licensePlates, vehicleSpawneds, itemIds, itemNames, itemCounts, itemDescriptions)
{
this.hudActive = true;
this.characterName = name;
Expand All @@ -243,6 +270,7 @@ class HUDManager
this.initTextMessages(textMessageIds, textMessageSenders, textMessageTimes, textMessages);
this.initContacts(contactNames, contactNumbers);
this.initVehicles(vehicleIds, licensePlates, vehicleSpawneds);
this.initItems(itemIds, itemNames, itemCounts, itemDescriptions);
}

draw()
Expand All @@ -253,14 +281,10 @@ class HUDManager
this.screenResolution = API.getScreenResolutionMaintainRatio();
}

let xPos = this.screenResolution.Width * 0.145;
let yPos = this.screenResolution.Height * 0.82;
let xPos = this.screenResolution.Width * 0.164;
let yPos = this.screenResolution.Height * 0.809;
let increment = yPos * 0.036;

/*let xPos = 278.4;
let yPos = 885.6;
let increment = yPos * 0.036;*/

API.drawText(this.characterName, xPos, yPos, 0.8, 255, 255, 255, 255, 1, 0, true, true, 1000);
API.drawText(this.factionText, xPos, yPos + increment * 2.3, 0.65, this.factionTextColorR, this.factionTextColorG, this.factionTextColorB, 255, 6, 0, false, true, 1000);
API.drawText(this.employmentText, xPos, yPos + increment * 3.4, 0.65, this.employmentTextColorR, this.employmentTextColorG, this.employmentTextColorB, 255, 6, 0, false, true, 1000);
Expand Down Expand Up @@ -294,6 +318,24 @@ class HUDManager
}
}

useItem(id) {
API.triggerServerEvent("EVENT_TRY_USE_ITEM", id);
}

createItemsMenu() {
let menu = API.createMenu("Player Menu", "Inventory", 0, 0, 6);
for (var i = 0; i < this.items.length; i++) {
let item = API.createMenuItem(this.items[i].name, this.items[i].description);
item.SetRightLabel(this.items[i].amount.toString());
let val = this.items[i].id;
item.Activated.connect(() => this.useItem(val));
menu.AddItem(item);
}
return menu;
}



createHouseMenu()
{
let menu = API.createMenu("Player Menu", "Houses", 0, 0, 6);
Expand Down Expand Up @@ -365,8 +407,8 @@ class HUDManager
item3.Activated.connect((menu, sender) => this.lockVehicle(menu, sender));
item4.Activated.connect((menu, sender) => this.buyParkSpot(menu, sender));

menu.AddItem(item1);
menu.AddItem(item2);
menu.AddItem(item1);
menu.AddItem(item3);
menu.AddItem(item4);
return menu;
Expand Down Expand Up @@ -719,7 +761,7 @@ class HUDManager
menu.OnMenuChange.connect((sender, next, forward) => this.menuChanged(sender, next, forward));
menu.OnMenuClose.connect((sender) => this.menuClosed(sender));

let item = API.createMenuItem("Inventory (Not yet implemented)", "");
let item = API.createMenuItem("Inventory", "");
let item2 = API.createMenuItem("Vehicles", "");
if (this.vehicles.length == 0) {
item2.Enabled = false;
Expand Down Expand Up @@ -747,12 +789,14 @@ class HUDManager
var menu2 = this.createActionsMenu();
var menu4 = this.createVehicleMenu();
var menu3 = this.createPhoneMenu();
var inventoryMenu = this.createItemsMenu();


menu.BindMenuToItem(menu1, item3);
menu.BindMenuToItem(menu2, item4);
menu.BindMenuToItem(menu3, item5);
menu.BindMenuToItem(menu4, item2);
menu.BindMenuToItem(inventoryMenu, item);

menu.Visible = true;
}
Expand Down
91 changes: 91 additions & 0 deletions Client/HouseMarketManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
class HouseForSale {
constructor(id, name, price, seller, buildingName) {
this.id = id;
this.name = name;
this.price = price;
this.seller = seller;
this.buildingName = buildingName;
}
}


class HouseMarketManager {
constructor() {
this.housesForSale = [];
}

initializeHouses(houseIds, houseNames, housePrices, houseSellers, houseBuildingNames) {
this.housesForSale = [];
for (var i = 0; i < houseIds.Count; i++) {
this.housesForSale.push(new HouseForSale(houseIds[i], houseNames[i], housePrices[i], houseSellers[i], houseBuildingNames[i]));
}
}

closeHouseMenu() {
API.closeAllMenus();
}

showHouseBuySellSelectMenu(houseIds, houseNames, housePrices, houseSellers, houseBuildingNames) {
API.closeAllMenus();
this.initializeHouses(houseIds, houseNames, housePrices, houseSellers, houseBuildingNames);

let menu = API.createMenu("LS Properties", "Options", 0, 0, 6);
let item1 = API.createMenuItem("Buy properties", "");
let item2 = API.createMenuItem("Sell properties", "");

menu.BindMenuToItem(this.getMarketMenu(), item1);

menu.AddItem(item1);
menu.AddItem(item2);

menu.Visible = true;

}

getUserInputForHouseName(menu, item) {
var name = API.getUserInput("", 20);
item.Text = "Name: " + name;
}

tryBuyPropertyWithId(id, name) {
API.triggerServerEvent("EVENT_TRY_BUY_PROPERTY", id, name);
}

getBuyHouseDetailMenu(id, name, price, seller, buildingName) {
let menu = API.createMenu("LS Properties", "Building: " + buildingName, 0, 0, 6);
let item1 = API.createMenuItem("Seller: " + seller, "");
let item2 = API.createMenuItem("Price: $" + price.toString(), "");
let item5 = API.createMenuItem("Name: " + name, "Press to rename house");
let item4 = API.createColoredItem("Buy property", "", "#53a828", "#69d831");
item4.Activated.connect(() => this.tryBuyPropertyWithId(id, item5.Text.substring(6)));
item5.Activated.connect(() => this.getUserInputForHouseName(menu, item5));
menu.AddItem(item1);
menu.AddItem(item2);
menu.AddItem(item5);
menu.AddItem(item4);
return menu;
}

getMarketMenu() {
let menu = API.createMenu("LS Properties", "Properties for sale", 0, 0, 6);
for (var i = 0; i < this.housesForSale.length; i++) {
let item = API.createMenuItem(this.housesForSale[i].name, "Seller: " + this.housesForSale[i].seller);
item.SetRightLabel("$ " + this.housesForSale[i].price.toString());
menu.AddItem(item);
menu.BindMenuToItem(this.getBuyHouseDetailMenu(this.housesForSale[i].id, this.housesForSale[i].name, this.housesForSale[i].price, this.housesForSale[i].seller, this.housesForSale[i].buildingName), item);
}
return menu;
}

handleHouseMarketEvent(eventName, args) {
if (eventName == "EVENT_OPEN_HOUSE_MARKET_MENU") {
this.showHouseBuySellSelectMenu(args[0], args[1], args[2], args[3], args[4]);
}
else if (eventName == "EVENT_CLOSE_HOUSE_MARKET_MENU") {
this.closeHouseMenu();
}
}
}

let houseMarketManager = new HouseMarketManager();
API.onServerEventTrigger.connect((eventName, args) => houseMarketManager.handleHouseMarketEvent(eventName, args));
57 changes: 57 additions & 0 deletions Client/ItemShopManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class ItemForSale {
constructor(id, name, description, amount, price) {
this.id = id;
this.name = name;
this.description = description;
this.amount = amount;
this.price = price;
}
}

class ItemShopManager {
constructor() {
this.itemsForSale = [];
}

handleItemShopEvent(eventName, args) {
if (eventName == "EVENT_OPEN_ITEM_SHOP_MENU") {
this.initializeItems(args[0], args[1], args[2], args[3], args[4]);
this.createShopMenu();
}
}

initializeItems(ids, names, descriptions, amounts, prices) {
for (var i = 0; i < ids.Count; i++) {
this.itemsForSale.push(new ItemForSale(ids[i], names[i], descriptions[i], amounts[i], prices[i]));
}
}

createShopMenu() {
let menu = API.createMenu("247 Supermarket", "Options", 0, 0, 6);
let item1 = API.createMenuItem("Buy items", "");
let item2 = API.createMenuItem("Sell items", "");

menu.BindMenuToItem(this.createShopBuyMenu(), item1);

menu.AddItem(item1);
menu.AddItem(item2);
menu.Visible = true;
}

createShopBuyMenu() {
let menu = API.createMenu("247 Supermarket", "Items on sale", 0, 0, 6);
for (var i = 0; i < this.itemsForSale.length; i++) {
let item = API.createMenuItem(this.itemsForSale[i].name, this.itemsForSale[i].description);
item.SetRightLabel("$" + this.itemsForSale[i].price.toString());
menu.AddItem(item);
}
return menu;
}

createShopSellMenu() {

}
}

let itemShopManager = new ItemShopManager();
API.onServerEventTrigger.connect((eventName, args) => itemShopManager.handleItemShopEvent(eventName, args));
4 changes: 2 additions & 2 deletions Client/JobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
this.createTakeJobMenu(args[0], args[1], args[2], args[3]);
}
else if (eventName == "EVENT_CLOSE_TAKE_JOB_MENU") {
if (this.jobMenu != null) this.jobMenu.Visible = false;
if (this.jobMenu != null) this.closeJobMenu();
}
}

Expand All @@ -24,7 +24,7 @@
let item3 = API.createMenuItem("Salary: " + salary, description);

item2.Activated.connect((menu, sender) => this.closeJobMenu());
item3.Activated.connect((menu, sender) => this.acceptJob());
item1.Activated.connect((menu, sender) => this.acceptJob());

menu.AddItem(item3);
menu.AddItem(item1);
Expand Down

0 comments on commit 299e774

Please sign in to comment.