PC Editor: Fix item menus for scenarios with less than 400 or more than 403 items.
- On Mac, Items 2 - 4 would give you the wrong item. - On both Windows and Macs, items at the end of the list might be missing altogether.
This commit is contained in:
@@ -321,9 +321,8 @@ void handle_menu_choice(eMenu item_hit) {
|
||||
}
|
||||
|
||||
// TODO: Let this take the item directly instead of the index
|
||||
void handle_item_menu(int item_hit) {
|
||||
cItem store_i;
|
||||
store_i = univ.scenario.scen_items[item_hit];
|
||||
void handle_item_menu(cItem& item) {
|
||||
cItem store_i = item;
|
||||
store_i.ident = true;
|
||||
if(!univ.party[current_active_pc].give_item(store_i,GIVE_ALLOW_OVERLOAD))
|
||||
showError("Sorry, that PC has no free inventory slots left! You'll have to either drop something or give it to a different PC.");
|
||||
|
@@ -25,7 +25,7 @@ enum class eMenu {
|
||||
EDIT_DAY, LEAVE_TOWN, RESET_TOWNS, ADD_OUT_MAPS, ADD_TOWN_MAPS, LEAVE_SCENARIO, SET_SDF,
|
||||
};
|
||||
|
||||
void handle_item_menu(int item_hit);
|
||||
void handle_item_menu(class cItem& item);
|
||||
void handle_menu_choice(eMenu item_hit);
|
||||
|
||||
#endif
|
||||
|
@@ -108,17 +108,16 @@ void menu_activate() {
|
||||
void update_item_menu() {
|
||||
id targ = [[file_menu itemAtIndex: 0] target];
|
||||
auto& item_list = univ.scenario.scen_items;
|
||||
int per_menu = item_list.size() / 4;
|
||||
int per_menu = 1 + (item_list.size() - 1) / 4;
|
||||
for(int j = 0; j < 4; j++){
|
||||
[items_menu[j] removeAllItems];
|
||||
if(!scen_items_loaded) {
|
||||
[[items_menu[j] addItemWithTitle: @"Items Not Loaded" action: @selector(itemMenu:) keyEquivalent: @""] setEnabled: NO];
|
||||
} else for(int i = 0; i < per_menu && i + j * per_menu < item_list.size(); i++) {
|
||||
ItemWrapper* item = [ItemWrapper withItem: i + per_menu * j];
|
||||
ItemWrapper* item = [ItemWrapper withItem: i + j * per_menu];
|
||||
NSString* item_name = [NSString stringWithCString: item_list[i + j * per_menu].full_name.c_str() encoding: NSASCIIStringEncoding];
|
||||
NSMenuItem* choice = [items_menu[j] addItemWithTitle: item_name action: @selector(itemMenu:) keyEquivalent: @""];
|
||||
[choice setTarget: targ];
|
||||
// TODO: Also disable gold or food
|
||||
[choice setEnabled: [item item].variety != eItemType::NO_ITEM];
|
||||
[choice setRepresentedObject: item];
|
||||
}
|
||||
@@ -129,12 +128,7 @@ void update_item_menu() {
|
||||
-(void) itemMenu:(id) sender {
|
||||
ItemWrapper* item = [sender representedObject];
|
||||
class cItem& theItem = [item item];
|
||||
(void) theItem; // Suppress "unused parameter" warning
|
||||
for(int i = 0; i < 4; i++) {
|
||||
int whichItem = [items_menu[i] indexOfItem: sender];
|
||||
if(whichItem >= 0)
|
||||
handle_item_menu(whichItem + 100 * i);
|
||||
}
|
||||
handle_item_menu(theItem);
|
||||
}
|
||||
|
||||
-(void) menuChoice:(id) sender {
|
||||
|
@@ -113,8 +113,8 @@ void init_menubar() {
|
||||
void update_item_menu() {
|
||||
if(menuHandle == NULL) return;
|
||||
auto& item_list = univ.scenario.scen_items;
|
||||
int per_menu = item_list.size() / 4;
|
||||
int per_col = per_menu / 4;
|
||||
int per_menu = 1 + (item_list.size() - 1) / 4;
|
||||
int per_col = 1 + (per_menu - 1) / 4;
|
||||
for(int j = 0; j < 4; j++) {
|
||||
HMENU items_menu = GetSubMenu(menuHandle, ITEMS_MENU_POS + j);
|
||||
while(GetMenuItemCount(items_menu)) RemoveMenu(items_menu, 0, MF_BYPOSITION);
|
||||
@@ -125,7 +125,6 @@ void update_item_menu() {
|
||||
UINT flags = MF_STRING | MF_ENABLED;
|
||||
if(i % per_col == 0) flags |= MF_MENUBARBREAK;
|
||||
AppendMenuA(items_menu, flags, 1000 + j * per_menu + i, item.full_name.c_str());
|
||||
// TODO: Also disable gold or food
|
||||
EnableMenuItem(items_menu, i, MF_BYPOSITION | (item.variety != eItemType::NO_ITEM ? MF_ENABLED : MF_GRAYED));
|
||||
}
|
||||
}
|
||||
@@ -160,7 +159,7 @@ LRESULT CALLBACK menuProc(HWND handle, UINT message, WPARAM wParam, LPARAM lPara
|
||||
if(message == WM_COMMAND) {
|
||||
int cmd = LOWORD(wParam);
|
||||
if(cmd >= 1000) { // Item menus
|
||||
handle_item_menu(cmd - 1000);
|
||||
handle_item_menu(univ.scenario.scen_items[cmd - 1000]);
|
||||
} else handle_menu_choice(menuChoices[cmd]);
|
||||
} else if(message == WM_SETCURSOR) {
|
||||
// Windows resets the cursor to an arrow whenever the mouse moves, unless we do this.
|
||||
|
Reference in New Issue
Block a user