Commit Graph

428 Commits

Author SHA1 Message Date
Rubidium d183d8e587 Codechange: remove INVALID_STRING_ID now drop down uses spans 2024-04-28 18:47:31 +02:00
Rubidium 546a996d95 Codechange: pass options to ShowDropDownMenu using a span 2024-04-28 18:47:31 +02:00
Peter Nelson 33aedc43a5 Codechange: Shrink GUIList vectors less often, reserve before use.
After sorting and filter lists for GUI, we often shirnk them to reduce size. However this has very little benefit:

1) The memory has already been allocated, so it doesn't prevent that memory being required.
2) It causes a new allocation and copy when the vector is shrunk, actually using more memory.
3) The list is in window state, so the lifetime is only while the window is open.
4) When a filter is clearer, the original size will be needed again, which will cause another allocation.

In fact it is beneficial to reserve to the known maximum in most cases, so do that instead.
2024-04-27 19:25:34 +01:00
Peter Nelson f44d8fa2e4
Codechange: Remove CDECL from filter functions. (#12578)
These functions are not passed to qsort()...
2024-04-25 22:13:23 +01:00
Peter Nelson 0075a95278
Codefix: Make three _filter_funcs definitions distinct. (#12573)
Rename the GUIList function lists defined as the same symbol.
2024-04-25 21:01:15 +01:00
Rubidium b2218e75d4 Codefix: missing space between close parenthesis and open curly brace 2024-04-16 19:28:09 +02:00
Peter Nelson dc7c2bb30d
Fix: Draw continuation lines for engine variant hierarchy tree. (#12434) 2024-04-09 08:35:12 +01:00
Peter Nelson de4e00c93f
Codechange: Pass by reference to UpdateWidgetSize. (#12457)
These parameters are always provided and not optional.
2024-04-09 08:34:45 +01:00
Peter Nelson 56cac21086 Codechange: Use functions to create common drop down list items. 2024-04-01 22:33:16 +01:00
Peter Nelson d683ec0183
Codechange: Move dropdown and slider out of widgets directory. (#12403)
Also shuffle headers to place widget includes near end.

This leaves the widgets directory solely for defining Widget IDs.
2024-03-31 19:37:16 +01:00
Patric Stout a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 2024-03-16 23:59:32 +01:00
Rubidium 86cb184eb4 Codechange: use std::source_location over __FILE__ and __LINE__ for WindowDesc 2024-03-10 10:14:20 +01:00
Peter Nelson a61311fcb0 Codefix: DrawEngineList does not accept EngineID.
Replace min/max parameters of DrawEngineList with scrollbar reference, and use iterators instead of indices.
2024-02-27 17:18:53 +00:00
Peter Nelson 912d7bd80e Codechange: Give ColourShade values names instead of numbers. 2024-02-25 12:38:07 +00:00
Peter Nelson ae3390fe48 Codechange: Add ColourShade enum. 2024-02-25 12:38:07 +00:00
Peter Nelson 0463d4c198 Codechange: Remove direct access to _colour_gradient.
Access is now through GetColourGradient, which ensures parameters are in range.
2024-02-25 12:38:07 +00:00
Peter Nelson 2b79e7cdf5
Fix b7630b0: Incorrect padding for text purchase list. (#12160)
Restore to original (and more normal) framerect padding.
2024-02-22 22:23:29 +00:00
Peter Nelson 2fd9096070
Change: Decouple and remove landscape-dependent cargo types. (#11719)
Cargo types of default engines, industries and houses are now specified in terms of label.
2024-02-04 10:16:08 +00:00
frosch 68c64d2511 Codechange: Remove TKM string codes by duplicating strings. 2024-01-28 14:44:24 +01:00
Peter Nelson 7737aa6640 Codechange: Make all NWidgetPart arrays constexpr.
This ensures that the arrays are not created at runtime and prevents using non-constexpr values.
2024-01-16 21:57:05 +00:00
Peter Nelson 71aaed860b
Codechange: Missing some conversions to WidgetID. (#11773) 2024-01-14 16:47:10 +00:00
Jonathan G Rennison 1101b04371 Fix: Build button text when train purchase window using "Engines" filter 2024-01-12 16:34:39 +01:00
Peter Nelson 400ae65ff2 Codechange: Redefine some cargo-related values in terms of CargoID instead of CargoType.
Values used as special filter types are now defined as offsets from NUM_CARGO instead of confusingly reusing CARGO_NO_REFIT/CARGO_AUTO_REFIT types.
2024-01-09 18:56:05 +00:00
Peter Nelson 952d111b94 Codechange: Split CT_INVALID into CT_INVALID and INVALID_CARGO.
INVALID_CARGO is a CargoID and should be used for most purposes in game.
CT_INVALID is a CargoType used for defining default properties.
2024-01-09 18:56:05 +00:00
Peter Nelson a0dfb76e34 Codechange: Replace mishmash of types for widget index with WidgetID.
Indices were stored as int, but often passed around as uint/uint8_t and casts.

Now they should all use WidgetID.
2023-12-30 00:23:57 +00:00
Peter Nelson 33ff64ef74
Codechange: Simplify ConvertDateToYMD by returning YearMonthDay instead of outputting to a pointer. (#11637) 2023-12-28 21:34:08 +00:00
Peter Nelson 58c252b81a Cleanup: Remove unnecessary pressed button offset code. 2023-12-05 21:12:35 +00:00
Peter Nelson 1aedea8eda Feature: Place cargo icon on cargo filter dropdowns.
Reveal the pixel art.
2023-12-02 15:23:05 +00:00
Peter Nelson 47eabe0cd9
Fix 7cfcf65: Check if last-remembered build vehicle cargo filter is valid. (#11486)
This can be invalid when switching between games with different cargoes loaded.
2023-11-23 22:46:22 +00:00
Peter Nelson c18a1494b7
Codechange: Remove FONT_HEIGHT_... macros. (#11481)
These make it look like we're dealing with a constant, but actually each is a call to `GetCharacterHeight(...)`.
2023-11-21 19:04:24 +00:00
Peter Nelson 7cfcf65f95 Codechange: Simplify cargo filter lists, building only when required.
Some cargo filter lists were built in advance, and used as lookups to test which cargo type to filter.

Instead, use the Cargo ID directly as the filter parameter, and build the lists only when the drop down list is used.
2023-11-13 21:30:46 +00:00
Peter Nelson ab535c0a86
Codechange: Add base() method to StrongType to allow access to the base type without casting. (#11445)
This removes the ability to explicitly cast to the base type, but the requirement
to use .base() means the conversion is still explicit.
2023-11-06 20:29:35 +00:00
Peter Nelson 18fb8e153f Codechange: Add __FILE__/__LINE__ of WindowDesc to WindowDesc.
This is to allow unit-tests to produce more useful output.
2023-11-02 22:25:01 +00:00
Peter Nelson bb6fa9bf3b
Change: Display cargo lists in sorted cargo order. (#11383) 2023-10-20 17:32:17 +01:00
merni-ns c794676928
Fix #10763, Fix #11168: Display variant groups that consist only of unavailable sub-groups (#11342) 2023-10-03 12:43:15 +00:00
Peter Nelson 5869f790d8
Fix: Check for engine variant loops during NewGRF initialization. (#11343)
Invalid NewGRFs could set up an engine variant loop that never ends. This
was checked for in some places that evaluated variants, but not all. In
most cases this would result in the engines not appearing, but could
potentially cause an infinite loop and crash.

Instead, during NewGRF initialization detect loops and remove invalid
variants before setting display flags.
2023-10-03 12:14:32 +01:00
PeterN 48dc4219ea
Codechange: Don't pass GUI cargo filter constants to command system. (#11320)
CMD_BUILD_VEHICLE expects CT_INVALID to indicate a new vehicle should not
be refitted on build, but the code passed CF_NONE instead. CF_NONE has the
same numeric value at CT_INVALID, so the test passed, but...
2023-09-20 08:56:53 +01:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
Rubidium 8ab0936491 Codechange: use parameter pack/folding instead of va_arg macros for widget states 2023-09-16 23:09:53 +02:00
Daniel Robinson 71c2878799
Fix #10600: 'Replace Vehicles' didn't show numbers >999 (#10680) 2023-09-13 15:19:44 +00:00
PeterN acd7d3c913
Codechange: Rename *Railtype* to *RailType* for consistency. (#11287) 2023-09-11 08:55:12 +00:00
Tyler Trahan 77173a6a10 Codechange: Move date consts and functions to CalendarTime and TimerGameCalendar classes 2023-09-10 08:40:25 -04:00
Peter Nelson e8015e497d Codechange: Use begin/end of nwidget parts of begin/length.
This simplifies processing nwidget parts as, unlike the remaining length, the pointer to the end of the list never changes. This is the same principle as we use(d) for tracking end instead of length for C-style strings.

And this removes 160~ instances of the lengthof() macro.
2023-09-04 10:20:45 +01:00
Patric Stout 07730584d7
Codechange: make explicit when a TileIndex is cast to its basetype (#11190)
This prevents people accidentially assigning a TileIndex to a Date
or any other type they shouldn't.
2023-08-15 18:12:05 +02:00
Tyler Trahan 6190f48df0
Codechange: Add a DateToYear function instead of dividing each time (#11173) 2023-08-11 08:19:54 -04:00
Tyler Trahan 93069066f9
Codechange: Use auto type when sorting dates (#11175) 2023-08-11 08:18:32 -04:00
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
2023-07-19 19:30:14 +02:00
merni-ns b3669a8795
Fix #11026: Use real engine name instead of default name for filtering (#11033) 2023-06-19 01:03:32 +02:00
PeterN f814c86389
Codechange: Reorganise hotkey initialisation. (#10951)
Hotkeys are now initialized inline, and use std::vector instead of
separate static C-arrays and std::string instead of char *. The list end
marker is no longer required.
2023-06-05 18:12:30 +01:00
Rubidium f29606fd14 Codechange: use std::string to cache engine/group/vehicle names 2023-05-31 19:31:09 +02:00