Commit graph

4444 commits

Author SHA1 Message Date
Robert Müller e175c0a79f Remove duplicate enter hotkey used for connecting to server
The list box already takes care of the enter hotkey for connecting. Furthermore, the list box can be inactive, whereas the now removed hotkey was always active.

Minor refactoring of `DoButtonMenu` usage.
2023-05-22 20:09:33 +02:00
Robert Müller 808d604579 Propagate list box active state to underlying scroll region
Fix inactive list box still consuming mouse scroll events.
2023-05-22 20:09:32 +02:00
Edgar a4abc1fdd9
factor out scorekind backwards compat gametype check 2023-05-22 17:22:52 +02:00
Edgar 1d30462e50
clean time score handling, with positive time values 2023-05-22 16:36:46 +02:00
Edgar 8a3d8fc53f
fix time score info on server detail 2023-05-22 13:53:23 +02:00
Robert Müller 1b6be5e10b Use different color for offline clanmates in friends list
Closes #6643.
2023-05-21 22:06:56 +02:00
Robert Müller 68d2d466d5 Fix use of invalid text container index for finish message HUD 2023-05-20 19:20:48 +02:00
bors[bot] 4ab55bd722
Merge #6626 #6629
6626: Remove popup for unofficial servers r=Robyt3 a=def-

Via https://github.com/ddnet/ddnet/pull/6618/files#r1199072246

Thoughts?

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


6629: Remove unused `CMenus::DoToolTip` declaration r=def- a=Robyt3



## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Dennis Felsing <dennis@felsin9.de>
Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-19 18:55:32 +00:00
Dennis Felsing 3593cce9b4 Revert "Add popup to confirm connecting to friend on non-official server"
This reverts commit 2e46460302.
2023-05-19 20:31:59 +02:00
Robert Müller 3d9d18c511 Remove unused CMenus::DoToolTip declaration 2023-05-19 19:40:46 +02:00
Robert Müller 56d1c8e560 Slightly increase font size of friend name 2023-05-19 19:22:11 +02:00
Dennis Felsing cca040274f Remove popup for unofficial servers
Via https://github.com/ddnet/ddnet/pull/6618/files#r1199072246

Thoughts?
2023-05-19 17:09:01 +02:00
Robert Müller 2e46460302 Add popup to confirm connecting to friend on non-official server 2023-05-19 15:51:05 +02:00
Robert Müller 1bea7a2cd5 Show race disconnect confirmation when joining friend
Closes #6622.
2023-05-19 15:16:32 +02:00
Robert Müller fc3583a18e Show official server icon in friends list
Show the official server icon for online friends who are currently on official servers.
2023-05-19 15:15:44 +02:00
Robert Müller 637f7fd736 Reduce duplicate UI spacing code 2023-05-19 15:14:46 +02:00
Robert Müller b33ce0f37d Change friend info text to Map | Mode | Country/Ping 2023-05-18 23:06:29 +02:00
Robert Müller a2cbc7fb24 Render tees for online friends in friends list
Closes #6614.
2023-05-18 22:03:43 +02:00
Robert Müller 15f839960a Port friends list UI from 0.7
Separate friends list into three groups, which can be expanded and collapsed: online players, online clanmates and offline friends.

Friends with the same name/clan are no longer grouped together. Instead, each individual player that is online and has name/clan matching a friend is shown in either the online players or online clanmates group. Friends for which no matching players are found are shown in the offline group.

Friends in the friend list can no longer be selected. Instead, left-clicking a friend selects the server that the friend is on. Double-clicking a friend joins the server that they are playing on.

Render small X button in top-right corner of every friend list entry to remove the respective friend instead of using one button that removes the selected friend.

Change "Add Friend" button to "Add Clan" when only clan is entered.

Remove excess empty space from layout.

Closes #6326.
2023-05-18 16:46:26 +02:00
bors[bot] 373595dec8
Merge #6608
6608: Support rendering tooltips with multiple lines of text, support overlapping tooltip activation rects, add alpha fade-in for tooltips  r=edg-l a=Robyt3



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-18 11:24:25 +00:00
Robert Müller 47fca7683d Add alpha fade-in for tooltips
After 0.75 seconds of hovering the tooltip rect without rendering the tooltip, start fading in the tooltip for the remaining 0.25 seconds.
2023-05-18 13:22:52 +02:00
Robert Müller 13ed0e386a Use const when possible 2023-05-18 12:21:34 +02:00
Robert Müller fe359e2909 Combine Margin function calls
Both calls put a margin around the same rect but the intermediate result is never used, so both margins can be combined.

