Commit Graph

364 Commits

Author SHA1 Message Date
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 8c22690ce1 Codechange: Update window's widget lookup map when switching displayed plane. 2024-02-15 22:28:58 +00:00
frosch b1718478c8 Codechange: Replace old non-standard attributes with C++17/20 standard attributes. 2024-02-02 22:29:28 +01:00
Rubidium 1403f24fa9 Codechange: replace LeastCommonMultiple with std::lcm 2024-01-20 16:45:21 +01:00
Peter Nelson 68843e3a96 Codechange: Move WidgetDimensions::unscaled to header to allow const use. 2024-01-16 21:57:05 +00:00
Peter Nelson d005e8f8bd
Fix 884b9e66: No need to include extra pixel for pressed state. (#11803) 2024-01-16 20:50:46 +00:00
Loïc Guilloux b18e78e21d
Change: Redesign script debug window (#11782) 2024-01-15 21:41:44 +01:00
Peter Nelson 7124b4eef1 Codechange: Use std::unique_ptr for all NWidgets. 2023-12-31 15:33:56 +00:00
Peter Nelson 9a3934ae23 Codechange: Use vector/unique_ptr inside widget containers.
This replaces a C-style double-linked-list which required all widgets
to have next/prev pointers, and removes the need for manual pointer management.
2023-12-31 15:33:56 +00:00
Peter Nelson c2c65d66ba Codechange: Add GetParentWidget() to widgets.
This allows to get parent widgets in the nested tree from bottom-up.
2023-12-30 22:02:37 +00:00
Peter Nelson 8ff0bef862
Codechange: Make widget index const to prevent changes. (#11658)
This guards against future widget index manipulation.
2023-12-30 18:55:16 +00:00
Peter Nelson 6215e9bf77
Fix #11655: Crash due to NWidgetMatrix modifying widget->index. (#11657)
NWidgetMatrix modifies its child widget's index to indicate which element
is to be drawn, which now causes issues with code that does not know about
stuffing extra data into the index.

Instead, let NWidgetMatrix store the currently processing element, and
retrieve this information from the matrix widget while child widgets are
being drawn.

This means only widgets that are children of NWidgetMatrix need to know
anything about their extra data.
2023-12-30 18:24:26 +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 b86182ab84 Codechange: Use std::map to provide indexed widget access.
This removes the need to determine the biggest widget index and replaces C-style memory handling.
2023-12-29 18:45:43 +00:00
Peter Nelson a12f426d69 Codechange: Rename nested array to widget lookup.
This changes from naming storage-type to naming functionality.

* `FillNestedArray` is renamed to `FillWidgetLookup`.
* `Window::nested_array` is renamed to `Window::widget_lookup`.
* `array` parameter renamed as well.
2023-12-29 18:45:43 +00:00
Peter Nelson feb94d233d
Codechange: Remove deferred nested_array initialization path. (#11640)
Having two ways (`FillNestedArray` and `SetupSmallestSize`) to initialize
`Window::nested_array` introduces confusion.

Instead, make `FillNestedArray` the canonical way, always call it, and remove
init_array from `SetupSmallestSize`.
2023-12-29 14:27:04 +00:00
Peter Nelson 6e8c27b8e5
Change: Hide bevel for resizeable sparse layout windows. (#11572)
When clicked, the button is still highlighted to show that it is active.

The bevel is controlled with widget_data by RWV_SHOW_BEVEL or RWV_HIDE_BEVEL values.
2023-12-10 17:25:36 +00:00
Peter Nelson ebf299e1b4 Codechange: Make SetDisplayedPlane return whether the plane changed or not. 2023-12-10 12:01:55 +00:00
Peter Nelson 60565da8f9
Codechange: Add specific WidgetDimension for dropdown list window. (#11554)
This avoids contorting fullbevel dimensions.
2023-12-07 16:10:09 +00:00
Peter Nelson 90e386acaa
Codechange: Vertical spacing for caption is captiontext, not framerect. (#11550)
This does not really matter as the caption height is sized correctly later anyway, so this just avoids confusion.
2023-12-06 21:36:51 +00:00
Peter Nelson 58c252b81a Cleanup: Remove unnecessary pressed button offset code. 2023-12-05 21:12:35 +00:00
Peter Nelson 884b9e6690 Change: Revert pressed-button content shifting introduced in r2161.
This restores original behaviour, and prevents all image buttons being slightly too large.
2023-12-05 21:12:35 +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 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 62d4fd0572 Codechange: Add method to guess the width/height required for a multiline string.
This is necessary for widget layouts where a minimum width is not yet known during UpdateWidgetSize().
2023-11-20 23:09:20 +00:00
Peter Nelson f281525492 Codechange: Add method to resize both width and height of a widget. 2023-11-20 23:09:20 +00:00
Peter Nelson 05b55c4d43
Fix: Extra space allocated to container-within-container may not get allocated to children. (#11471)
Always derive additional length from contained widgets instead of from the container, as the container's minimal length may have been adjusted by an NC_EQUALSIZE parent container.
2023-11-19 00:36:53 +00:00
Peter Nelson f93711838f
Fix 6317967: Missing exception for SetPipRatio(). (#11465) 2023-11-16 19:22:02 +00:00
Peter Nelson e2e0753916
Codechange: Use GetCurrentRect() where feasible. (#11460) 2023-11-16 17:06:57 +00:00
Peter Nelson 55adbe10b7 Add: WidgetDimensions for 'sparse' widget windows.
These are for windows that have space between widgets instead of being clumped together.
2023-11-07 23:09:05 +00:00
Peter Nelson 665902f5ba Codechange: Add widget dimensions to standardise picker winodws. 2023-11-05 20:09:45 +00:00
Peter Nelson 3cab980b30 Codechange: Skip invisible (zero-size) widgets in PIP Containers.
This gets rid of doubled-up spacing where an invisible child widget would be.
2023-11-05 20:09:45 +00:00
Peter Nelson 6317967dba Codechange: Add ability to allocate PIP-space dynamically by ratio.
This can be used to space out, centre, start-align, or end-align widgets without additional spacers.
2023-11-05 20:09:45 +00:00
Peter Nelson ac54bd7e58 Codechange: Apply PIP during AssignSizePosition() instead of SetupSmallestSize(). 2023-11-05 20:09:45 +00:00
Peter Nelson a9aaa2a183 Codechange: Don't be lenient with invalid NWidgetPart lists.
Some NWidgetPart combinations were ignored but it was not clear that they do nothing. Instead, assert if NWidgetPart is incorrectly applied.
2023-11-05 19:24:59 +00:00
Peter Nelson e8db137135 Codechange: Move test for Container WidgetType to helper function. 2023-11-03 09:38:41 +00:00
Peter Nelson bb50cbb772
Codechange: Assign/StoreSizePosition x/y can be negative. (#11416)
AssignSizePosition is used with negative values when an NWidgetMatrix is
scrolled, but they were passed as unsigned and then stored as signed.

Widget pos_x/pos_y were already made signed.
2023-11-01 18:44:23 +00:00
Peter Nelson c0aa9a5f87
Add: Debug tool to draw widget outlines. (#11401)
This is considered a developer tool and is controlled from the help menu (or default hotkey Ctrl-O).

This draws a white dashed outline around widgets. NWidgetSpacer and (unused) WWT_EMPTY widgets are also filled with check pattern to highlight them, as they usually indicate a design issue.
2023-10-28 19:07:50 +01:00
Peter Nelson 59a2abd298 Codechange: Use unified NWidgetContainer methods instead of duplicating.
Most NWidgetContainer derivatives implemented Draw() and GetWidgetFromPos()
the same way. Move this these to NWidgetContainer itself to avoid repeating.
2023-10-21 14:26:36 +01:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
Peter Nelson 152b0cac34 Codechange: Return update nwid_begin instead of count.
This avoids needing to keep track of how many widget parts have been consumed, instead we only to ensure nwid_begin < nwid_end.
2023-09-04 10:20:45 +01: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
Richard Wheeler 96fdfb941a
Feature: Transparency option for cost and income indicators (#11001) 2023-08-25 16:04:40 +02:00
Patric Stout 0238a2b567
Codechange: use std::variant instead of using bitflags in the value (#11191) 2023-08-12 16:05:00 +00: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
PeterN 43ddf19df3
Change: Allow text shadow on WWT_EMPTY/WWT_TEXT to extend horizontally. (#11065)
This alleviates text shadows of truetype fonts being cropped in some
window layouts.
2023-06-25 11:58:39 +01:00
PeterN 40f567d464
Fix #10811: Crash getting row from non-resizable widget. (#10833)
GetScrolled*FromWidget took line height from the widget's resize_y value,
however not all widgets are resizable, resulting in a division-by-zero.

Allow passing line height explicitly in cases where a widget is not
resizable.
2023-05-15 18:57:50 +01:00
Patric Stout 7634553d22 Feature: opt-in survey when exiting a game
On first start-up, the game will ask if you want to participate
in our automated survey. You have to opt-in, and can easily opt-out
(via the Options) at any time.

When opt-in, whenever you exit a game, a JSON blob will be send
to the survey server hosted by OpenTTD. This JSON blob contains
information that gives a global picture of the game just played:
- What settings were used
- How many humans vs AIs
- How long the game has been played
- Basic information about the OS / CPU

All this information is kept very generic, so there is no
chance we send private information to our survey server.
Nothing in the JSON blob could identify you as a person; it
mostly tells about the game played. At any time you can see
what the JSON blob includes, by pressing the "Preview Survey
Results" button in-game.
2023-05-14 23:22:02 +02:00