(PC Editor and Scenario Editor are unaffected by this commit.) Things removed: - All references to Carbon and QuickDraw are gone. - No more Resource Manager; the game no longer relies on old resource files at all - The old dialog framework (from dlogtool.c, functions usually prefixed with cd_) is no longer used. - Files that weren't being compiled - Boost libraries that are now in the C++ library (function, shared_ptr) - Obsolete build settings Replacement dependencies: - Boost Filesystem replaces references to things like FSSpec - SFML replaces all the QuickDraw code and most window management - Cocoa replaces AppleEvent management, menu management, and some window management - I wrote a resource manager interface to mimick the important aspects of the behaviour of the Mac Resource Manager - I had to rewrite some functions that QuickDraw provided natively, such as clipping regions; not all of these are tested Things added: - Every referenced dialog has been converted from a DITL resource into the new XML-based dialog format. - All referenced STR# resources have been extracted into simple text files - Now compiles against Mac OSX 10.7 SDK and libc++ - The first item in the Help menu opens the docs on Sylae's website - It seems all the constants for soundtool vanished somewhere, so I added them back from the original Mac source Other changes: - Updated to XCode 4(?) project format - Added the xcschemes created by XCode 4; I'm not sure how important these are, but they seem like they might be important - Added document on converting dialogs to the XML format. - Make string formatting mismatches into errors instead of warnings - Disable error limit - Graphics sheets that previously used masking now have alpha transparency - Converted all graphics sheets to 8-bit PNG - Trimmed white border from intro image - Converted dialogs in the resource file have their resource name set to the name of the XML file of the converted version - Referenced string resources in the resource file have their resource name set to the name of the text file of the extracted version - Add the black-and-white patterns from the PAT resources to the pixpats.png; at least one of them is used somewhere in the game - Recreated the menu.xib as a Cocoa xib file instead of a Carbon xib file - Disable GNU C++ extensions; maybe this'll make it easier to compile with cl.exe later - Add marks to the enormous handle_action function to make it easier to navigate\ - A build step to validate the XML dialogs using xmllint (doesn't quite work properly yet but does at least catch dialogs that are not well-formed)- Fix a lot of warnings about assigning string constants to non-const char pointers - Fixed the file and application icons (which had somehow become corrupted at some point) - Lots of additional functions in the custom location and rectangle classes, including implicit conversion to and from SFML rects and vectors; also they now store coordinates as int instead of char - A new enum for encounter note types - Much tweaking of the encounter note recording mechanisms - To ease porting, I added a simple function that converts from classic Mac ticks (about 1/60 of a second) to the SFML time type - Python script to convert STR# resources to txt files, replacing newlines with vertical bars - Extracted the Mac font (Dungeon Bold) from the resource file and also added the Windows font (MaidenWord) XML Dialog Framework changes: - Remove the static initialization object in favour of manually calling cDialog::init() - {set,get}Format() no longer used for colour; there's a dedicated {set,get}Colour() instead - draw() methods unprotected in the control classes so that controls can be drawn in the main window - There's no longer a friend relationship between the dialogs and the controls - Fixed buttons duplicating the "depressed" boolean - Buttons now properly offset the label for tiny and push buttons, and for LEDs - Buttons no longer assume that either none or both of "width" and "height" are given in the XML - Add {get,set}BtnType() to cButton - cLedGroup now overrides handleClick(), which has also been made virtual; this was necessary for LEDs within a group to properly hilite while being clicked - Add addChoice() to cLedGroup to insert additional LED choices - Moved the key enums and cKey to a separate file - Add a method to get a control's attached key - Add methods to get and set a control's rect and position - Controls can now directly take a window as a parent rather than a dialog - Add addLabelFor() method to cDialog which adds a static text control as a label for another control - Remove hack for storing a dialog result of arbitrary type in favour of boost::any - Add method to get default text colour for a dialog - Add method to get a dialog's rect - Add method to add the same event handler to multiple controls in a dialog - Add concept of default button to dialogs - Add enum for text field type (currently either number or text) - Implement the text field without use of native controls, including somewhat decent text input and a flashing insertion point - cPict no longer stores references to every sheet; it fetches them as needed from the resource manager - The many draw functions in cPict are no longer static, since they need to access the window containing the pict (before they could only be static due to QuickDraw's global state) - Add setPict() without a type argument to change the graphic without changing the type, which is a common operation - Add a scrollbar control; the specifics aren't implemented yet - Change signature of the record callback for cStrDlog; it will no longer be passed the strings - Publicize the no-button constructor of cChoiceDlog; it'll assume "okay" is the only button - Add operator-> to cPictChoice for accessing the underlying dialog - Add constructor to cPictChoice that takes a starting and ending pic num - Remove err parameter from giveError - Many more keys handled, plus support for catching copy, paste, cut, and select all keyboard shortcuts - Text input fields take priority, overriding any other keyboard shortcuts in the dialog, but they never catch help (F1), escape, or enter - Some changes to the format itself: -> keys go in the "def-key" attribute, but modifiers go in "key-mod" -> "clickable" is no longer a recognized attribute -> "title" is now a recognized text size (18pt, even larger than "large" at 12pt) -> "defbtn" attribute on the root element
361 lines
12 KiB
Plaintext
361 lines
12 KiB
Plaintext
//
|
|
// boe.menus.mm
|
|
// BoE
|
|
//
|
|
// Created by Celtic Minstrel on 14-03-25.
|
|
//
|
|
//
|
|
|
|
#include "boe.menus.h"
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
#include "universe.h"
|
|
#include "scenario.h"
|
|
#include "boe.party.h"
|
|
#include "boe.infodlg.h"
|
|
|
|
extern short on_spell_menu[2][62];
|
|
extern short spell_level[62];
|
|
extern short spell_cost[2][62];
|
|
extern short on_monst_menu[256];
|
|
extern const char* mage_s_name[62];
|
|
extern const char* priest_s_name[62];
|
|
extern bool in_startup_mode, party_in_memory;
|
|
extern short current_pc;
|
|
extern cUniverse univ;
|
|
extern cScenario scenario;
|
|
|
|
#ifndef __APPLE__
|
|
#error boe.menus.mm is Mac-specific code; try compiling boe.menus.win.cpp instead
|
|
#endif
|
|
|
|
using MenuHandle = NSMenu*;
|
|
|
|
MenuHandle menu_bar_handle;
|
|
MenuHandle apple_menu,file_menu,extra_menu,help_menu,monster_info_menu,library_menu;
|
|
MenuHandle actions_menu,music_menu,mage_spells_menu,priest_spells_menu;
|
|
|
|
@interface MenuHandler : NSObject
|
|
-(void) appMenu:(id) sender;
|
|
-(void) fileMenu:(id) sender;
|
|
-(void) optMenu:(id) sender;
|
|
-(void) actMenu:(id) sender;
|
|
-(void) monstMenu:(id) sender;
|
|
-(void) spellMenu:(id) sender;
|
|
-(void) libMenu:(id) sender;
|
|
-(void) helpMenu:(id) sender;
|
|
-(void) onlineHelp:(id) sender;
|
|
-(void) menuHelp:(id) sender; // The "About This Menu" options
|
|
@end
|
|
|
|
@interface MonsterWrapper : NSObject
|
|
@property cMonster* monst;
|
|
+(id) withMonster: (cMonster&) theMonster;
|
|
@end
|
|
|
|
@interface SpellWrapper : NSObject
|
|
@property int type, num;
|
|
+(id) withSpell:(int) num ofType:(int) type;
|
|
@end
|
|
|
|
void hideMenuBar() {
|
|
[NSMenu setMenuBarVisible:NO];
|
|
}
|
|
|
|
void showMenuBar() {
|
|
[NSMenu setMenuBarVisible:YES];
|
|
}
|
|
|
|
void adjust_monst_menu() {
|
|
short i,monst_pos = 0;
|
|
NSMenu* monst_menu;
|
|
char monst_name[256];
|
|
|
|
if(in_startup_mode == true) return;
|
|
|
|
monst_menu = [[menu_bar_handle itemWithTitle: @"Monsters"] submenu];
|
|
id targ = [[monst_menu itemAtIndex: 0] target];
|
|
for(i = 0; i < 256; i++) {
|
|
on_monst_menu[i] = -1;
|
|
}
|
|
for(i = 1; i < 256; i++) {
|
|
if ((i == 1) || (univ.party.m_noted[i] > 0)) {
|
|
on_monst_menu[monst_pos] = i;
|
|
monst_pos++;
|
|
}
|
|
}
|
|
|
|
for(i = 0; i < 256; i++) {
|
|
[monst_menu removeItemAtIndex: 1]; // TODO: I suspect it should be 2, not 1
|
|
}
|
|
for(i = 0; i < 256; i++) {
|
|
if(on_monst_menu[i] >= 0) {
|
|
std::string monst_name = scenario.scen_monsters[on_monst_menu[i]].m_name;
|
|
NSString* str = [NSString stringWithUTF8String: monst_name.c_str()];
|
|
NSMenuItem* newItem = [monst_menu addItemWithTitle: str action: @selector(monstMenu:) keyEquivalent: @""];
|
|
[newItem setTarget: targ];
|
|
[newItem setRepresentedObject: [MonsterWrapper withMonster: scenario.scen_monsters[on_monst_menu[i]]]];
|
|
}
|
|
}
|
|
}
|
|
|
|
void setMenuCallback(NSMenuItem* item, id targ, SEL selector, int num) {
|
|
[item setTarget: targ];
|
|
[item setAction: selector];
|
|
[item setRepresentedObject: [[NSNumber numberWithInt: num] retain]];
|
|
}
|
|
|
|
void init_menubar() {
|
|
NSApplication* app = [NSApplication sharedApplication];
|
|
BOOL loaded = [NSBundle loadNibNamed: @"menu" owner: app];
|
|
menu_bar_handle = [app mainMenu];
|
|
|
|
apple_menu = [[menu_bar_handle itemWithTitle: @"Blades of Exile"] submenu];
|
|
file_menu = [[menu_bar_handle itemWithTitle: @"File"] submenu];
|
|
extra_menu = [[menu_bar_handle itemWithTitle: @"Options"] submenu];
|
|
help_menu = [[menu_bar_handle itemWithTitle: @"Help"] submenu];
|
|
library_menu = [[menu_bar_handle itemWithTitle: @"Library"] submenu];
|
|
actions_menu = [[menu_bar_handle itemWithTitle: @"Actions"] submenu];
|
|
|
|
MenuHandler* handler = [[[MenuHandler alloc] init] retain];
|
|
setMenuCallback([help_menu itemAtIndex: 0], handler, @selector(onlineHelp:), 0);
|
|
// TODO: Do away with "handle_apple_menu" and "appMenu" in favour of pushing "About" to the help menu
|
|
setMenuCallback([apple_menu itemWithTitle: @"About Blades of Exile"], handler, @selector(appMenu:), 1);
|
|
setMenuCallback([apple_menu itemWithTitle: @"Preferences…"], handler, @selector(fileMenu:), 6);
|
|
setMenuCallback([apple_menu itemWithTitle: @"Quit Blades of Exile"], handler, @selector(fileMenu:), 8);
|
|
// TODO: Check to make sure that Cocoa 0-indexes its menus
|
|
// TODO: Need to verify arrangement of the File menu
|
|
setMenuCallback([file_menu itemWithTitle: @"New Game…"], handler, @selector(fileMenu:), 4);
|
|
setMenuCallback([file_menu itemWithTitle: @"Save"], handler, @selector(fileMenu:), 2);
|
|
setMenuCallback([file_menu itemWithTitle: @"Save As…"], handler, @selector(fileMenu:), 3);
|
|
setMenuCallback([file_menu itemWithTitle: @"Open…"], handler, @selector(fileMenu:), 1);
|
|
setMenuCallback([file_menu itemWithTitle: @"Abort"], handler, @selector(fileMenu:), 0);
|
|
// for(int i = 0; i < [file_menu numberOfItems]; i++)
|
|
// setMenuCallback([file_menu itemAtIndex: i], handler, @selector(fileMenu:), i + 1);
|
|
for(int i = 0; i < [extra_menu numberOfItems]; i++)
|
|
setMenuCallback([extra_menu itemAtIndex: i], handler, @selector(optMenu:), i + 1);
|
|
for(int i = 1; i < [help_menu numberOfItems]; i++)
|
|
setMenuCallback([help_menu itemAtIndex: i], handler, @selector(helpMenu:), i - 1);
|
|
for(int i = 0; i < [library_menu numberOfItems]; i++)
|
|
setMenuCallback([library_menu itemAtIndex: i], handler, @selector(libMenu:), i + 1);
|
|
for(int i = 0; i < [actions_menu numberOfItems]; i++)
|
|
setMenuCallback([actions_menu itemAtIndex: i], handler, @selector(actMenu:), i + 1);
|
|
// TODO: Spell menus and monster menu
|
|
NSMenu* mage_menu = [[menu_bar_handle itemWithTitle: @"Mage Spells"] submenu];
|
|
setMenuCallback([mage_menu itemAtIndex: 0], handler, @selector(menuHelp:), 0);
|
|
NSMenu* priest_menu = [[menu_bar_handle itemWithTitle: @"Priest Spells"] submenu];
|
|
setMenuCallback([priest_menu itemAtIndex: 0], handler, @selector(menuHelp:), 1);
|
|
NSMenu* monst_menu = [[menu_bar_handle itemWithTitle: @"Monsters"] submenu];
|
|
setMenuCallback([monst_menu itemAtIndex: 0], handler, @selector(menuHelp:), 2);
|
|
|
|
menu_activate();
|
|
}
|
|
|
|
void init_spell_menus()
|
|
{
|
|
short i,j;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 62; j++)
|
|
on_spell_menu[i][j] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void adjust_spell_menus()
|
|
{
|
|
short i,j,spell_pos = 0;
|
|
NSMenu* spell_menu;
|
|
char spell_name[256];
|
|
short old_on_spell_menu[2][62];
|
|
bool need_menu_change = false;
|
|
|
|
if (in_startup_mode || current_pc == 6)
|
|
return;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
for (j = 0; j < 62; j++)
|
|
old_on_spell_menu[i][j] = on_spell_menu[i][j];
|
|
|
|
spell_menu = [[menu_bar_handle itemWithTitle: @"Cast Mage"] submenu];
|
|
id targ = [[spell_menu itemAtIndex: 0] target];
|
|
|
|
for (i = 0; i < 62; i++) {
|
|
on_spell_menu[0][i] = -1;
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (pc_can_cast_spell(current_pc,0,i)) {
|
|
on_spell_menu[0][spell_pos] = i;
|
|
spell_pos++;
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (on_spell_menu[0][i] != old_on_spell_menu[0][i])
|
|
need_menu_change = true;
|
|
if (need_menu_change) {
|
|
for (i = 0; i < 62; i++) {
|
|
[spell_menu removeItemAtIndex: 3];
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (on_spell_menu[0][i] >= 0) {
|
|
if (spell_cost[0][on_spell_menu[0][i]] > 0)
|
|
sprintf(spell_name," L%d - %s, C %d",spell_level[on_spell_menu[0][i]],
|
|
mage_s_name[on_spell_menu[0][i]],spell_cost[0][on_spell_menu[0][i]]);
|
|
else sprintf(spell_name," L%d - %s, C ?",spell_level[on_spell_menu[0][i]],
|
|
mage_s_name[on_spell_menu[0][i]]);
|
|
spell_name[0] = strlen((char *) spell_name);
|
|
//strcpy((char *) (spell_name + 1),mage_s_name[on_spell_menu[0][i]]);
|
|
NSString* str = [NSString stringWithUTF8String: spell_name];
|
|
NSMenuItem* newItem = [spell_menu addItemWithTitle: str action: @selector(spellMenu:) keyEquivalent: @""];
|
|
[newItem setTarget: targ];
|
|
[newItem setRepresentedObject: [SpellWrapper withSpell: i ofType: 0]];
|
|
}
|
|
}
|
|
|
|
need_menu_change = false;
|
|
spell_pos = 0;
|
|
|
|
spell_menu = [[menu_bar_handle itemWithTitle: @"Cast Priest"] submenu];
|
|
|
|
for (i = 0; i < 62; i++) {
|
|
on_spell_menu[1][i] = -1;
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (pc_can_cast_spell(current_pc,1,i)) {
|
|
on_spell_menu[1][spell_pos] = i;
|
|
spell_pos++;
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (on_spell_menu[1][i] != old_on_spell_menu[1][i])
|
|
need_menu_change = true;
|
|
if (need_menu_change) {
|
|
for (i = 0; i < 62; i++) {
|
|
[spell_menu removeItemAtIndex: 3];
|
|
}
|
|
for (i = 0; i < 62; i++)
|
|
if (on_spell_menu[1][i] >= 0) {
|
|
//spell_name[0] = strlen((char *) priest_s_name[on_spell_menu[1][i]]);
|
|
//strcpy((char *) (spell_name + 1),priest_s_name[on_spell_menu[1][i]]);
|
|
if (spell_cost[1][on_spell_menu[1][i]] > 0)
|
|
sprintf(spell_name," L%d - %s, C %d",spell_level[on_spell_menu[1][i]],
|
|
priest_s_name[on_spell_menu[1][i]],spell_cost[1][on_spell_menu[1][i]]);
|
|
else sprintf(spell_name," L%d - %s, C ?",spell_level[i],
|
|
priest_s_name[on_spell_menu[1][i]]);
|
|
spell_name[0] = strlen((char *) spell_name);
|
|
// TODO: Figure out what to put for the action (which should be an Objective-C selector)
|
|
NSString* str = [NSString stringWithUTF8String: spell_name];
|
|
NSMenuItem* newItem = [spell_menu addItemWithTitle: str action: @selector(spellMenu:) keyEquivalent: @""];
|
|
[newItem setTarget: targ];
|
|
[newItem setRepresentedObject: [SpellWrapper withSpell: i ofType: 1]];
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void menu_activate() {
|
|
if(in_startup_mode) {
|
|
[[menu_bar_handle itemWithTitle: @"Options"] setEnabled: NO];
|
|
[[menu_bar_handle itemWithTitle: @"Monsters"] setEnabled: NO];
|
|
[[menu_bar_handle itemWithTitle: @"Actions"] setEnabled: NO];
|
|
[[menu_bar_handle itemWithTitle: @"Cast Mage"] setEnabled: NO];
|
|
[[menu_bar_handle itemWithTitle: @"Cast Priest"] setEnabled: NO];
|
|
|
|
[[file_menu itemWithTitle: @"Save"] setEnabled: NO];
|
|
if(!party_in_memory) {
|
|
[[file_menu itemWithTitle: @"Save As…"] setEnabled: NO];
|
|
} else {
|
|
[[file_menu itemWithTitle: @"Save As…"] setEnabled: YES];
|
|
}
|
|
return;
|
|
}
|
|
|
|
[[menu_bar_handle itemWithTitle: @"Options"] setEnabled: YES];
|
|
[[menu_bar_handle itemWithTitle: @"Monsters"] setEnabled: YES];
|
|
[[menu_bar_handle itemWithTitle: @"Actions"] setEnabled: YES];
|
|
[[menu_bar_handle itemWithTitle: @"Cast Mage"] setEnabled: YES];
|
|
[[menu_bar_handle itemWithTitle: @"Cast Priest"] setEnabled: YES];
|
|
|
|
[[file_menu itemWithTitle: @"Save"] setEnabled: YES];
|
|
[[file_menu itemWithTitle: @"Save As…"] setEnabled: YES];
|
|
}
|
|
|
|
void handle_apple_menu(int item_hit);
|
|
void handle_file_menu(int item_hit);
|
|
void handle_options_menu(int item_hit);
|
|
void handle_help_menu(int item_hit);
|
|
void handle_library_menu(int item_hit);
|
|
void handle_actions_menu(int item_hit);
|
|
void handle_monster_info_menu(int item_hit);
|
|
void handle_mage_spells_menu(int item_hit);
|
|
void handle_priest_spells_menu(int item_hit);
|
|
|
|
@implementation MenuHandler
|
|
-(void) appMenu:(id) sender {
|
|
handle_apple_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) fileMenu:(id) sender {
|
|
handle_file_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) optMenu:(id) sender {
|
|
handle_options_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) actMenu:(id) sender {
|
|
handle_actions_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) monstMenu:(id) sender {
|
|
handle_monster_info_menu(1);
|
|
}
|
|
|
|
-(void) spellMenu:(id) sender {
|
|
SpellWrapper* spell = [sender representedObject];
|
|
if([spell type] == 0) handle_mage_spells_menu([spell num]);
|
|
else if([spell type] == 1) handle_priest_spells_menu([spell num]);
|
|
}
|
|
|
|
-(void) libMenu:(id) sender {
|
|
handle_library_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) helpMenu:(id) sender {
|
|
handle_help_menu([[sender representedObject] intValue]);
|
|
}
|
|
|
|
-(void) onlineHelp:(id) sender {
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"https://calref.net/~sylae/boe-doc/game/Contents.html"]];
|
|
}
|
|
|
|
-(void) menuHelp:(id) sender {
|
|
// TODO: Do something for monster menu as well
|
|
if([[sender representedObject] intValue] < 2)
|
|
give_help(209,0);
|
|
}
|
|
@end
|
|
|
|
@implementation MonsterWrapper
|
|
@synthesize monst;
|
|
|
|
+(id) withMonster:(cMonster&) theMonster {
|
|
MonsterWrapper* wrapper = [[MonsterWrapper alloc] init];
|
|
[wrapper setMonst: &theMonster];
|
|
return [wrapper retain];
|
|
}
|
|
@end
|
|
|
|
@implementation SpellWrapper
|
|
@synthesize type, num;
|
|
|
|
+(id) withSpell:(int) num ofType:(int) type {
|
|
SpellWrapper* wrapper = [[SpellWrapper alloc] init];
|
|
[wrapper setType: type];
|
|
[wrapper setNum: num];
|
|
return [wrapper retain];
|
|
}
|
|
@end
|
|
|