The variable `Screen` is also not necessary.
2023-05-18 12:20:53 +02:00
Robert Müller f60dd0d3c2 Fix name of static variable s_LastLoadRender 2023-05-18 12:19:10 +02:00
Robert Müller af67130dbd Use nullptr for unused UI rect splitting parameters 2023-05-18 12:18:22 +02:00
Robert Müller 05f2b19391 Remove unused SLabelProperties Props variable 2023-05-18 12:17:15 +02:00
Robert Müller 31304c4573 Support overlapping tooltip activation rects
When the activation rects for two tooltips overlap, this always causes the first tooltip to be rendered.

This is changed so the last active tooltip is rendered instead, to simplify the usage of the tooltip function.
2023-05-18 12:12:44 +02:00
Robert Müller ed09bba45a Support rendering tooltips with multiple lines of text
Render tooltip text correctly with multiple lines when the maximum tooltip width is limited.

Add missing padding when rendering multi-line tooltip.

Update doxygen documentation.
2023-05-18 12:12:26 +02:00
bors[bot] a38dea4454
Merge #6590
6590: Make text containers bit safer r=Robyt3 a=Jupeyy

From reading the code I couldn't understand how https://github.com/ddnet/ddnet/issues/5143#issuecomment-1546735484 could happen

either (checked = not the case):
 - [x] teini used an outdated client
 - [ ] i am blind
 - [ ] it was a name/clan -plate, scoreboard entry
 - [ ] it leaked somewhere in text.cpp or similar impl
 - [ ] it happened because of an outside write.

We don't really come further with this, so we should probably at least try it out?
`@Robyt3` your opinion? We can still always remove it again

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
2023-05-14 19:16:16 +00:00
bors[bot] cca6d867cb
Merge #6588 #6589
6588: Add default argument to `CDataFileReader/IMap::GetItem` r=def- a=Robyt3

Add default value `nullptr` for `int *pType` and `int *pID` output parameters of `GetItem` functions.

Use `nullptr` instead of `0`.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


6589: Fix heap-use-after-free when quitting/restarting r=def- a=Robyt3

Items and particles were also rendered in the client states quitting and restarting, which was causing accesses to the already freed map data.

Closes #6387 until further notice.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-14 18:58:08 +00:00
Jupeyy 370d37b8fd Add shared ptr to track usage 2023-05-14 20:21:59 +02:00
Robert Müller f3e8513477 Fix heap-use-after-free when quitting/restarting
Items and particles were also rendered in the client states quitting and restarting, which was causing accesses to the already freed map data.
2023-05-14 18:12:47 +02:00
Robert Müller d08626cf69 Add default argument to CDataFileReader/IMap::GetItem
Add default value `nullptr` for `int *pType` and `int *pID` output parameters of `GetItem` functions.

Use `nullptr` instead of `0`.
2023-05-14 16:39:46 +02:00
bors[bot] 03d17a98ed
Merge #6585
6585: Add client_score_kind field to serverinfo (followup) r=Robyt3 a=edg-l

followup on #5960 (fixes conflicts)

It specifies whether the scores are to be interpreted as times (string value starting with "time") or as points (string value starting with "points").

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
Co-authored-by: Edgar Luque <git@edgarluque.com>
2023-05-14 12:17:55 +00:00
bors[bot] ada7c4d597
Merge #6497
6497: Fix client crash/hang when launching without data directory r=edg-l a=Robyt3

Closes #4638.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [X] Considered possible null pointers and out of bounds array indexing
- [X] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-14 09:43:06 +00:00
Edgar 1ca7870bf2
fix conflicts 2023-05-14 11:22:06 +02:00
bors[bot] e9d08a15fd
Merge #6560
6560: Replace EntityEx with new netobjs r=edg-l a=trml

This is a proposal for replacing EntityEx with new netobjects, like suggested in #5860.
- Adds a new DDNetPickup that includes switch number
- a new DDNetProjectile that replaces the old one (which is renamed to DDRaceProjectile)
  - includes switch number, tunezone and velocity/speed (plus a flag that can be used to send velocitiy of player projectiles with full precision)
- switch number and subtype is added to DDNetLaser (to distinguish e.g. draggers with different strength)

The pr removes EntityEx from the server, but keeps compatibility in the client.

