Commit Graph

371 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 37a03b513f Codechange: refactor string list dimension finding into a separate function 2024-04-28 18:47:31 +02:00
Rubidium ad50c4f298 Codechange: inline sorter name definitions and use proper static accessor instead of (implying) this-> 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 5bc9854be2
Codechange: Make sort list function lists safer. (#12574)
GUIList has a pointer only to the start of each sort/filter func list, which has the potential for UB as it is unable to validate that the selected sort or filter type is in range.

Use a std::span instead and check if the selected type is in range before using it.
2024-04-25 21:00:49 +01:00
Peter Nelson 16eb17418b Change: Use aspect ratios for some common widgets. 2024-04-19 22:11:16 +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 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
Rubidium 86cb184eb4 Codechange: use std::source_location over __FILE__ and __LINE__ for WindowDesc 2024-03-10 10:14:20 +01:00
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
frosch b1718478c8 Codechange: Replace old non-standard attributes with C++17/20 standard attributes. 2024-02-02 22:29:28 +01:00
Peter Nelson 6d93fa649c Change: Towns generate cargo based on town production effect.
This replaces the fixed handling of passengers and mail.
2024-02-02 20:37:49 +00:00
Peter Nelson 60dcf3b5e2 Codechange: Rename TownEffect to TownAcceptanceEffect.
This makes it clearer that TownEffect only affects acceptance behaviour.
2024-02-02 20:37:49 +00:00
merni-ns ccaa383e85
Fix #11938: Check infinite money setting in cases where it was missed (#11939) 2024-01-31 20:11:48 +01:00
frosch a9d1078434 Codechange: Remove TKM from town action tooltips. 2024-01-28 14:44:24 +01: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 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
Finn Willard 7d3ae4a058 Add: Hotkey to focus town directory filter box
Co-authored-by: Tyler Trahan <tyler@tylertrahan.com>
2023-12-19 11:23:37 -05:00
Peter Nelson bdef9b451c
Codechange: Remove unnecessary SetMinimalTextLines for text buttons alongside captions. (#11549) 2023-12-06 21:14:09 +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 9122b4eb47
Codechange: SetMinimalTextLines(1, 0) is implied for widgets with text. (#11536) 2023-12-03 22:42:50 +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 0578b8eaa9
Change: Use picker-spacing for scenario found town window. (#11478) 2023-11-20 23:06:15 +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
Rubidium c9276c2959 Codechange: replace x.size() == 0 with x.empty() 2023-10-20 23:05:43 +02:00
Tyler Trahan 088db62dba
Change: Always allow expanding towns in Scenario Editor to build new roads (#11377) 2023-10-19 17:01:45 -04:00
Peter Nelson f379b31e28 Add: data parameter in Window::Close method.
This allows passing data when closing a window, e.g. to indicate how it was closed.
2023-10-13 20:47:28 +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
Tyler Trahan fca2b37726 Codechange: Move Ticks into their own class 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
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 74924c8186 Codechange: includes must be before 'safeguards.h' 2023-06-18 21:22:14 +02:00
Rubidium 2dd2b698d2 Codechange: convert C-style GetTownName API to std::string returning API 2023-06-05 17:07:39 +02:00
Patric Stout 772729cc7d
Fix: when syncing width of GUI items, take padding into account (#10915) 2023-06-05 10:27:04 +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
Peter Nelson d2034d9c38 Codechange: Scrollbar methods now accept size_t.
This clears up a lot of casts from size_t to int.
2023-05-07 20:25:44 +01:00
Rubidium c829930440 Codechange: replace strnatcmp with C++ string capable version 2023-04-29 12:07:45 +02:00
Jonathan G Rennison 684c7bbc93 Fix: Violation of strict weak ordering in TownRatingSorter
If two unrated town names compare equal in TownNameSorter
2023-04-23 12:52:12 +01:00
Patric Stout 3ebc7ad16e Codechange: migrate all game-time-related timers to the new framework 2023-04-15 13:58:55 +02:00
Patric Stout 1ba4dcc924 Codechange: migrate all Window-related timers to the new framework
This means we also say goodbye to GUITimers.
2023-04-15 13:58:55 +02:00
glx22 3278f4c7bb Fix #10280, 59645c6: Ignore double-click for unavailable town actions 2023-02-10 19:39:21 +01:00
glx22 d6aa526b69 Fix #10461, 59645c6: Properly check for _local_company validity 2023-02-10 19:39:21 +01:00
Rubidium 3373128233 Codechange: pass the randomizer directly to the town name generation 2023-01-14 22:00:11 +01:00
PeterN 9e56e16147
Fix: Local authority window rating list height ignored icon sizes. (#10285)
Only font height was taken into account, so the list was broken if icon
sizes were taller than font height.
2022-12-26 18:26:01 +00:00
Didac Perez Parera 35d55bd534
Feature: Expand all towns in the scenario editor (#10215) 2022-12-25 19:42:50 +01:00
Peter Nelson 890b2666d3 Change: Use scaled WidgetDimensions. 2022-11-12 18:28:39 +00:00
Peter Nelson 6f95e04005 Change: Use Rect helpers for widget drawing.
This replaces repetitive and sometimes unwieldy use of constants.
2022-11-12 18:28:39 +00:00