12 #include "../clib/cfgelem.h" 13 #include "../clib/cfgfile.h" 14 #include "../clib/clib.h" 15 #include "../clib/fileutil.h" 16 #include "../clib/logfacility.h" 17 #include "../clib/passert.h" 18 #include "../clib/rawtypes.h" 19 #include "../clib/stlutil.h" 20 #include "../plib/systemstate.h" 65 size_t size =
sizeof(
Menu );
84 if ( stricmp( menu->
name, name ) == 0 )
106 INFO_PRINT <<
"File config/menus.cfg not found, skipping.\n";
114 while ( cf.
read( elem ) )
116 std::string menu_name;
117 std::string menu_title;
118 std::string propname;
121 if ( stricmp( elem.
type(),
"ItemMenu" ) != 0 )
136 if ( stricmp( propname.c_str(),
"SubMenu" ) == 0 ||
137 stricmp( propname.c_str(),
"Entry" ) == 0 )
139 std::string submenu_name;
140 std::string objtype_str;
149 if ( stricmp( propname.c_str(),
"SubMenu" ) == 0 )
152 is >> submenu_name >> objtype_str;
157 std::getline( is, title );
160 while ( isspace( title[0] ) )
182 std::getline( is, title );
184 while ( isspace( title[0] ) )
188 if ( objtype_str ==
"" )
191 <<
" must provide at least an object type\n";
192 throw std::runtime_error(
"Data error in MENUS.CFG" );
194 u32 objtype = (
u32)strtoul( objtype_str.c_str(),
nullptr, 0 );
197 ERROR_PRINT <<
"Entry in menu " << menu->
name <<
" cannot specify [" << objtype_str
198 <<
"] as an Object Type.\n";
199 throw std::runtime_error(
"Data error in MENUS.CFG" );
201 if ( ( stricmp( propname.c_str(),
"SubMenu" ) == 0 ) && ( submenu_name ==
"" ) )
204 <<
" needs format: Objtype, Title, SubMenuName [got '" << value <<
"']\n";
205 throw std::runtime_error(
"Data error in MENUS.CFG" );
207 if ( ( stricmp( propname.c_str(),
"Entry" ) == 0 ) && ( submenu_name !=
"" ) )
209 ERROR_PRINT <<
"Entry in menu " << menu->
name <<
" must not specify SubMenuName [got '" 211 throw std::runtime_error(
"Data error in MENUS.CFG" );
226 if ( submenu_name !=
"" )
235 ERROR_PRINT <<
"Unexpected property in menu " << menu->
name <<
": " << propname <<
"\n";
236 throw std::runtime_error(
"Data error in MENUS.CFG" );
242 for (
unsigned menuidx = 0; menuidx <
gamestate.
menus.size(); menuidx++ )
245 for (
unsigned itemidx = 0; itemidx < menu->
menuitems_.size(); itemidx++ )
bool remove_first_prop(std::string *propname, std::string *value)
std::string remove_string(const char *propname)
unsigned short getcolor(unsigned int objtype)
unsigned short getgraphic(u32 objtype)
std::vector< Menu > menus
bool FileExists(const char *filename)
bool read(ConfigElem &elem)
const char * type() const