Commit Graph

454 Commits

Author SHA1 Message Date
Rubidium bab5a8a787 Codechange: use std::source_location over __FILE__ and __LINE__ for Backup 2024-03-10 10:14:20 +01:00
Peter Nelson d4f0f0e2c5
Codechange: Use `GetVisibleRangeIterators()` in more places. (#12190)
This replaces more first/last index calculation, along with indexed array/vector access, with iterator access instead.
2024-02-27 20:10:06 +00:00
Peter Nelson 481fa7dbb5
Change: Show cargo icons on Industry View window. (#12071) 2024-02-12 00:50:58 +00:00
Peter Nelson d6f34a21e8
Codefix: Incorrect storage type in cargo field of industry cargo chains window. (#12051)
`supp_cargoes` and `cust_cargoes` actually contains a column index, however this index is always stored at the indexed position...

Replace with a bitmask instead, which stores if the column indices are linked.
2024-02-11 23:05:29 +00:00
frosch b1718478c8 Codechange: Replace old non-standard attributes with C++17/20 standard attributes. 2024-02-02 22:29:28 +01:00
Peter Nelson 2e6c6b719f Change: Link houses production on industry chain graph by TPE_PASSENGERS or TPE_MAIL cargo. 2024-02-02 20:37:49 +00:00
Tyler Trahan 41f2eed425
Feature: Settings to scale cargo production of towns and industries (#10606) 2024-01-30 15:11:46 -05: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 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 313ee13e5f Codechange: Add Rect version of FillDrawPixelInfo().
This simplifies most callers as they longer have to split out a rect.
2023-12-20 09:29:28 +00:00
Finn Willard 3a42340db3 Add: Hotkey to focus industry directory filter box
Co-authored-by: Tyler Trahan <tyler@tylertrahan.com>
2023-12-19 11:23:37 -05:00
Peter Nelson 12bb750128
Codechange: Cargo filters no longer take an index. (#11582)
Update naming of functions to reflect that parameter is now a cargoid.
2023-12-14 01:48:45 +00:00
Peter Nelson 8186182e4c Codechange: Set displayed plane earlier to avoid ReInit. 2023-12-10 12:01:55 +00:00
Peter Nelson dcf730f1f6 Codechange: Optionally allow passing state to GUIList sorter function.
GUIList sorter functions can currently only use global state, which makes per-window-instance sorting difficult.
2023-12-04 08:24:39 +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 6f7153bf71
Codechange: Make a generic DrawRectOutline function from DrawOutline. (#11524)
This allows drawing an outline from Rect, not just constrained to a Widget's Rect. And reduces duplication a little.
2023-11-30 18:10:07 +00:00
Peter Nelson 09d01bd015
Fix: Restore original cargo legend 'blob' dimensions. (#11480)
An off-by-one in a previous life made the 'blob' too narrow.
2023-11-21 19:51:24 +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 badce415ea Change: Add horizontal scrollbar to Industry Directory window.
This list could be very wide depending on industries and language.
2023-11-05 22:22:32 +00:00
Peter Nelson 8ff6562b2f Codechange: Reduce variable scope. 2023-11-05 22:22:32 +00:00
Peter Nelson 6b9dc8cfcf Codechange: Don't filter industry list by cargo type every 3-sec refresh.
The 3-sec refresh is to update the list sorting. The filter only needs to
be applied once rebuilding the list.
2023-11-05 22:22:32 +00:00
Peter Nelson 4033750968 Codechange: Remove redundant NWID_VERTICAL in Industry Directory layout. 2023-11-05 22:22:32 +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 ff5e8bb9a3 Fix #11413: Incorrect sorting by industry production.
Error caused by single character mistake. However this algorithm was inefficent if a filter was specified, and clearly the flow was error-prone.

Now using separately-scoped loops to avoid similar.
2023-11-01 21:37:53 +00:00
Rubidium c9276c2959 Codechange: replace x.size() == 0 with x.empty() 2023-10-20 23:05:43 +02:00
Peter Nelson fd6f1e844a
Codechange: Avoid emplace_back(new()) into a unique_ptr. (#11384)
This could theoretically leave an unmanaged pointer in certain circumstances, and directly using
make_unique shows intent.
2023-10-20 18:40:48 +01:00
Peter Nelson e4f94747f3 Codechange: Use comparator struct to sort cargo ID by predefined sort order.
This allows reuse of the comparator where a typename is used instead.
2023-10-20 18:39:32 +01:00
Peter Nelson 9602de474d Codechange: Use iterators and/or range-for on cargo related loops. 2023-10-19 17:03:25 +01:00
PeterN a0c6259e33
Codechange: Don't access cargo filter before it is initialized. (#11321)
The cargo filter list is initialized during window OnInit, but the first
build of the filtered list occurred before this.
2023-09-20 08:58:08 +01:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
Peter Nelson 6fb89b189f Fix #11315: Sort industries and cargoes by name* in industry chain window.
*Cargo types are sorted by the normal method so it's not strictly alphabetical.
2023-09-19 12:25:20 +01:00
Peter Nelson 106f29f761 Codechange: Use iteration to copy cargo list into CFT_CARGO. 2023-09-19 12:25:20 +01:00
Peter Nelson 4f8d06ff73 Codechange: Use uint8_t instead of byte for numeric values. 2023-09-19 12:25:20 +01:00
Peter Nelson 9457bda614 Codechange: Use std::fill instead of memset when initializing GUI cargo fields. 2023-09-19 12:25:20 +01:00
Peter Nelson 9d1b131c44 Codechange: Use correct constant for invalid cargo type. 2023-09-17 16:56:07 +01:00
Rubidium 7ef22af2bb Codechange: introduce and use function to raise and dirty a set of widgets when they are lowered 2023-09-17 16:03:01 +02: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
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
Rubidium 836541b41c Codechange: use SetDParam and CopyOutDParam for tooltips 2023-06-17 10:01:19 +02:00
Rubidium d4c2043294 Codechange: remove a number of unneeded c_str() calls 2023-06-15 22:14:45 +02:00
PeterN 584faaf064
Change: Reorganise industry accept/produce arrays. (#10853)
Use a array of struct for each cargo instead of an array for each statistic.
This makes iterating for acceptance and production much simpler.
pct_transported is now calculated when needed.
2023-05-25 21:25:46 +01:00
Peter Nelson 09408e8e46 Codechange: Add IsCargoAccepted/Produced() helpers. 2023-05-24 17:34:11 +01:00
Peter Nelson 76516d7f70 Codechange: Use IsValidCargoID/IsValidCargoType.
IsValidCargoType() is used only for unmapped IDs.
2023-05-22 20:43:40 +01:00
Peter Nelson c4ca6a0f74 Codechange: Rename IsCargo..Valid to IsValidCargo..
This better fits our naming pattern for this type of function.
2023-05-22 20:43:40 +01:00
Rubidium 63d9bb93b8 Codechange: migrate from C-style GetString to C++-style GetString 2023-05-21 21:17:12 +02:00
Peter Nelson 941dbadf9e Codechange: Add and use GetScrolledItemFromWidget to get a list item.
This function returns an iterator, either to the selected item or the
container's end.

This makes handling the result more robust as indices are not used.
2023-05-12 21:45:32 +01:00