/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on the * source. * */ /* * $Logfile: /Freespace2/code/Hud/HUDconfig.cpp $ * $Revision: 2.27 $ * $Date: 2007-09-02 02:10:25 $ * $Author: Goober5000 $ * * C module to handle HUD configuration * * $Log: not supported by cvs2svn $ * Revision 2.26 2007/08/17 03:29:44 Goober5000 * generalize the way radar ranges are handled (inspired by Shade's fix) * * Revision 2.25 2006/09/11 06:49:39 taylor * fixes for stuff_string() bounds checking * * Revision 2.24 2006/09/08 06:20:14 taylor * fix things that strict compiling balked at (from compiling with -ansi and -pedantic) * * Revision 2.23 2006/01/26 03:23:29 Goober5000 * pare down the pragmas some more * --Goober5000 * * Revision 2.22 2006/01/13 03:30:59 Goober5000 * übercommit of custom IFF stuff :) * * Revision 2.21 2005/10/10 17:21:04 taylor * remove NO_NETWORK * * Revision 2.20 2005/07/22 10:18:38 Goober5000 * CVS header tweaks * --Goober5000 * * Revision 2.19 2005/07/13 03:15:51 Goober5000 * remove PreProcDefine #includes in FS2 * --Goober5000 * * Revision 2.18 2005/07/02 19:42:15 taylor * ton of non-standard resolution fixes * * Revision 2.17 2005/05/12 17:49:12 taylor * use vm_malloc(), vm_free(), vm_realloc(), vm_strdup() rather than system named macros * fixes various problems and is past time to make the switch * * Revision 2.16 2005/04/28 01:34:33 wmcoolmon * stuff_byte to stuff_ubyte; does the same thing, but with a better name. * * Revision 2.15 2005/04/11 05:42:02 taylor * some demo related fixes (Jens Granseuer) * * Revision 2.14 2005/03/10 08:00:06 taylor * change min/max to MIN/MAX to fix GCC problems * add lab stuff to Makefile * build unbreakage for everything that's not MSVC++ 6 * lots of warning fixes * fix OpenGL rendering problem with ship insignias * no Warnings() in non-debug mode for Linux (like Windows) * some campaign savefile fixage to stop reverting everyones data * * Revision 2.13 2005/03/02 21:24:44 taylor * more network/inferno goodness for Windows, takes care of a few warnings too * * Revision 2.12 2005/02/23 13:17:05 taylor * few more compiler warning fixes (didn't mean to commit iostream.h change) * lower warning level to 3 to stop MSVC6 from complaining about C++ headers * * Revision 2.11 2005/02/23 04:51:56 taylor * some bm_unload() -> bm_release() changes to save bmpman slots * * Revision 2.10 2005/01/31 23:27:53 taylor * merge with Linux/OSX tree - p0131-2 * * Revision 2.9 2004/07/26 20:47:32 Kazan * remove MCD complete * * Revision 2.8 2004/07/12 16:32:49 Kazan * MCD - define _MCD_CHECK to use memory tracking * * Revision 2.7 2004/04/06 01:11:41 Kazan * make custom build work again * * Revision 2.6 2004/03/31 05:42:27 Goober5000 * got rid of all those nasty warnings from xlocale and so forth; also added comments * to indicate which warnings were being disabled * --Goober5000 * * Revision 2.5 2004/03/05 09:02:03 Goober5000 * Uber pass at reducing #includes * --Goober5000 * * Revision 2.4 2003/03/18 10:07:03 unknownplayer * The big DX/main line merge. This has been uploaded to the main CVS since I can't manage to get it to upload to the DX branch. Apologies to all who may be affected adversely, but I'll work to debug it as fast as I can. * * Revision 2.3 2003/01/15 21:29:04 anonymous * fixed the demo compilation. Define FS2_DEMO globally to compile as a demo. Make sure warp.pof is in your data/models directory. * * Revision 2.2.2.1 2002/09/24 18:56:43 randomtiger * DX8 branch commit * * This is the scub of UP's previous code with the more up to date RT code. * For full details check previous dev e-mails * * Revision 2.2 2002/08/01 01:41:05 penguin * The big include file move * * Revision 2.1 2002/07/18 20:07:49 penguin * Fixed bug (potential access of unitialized pointer) in hud_config_render_gauges() -- thanks to DTP for finding it! * * Revision 2.0 2002/06/03 04:02:23 penguin * Warpcore CVS sync * * Revision 1.3 2002/05/29 14:44:54 mharris * Don't use pointers to temp. auto variables in init_alphacolor(); instead * use pointers to global HUD_config array. * * Revision 1.2 2002/05/13 21:09:28 mharris * I think the last of the networking code has ifndef NO_NETWORK... * * Revision 1.1 2002/05/02 18:03:08 mharris * Initial checkin - converted filenames and includes to lower case * * * 19 10/25/99 5:43p Jefff * reassigned some xstr ids * * 18 10/14/99 2:50p Jefff * localization fixes * * 17 9/02/99 5:09p Jefff * disabled options now draw as a dark gray color * * 16 9/01/99 11:16a Dave * Reverse direction of HUD config RGB sliders. * * 15 8/19/99 3:17p Dave * Fixed talking head disappearing. * * 14 8/19/99 2:33p Dave * Make sure support gauge and net lag gauge are configurable. * * 13 8/16/99 5:25p Dave * New hud config. Whee! * * 12 8/16/99 4:04p Dave * Big honking checkin. * * 11 7/30/99 10:31p Dave * Added comm menu to the configurable hud files. * * 10 7/30/99 11:05a Jasenw * Fixed hud config for new text warning gauge, * * 9 7/24/99 1:54p Dave * Hud text flash gauge. Reworked dead popup to use 4 buttons in red-alert * missions. * * 8 7/15/99 9:20a Andsager * FS2_DEMO initial checkin * * 7 6/08/99 2:33p Dave * Fixed release build warning. Put in hud config stuff. * * 6 6/08/99 1:14a Dave * Multi colored hud test. * * 5 1/30/99 5:08p Dave * More new hi-res stuff.Support for nice D3D textures. * * 4 10/13/98 9:28a Dave * Started neatening up freespace.h. Many variables renamed and * reorganized. Added AlphaColors.[h,cpp] * * 3 10/07/98 11:28a Dave * Removed wacky pragma. * * 2 10/07/98 10:53a Dave * Initial checkin. * * 1 10/07/98 10:49a Dave * * 72 8/25/98 1:48p Dave * First rev of EMP effect. Player side stuff basically done. Next comes * AI code. * * 71 6/09/98 10:31a Hoffoss * Created index numbers for all xstr() references. Any new xstr() stuff * added from here on out should be added to the end if the list. The * current list count can be found in FreeSpace.cpp (search for * XSTR_SIZE). * * 70 6/01/98 11:43a John * JAS & MK: Classified all strings for localization. * * 69 5/24/98 9:01p Lawrance * Add commit sounds when accept is pressed * * 68 5/23/98 3:31p Dave * Tweaked pxo code. Fixed observer HUD stuff. * * 67 5/08/98 10:12a Lawrance * play sound for auto-target toggle, don't display HUD message * * 66 4/29/98 6:00p Dave * Fixed chatbox font colors. Made observer offscreen indicators work. * Numerous small UI fixes. Fix rank limitations for mp games. * * 65 4/20/98 12:04a Lawrance * tweak how button light up * * 64 4/16/98 4:07p Hoffoss * Fixed bug with palette reseting when loading a new pilot. Also made * barracks default to palette merging mode. * * 63 4/16/98 10:48a Lawrance * reposition a couple of gauges * * 62 4/14/98 6:16p Lawrance * Fix bug that was preventing non-green HUD color from getting set. * * 61 4/12/98 5:32p Lawrance * don't show talking head in demo version of hud config * * 60 4/10/98 12:07a Lawrance * Fix up talking head gauge. * * 59 4/08/98 10:15a Lawrance * allow kills gauge to be popup * * 58 4/08/98 1:18a Lawrance * Add in kills gauge art to HUD config. * * 57 4/05/98 7:42p Lawrance * Add kills gauge * * 56 4/03/98 3:13p Dave * More work on udp reliable transport. Fixed observer hud offset problem. * Made observer join and ingame join work again. Put subnet broadcasting * in for TCP. * * 55 4/01/98 6:46p Lawrance * default damage popup to on * * 54 3/31/98 11:47p Lawrance * Add popup functionality for the countermeasure gauge. * * 53 3/30/98 4:48p Lawrance * Turn on offscreen indicator range by default * * 52 3/26/98 5:45p Lawrance * Added new gauges to HUD config * * 51 3/15/98 4:17p Dave * Fixed oberver hud problems. Put in handy netplayer macros. Reduced size * of network orientation matrices. * * 50 3/12/98 5:45p Dave * Put in new observer HUD. Made it possible for observers to join at the * beginning of a game and follow it around as an observer full-time. * * 49 3/11/98 12:13a Lawrance * redraw pressed buttons * * 48 3/05/98 12:39a Lawrance * show comma in 10000 * * 47 2/22/98 4:30p John * More string externalization classification * * 46 2/22/98 4:17p John * More string externalization classification... 190 left to go! * * 45 2/22/98 12:19p John * Externalized some strings * * 44 1/23/98 6:24p Lawrance * Implement wingman status gauge * * 43 1/22/98 10:45p Lawrance * Add coutermeasures and objective display to hud config. * * 42 1/19/98 11:37p Lawrance * Fixing Optimization build warnings * * 41 1/17/98 10:02p Lawrance * Fix bug with damage popup that would sometimes display with . * * 40 1/17/98 1:30a Lawrance * Add countermeasure gauge * * 39 1/15/98 5:10p Allender * ton of interface changes. chatbox in multiplayer now behaves * differently than before. It's always active in any screen that uses * it. Only non-printatble characters will get passed back out from * chatbox * * 38 1/14/98 11:07p Lawrance * Hook in brightness slider to HUD config. * * 37 1/14/98 6:42p Hoffoss * Massive changes to UI code. A lot cleaner and better now. Did all * this to get the new UI_DOT_SLIDER to work properly, which the old code * wasn't flexible enough to handle. * * 36 1/14/98 12:25p Lawrance * center gauge text, use correct game palette. * * 35 1/13/98 5:33p Lawrance * Tweaking HUD config. * * 34 1/13/98 2:20p John * Added code to load palette based on hud color. Added code to turn off * nebulas using detail. Added code in WinMain to time out after waiting * too long for window creation. * * 33 1/13/98 10:22a Lawrance * Integrate new art changes. * * 32 1/12/98 11:16p Lawrance * Wonderful HUD config. * * 31 1/10/98 12:41a Lawrance * start work on new HUD config * * 30 1/05/98 9:38p Lawrance * Implement flashing HUD gauges. * * 29 1/02/98 9:10p Lawrance * Big changes to how colors get set on the HUD. * * 28 12/16/97 9:13p Lawrance * Integrate new gauges into HUD config. * * 27 12/01/97 12:27a Lawrance * redo default alpha color for HUD, make it easy to modify in the future * * * $NoKeywords: $ * */ #include "hud/hudconfig.h" #include "gamesequence/gamesequence.h" #include "playerman/player.h" #include "io/key.h" #include "ui/ui.h" #include "hud/hudobserver.h" #include "gamesnd/gamesnd.h" #include "globalincs/alphacolors.h" #include "globalincs/pstypes.h" #include "popup/popup.h" #include "ship/ship.h" #include "parse/parselo.h" #include "cfile/cfile.h" #include "iff_defs/iff_defs.h" ////////////////////////////////////////////////////////////////////////////// // Game-wide Globals ////////////////////////////////////////////////////////////////////////////// #define MAX_HCF_FILES 30 int HC_num_files = -1; // num known hcf files int HC_current_file = -1; // current hcf file char *HC_filenames[MAX_HCF_FILES]; char HC_fname[MAX_FILENAME_LEN+1] = ""; UI_INPUTBOX HC_fname_input; int HC_fname_coords[GR_NUM_RESOLUTIONS][4] = { { // GR_640 44, 449, 218, 17 }, { // GR_1024 101, 730, 319, 27 } }; HUD_CONFIG_TYPE HUD_config; // Player HUD configuration // specify the max distance that the radar should detect objects // See RR_ #defines in HUDconfig.h. float Radar_ranges[RR_MAX_RANGES] = { 2000.0f, // short 10000.0f, // med 10000000.0f, // infinity }; float Radar_ranges_default[RR_MAX_RANGES] = { 2000.0f, // short 10000.0f, // med 10000000.0f, // infinity }; void Radar_range_stuff_text(char *buf, int n) { int range = (int) Radar_ranges[n]; if (range >= RR_INFINITY_THRESHOLD) { strcpy(buf, XSTR("infinity", 248)); } else { format_integer_with_commas(buf, range, false); strcat(buf, " M"); } } void hud_set_radar_max_range(float range) { for (int i = 0; i < RR_MAX_RANGES; i++) { if (range > 0 && range < Radar_ranges_default[i]) Radar_ranges[i] = range; else Radar_ranges[i] = Radar_ranges_default[i]; } } // default flags for observer HUD int HUD_observer_default_flags = { (1<= 0){ HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV(HUD_config.clr[i].red) ); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV(HUD_config.clr[i].green) ); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV(HUD_config.clr[i].blue) ); HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV(HUD_config.clr[i].alpha) ); } } // reset some ui components based on HUD config data void hud_config_synch_ui() { // game_load_palette(); HUD_init_hud_color_array(); // HC_sliders[gr_screen.res][HC_BRIGHTNESS_SLIDER].slider.pos = HUD_color_alpha-3; // convert to value from 0-10 // sync sliders to currently selected gauge hud_config_synch_sliders(HC_gauge_selected); } // Init the UI components void hud_config_init_ui() { int i; struct HC_gauge_region *hg; struct ui_button_info *hb; // common_set_interface_palette("HUDConfigPalette"); // set the interface palette hud_config_synch_ui(); HC_background_bitmap = bm_load(Hud_config_fname[gr_screen.res]); HC_ui_window.create( 0, 0, gr_screen.max_w_unscaled, gr_screen.max_h_unscaled, 0 ); HC_ui_window.set_mask_bmap(Hud_config_mask_fname[gr_screen.res]); for (i=0; ifilename, NOX("none")) ) { continue; } hg->button.create(&HC_ui_window, "", hg->x, hg->y, 60, 30, 0, 1); // set up callback for when a mouse first goes over a button // hg->button.set_highlight_action(common_play_highlight_sound); hg->button.hide(); hg->button.link_hotspot(hg->hotspot); // if ( hg->use_iff ) { // hg->bitmap = bm_load_animation(hg->filename, &hg->nframes); // } else { hg->bitmap = bm_load(hg->filename); hg->nframes = 1; // } } // add text for(i=0; ibutton.create(&HC_ui_window, "", hb->x, hb->y, 60, 30, 0, 1); // set up callback for when a mouse first goes over a button hb->button.set_bmaps(hb->filename); hb->button.set_highlight_action(common_play_highlight_sound); hb->button.link_hotspot(hb->hotspot); } // config file input name HC_fname_input.create(&HC_ui_window, HC_fname_coords[gr_screen.res][0], HC_fname_coords[gr_screen.res][1], HC_fname_coords[gr_screen.res][2], MAX_FILENAME_LEN, "", UI_INPUTBOX_FLAG_INVIS | UI_INPUTBOX_FLAG_ESC_FOC); HC_fname_input.set_text(""); /* for (i=0; ired, use_color->green, use_color->blue, alpha); gr_set_color_fast(use_color); } else { // if its off, make it dark gray use_color = &HUD_config.clr[i]; gr_init_alphacolor(use_color, 127, 127, 127, 64); gr_set_color_fast(use_color); } // draw if ( HC_gauge_regions[gr_screen.res][i].bitmap >= 0 ) { gr_set_bitmap(HC_gauge_regions[gr_screen.res][i].bitmap); gr_aabitmap(HC_gauge_regions[gr_screen.res][i].x, HC_gauge_regions[gr_screen.res][i].y); } /* else { int offset=0; // set correct frame if using iff if ( HC_gauge_regions[i].use_iff ) { if ( HC_gauge_selected == i ) { offset=2; } else if ( HC_gauge_hot == i ) { offset=1; } // If gauge is disabled, then draw disabled frame if ( !(hud_config_show_flag_is_set(i)) ) { offset=3; } } if ( HC_gauge_regions[i].bitmap >= 0 ) { Assert(offset < HC_gauge_regions[i].nframes); gr_set_bitmap(HC_gauge_regions[i].bitmap+offset); gr_bitmap(HC_gauge_regions[i].x, HC_gauge_regions[i].y); } } */ } } // hud_config_init() is called when the game enters the state GS_STATE_HUD_CONFIG void hud_config_init() { hud_config_init_ui(); hud_config_backup(); // save the HUD configuration in case the player decides to cancel changes HUD_config_inited = 1; } // check for the mouse over gauge regions void hud_config_check_regions() { int i; UI_BUTTON *b; for ( i=0; ibutton_hilighted() ) { HC_gauge_hot = i; } if ( b->pressed() ) { gamesnd_play_iface(SND_USER_SELECT); HC_gauge_selected = i; // turn off select all hud_config_select_all_toggle(0); // maybe setup rgb sliders if(HC_gauge_regions[gr_screen.res][i].use_iff){ HC_color_sliders[HCS_RED].hide(); HC_color_sliders[HCS_GREEN].hide(); HC_color_sliders[HCS_BLUE].hide(); HC_color_sliders[HCS_ALPHA].hide(); HC_color_sliders[HCS_RED].disable(); HC_color_sliders[HCS_GREEN].disable(); HC_color_sliders[HCS_BLUE].disable(); HC_color_sliders[HCS_ALPHA].disable(); } else { HC_color_sliders[HCS_RED].enable(); HC_color_sliders[HCS_GREEN].enable(); HC_color_sliders[HCS_BLUE].enable(); HC_color_sliders[HCS_ALPHA].enable(); HC_color_sliders[HCS_RED].unhide(); HC_color_sliders[HCS_GREEN].unhide(); HC_color_sliders[HCS_BLUE].unhide(); HC_color_sliders[HCS_ALPHA].unhide(); HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV(HUD_config.clr[i].red) ); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV(HUD_config.clr[i].green) ); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV(HUD_config.clr[i].blue) ); HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV(HUD_config.clr[i].alpha) ); } // recalc alpha slider hud_config_recalc_alpha_slider(); } } } // set the display flags for a HUD gauge void hud_config_set_gauge_flags(int gauge_index, int on_flag, int popup_flag) { if ( on_flag ) { hud_config_show_flag_set(gauge_index); } else { hud_config_show_flag_clear(gauge_index); } if ( popup_flag ) { hud_config_popup_flag_set(gauge_index); } else { hud_config_popup_flag_clear(gauge_index); } } void hud_config_record_color(int color) { HUD_config.main_color = color; HUD_color_red = HC_colors[color].r; HUD_color_green = HC_colors[color].g; HUD_color_blue = HC_colors[color].b; } // Set the HUD color void hud_config_set_color(int color) { int idx; hud_config_record_color(color); // game_load_palette(); HUD_init_hud_color_array(); // apply the color to all gauges for(idx=0; idxoff->popup void hud_cycle_gauge_status() { if ( HC_gauge_selected < 0 ) { return; } // gauge is off, move to popup if ( !(hud_config_show_flag_is_set(HC_gauge_selected)) ) { if ( HC_gauge_regions[gr_screen.res][HC_gauge_selected].can_popup ) { hud_config_set_gauge_flags(HC_gauge_selected, 1, 1); } else { hud_config_set_gauge_flags(HC_gauge_selected, 1, 0); } return; } // if gauge is popup, move to on if ( hud_config_popup_flag_is_set(HC_gauge_selected) ) { hud_config_set_gauge_flags(HC_gauge_selected, 1, 0); return; } // gauge must be on, move to off hud_config_set_gauge_flags(HC_gauge_selected, 0, 0); } // handle keyboard input while in hud config void hud_config_handle_keypresses(int k) { switch(k) { case KEY_ESC: hud_config_cancel(); break; case KEY_CTRLED+KEY_ENTER: hud_config_commit(); break; case KEY_TAB: gamesnd_play_iface(SND_USER_SELECT); hud_cycle_gauge_status(); break; } } // Handlers for when buttons get pressed void hud_config_button_do(int n) { int idx; char name[256] = ""; switch (n) { case HCB_AMBER: hud_config_set_color(HUD_COLOR_AMBER); gamesnd_play_iface(SND_USER_SELECT); break; case HCB_BLUE: hud_config_set_color(HUD_COLOR_BLUE); gamesnd_play_iface(SND_USER_SELECT); break; case HCB_GREEN: hud_config_set_color(HUD_COLOR_GREEN); gamesnd_play_iface(SND_USER_SELECT); break; case HCB_ON: if ( HC_gauge_selected < 0 ) { break; } gamesnd_play_iface(SND_USER_SELECT); hud_config_set_gauge_flags(HC_gauge_selected,1,0); break; case HCB_OFF: if ( HC_gauge_selected < 0 ) { break; } gamesnd_play_iface(SND_USER_SELECT); hud_config_set_gauge_flags(HC_gauge_selected,0,0); break; case HCB_POPUP: if ( HC_gauge_selected < 0 ) { break; } gamesnd_play_iface(SND_USER_SELECT); hud_config_set_gauge_flags(HC_gauge_selected,1,1); break; case HCB_RESET: gamesnd_play_iface(SND_RESET_PRESSED); hud_config_select_all_toggle(0); hud_set_default_hud_config(Player); hud_config_synch_ui(); break; case HCB_ACCEPT: hud_config_commit(); break; // new stuff case HCB_RED_UP: if( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) >= 255){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) + 1) ); hud_config_red_slider(); } break; case HCB_GREEN_UP: if( HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) >= 255){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) + 1) ); hud_config_green_slider(); } break; case HCB_BLUE_UP: if( HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) >= 255){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) + 1) ); hud_config_blue_slider(); } break; case HCB_I_UP: if( HCS_CONV(HC_color_sliders[HCS_ALPHA].get_currentItem()) >= 255){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_ALPHA].get_currentItem()) + 1) ); hud_config_alpha_slider_up(); } break; case HCB_RED_DOWN: if( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) <= 0){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) - 1) ); hud_config_red_slider(); } break; case HCB_GREEN_DOWN: if( HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) <= 0){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) - 1) ); hud_config_green_slider(); } break; case HCB_BLUE_DOWN: if( HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) <= 0){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) - 1) ); hud_config_blue_slider(); } break; case HCB_I_DOWN: if( HCS_CONV(HC_color_sliders[HCS_ALPHA].get_currentItem()) <= 0){ gamesnd_play_iface(SND_GENERAL_FAIL); } else { gamesnd_play_iface(SND_USER_SELECT); HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV( HCS_CONV(HC_color_sliders[HCS_ALPHA].get_currentItem()) - 1) ); hud_config_alpha_slider_down(); } break; case HCB_SAVE_HCF: int exists; char *out; // get the text in the input control exists = 0; HC_fname_input.get_text(name); if(strlen(name) > 0){ // if the filename in there already exists for(idx=0; idx= MAX_HCF_FILES){ popup(PF_USE_AFFIRMATIVE_ICON, 1, "OK", "Max number of hud config files reached!"); break; } // save the file, maybe generating a new filename if(strlen(name) <= 0){ sprintf(name, "hud_%d.hcf", HC_num_files + 1); out = name; } else { out = cf_add_ext(name, ".hcf"); } HC_filenames[HC_num_files++] = vm_strdup(out); hud_config_color_save(out); HC_fname_input.set_text(out); break; case HCB_PREV_HCF: if(HC_num_files <= 0){ break; } if(HC_current_file <= 0){ HC_current_file = HC_num_files - 1; } else { HC_current_file--; } // load em up hud_config_color_load(HC_filenames[HC_current_file]); hud_config_synch_ui(); HC_fname_input.set_text(HC_filenames[HC_current_file]); break; case HCB_NEXT_HCF: if(HC_num_files <= 0){ break; } if(HC_current_file >= HC_num_files - 1){ HC_current_file = 0; } else { HC_current_file++; } // load em up hud_config_color_load(HC_filenames[HC_current_file]); hud_config_synch_ui(); HC_fname_input.set_text(HC_filenames[HC_current_file]); break; case HCB_SELECT_ALL: hud_config_select_all_toggle(!HC_select_all); break; default: Int3(); break; } } // Check if any buttons have been pressed void hud_config_check_buttons() { int i; UI_BUTTON *b; for ( i=0; ipressed() ) { hud_config_button_do(i); } } } // set the hud color button void hud_config_draw_color_status() { if ( HC_buttons[gr_screen.res][HCB_AMBER].button.button_down() || HC_buttons[gr_screen.res][HCB_GREEN].button.button_down() || HC_buttons[gr_screen.res][HCB_BLUE].button.button_down() ) { return; } switch(HUD_config.main_color) { case HUD_COLOR_AMBER: HC_buttons[gr_screen.res][HCB_AMBER].button.draw_forced(2); break; case HUD_COLOR_GREEN: HC_buttons[gr_screen.res][HCB_GREEN].button.draw_forced(2); break; case HUD_COLOR_BLUE: HC_buttons[gr_screen.res][HCB_BLUE].button.draw_forced(2); break; } } // set the status (on/off/popup) for the selected gauge void hud_config_draw_gauge_status() { if ( HC_gauge_selected < 0 ) { return; } if ( HC_buttons[gr_screen.res][HCB_OFF].button.button_down() || HC_buttons[gr_screen.res][HCB_POPUP].button.button_down() || HC_buttons[gr_screen.res][HCB_ON].button.button_down() ) { return; } // check if off if ( !(hud_config_show_flag_is_set(HC_gauge_selected)) ) { HC_buttons[gr_screen.res][HCB_OFF].button.draw_forced(2); return; } // check if popup if ( hud_config_popup_flag_is_set(HC_gauge_selected) ) { HC_buttons[gr_screen.res][HCB_POPUP].button.draw_forced(2); return; } // check if on if ( hud_config_show_flag_is_set(HC_gauge_selected) ) { HC_buttons[gr_screen.res][HCB_ON].button.draw_forced(2); return; } Int3(); // should never get here } // disable a HUD config button void hud_config_button_disable(int index) { // HC_buttons[gr_screen.res][index].button.hide(); HC_buttons[gr_screen.res][index].button.disable(); } // enable a HUD config button void hud_config_button_enable(int index) { // HC_buttons[gr_screen.res][index].button.unhide(); HC_buttons[gr_screen.res][index].button.enable(); } // determine if on/off/popup buttons should be shown void hud_config_set_button_state() { if ( HC_gauge_selected < 0 ) { hud_config_button_disable(HCB_ON); hud_config_button_disable(HCB_OFF); hud_config_button_disable(HCB_POPUP); return; } // on/off are always on hud_config_button_enable(HCB_ON); hud_config_button_enable(HCB_OFF); // popup is maybe available if ( HC_gauge_regions[gr_screen.res][HC_gauge_selected].can_popup ) { hud_config_button_enable(HCB_POPUP); } else { hud_config_button_disable(HCB_POPUP); } } void hud_config_render_description() { int w,h,sx,sy; if ( HC_gauge_selected >= 0 ) { gr_set_color_fast(&Color_normal); gr_get_string_size(&w, &h, HC_gauge_descriptions(HC_gauge_selected)); sx = fl2i(HC_gauge_description_coords[gr_screen.res][0] + (HC_gauge_description_coords[gr_screen.res][2] - w)/2.0f); sy = HC_gauge_description_coords[gr_screen.res][1]; gr_string(sx, sy, HC_gauge_descriptions(HC_gauge_selected)); } } void hud_config_render_special_bitmaps() { /* int i; for (i=1; i= 0) { gr_set_bitmap(HC_special_bitmaps[i].bitmap); gr_bitmap(HC_special_bitmaps[i].x, HC_special_bitmaps[i].y); } } */ } // update HUD_color_alpha based on brightness slider void hud_config_update_brightness() { // HUD_color_alpha = HC_sliders[gr_screen.res][HC_BRIGHTNESS_SLIDER].slider.pos+3; // Assert(HUD_color_alpha >= HUD_COLOR_ALPHA_USER_MIN); // Assert(HUD_color_alpha <= HUD_COLOR_ALPHA_USER_MAX); } // redraw any pressed buttons, needed since the glow on pressed buttons might get clipped off by // adjacent buttons otherwise void hud_config_redraw_pressed_buttons() { int i; UI_BUTTON *b; for ( i = 0; i < NUM_HUD_BUTTONS; i++ ) { b = &HC_buttons[gr_screen.res][i].button; if ( b->button_down() ) { b->draw_forced(2); } } } // hud_config_do_frame() is called from the main freespace loop while the game is in the state // GS_STATE_HUD_CONFIG. // void hud_config_do_frame(float frametime) { int k; if (!HUD_config_inited) { hud_config_init(); } HC_gauge_hot = -1; hud_config_set_button_state(); k = HC_ui_window.process(); hud_config_handle_keypresses(k); hud_config_check_regions(); hud_config_check_buttons(); hud_config_update_brightness(); // set the background GR_MAYBE_CLEAR_RES(HC_background_bitmap); if ( HC_background_bitmap > 0 ) { gr_set_bitmap(HC_background_bitmap); gr_bitmap(0,0); } // rgb slider/button stuff hud_config_process_colors(); HC_ui_window.draw(); hud_config_redraw_pressed_buttons(); hud_config_draw_gauge_status(); hud_config_draw_color_status(); /* if (HC_special_bitmaps[HC_SPECIAL_RETICLE].bitmap >= 0) { hud_set_default_color(); gr_set_bitmap(HC_special_bitmaps[HC_SPECIAL_RETICLE].bitmap); gr_aabitmap(HC_special_bitmaps[HC_SPECIAL_RETICLE].x, HC_special_bitmaps[HC_SPECIAL_RETICLE].y); } */ // maybe force draw the select all button if(HC_select_all){ HC_buttons[gr_screen.res][HCB_SELECT_ALL].button.draw_forced(2); } hud_config_render_gauges(); hud_config_render_special_bitmaps(); hud_config_render_description(); gr_flip(); } void hud_config_unload_gauges() { int i; HC_gauge_region *hg; for (i=0; ibitmap >= 0 ) { bm_release(hg->bitmap); } hg->bitmap=-1; hg->nframes=0; } } // hud_config_close() is called when the player leaves the hud configuration screen // void hud_config_close() { // common_free_interface_palette(); // restore game palette hud_config_unload_gauges(); hud_init_popup_timers(); // ensure no popup gauges are active hud_config_color_close(); HC_ui_window.destroy(); } // hud_set_default_hud_config() will set the hud configuration to default values void hud_set_default_hud_config(player *p) { int idx; HUD_color_alpha = HUD_COLOR_ALPHA_DEFAULT; HUD_config.main_color = HUD_COLOR_GREEN; HUD_color_red = HC_colors[HUD_config.main_color].r; HUD_color_green = HC_colors[HUD_config.main_color].g; HUD_color_blue = HC_colors[HUD_config.main_color].b; for(idx=0; idx= 255){ HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV(pos - 1) ); return; } // otherwise bump everybody up by one HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) + 1) ); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) + 1) ); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) + 1) ); // apply if(HC_select_all){ hud_config_stuff_colors( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) ); } else { gr_init_alphacolor(&HUD_config.clr[HC_gauge_selected], HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()), 255); } } void hud_config_alpha_slider_down() { int pos = HCS_CONV(HC_color_sliders[HCS_ALPHA].get_currentItem()); int min = MIN(MIN( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) ), HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) ); // if this would put the brightest element past its limit, skip if(min <= 0){ HC_color_sliders[HCS_ALPHA].force_currentItem( HCS_CONV(pos + 1) ); return; } // otherwise bump everybody up by one HC_color_sliders[HCS_RED].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) - 1) ); HC_color_sliders[HCS_GREEN].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()) - 1) ); HC_color_sliders[HCS_BLUE].force_currentItem( HCS_CONV(HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) - 1) ); // apply if(HC_select_all){ hud_config_stuff_colors( HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()) ); } else { gr_init_alphacolor(&HUD_config.clr[HC_gauge_selected], HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_GREEN].get_currentItem()), HCS_CONV(HC_color_sliders[HCS_BLUE].get_currentItem()), 255); } } void hud_config_recalc_alpha_slider() { int avg =HC_color_sliders[HCS_RED].get_currentItem() + HC_color_sliders[HCS_GREEN].get_currentItem() + HC_color_sliders[HCS_BLUE].get_currentItem(); avg /= 3; HC_color_sliders[HCS_ALPHA].force_currentItem( avg ); } void hud_config_red_slider() { int idx; int pos = HCS_CONV(HC_color_sliders[HCS_RED].get_currentItem()) ; // select all ? if(HC_select_all){ for(idx=0; idx