diff -r 5a9dc001e1ad -r 1c4a4a609f85 src/misc_gui.cpp --- a/src/misc_gui.cpp Mon Dec 03 23:39:38 2007 +0000 +++ b/src/misc_gui.cpp Tue Jan 22 21:00:30 2008 +0000 @@ -6,43 +6,48 @@ #include "openttd.h" #include "heightmap.h" #include "debug.h" -#include "functions.h" #include "landscape.h" #include "newgrf.h" #include "newgrf_text.h" #include "saveload.h" -#include "strings.h" +#include "tile_map.h" +#include "gui.h" +#include "window_gui.h" +#include "station_gui.h" +#include "textbuf_gui.h" +#include "viewport_func.h" +#include "gfx_func.h" +#include "station.h" +#include "command_func.h" +#include "player_func.h" +#include "player_base.h" +#include "town.h" +#include "network/network.h" +#include "variables.h" +#include "train.h" +#include "tgp.h" +#include "cargotype.h" +#include "player_face.h" +#include "strings_func.h" +#include "fileio.h" +#include "fios.h" +#include "tile_cmd.h" +#include "zoom_func.h" +#include "functions.h" +#include "window_func.h" +#include "date_func.h" +#include "sound_func.h" +#include "string_func.h" +#include "player_gui.h" +#include "settings_type.h" + #include "table/sprites.h" #include "table/strings.h" -#include "strings.h" #include "table/tree_land.h" -#include "map.h" -#include "window.h" -#include "gui.h" -#include "viewport.h" -#include "gfx.h" -#include "station.h" -#include "command.h" -#include "player.h" -#include "town.h" -#include "sound.h" -#include "network/network.h" -#include "string.h" -#include "variables.h" -#include "vehicle.h" -#include "train.h" -#include "tgp.h" -#include "settings.h" -#include "date.h" -#include "cargotype.h" -#include "player_face.h" -#include "fileio.h" -#include "fileio.h" -#include "fios.h" /* Variables to display file lists */ FiosItem *_fios_list; -int _saveload_mode; +SaveLoadDialogMode _saveload_mode; static bool _fios_path_changed; @@ -210,18 +215,22 @@ "Original graphics by Simon Foster", "", "The OpenTTD team (in alphabetical order):", - " Jean-Francois Claeys (Belugas) - In training, not yet specialized", - " Bjarni Corfitzen (Bjarni) - MacOSX port, coder", - " Matthijs Kooijman (blathijs) - Pathfinder-guru", - " Victor Fischer (Celestar) - Programming everywhere you need him to", - " Tamás Faragó (Darkvater) - Lead coder", - " Loïc Guilloux (glx) - In training, not yet specialized", + " Jean-Francois Claeys (Belugas) - GUI, newindustries and more", + " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles", + " Matthijs Kooijman (blathijs) - Pathfinder-guru, pool rework", + " Loïc Guilloux (glx) - General coding", " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;)", " Jonathan Coome (Maedhros) - High priest of the newGRF Temple", " Attila Bán (MiHaMiX) - WebTranslator, Nightlies, Wiki and bugtracker host", " Owen Rudge (orudge) - Forum host, OS/2 port", - " Peter Nelson (peter1138) - Spiritual descendant from newgrf gods", - " Remko Bijker (Rubidium) - THE desync hunter", + " Peter Nelson (peter1138) - Spiritual descendant from newGRF gods", + " Remko Bijker (Rubidium) - Lead coder and way more", + " Benedikt Brüggemeier (skidd13) - Bug fixer and code reworker", + " Zdenek Sojka (SmatZ) - Bug finder and fixer", + "", + "Inactive Developers:", + " Victor Fischer (Celestar) - Programming everywhere you need him to", + " Tamás Faragó (Darkvater) - Ex-Lead coder", " Christoph Mallon (Tron) - Programmer, code correctness police", "", "Retired Developers:", @@ -233,9 +242,9 @@ "Special thanks go out to:", " Josef Drexler - For his great work on TTDPatch", " Marcin Grzegorczyk - For his documentation of TTD internals", - " Petr Baudis (pasky) - Many patches, newgrf support", + " Petr Baudis (pasky) - Many patches, newGRF support", " Stefan Meißner (sign_de) - For his work on the console", - " Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with (and PBS)", + " Simon Sasburg (HackyKid) - Many bugfixes he has blessed us with", " Cian Duffy (MYOB) - BeOS port / manual writing", " Christian Rosentreter (tokai) - MorphOS / AmigaOS port", " Richard Kempton (richK) - additional airports, initial TGP implementation", @@ -256,7 +265,7 @@ { switch (e->event) { case WE_CREATE: // Set up window counter and start position of scroller - WP(w, scroller_d).counter = 0; + WP(w, scroller_d).counter = 5; WP(w, scroller_d).height = w->height - 40; break; case WE_PAINT: { @@ -282,8 +291,9 @@ DoDrawStringCentered(210, w->height - 25, "Website: http://www.openttd.org", TC_BLACK); DrawStringCentered(210, w->height - 15, STR_00BA_COPYRIGHT_OPENTTD, TC_FROMSTRING); } break; - case WE_MOUSELOOP: // Timer to scroll the text and adjust the new top - if (WP(w, scroller_d).counter++ % 3 == 0) { + case WE_TICK: // Timer to scroll the text and adjust the new top + if (--WP(w, scroller_d).counter == 0) { + WP(w, scroller_d).counter = 5; WP(w, scroller_d).height--; SetWindowDirty(w); } @@ -338,8 +348,8 @@ DrawWindowWidgets(w); - WP(w,tree_d).base = i = _tree_base_by_landscape[_opt.landscape]; - WP(w,tree_d).count = count = _tree_count_by_landscape[_opt.landscape]; + WP(w, tree_d).base = i = _tree_base_by_landscape[_opt.landscape]; + WP(w, tree_d).count = count = _tree_count_by_landscape[_opt.landscape]; x = 18; y = 54; @@ -364,10 +374,10 @@ case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11:case 12: case 13: case 14: - if (wid - 3 >= WP(w,tree_d).count) break; + if (wid - 3 >= WP(w, tree_d).count) break; if (HandlePlacePushButton(w, wid, SPR_CURSOR_TREE, VHM_RECT, NULL)) - _tree_to_plant = WP(w,tree_d).base + wid - 3; + _tree_to_plant = WP(w, tree_d).base + wid - 3; break; case 15: // tree of random type. @@ -406,7 +416,7 @@ break; case WE_ABORT_PLACE_OBJ: - RaiseWindowButtons(w); + w->RaiseButtons(); break; } } @@ -721,7 +731,7 @@ void GuiShowTooltipsWithArgs(StringID str, uint paramcount, const uint64 params[]) { char buffer[512]; - BoundingRect br; + Dimension br; Window *w; uint i; int x, y; @@ -772,7 +782,7 @@ b = InlineString(b, STR_000D_ACCEPTS); for (CargoID i = 0; i < NUM_CARGO; i++) { - if (b >= lastof(_userstring) - 5) break; + if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode() switch (sct) { case SCT_PASSENGERS_ONLY: if (!IsCargoInClass(i, CC_PASSENGERS)) continue; break; case SCT_NON_PASSENGERS_ONLY: if (IsCargoInClass(i, CC_PASSENGERS)) continue; break; @@ -795,6 +805,10 @@ if (first) b = InlineString(b, STR_00D0_NOTHING); *b = '\0'; + + /* Make sure we detect any buffer overflow */ + assert(b < endof(_userstring)); + DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144); } @@ -1016,24 +1030,24 @@ case WKC_RETURN: case WKC_NUM_ENTER: return 1; case (WKC_CTRL | 'V'): if (InsertTextBufferClipboard(&string->text)) - InvalidateWidget(w, wid); + w->InvalidateWidget(wid); break; case (WKC_CTRL | 'U'): DeleteTextBufferAll(&string->text); - InvalidateWidget(w, wid); + w->InvalidateWidget(wid); break; case WKC_BACKSPACE: case WKC_DELETE: if (DeleteTextBufferChar(&string->text, e->we.keypress.keycode)) - InvalidateWidget(w, wid); + w->InvalidateWidget(wid); break; case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME: if (MoveTextBufferPos(&string->text, e->we.keypress.keycode)) - InvalidateWidget(w, wid); + w->InvalidateWidget(wid); break; default: if (IsValidChar(e->we.keypress.key, string->afilter)) { if (InsertTextBufferChar(&string->text, e->we.keypress.key)) { - InvalidateWidget(w, wid); + w->InvalidateWidget(wid); } } else { // key wasn't caught. Continue only if standard entry specified e->we.keypress.cont = (string->afilter == CS_ALPHANUMERAL); @@ -1057,7 +1071,7 @@ void HandleEditBox(Window *w, querystr_d *string, int wid) { - if (HandleCaret(&string->text)) InvalidateWidget(w, wid); + if (HandleCaret(&string->text)) w->InvalidateWidget(wid); } void DrawEditBox(Window *w, querystr_d *string, int wid) @@ -1491,11 +1505,7 @@ } GfxFillRect(w->widget[7].left + 1, w->widget[7].top + 1, w->widget[7].right, w->widget[7].bottom, 0xD7); - DoDrawString( - _savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW, - _savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9, - 15, TC_BLACK - ); + DrawSortButtonState(w, _savegame_sort_order & SORT_BY_NAME ? 2 : 3, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP); y = w->widget[7].top + 1; for (pos = w->vscroll.pos; pos < _fios_num; pos++) { @@ -1564,7 +1574,7 @@ /* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */ ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength); UpdateTextBufferSize(&WP(w, querystr_d).text); - InvalidateWidget(w, 10); + w->InvalidateWidget(10); } } else { /* Changed directory, need repaint. */ @@ -1591,7 +1601,7 @@ if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { if (HandleEditBoxKey(w, &WP(w, querystr_d), 10, e) == 1) // Press Enter - HandleButtonClick(w, 12); + w->HandleButtonClick(12); } break; case WE_TIMEOUT: @@ -1661,7 +1671,18 @@ SaveLoadDlgWndProc, }; -void ShowSaveLoadDialog(int mode) +/** These values are used to convert the file/operations mode into a corresponding file type. + * So each entry, as expressed by the related comment, is based on the enum */ +static const FileType _file_modetotype[] = { + FT_SAVEGAME, ///< used for SLD_LOAD_GAME + FT_SCENARIO, ///< used for SLD_LOAD_SCENARIO + FT_SAVEGAME, ///< used for SLD_SAVE_GAME + FT_SCENARIO, ///< used for SLD_SAVE_SCENARIO + FT_HEIGHTMAP, ///< used for SLD_LOAD_HEIGHTMAP + FT_SAVEGAME, ///< SLD_NEW_GAME +}; + +void ShowSaveLoadDialog(SaveLoadDialogMode mode) { static const StringID saveload_captions[] = { STR_4001_LOAD_GAME, @@ -1682,6 +1703,9 @@ _saveload_mode = mode; SetBit(_no_scroll, SCROLL_SAVE); + /* Use an array to define what will be the current file type being handled + * by current file mode */ + _file_to_saveload.filetype = _file_modetotype[mode]; switch (mode) { case SLD_SAVE_GAME: GenerateFileName(); break; case SLD_SAVE_SCENARIO: strcpy(_edit_str_buf, "UNNAMED"); break; @@ -1847,7 +1871,7 @@ { switch (e->event) { case WE_PAINT: { - int clk = WP(w,def_d).data_1; + int clk = WP(w, def_d).data_1; int x, y; int i; @@ -1926,7 +1950,7 @@ switch (ce->type) { case SLE_BOOL: - if (ce->flags & CE_CLICK) WP(w,def_d).data_1 = btn * 2 + 1; + if (ce->flags & CE_CLICK) WP(w, def_d).data_1 = btn * 2 + 1; value ^= 1; if (ce->proc != NULL) ce->proc(value, 0); break; @@ -1944,7 +1968,7 @@ value = ce->proc(value, (x >= 30) ? 1 : -1); if (value != oldvalue) { - WP(w,def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0); + WP(w, def_d).data_1 = btn * 2 + 1 + ((x >= 30) ? 1 : 0); } } break; } @@ -1960,7 +1984,7 @@ } break; case WE_TIMEOUT: - WP(w,def_d).data_1 = 0; + WP(w, def_d).data_1 = 0; SetWindowDirty(w); break; }