From 10461e8ba468cf400d83e1eaff3857552f3fcd75 Mon Sep 17 00:00:00 2001 From: zaCade Date: Sat, 9 Mar 2019 13:44:42 +0100 Subject: [PATCH] ZMarket: Rework display name system, it applies to all menus now. --- src/zr/weapons/menu_weapons.inc | 2 +- src/zr/weapons/weapons.inc | 19 ++++++++++++++++--- src/zr/weapons/zmarket.inc | 18 +++++------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/zr/weapons/menu_weapons.inc b/src/zr/weapons/menu_weapons.inc index babc1bc..e816382 100644 --- a/src/zr/weapons/menu_weapons.inc +++ b/src/zr/weapons/menu_weapons.inc @@ -239,7 +239,7 @@ WeaponsMenuTypeWeapons(client) new weaponindex = GetArrayCell(arrayTypeWeapons, x); // Get name of weapon. - WeaponsGetName(weaponindex, typeweapon, sizeof(typeweapon)); + WeaponsGetName(weaponindex, typeweapon, sizeof(typeweapon), true); strcopy(display, sizeof(display), typeweapon); if (RestrictIsWeaponRestricted(weaponindex)) diff --git a/src/zr/weapons/weapons.inc b/src/zr/weapons/weapons.inc index 241a5f7..6bbd6a3 100644 --- a/src/zr/weapons/weapons.inc +++ b/src/zr/weapons/weapons.inc @@ -471,7 +471,7 @@ stock WeaponsEntityToDisplay(const String:entityname[], String:display[], displa } // The entity names match, so return display. - WeaponsGetName(x, display, displaymaxlen); + WeaponsGetName(x, display, displaymaxlen, true); // Return the weapon index. return x; @@ -497,13 +497,26 @@ stock bool:WeaponsIsWeaponValid(const String:weapon[]) * @param weapon The string to return name in. * @param maxlen The max length of the string. */ -stock WeaponsGetName(index, String:weapon[], maxlen) +stock WeaponsGetName(index, String:weapon[], maxlen, bool zmarket = false) { // Get array handle of weapon at given index. new Handle:arrayWeapon = GetArrayCell(arrayWeapons, index); + new String:weaponName[WEAPONS_MAX_LENGTH]; + new String:marketName[WEAPONS_MAX_LENGTH]; + // Get weapon name. - GetArrayString(arrayWeapon, _:WEAPONS_DATA_NAME, weapon, maxlen); + GetArrayString(arrayWeapon, _:WEAPONS_DATA_NAME, weaponName, maxlen); + + // Get weapon zmarket name. + if (zmarket) + GetArrayString(arrayWeapon, _:WEAPONS_DATA_ZMARKETNAME, marketName, maxlen); + + // Are we in zmarket, and is our name valid? + if (zmarket && strlen(marketName)) + strcopy(weapon, maxlen, marketName); + else + strcopy(weapon, maxlen, weaponName); } /** diff --git a/src/zr/weapons/zmarket.inc b/src/zr/weapons/zmarket.inc index 77633a6..6a86257 100644 --- a/src/zr/weapons/zmarket.inc +++ b/src/zr/weapons/zmarket.inc @@ -610,7 +610,7 @@ ZMarketMenuLoadoutWeapons(client, WeaponsSlot:slot) if(wslot != slot) continue; - WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); + WeaponsGetName(weaponindex, weaponname, sizeof(weaponname), true); // Get restricted status on the weapon. new bool:restricted = RestrictIsWeaponRestricted(weaponindex); @@ -787,7 +787,6 @@ ZMarketMenuTypeWeapons(client) decl String:typeweapon[WEAPONS_MAX_LENGTH]; decl String:typeweapondisplay[MENU_LINE_REG_LENGTH]; decl String:typeweaponentity[WEAPONS_MAX_LENGTH]; - decl String:displayname[MENU_LINE_REG_LENGTH]; decl String:display[MENU_LINE_BIG_LENGTH]; // Get an array populated with all weapons of the given type. @@ -803,18 +802,11 @@ ZMarketMenuTypeWeapons(client) new weaponindex = GetArrayCell(arrayTypeWeapons, x); // Get name of weapon. - WeaponsGetName(weaponindex, typeweapon, sizeof(typeweapon)); + WeaponsGetName(weaponindex, typeweapon, sizeof(typeweapon), true); // Get entity name of weapon. WeaponsGetEntity(weaponindex, typeweaponentity, sizeof(typeweaponentity)); - // Get display name of weapon. - WeaponsGetZMarketName(weaponindex, displayname, sizeof(displayname)); - - // Use display name if set, use name otherwise. - if (!strlen(displayname)) - strcopy(displayname, sizeof(displayname), typeweapon); - // Check if client is buying the weapon or ammo for it, and get the price of the item. new bool:hasweapon = WeaponsClientHasWeapon(client, typeweaponentity); @@ -835,7 +827,7 @@ ZMarketMenuTypeWeapons(client) itemprice = WeaponsGetAmmoPrice(weaponindex); // Tell client they are buying ammo. - Format(typeweapondisplay, sizeof(typeweapondisplay), "%s %t", displayname, "Weapons menu zmarket types weapon ammo"); + Format(typeweapondisplay, sizeof(typeweapondisplay), "%s %t", typeweapon, "Weapons menu zmarket types weapon ammo"); } // If the itemprice is invalid, then set to known integer to be later replaced. @@ -850,10 +842,10 @@ ZMarketMenuTypeWeapons(client) new bool:restricted = RestrictIsWeaponRestricted(weaponindex); // If weapon is restricted then format "[]" around it. - strcopy(typeweapondisplay, sizeof(typeweapondisplay), displayname); + strcopy(typeweapondisplay, sizeof(typeweapondisplay), typeweapon); if (restricted) { - Format(typeweapondisplay, sizeof(typeweapondisplay), "[%s]", displayname); + Format(typeweapondisplay, sizeof(typeweapondisplay), "[%s]", typeweapon); } // DO PURCHASE MAX STUFF HERE.