src/mess/osd/windows/menu.c
| r7990 | r7991 | |
| 23 | 23 | #include "opcntrl.h" |
| 24 | 24 | #include "strconv.h" |
| 25 | 25 | #include "utils.h" |
| 26 | | #include "png.h" |
| 27 | 26 | #include "debug/debugcpu.h" |
| 28 | 27 | #include "inptport.h" |
| 29 | 28 | #include "devices/cassette.h" |
| r7990 | r7991 | |
| 135 | 134 | // artwork_get_inputscreen_customizations |
| 136 | 135 | //============================================================ |
| 137 | 136 | |
| 138 | | int artwork_get_inputscreen_customizations(png_info *png, artwork_cust_type cust_type, |
| 139 | | const char *section, |
| 140 | | struct inputform_customization *customizations, |
| 141 | | int customizations_length) |
| 137 | int artwork_get_inputscreen_customizations(struct inputform_customization *customizations, int customizations_length) |
| 142 | 138 | { |
| 143 | | file_error filerr; |
| 144 | | mame_file *file; |
| 145 | | char buffer[1000]; |
| 146 | | char current_section[64]; |
| 147 | | char ipt_name[64]; |
| 148 | | char *p; |
| 149 | | int x1, y1, x2, y2; |
| 150 | | const char *png_filename; |
| 151 | | const char *ini_filename; |
| 152 | | int enabled = TRUE; |
| 153 | | int item_count = 0; |
| 154 | | |
| 155 | | static const char *const cust_files[] = |
| 156 | | { |
| 157 | | "ctrlr.png", "ctrlr.ini", |
| 158 | | "keyboard.png", "keyboard.ini" |
| 159 | | "misc.png", "misc.ini" |
| 160 | | }; |
| 161 | | |
| 162 | | if ((cust_type >= 0) && (cust_type < (ARRAY_LENGTH(cust_files) / 2))) |
| 163 | | { |
| 164 | | png_filename = cust_files[cust_type * 2 + 0]; |
| 165 | | ini_filename = cust_files[cust_type * 2 + 1]; |
| 166 | | } |
| 167 | | else |
| 168 | | { |
| 169 | | png_filename = NULL; |
| 170 | | ini_filename = NULL; |
| 171 | | } |
| 172 | | |
| 173 | | /* subtract one from the customizations length; so we can place IPT_END */ |
| 174 | | customizations_length--; |
| 175 | | |
| 176 | | /* open the INI file, if available */ |
| 177 | | if (ini_filename) |
| 178 | | { |
| 179 | | filerr = mame_fopen(SEARCHPATH_ARTWORK, ini_filename, OPEN_FLAG_READ, &file); |
| 180 | | if (filerr == FILERR_NONE) |
| 181 | | { |
| 182 | | /* loop until we run out of lines */ |
| 183 | | while (customizations_length && mame_fgets(buffer, sizeof(buffer), file)) |
| 184 | | { |
| 185 | | /* strip off any comments */ |
| 186 | | p = strstr(buffer, "//"); |
| 187 | | if (p) |
| 188 | | *p = 0; |
| 189 | | |
| 190 | | /* section header? */ |
| 191 | | if (buffer[0] == '[') |
| 192 | | { |
| 193 | | strncpyz(current_section, &buffer[1], |
| 194 | | ARRAY_LENGTH(current_section)); |
| 195 | | p = strchr(current_section, ']'); |
| 196 | | if (!p) |
| 197 | | continue; |
| 198 | | *p = '\0'; |
| 199 | | if (section) |
| 200 | | enabled = !mame_stricmp(current_section, section); |
| 201 | | continue; |
| 202 | | } |
| 203 | | |
| 204 | | if (!enabled || sscanf(buffer, "%64s (%d,%d)-(%d,%d)", ipt_name, &x1, &y1, &x2, &y2) != 5) |
| 205 | | continue; |
| 206 | | |
| 207 | | #if 0 |
| 208 | | /* temporarily disabled */ |
| 209 | | for (pik = input_keywords; pik->name[0]; pik++) |
| 210 | | { |
| 211 | | pik_name = pik->name; |
| 212 | | if ((pik_name[0] == 'P') && (pik_name[1] == '1') && (pik_name[2] == '_')) |
| 213 | | pik_name += 3; |
| 214 | | |
| 215 | | if (!strcmp(ipt_name, pik_name)) |
| 216 | | { |
| 217 | | if ((x1 > 0) && (y1 > 0) && (x2 > x1) && (y2 > y1)) |
| 218 | | { |
| 219 | | customizations->ipt = pik->val; |
| 220 | | customizations->x = x1; |
| 221 | | customizations->y = y1; |
| 222 | | customizations->width = x2 - x1; |
| 223 | | customizations->height = y2 - y1; |
| 224 | | customizations++; |
| 225 | | customizations_length--; |
| 226 | | item_count++; |
| 227 | | } |
| 228 | | break; |
| 229 | | } |
| 230 | | } |
| 231 | | #endif |
| 232 | | } |
| 233 | | mame_fclose(file); |
| 234 | | } |
| 235 | | } |
| 236 | | |
| 237 | 139 | /* terminate list */ |
| 238 | 140 | customizations->ipt = IPT_END; |
| 239 | 141 | customizations->x = -1; |
| r7990 | r7991 | |
| 241 | 143 | customizations->width = -1; |
| 242 | 144 | customizations->height = -1; |
| 243 | 145 | |
| 244 | | /* open the PNG, if available */ |
| 245 | | memset(png, 0, sizeof(*png)); |
| 246 | | if (png_filename && item_count > 0) |
| 247 | | { |
| 248 | | filerr = mame_fopen(SEARCHPATH_ARTWORK, ini_filename, OPEN_FLAG_READ, &file); |
| 249 | | if (filerr == FILERR_NONE) |
| 250 | | { |
| 251 | | png_read_file(mame_core_file(file), png); |
| 252 | | mame_fclose(file); |
| 253 | | } |
| 254 | | } |
| 255 | | return item_count; |
| 146 | return 0; |
| 256 | 147 | } |
| 257 | 148 | |
| 258 | 149 | |
| r7990 | r7991 | |
| 341 | 232 | // customize_input |
| 342 | 233 | //============================================================ |
| 343 | 234 | |
| 344 | | static void customize_input(running_machine *machine, HWND wnd, const char *title, artwork_cust_type cust_type, int player, int inputclass, const char *section) |
| 235 | static void customize_input(running_machine *machine, HWND wnd, const char *title, int player, int inputclass) |
| 345 | 236 | { |
| 346 | 237 | dialog_box *dlg; |
| 347 | 238 | const input_port_config *port; |
| 348 | 239 | const input_field_config *field; |
| 349 | | png_info png; |
| 350 | 240 | struct inputform_customization customizations[128]; |
| 351 | 241 | RECT *pr; |
| 352 | 242 | int this_inputclass, this_player, portslot_count, i; |
| r7990 | r7991 | |
| 359 | 249 | |
| 360 | 250 | /* check to see if there is any custom artwork for this configure dialog, |
| 361 | 251 | * and if so, retrieve the info */ |
| 362 | | portslot_count = artwork_get_inputscreen_customizations(&png, cust_type, section, |
| 363 | | customizations, ARRAY_LENGTH(customizations)); |
| 252 | portslot_count = artwork_get_inputscreen_customizations(customizations, ARRAY_LENGTH(customizations)); |
| 364 | 253 | |
| 365 | 254 | /* zero out the portslots that correspond to customizations */ |
| 366 | 255 | memset(portslots, 0, sizeof(portslots[0]) * portslot_count); |
| r7990 | r7991 | |
| 370 | 259 | if (!dlg) |
| 371 | 260 | goto done; |
| 372 | 261 | |
| 373 | | if (png.width > 0) |
| 374 | | { |
| 375 | | win_dialog_add_image(dlg, &png); |
| 376 | | win_dialog_add_separator(dlg); |
| 377 | | } |
| 378 | | |
| 379 | 262 | for (port = machine->portlist.first(); port != NULL; port = port->next) |
| 380 | 263 | { |
| 381 | 264 | for (field = port->fieldlist; field != NULL; field = field->next) |
| r7990 | r7991 | |
| 456 | 339 | |
| 457 | 340 | static void customize_joystick(running_machine *machine, HWND wnd, int joystick_num) |
| 458 | 341 | { |
| 459 | | customize_input(machine, wnd, "Joysticks/Controllers", ARTWORK_CUSTTYPE_JOYSTICK, joystick_num, INPUT_CLASS_CONTROLLER, NULL); |
| 342 | customize_input(machine, wnd, "Joysticks/Controllers", joystick_num, INPUT_CLASS_CONTROLLER); |
| 460 | 343 | } |
| 461 | 344 | |
| 462 | 345 | |
| r7990 | r7991 | |
| 467 | 350 | |
| 468 | 351 | static void customize_keyboard(running_machine *machine, HWND wnd) |
| 469 | 352 | { |
| 470 | | customize_input(machine, wnd, "Emulated Keyboard", ARTWORK_CUSTTYPE_KEYBOARD, 0, INPUT_CLASS_KEYBOARD, NULL); |
| 353 | customize_input(machine, wnd, "Emulated Keyboard", 0, INPUT_CLASS_KEYBOARD); |
| 471 | 354 | } |
| 472 | 355 | |
| 473 | 356 | |
| r7990 | r7991 | |
| 478 | 361 | |
| 479 | 362 | static void customize_miscinput(running_machine *machine, HWND wnd) |
| 480 | 363 | { |
| 481 | | customize_input(machine, wnd, "Miscellaneous Input", ARTWORK_CUSTTYPE_MISC, 0, INPUT_CLASS_MISC, NULL); |
| 364 | customize_input(machine, wnd, "Miscellaneous Input", 0, INPUT_CLASS_MISC); |
| 482 | 365 | } |
| 483 | 366 | |
| 484 | 367 | |
| r7990 | r7991 | |
| 487 | 370 | // customize_categorizedinput |
| 488 | 371 | //============================================================ |
| 489 | 372 | |
| 490 | | static void customize_categorizedinput(running_machine *machine, HWND wnd, const char *section, int category) |
| 373 | static void customize_categorizedinput(running_machine *machine, HWND wnd, int category) |
| 491 | 374 | { |
| 492 | 375 | assert(category > 0); |
| 493 | | customize_input(machine, wnd, "Input", ARTWORK_CUSTTYPE_JOYSTICK, category, INPUT_CLASS_CATEGORIZED, section); |
| 376 | customize_input(machine, wnd, "Input", category, INPUT_CLASS_CATEGORIZED); |
| 494 | 377 | } |
| 495 | 378 | |
| 496 | 379 | |
| r7990 | r7991 | |
| 1891 | 1774 | int dev_command; |
| 1892 | 1775 | running_device *img; |
| 1893 | 1776 | UINT16 category; |
| 1894 | | const char *section; |
| 1895 | 1777 | const input_field_config *field; |
| 1896 | 1778 | const input_setting_config *setting; |
| 1897 | 1779 | LONG_PTR ptr = GetWindowLongPtr(wnd, GWLP_USERDATA); |
| r7990 | r7991 | |
| 2090 | 1972 | // customize the input type |
| 2091 | 1973 | input_field_get_user_settings(field, &settings); |
| 2092 | 1974 | category = 0; |
| 2093 | | section = NULL; |
| 2094 | 1975 | |
| 2095 | 1976 | for (setting = field->settinglist; setting != NULL; setting = setting->next) |
| 2096 | 1977 | { |
| 2097 | 1978 | if (settings.value == setting->value) |
| 2098 | 1979 | { |
| 2099 | 1980 | category = setting->category; |
| 2100 | | section = setting->name; |
| 2101 | 1981 | } |
| 2102 | 1982 | } |
| 2103 | 1983 | if (category) |
| 2104 | | customize_categorizedinput(window->machine, wnd, section, category); |
| 1984 | customize_categorizedinput(window->machine, wnd, category); |
| 2105 | 1985 | } |
| 2106 | 1986 | else |
| 2107 | 1987 | { |