Commit graph

1236 commits

Author SHA1 Message Date
phosit
0f7417bb47
Remove Engine.SwitchGuiPage
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled
This function isn't used by JavaScript anymore.

Fixes: #6929
2026-04-26 12:44:41 +02:00
phosit
6ead0d2f92
Add Engine.openRequest
Pages can replace themselfe by another (continuation) page.
2026-04-26 12:44:39 +02:00
Vantha
5a92c22d90 Compute actual size of GUI objects lazily
Some checks failed
checkrefs / lfscheck (push) Has been cancelled
checkrefs / checkrefs (push) Has been cancelled
lint / cppcheck (push) Has been cancelled
lint / copyright (push) Has been cancelled
lint / jenkinsfiles (push) Has been cancelled
pre-commit / build (push) Has been cancelled
This shifts the responsibility of updating the actual size more towards
IGUIObject, and enables only ever doing it when the value is actually
needed. This allows us to remove the delay of size changed
notifications, since the value is now already recalculated as
infrequently as possible anyways.

All of that ensures that the actual size (returned by GetActualSize) is
always up-to-date e.g. when reading it from the parent, which was
previously broken.

Fixes #8200
2026-04-12 00:17:02 +02:00
Vantha
8a2a450686 Align text as usual if the scrollbar is invisible
Previously, while `scrollbar` was set to true, the text was always
vertically aligned to the top, no matter what its `text_valign` was, by
the scrolling logic. However, this was done even when the text's caption
was so short that no scrollbar was required in the first place (and not
rendered). Falling back to the specified `text_valign` value in that case
instead seems like the expected behavior.

On a few occasions in the GUI, the text was supposed to be aligned to
the top in either case, but still set `text_valign` to a different value
(for whatever reason), which didn't have any effect previously. But
now since it does, the values have to be corrected to specify what is
actually desired.
2026-04-06 21:39:18 +02:00
phosit
262c5c037e
Use promises to fetch net messages
Refs: #5585
2026-03-13 18:07:56 +01:00
Vantha
01476b9836 Only render the minimap texture if it'll be displayed
This patch implements a way for minimap-type GUI objects to request the rendering
of the minimap texture each frame. If it wasn't requested the minimap
texture isn't rendered at all and the objects only request it while they are
being displayed. This saves unnecessary work and fixes a bug where the
minimap briefly showed the revealed map after a cinema path ended
playing, since it isn't updated every frame (only 2x per second).
2026-03-03 11:25:52 +01:00
phosit
df18e22277
Remove Script::CreateArray
It's better to construct a js-array from a `JS::RootedValueVector`.
Because it is more strongly typed and the index doesn't has to be
specified when appending an element.
Some usages are replaced with `JS::RootedValueArray`.