<!-- What is the motivation for the changes of this pull request? -->

<!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: trml <trml@users.noreply.github.com>
2023-05-14 08:43:02 +00:00
Edgar 1e319fa279
fix opacity for jumps 2023-05-11 23:04:05 +02:00
Edgar 0db2f6243f
fix nameplate related indicators opacity 2023-05-11 22:23:48 +02:00
Robert Müller d9307ca756 Use FileExists/fs_is_file instead of opening file
This is more concise and works more reliable e.g. on Windows.

See: https://devblogs.microsoft.com/oldnewthing/20071023-00/?p=24713
2023-05-10 21:04:02 +02:00
bors[bot] 7fff049471
Merge #6575
6575: Replace usages of `atan2f` and `atan2` with `std::atan2` r=def- a=Robyt3

Another leftover from #6372.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-09 22:26:22 +00:00
Robert Müller 58184c2d67 Replace usages of atan2f and atan2 with std::atan2
Another leftover from #6372.
2023-05-09 22:38:44 +02:00
Jupeyy 0b1960c532 Fix Y Alignment by respecting cursor height independent of character height 2023-05-08 17:49:05 +02:00
Robert Müller 98a8507184 Fix division by zero when using random theme with no themes 2023-05-08 14:04:22 +02:00
bors[bot] 1112c9e6b7
Merge #6566
6566: Allow using rescue (/r) on health pickup r=heinrich5991 a=Robyt3

Check if character is in range of health pickup and don't set rescue position if that's the case, so rescue can be used to get out of the health pickup's freeze effect.

The existing `m_Core.m_IsInFreeze` is not set so this should not have any side-effects.

Closes #3330.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [X] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-08 11:31:39 +00:00
Robert Müller b590eff24e Add missing HUD text container deletion
See #5143.
2023-05-07 15:37:08 +02:00
Robert Müller 72c2ed062b Remove magic number 20.0f from pickup handling 2023-05-07 11:02:50 +02:00
Robert Müller 73091cdd83 Add CPickup::Type and CPickup::Subtype getters 2023-05-07 11:02:50 +02:00
Robert Müller 2596dac47a Remove dead code 2023-05-07 11:02:50 +02:00
Robert Müller ce4228e08a Simplify by calculating broadcast render offset in OnRender
And ensure that the render offset is recalculated after the window is resized.
2023-05-06 15:57:44 +02:00
Robert Müller bd20423de2 Wrap long broadcast text instead of stopping
Instead of stopping when a broadcast line exceeds the screen width, wrap the text to the next line. Otherwise one long line in a broadcast can end the rendering so following lines are skipped.
2023-05-06 15:56:34 +02:00
Robert Müller 5c78093da4 Fade out broadcast in last second, use text container
Fade the broadcast alpha to zero in the last second that the broadcast is shown.

Use text container to support the fade out and to make broadcast rendering more efficient.
2023-05-06 15:55:42 +02:00
Robert Müller 74c1f38ca0 Use str_next_token to reduce duplicate code
Instead of manually splitting a string at newline characters.
2023-05-06 15:54:33 +02:00
Robert Müller 00ed9d0ecd Fix horizontal centering of broadcast
The screen also needs to be mapped when calculating the width of the broadcast text, otherwise the width is not correct and so the text is not correctly centered horizontally.

The wrong text width was also being calculated when the text has multiple lines. Now `TextWidth` is used so the width is also correct for multi-line text.
2023-05-06 15:54:33 +02:00
Robert Müller 8617411bfa Render broadcast only when online or in demo playback 2023-05-06 15:54:32 +02:00
Robert Müller c2d0835743 Extract CBroadcast::RenderServerBroadcast function 2023-05-06 15:54:32 +02:00
Robert Müller 7afa11e92c Extract CBroadcast::OnBroadcastMessage function 2023-05-06 15:54:28 +02:00
Robert Müller 6d2e2788e2 Use DefaultTextColor and DefaultTextOutlineColor 2023-05-06 15:22:58 +02:00
Robert Müller 4b2ec2c202 Remove dead code 2023-05-06 15:22:58 +02:00
bors[bot] e16e271f17
Merge #6562
6562: Fix server password input not being activated automatically, always move cursor to end when selecting all text r=Jupeyy a=Robyt3


## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-05-05 15:10:59 +00:00
Robert Müller b4a7038fad Fix server password input not being activated automatically 2023-05-05 16:20:55 +02:00
Robert Müller 1be1c9780c Always move cursor to end when selecting all text 2023-05-05 16:20:54 +02:00
Robert Müller a443d99ccf Remove unused CMenus::setPopup function 2023-05-05 16:08:43 +02:00
Robert Müller 0c32eacbab Make text container index type-safe
Use `STextContainerIndex` wrapper instead of `int` for text container index for type-safety.

Add missing checks to ensure valid text container index before rendering FPS and finish time text containers.
2023-05-05 15:58:17 +02:00
trml e10f528215 Add net netobjs for projectile and pickup, extend ddnetlaser, remove EntityEx server-side 2023-05-04 23:43:05 +02:00
Jupeyy 54e013fa1a Fix alpha fading in hud 2023-05-01 12:33:47 +02:00
Robert Müller 11cb72be32 Fix Ctrl+F not activating search box in browser and tee settings
Closes #6537.
2023-04-28 17:17:30 +02:00
Robert Müller abbe2ce1de Use Height variable to reduce duplicate code 2023-04-27 20:47:56 +02:00
Robert Müller 5cb9902745 Fix variable name m_VictimTextWidth 2023-04-27 20:46:58 +02:00
Robert Müller be68c5ad7a Fix client crash on team kill message with invalid team
The client crashes when a team kill message specifies a team for which no client can be found. This can easily happen when the server sends an unknown team on purpose. It may also happen sporadically during normal gameplay, assuming a team is dissolved or the last team member leaves at the same time as the kill message is received.

The crash is fixed by not rendering any tee for these kill messages. The kill message text is always set depending on the team number in the team kill message, regardless of whether the team exists.

Closes #6533.
2023-04-27 20:45:30 +02:00
Robert Müller 2e5f37c61b Don't render switch number and delay for tiles where they are unused 2023-04-26 19:04:56 +02:00
Robert Müller 60c0da7c4d Use IsValid***Tile functions
Use the utility function to check if tele/speedup/switch/tune tile indices are valid.

Using `IsValidSwitchTile` fixes that the switch number and delay were not updated when selecting freeze, deep freeze, deep unfreeze, live freeze and live unfreeze tiles, as those tiles were missing in the existing condition.
2023-04-26 19:04:56 +02:00
Robert Müller ebb2e4253d Port line input and IME support from 0.7
Port the line input (UI edit boxes, chat, console) and Input Method Editor (IME) support from upstream. Closes #4397.

General
------------------------------

Fix issues with the text input. Closes #4346. Closes #4524.

Word skipping (when holding Ctrl) is overhauled to be consistent with the Windows / Firefox experience that I took as reference.

Improve usability by not blinking (i.e. always rendering) the caret shortly after is has been moved.

UI text input
------------------------------

