Skip to content

Commit

Permalink
Add support for localized item names (#20)
Browse files Browse the repository at this point in the history
Adds a new item config section `localized_name` which provides language-specific item names.

Co-authored-by: nosoop <[email protected]>
  • Loading branch information
ShadowMario and nosoop authored May 4, 2021
1 parent ced68e9 commit 7a4df57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions scripting/cwx/item_config.sp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum struct CustomItemDefinition {

int defindex;
char displayName[128];
KeyValues localizedNames;
char className[128];
int loadoutPosition[NUM_PLAYER_CLASSES];

Expand All @@ -29,6 +30,7 @@ enum struct CustomItemDefinition {
delete this.source;
delete this.nativeAttributes;
delete this.customAttributes;
delete this.localizedNames;
}
}

Expand Down Expand Up @@ -197,6 +199,12 @@ bool CreateItemFromSection(KeyValues config) {
config.GoBack();
}

if (config.JumpToKey("localized_name")) {
item.localizedNames = new KeyValues("localized_name");
item.localizedNames.Import(config);
config.GoBack();
}

g_CustomItems.SetArray(uid, item, sizeof(item));
return true;
}
Expand Down
14 changes: 13 additions & 1 deletion scripting/cwx/loadout_radio_menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ static int OnEquipMenuEvent(Menu menu, MenuAction action, int param1, int param2
int client = param1;
int position = param2;

// TODO: support localization of item names
char uid[MAX_ITEM_IDENTIFIER_LENGTH], itemName[MAX_ITEM_NAME_LENGTH];
menu.GetItem(position, uid, sizeof(uid), _, itemName, sizeof(itemName));

CustomItemDefinition item;
GetCustomItemDefinition(uid, item);

int menuClass = g_iPlayerClassInMenu[client];
int menuSlot = g_iPlayerSlotInMenu[client];

Expand All @@ -354,6 +356,16 @@ static int OnEquipMenuEvent(Menu menu, MenuAction action, int param1, int param2
if (!uid[0]) {
FormatEx(itemName, sizeof(itemName), "%t", "UnequipCustomItem");
redraw = true;
} else if (item.localizedNames) {
// attempt to look up a localized name based on shortcode
char langcode[16], localizedName[MAX_ITEM_NAME_LENGTH];
GetLanguageInfo(GetClientLanguage(client), langcode, sizeof(langcode));

item.localizedNames.GetString(langcode, localizedName, sizeof(localizedName));
if (localizedName[0]) {
strcopy(itemName, sizeof(itemName), localizedName);
redraw = true;
}
}

if (equipped) {
Expand Down

0 comments on commit 7a4df57

Please sign in to comment.