Fixes: #8702
2026-02-08 19:27:50 +01:00
Vantha
b5c4a4635c Revert temporary workarounds for font baseline issues
Those workarounds were added in order to hide issues with the font
rendering in the short term for R28 and will hopefully be properly fixed
for R29.
2026-01-29 19:05:34 +01:00
Vantha
7fd788af0f Temporary workaround for icon misalignment
Quick temporary fix for #8194 for the release of R28.
2026-01-29 19:05:34 +01:00
phosit
03a5198ed3
Remove g_GUI usage in simulation2/*
This is the last remaining inclusion of a gui file in simulation2/.
2026-01-23 21:05:18 +01:00
Vantha
2e450f0f52 Remove inconsistent override in CDropdown.h
It was added in 670f1e5d42 and, while not illegal, was inconsistent with the
rest of the header file, which caused compiler warnings.
As a quick solution the override keyword is simply removed again.
In the long run, it would be good to still modernise the style of all files
in that directory (at once).
2025-12-29 13:46:47 +01:00
phosit
e62eb96092
Allow swapped in pages to close themselves
This wasn't possible because init functions are called inside each
other and the outer one overwrites the result of the inner one.
Now the outer result doesn't overwrite the inner result but stores it to
the pointed to location.
2025-12-27 18:21:18 +01:00
Vantha
670f1e5d42 Fix warnings on the charts tab of summary screen
Engine.GetTextWidth has been deprecated since e845da025a

Idea:
If you look at a dropdown as just a text field (its header) that can
change caption like any other, then getPreferredHeaderTextSize is the
equivalent to getPreferredTextSize (present on buttons and text fields).

Fixes #8493
2025-12-23 10:28:22 +01:00
Vantha
fbb6052c30 Fix oversight in 83f4d8789b 2025-12-23 10:28:22 +01:00
phosit
2748a45fc6
Remove ScriptEvent with only one parameter
The effect is the same when the second parameter is defaulted.
2025-11-05 14:39:44 +01:00
phosit
7ccea4ace9
Remove *WithReturn duplication
This has been introduced in 1ed64439ea.
2025-11-05 14:39:44 +01:00
Itms
9150c20818
Remove ScriptTypes and ScriptExtraHeaders headers
The first header was used to include the SpiderMonkey JS API at once,
with safeguards and preprocessor defines. Nowadays, SpiderMonkey
provides modular headers allowing us to include what we use, refs #8086.

Some defines have to be moved to compiler options but it is apparently
a mistake from the SM developers:
https://bugzilla.mozilla.org/show_bug.cgi?id=1987876
2025-09-14 13:17:18 +02:00
trompetin17
423ba82837
Fix text right alignment with GUI Scale
Now that size uses float when emulating positioning, it was getting a
different value, like 0.008. This commit fixed that issue by using
std::floor to remove small noise.

Symmetrical for LEFT with std::ceil.
2025-09-13 10:01:51 -05:00
Vantha
83f4d8789b Lift window width constraint of .getPreferredTextSize
The method's point is to calculate a text's height and width if it was written
in a single line -- no matter how long the caption, even if it's wider
than the window.
2025-08-24 11:03:34 +02:00
Ralph Sennhauser
5b5f678e3f
Fix some includes all over the place
Make include-what-you-use happy with some files in source and fix what
needs to be fixed.

Add markers to precompiled.h header includes to avoid
include-what-you-use wanting them to be removed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-14 20:15:30 +02:00
Vantha
2026a5fece Clean up Engine.GetGUIObjectByName calls
GetGUIObjectByName was previously made stricter, logging an
error if it doesn't find the target object.
This commit deals with the resulting error-causing (invalid) calls,
by deleting them if they're unnecessary or converting them to the new
TryGetGUIObjectByName (which doesn't log any errors).
2025-08-14 10:22:56 +02:00
Vantha
6515c3fb1f Show an error when Engine.GetGUIObjectByName fails
It previously failed silently and just returned undefined which would often
only cause errors later on. Printing an error as soon as that happens helps
with debugging, by directly catching typos, for example.

For cases where the queried object may not exist, a new Engine function
called TryGetGUIObjectByName is introduced. It doesn't log any errors
and behaves exactly as GetGUIObjectByName used to.
2025-08-14 10:22:56 +02:00
Itms
cea708ac91 Cleanup of IGUIObject classes
- Explicitly delete move constructor and move assignment operator to
  avoid risk of memory leaks
- Remove unused class and typo
- Use same invocation of ScriptInterface as elsewhere
2025-08-11 18:38:01 +02:00
Itms
74bbdca25f Remove default dtors of IGUIObject derived classes 2025-08-11 18:38:01 +02:00
Ralph Sennhauser
fbc74482db
Fix some includes in atlas
Make include-what-you-use happy with some files in source/tools/atlas
and fix what needs to be fixed.

Drop the wxWidgets specific handling of precompiled headers in some
places, it isn't consistently used which it would have to to have meaning
and was mostly for early VS implementation of precompiled headers and a
lot of time has gone by since.

Drop Borland C++ compiler specific quirk, that compiler was
discontinued long ago and doesn't support modern C++.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-08-09 18:28:46 +02:00
trompetin17
690838e3dc
Add [locale] inline tag for per-locale fonts
New `[locale='xx']...[/locale]` markup lets GUI text sections render
with a locale-specific font (e.g. CJK) while the rest of the caption
keeps the current game font.

guiObject.caption = "Hello [locale='ja']世界[/locale], how do you
[locale='zh']感覺[/locale]" This is ideal for language pickers and
similar UI where you want the language name shown in its own script.

This commit unlocks richer, self-explanatory international UI while
keeping the legacy text behaviour unchanged.
2025-08-04 09:35:41 -05:00
phosit
eee48b74dd Store IGUIObjects in std::unique_ptr in CGUI
The object are automatically deleted. The destructor can now be
defaulted.
2025-08-03 16:55:43 +02:00
phosit
6eac128f12 Pass IGUIObject as reference
Where nullptr isn't allowed references should be used.
2025-08-03 16:55:43 +02:00
phosit
f2dfb94b88 Return void from CGUI::Xeromyces_ReadObject
The returned value was never used.
Now all CGUI::Xeromyces_Read* functions return void.
2025-08-03 16:55:43 +02:00
phosit
f721f56ad4 Replace TIMER with PROFILE2
`TIMER` messages where printed to stdout which lead to noise.

Refs: #1003
2025-07-29 18:19:49 +02:00
Itms
8ccba254fe Remove modmod dependency in test_CGUIText.h
The test loading the `mod` mod uses the bold variant that is present in
`_test.minimal`. Removing the need for the `mod` mod allows packagers to
build and run tests from the `unix-build` tarball without needing the
`unix-data` one.

The setup for this test suite defines the italic variant of the sans
serif font, but this variant is not present in `_test.minimal` and is
not used in any test, so remove that as well.
2025-07-23 12:20:19 +02:00
Itms
2d6d510ffa
Hide compiler warnings from external includes 2025-07-23 10:21:26 +02:00
trompetin17
4fd3533f37
Fix wrapping by passing window width to text size
Why
Passing 0 as the width to `CGUIText` meant "no wrapping".
Buttons and text objects therefore treated every caption as a
single unbroken line, ignoring embedded new-line characters and
overflowing their allotted space.

What
`GetPreferredTextSize` in both `CButton` and `CText` now forwards
`m_pGUI.GetWindowSize().Width` instead of 0.
With a real width the underlying `CGUIText::GetSize()` can measure
the caption using normal word-wrap rules, restoring correct
multi-line behaviour and preventing layout glitches.

Fixes: #8193
2025-07-14 15:02:13 -05:00
trompetin17
0f156e3544
GUIProxy: Support property introspection for debugging
This commit enables proper property enumeration and inspection for GUI
proxy objects in debugging sessions using the SpiderMonkey Debugger API.

Interface (IGUIProxyObject):
- Added a pure virtual method getPropsNames() to expose cached property
  names from the GUI object implementation.

Proxy handler (JSI_GUIProxy):
- Implemented ownPropertyKeys() to enumerate all visible properties of
  the proxy, including: -- Built-in GUI fields: "name", "parent",
  "children". -- Dynamic settings stored in m_Settings. -- Script event
  handlers prefixed with "on" from m_ScriptHandlers. -- Function
  properties returned by getPropsNames().
- Implemented getOwnPropertyDescriptor() to synthesize descriptors for
  debugger queries: -- Returns undefined if the property is not defined.
  -- Returns a read-only enumerable descriptor otherwise.
- Both methods are marked final and override SpiderMonkey's
  BaseProxyHandler.

Why:
- SpiderMonkey’s Debugger API requires ownPropertyKeys and
  getOwnPropertyDescriptor for proxy objects to be introspectable in dev
  tools like VS Code.
- Without these, properties of GUI objects are hidden during debugging.
- This change improves the developer experience by making all meaningful
  GUI object fields visible and explorable at runtime.
2025-07-11 11:06:06 -05:00
phosit
9822a22573 Replace ScriptException::Raise in Engine functions
Now exceptions can be thrown. The function throwing exceptions becomes
cleaner and doesn't require a `ScriptRequest` anymore.
2025-07-08 19:11:49 +02:00
Ralph Sennhauser
5e4b49f65f
Fix some includes in source/renderer
Make include-what-you-use happy with some files in source/renderer and
fix what needs to be fixed.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-07 17:45:54 +02:00
Ralph Sennhauser
461ff6c20c
Fix most headers in gui
Make include-what-you-use happy with most of the files in source/gui and
fix what needs to be fixed after including missing compile flags.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-05 12:42:34 +02:00
Ralph Sennhauser
8227e76845
Restore includes for suppressing warnings on vs2017
Commit d888b10931 remove those headers which have the side effect of
suppressing some warnings on Windows using vs2017. Keep those headers
around for till vs2019+.

Add additional suppressions where needed for spidermonkey headers.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-02 17:40:27 +02:00
Ralph Sennhauser
61326cfca6
Fix some headers in gui
Make include-what-you-use happy with a part of the files in source/gui
and fix what needs to be fixed after including missing compile flags.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-07-02 13:20:13 +02:00
Ralph Sennhauser
758d901883
more objecttype 2025-06-30 21:18:16 +02:00
Ralph Sennhauser
af582b09aa
fixup! Fix headers for gui/ObjectTypes 2025-06-30 21:09:46 +02:00
Ralph Sennhauser
00f9d887b1
fixup! Fix headers for gui/ObjectTypes 2025-06-30 21:07:53 +02:00
Ralph Sennhauser
49863da3b4
Fix headers for gui/ObjectTypes
Make include-what-you-use happy with files in source/gui/ObjectTypes and
fix what needs to be fixed after.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-30 20:38:16 +02:00
Ralph Sennhauser
d888b10931
Fix headers for gui/ObjectBases
Make include-what-you-use happy with files in source/gui/ObjectBases and
fix what needs to be fixed after.

Ref: #8086
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-30 19:56:41 +02:00
trompetin17
571b536e1f
Log GUISize/GetTextSize deprecations once
Replace repeated LOGWARNING calls with ONCE(LOGWARNING) in
JSInterface_CGUISize.cpp and JSInterface_Main.cpp.

Why – The old behaviour printed a warning every time the deprecated
API was used, cluttering the log and annoying modders. We still want to
nudge them toward the new APIs (object.size = {...} and
guiObject.GetPreferedTextSize/getTextSize), but a single reminder is
enough.

What changed

CGUISimpleSetting<CGUISize>::DoFromJSVal now wraps the deprecation
message in ONCE(...).

Engine.GetTextSize warning is likewise wrapped.

Impact – Functionality is unchanged; only the frequency of the
warnings is throttled to one per session, making the transition less
intrusive and more user-friendly.
2025-06-29 09:12:21 -05:00
trompetin17
19e82ebceb
Add getPreferredTextSize to calculate unconstrained text width
Introduces (CButton|CText).getPreferredTextSize, a new method for estimating
the natural width of a caption if the object had no width constraints.

Unlike .getTextSize, which reports the size after applying current
layout constraints (e.g., fixed width or anchors), getPreferredTextSize
answers the question: "How wide would this object need to be to display
the caption on a single line?"

This is particularly useful for modders and layout logic that wants to
dynamically size elements *before* assigning a fixed width or anchoring.
2025-06-26 16:58:32 -05:00
phosit
891908b801 Remove UNUSED
The `UNUSED` macro is used to mark a variable as unused but with a name.
Those usages are replaced with comments so that `UNUSED` can be removed.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-unused
2025-06-26 17:25:05 +02:00
phosit
77b1addb45 Enable modules in the GUI
Doesn't actually change a GUI-page to use modules. Adopting a GUI-page
now only requires JS and XML changes.

Ref: #8081
2025-06-26 10:50:21 +02:00
phosit
93666d8628 Remove ignore_result
`std::ignore` serves the same purpose and is C++ standard.
2025-06-19 19:05:56 +02:00
Ralph Sennhauser
0108ff51f4
Fix no-pch build after b34f4b79aa
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-18 21:12:33 +02:00