Fix inconsistent mouse-based left and right scrolling (closes #4347).

Support smooth left and right scrolling.

Chat
------------------------------

Support keyboard-based text selection of the chat input.

Mouse-based selection could be support in the future when we decide to add something like an ingame UI cursor.

Support smooth up and down scrolling of the chat input, removing the old hack that offsets the input string to simulate scrolling.

Console
------------------------------

Also support mouse-based text selection of the command input.

Only text from either the command input or the console log can be selected at the same time. This ensures that Ctrl+C will always copy the text that is currently visually selected in the console.

Check for Ctrl+C input event in event handler instead of in render function, to hopefully fix the issue that copying does not work sometimes (closes #5974 until further notice).

When Ctrl+C is used to copy text from the console log, the selection is cleared. This should make it more clear when text was copied from the log.

Fix an issue that was preventing the console log selection from being cleared, when all log lines are selected.

Remove Ctrl+A/E hotkeys that move cursor to beginning/end respectively. Ctrl+A now selectes all text like for all other inputs. Home and End keys can still be used to go the beginning and end.

Remove Ctrl+U/K hotkeys that clear everything before/after the cursor respectively. Hold shift and use Home/End to select everything instead.

IME support
------------------------------

Render list of IME candidates in the client on Windows, so the candidate list can also be viewed in fullscreen mode. There is no API available to retrieve a candidate list on the other operating systems.

Improve composition rendering by underlining the composition text instead of putting it in square brackets.

Track active input globally to properly activate and deactivate IME through the SDL functions.

Closes #1030. Closes #1008.

Password rendering
------------------------------

Fix rendering of passwords containing unicode. Instead of rendering one star character for each UTF-8 `char`, render on star for every unicode codepoint.

Show the composition text also for passwords. Without seeing the composition text it's hard to type a password containing those characters. The candidate window exposes the composition anyway. If you don't want to expose your password this way, e.g. while streaming, you could:

1. Use a latin password and switch off the IME for the password input with the IME hotkey.
2. Blank your screen with an external program while you are streaming and entering passwords.
3. Use binds to authenticate in rcon or to set the server browser password.

Refactoring
------------------------------

Move all text input logic and general rendering to `CLineInput`.

A `CLineInput` is associated with a particular `char` buffer given as a pointer either in the constructor or with `SetBuffer`. The maximum byte size of the buffer must also be specified. The maximum length in unicode codepoints can also be specified separately (e.g. on upstream, name are limited by the number of unicode codepoints instead).

Add `CLineInputBuffered`, which is a `CLineInput` that own a `char` buffer of a fixed size, which is specified as a template argument. As `CLineInput` does not own a buffer anymore, this reduces duplicate code for line inputs that need their own buffer.

Add `CLineInputNumber` which has additional convenience functions to consider the text as an `int` or `float`, to reduce duplicate code in those cases. In the future we could also add an input filter function so that only numbers can be entered in the number input.

Add `CLineInput::SetClipboardLineCallback` to handle the case that multiple lines of text are pasted into a lineinput. This reduces duplicate code, as this behavior was previously implemented separately for chat and console. The behavior is also fixed to be consistent with the console on Windows, so the first line being pasted edits the current input text and then sends it instead of being sent on its own without the existing input text.

Add `CalcFontSizeAndBoundingBox` to UI to reduce duplicate code. Expose `CalcAlignedCursorPos` as static member function to reuse it for line input.

Dispatch input events to UI inputs through the event handler instead of storing them in a duplicate buffer.

Use `size_t` for line input cursor position, length etc. and for `str_utf8_stats`.

Add `IButtonColorFunction` to UI to describe a functions that defines colors for the Default, Active and Hovered states of UI elements. Add some default button color functions. Use button color function to reduce duplicate code in scrollbar rendering.

Use `vec2` instead of two `floats` to represent the mouse positions in the text renderer.

Remove `CaretPosition` again, as it does not calculate the correct Y position near line breaks due to the wrapping being different when not rendering the entire string. Instead, calculate the exact caret position when rending a text container and store the caret position in the text cursor for later use.

IME usage guide (Windows)
------------------------------

1. Install the respective language and the Microsoft-IME keyboard (e.g. for Chinese, Japanese or Korean).
2. Launch the game (or a text editor to first try out the IME). Note that Windows may track the input language separately for every application. You can change this in the Windows input settings so the input language is changed globally.
2. Switch the input language using the hotkey Windows+Space or another hotkey that you configured in the Windows input settings (Alt+Shift is the default, but you should consider disabling it, to avoid accidentally changing the input language while playing).
3. Switch from Latin/English input mode to the respective asian input mode.
   - Chinese: Use Ctrl+Space to switch between English and Chinese input mode. You can change this hotkey in the IME's settings.
   - Japanese: Use Ctrl+Space to switch between Alphanumeric and Hiragana/Katakana input mode. You can change this hotkey in the IME's settings.
   - Korean: Use Right Alt to switch between English and Hangul input mode. You cannot change this hotkey as of yet.
   - Note that the input mode is also tracked per application, but there is no setting to change this behavior as far as I know, so you'll need to switch for every application separately.
4. Start typing. The underlined text is the current composition text. While a composition is active, you can only edit the composition text. Confirm the composition with Space or by selecting a candidate from the candidate list with the arrow keys. Cancel the composition with Escape or by using Backspace to delete the composition text. Note that not all languages offer a candidate list.

SDL version-specific issues
------------------------------

- 2.26.5, 2.24.2, 2.0.22: IME candidates work. But there are minor bugs when moving the composition cursor.
- 2.0.18, 2.0.20: IME candidates work.
- 2.0.16 (our current version): IME candidates cannot be determined with Windows API. Windows tries to draw the composition window like before, so this does not work in fullscreen mode.
- 2.0.8 (upstream 0.7): IME candidates work. But this SDL version is too old for us.
2023-04-23 15:00:29 +02:00
Robert Müller 09462cff67 Use KEY_FIRST and KEY_UNKNOWN instead of 0 2023-04-21 18:47:44 +02:00
Robert Müller ecc49a699f Use size_t for number of input events 2023-04-21 18:44:49 +02:00
Robert Müller 2b7f054590 Use const reference to pass CEvent objects
The size of the `CEvent` class is 140 bytes, so it's more efficient to pass objects by reference.
2023-04-21 18:44:48 +02:00
bors[bot] cdd19beee4
Merge #6437
6437: Make team kills condensed in killfeed r=heinrich5991 a=VoxelDoesCode

For those who still have the killfeed on, I wanted to modernize it, by having team kills become one line instead of a bunch!

![image](https://user-images.githubusercontent.com/95713843/226060109-ed74c2f6-1289-4247-81dc-1725428ddf59.png)
## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: VoxelDoesCode <dante_n_cedroni@hotmail.com>
2023-04-21 10:37:40 +00:00
VoxelDoesCode 049d89ca41 Simplify NetMsg even more, with help from Fokko
Quick changes

Add m_First

one more thing

fokko pointed this out at 3 am

Final push
2023-04-18 07:51:44 -04:00
bors[bot] 391c127cb3
Merge #6515
6515: Add OnNewSnapshot to component hooks r=heinrich5991 a=ChillerDragon

Waste some clock cycles on zero lines code removed :D
Downstream client maintainers will love it tho 

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: ChillerDragon <ChillerDragon@gmail.com>
2023-04-18 11:33:14 +00:00
Robert Müller a2c9b752e0 Remove unused CListBox::FilterMatches 2023-04-15 13:07:40 +02:00
ChillerDragon 7c2c5aeee7 Add OnNewSnapshot to component hooks 2023-04-15 12:47:33 +02:00
Robert Müller c7cea0a37f Fix incorrect chat background rect width calculation
The calculation of `m_LongestLineWidth` was adjusted in bf1e757581 so it's really the width of the line and not the X position of the end of the line. This caused the background rects of chat messages to be rendered incorrectly.
2023-04-15 12:17:49 +02:00
bors[bot] b1f2862cff
Merge #6511
6511: Refactor vertical alignment of UI labels, add more text render convenience functions r=def- a=Robyt3

Should change layout only very little.

### Notes if you are porting this downstream

`SLabelProperties::m_AlignVertically` is removed. The usage was previously confusing and inconvenient, as the `SLabelProperties` parameter object was necessary to change the vertical alignment. If `m_AlignVertically == 1` (which is the default value) then the text is vertically centered and this works correctly also for multi-line text, assuming that the correct rect height is specified and the previous fixes have been applied (#6507). If `m_AlignVertically == 0` then the text is somehow more correctly aligned for some UI elements that span only one line in cases where the previous option doesn't work correctly. Other `m_AlignVertically` values besides `0` and `1` are not used.

With this PR most text is centered vertically by setting `TEXTALIGN_MIDDLE`. The UI code always uses shorthand constants for combinations of horizontal and vertical alignment, e.g. `TEXTALIGN_MC` for `TEXTALIGN_MIDDLE | TEXTALIGN_CENTER`. To port your own code, I'd recommend replacing all of your usages of `TEXTALIGN_LEFT`, `TEXTALIGN_CENTER` and `TEXTALIGN_RIGHT` with `TEXTALIGN_ML`, `TEXTALIGN_MC` and `TEXTALIGN_MR` respectively. Remove all usages of `m_AlignVertically` and also the `SLabelProperties` variables for which only `m_AlignVertically` was changed. This means all text will be vertically centered and have the same horizontal alignment as before. For some labels the vertical centering does not work correctly though, so you'll have to visually check if any of the texts are misaligned and then manually adjust the alignment or the UI rect position and/or size.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-04-10 17:29:23 +00:00
bors[bot] 4d697c7be3
Merge #6509
6509: Fix client crash when spectating on server with missing game info r=def- a=Robyt3



## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
2023-04-10 17:08:19 +00:00
Robert Müller 301567507f Fix client crash when spectating on server with missing game info 2023-04-10 17:27:21 +02:00
Robert Müller 8f5708a882 Use TextBoundingBox for tooltip rendering
Calculate correct height for tooltip and apply consistent padding.

Ensure tooltip width and height do not exceed size of screen.
2023-04-10 17:22:10 +02:00
Robert Müller a6f9fdd6d5 Add function to get caret position to ITextRender
Add `CaretPosition` function to get position of text caret. Replace some existing usages of `TextWidth`, which would no longer work correctly for multi-line text.

Having this function is also useful when porting the upstream UI lineinput.
2023-04-10 17:22:10 +02:00
Robert Müller 9ad2f9f4df Add functions to get text bounding box to ITextRender
Add separate `STextBoundingBox` to describe text bounding box (same as on upstream). Add `GetBoundingBoxTextContainer` to get bounding box for a text container. Add `TextBoundingBox` function to get bounding box with old text render interface.

Using this function to get the bounding box width and height is cleaner than using `TextWidth`. This function additionally can get the bounding box X and Y position for convenience.

Some usages of `TextWidth` are replaced with `TextBoundingBox` to improve readability.

It will be useful to have these functions when porting the upstream UI lineinput.
2023-04-10 17:22:10 +02:00
Robert Müller 8507a651d1 Refactor vertical alignment in UI
Add separate constants `TEXTALIGN_TOP`, `TEXTALIGN_MIDDLE` and `TEXTALIGN_BOTTOM` for vertical alignment.

Add shorthand constants for all possible combinations of horizontal and vertical alignment, e.g. `TEXTALIGN_MC` for `TEXTALIGN_MIDDLE | TEXTALIGN_CENTER`.

Replace usage of `SLabelProperties::m_AlignVertically` with these constants in all menu and editor code for more convenient and versatile alignment of text. Use combined horizontal-vertical alignment constants for all existing labels. Manually adjust layout for some elements which were initially misaligned with the new implementation.

Refactoring:

- Use `CORNER_NONE` instead of `0`.
- Improve some `CUIRect` variables names and usage.
2023-04-10 17:22:09 +02:00
Robert Müller 76ad9e2e3b Use Localizable instead of comment with Localize 2023-04-10 16:43:53 +02:00
Robert Müller 430e96346f Fix inconsistent text wrapping of popup labels
Round up the calculated text width to prevent inconsistent text wrapping in the popups in cases where the current text width is very close to the maximum line width.
2023-04-09 20:10:44 +02:00
Robert Müller 6decf14137 Use Text instead of TextEx for popup labels
To reduce duplicate code and ensure that the same flags are used with `TextWidth` and when actually rendering the text.
2023-04-09 20:10:44 +02:00
Robert Müller 9bb9c7ce6b Replace usages of TextLineCount with TextWidth
Calculate text height for popups with `TextWidth` instead of using `TextLineCount`, which can be incorrect if the aligned font size differs from the normal one.
2023-04-09 20:10:44 +02:00
Robert Müller 9693d4beac Fix vertical centering of multi-line UI labels
Also calculate text height in `TextWidth`.

Use calculated text height to verically center UI labels.

The text cursor flags (in particular, the `TEXTFLAG_STOP_AT_END` flag) must also be passed to `TextWidth`. Otherwise, for example, when `TEXTFLAG_STOP_AT_END` is missing, the wrong text height is calculated, as text is rendered over multiple lines instead of stopping at the end of the first line.

Closes #5396.
2023-04-09 20:10:09 +02:00
Robert Müller 07c59d130b Minor refactoring of DoLabel functions 2023-04-09 20:10:09 +02:00
Robert Müller ede3e5631f Move generic popup handling to UI (port from editor and upstream)
Support using editor popup rendering in game client.

Support unlimited number of popup menus instead of maximum of 8.

Fix non-active popups handling key events. Add `Active` parameter to popup function, so key events are only processed by the active (top-most) popup. Previously the "New folder" popup could be confirmed with enter while an error message is shown, which causes multiple error messages to stack.

Allow popups to close without closing their child popups. Previously a popup could not open another popup and close itself immediately afterwards, as this was causing the newly opened popup to be closed instead.

Support using return/enter keys to confirm binary choice popups and to close message popups for more convenient usage.
2023-04-07 17:16:16 +02:00
Robert Müller 72775f236b Let CUI::Screen return a const pointer
Callers should never modify the UI screen.
2023-04-07 11:50:48 +02:00
Valentin Bashkirov 85485d23ce highlight game type 2023-04-05 20:02:25 +02:00
VoxelDoesCode df48c44e78 Bring every Font Icon unicode into a namespace
Fix namespace hopefully
2023-04-03 20:25:28 -04:00
VoxelDoesCode 0dfced4ca4 Bring Team logic into teams.cpp
MsgPlus -> Msg
2023-04-02 21:40:39 -04:00