Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hud config framework #6495

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MjnMixael
Copy link
Contributor

@MjnMixael MjnMixael commented Dec 29, 2024

This PR relies on #6487 and #6481 . It sets up the necessary framework to be able to render each HUD gauge in "config" mode which will allow rendering the gauges outside of a mission environment, namely the HUD Config screen. For now the config argument is commented out because it's unused. The bulk of the changes here are in hud.cpp and the various rendering methods where in config mode we don't do any screen resizing.

Config mode requests to render each gauge not only scaled down slightly but at an arbitrary offset depending on whether we're rendering through the retail UI or SCPUI. For that reason I found it was much easier to calculate a gauge's position and scale manually within the gauge render code itself where we also have access to the bitmap with it's height and width. This also allows us to save those coordinates to an array to use against the mouse coords to detect mouseover and click on these rendered gauges. The relevant code, shown below, is currently unreachable since nothing calls them. HC_gauge_coordinates is never initialized for now. That will be resolved in the big HUD Config UI overhaul PR.

Future PRs will systematically go through each gauge rendering code and build out the full config mode rendering path which mostly consists of setting the coords, scale, and providing dummy data where mission data is currently expected.

void hud_config_convert_coords(int x, int y, float scale, int& outX, int& outY)
{
	outX = HC_gauge_coordinates[0] + static_cast<int>(x * scale);
	outY = HC_gauge_coordinates[2] + static_cast<int>(y * scale);
}

void hud_config_get_scale(int baseW, int baseH, float& outScale)
{
	// Determine the scaling factor
	float scaleX = static_cast<float>(HC_gauge_coordinates[4]) / baseW;
	float scaleY = static_cast<float>(HC_gauge_coordinates[5]) / baseH;

	// Use the smallest scale factor
	outScale = std::min(scaleX, scaleY);
}

void hud_config_convert_coord_sys(int x, int y, int baseW, int baseH, int& outX, int& outY, float& outScale)
{
	hud_config_get_scale(baseW, baseH, outScale);
	hud_config_convert_coords(x, y, outScale, outX, outY);
}

void hud_config_set_mouse_coords(int gauge_config, int x1, int x2, int y1, int y2) {
	HC_gauge_mouse_coords[gauge_config] = {x1, x2, y1, y2};
}

@MjnMixael MjnMixael force-pushed the hud_config_framework branch from 31de7a4 to 3d75c10 Compare December 29, 2024 03:31
@wookieejedi wookieejedi added enhancement A new feature or upgrade of an existing feature to add additional functionality. HUD A feature or issue related to the HUD refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability feature A totally new sort of functionality labels Dec 29, 2024
@MjnMixael MjnMixael force-pushed the hud_config_framework branch 2 times, most recently from 9bcf290 to 74ccc32 Compare December 29, 2024 04:33
@wookieejedi
Copy link
Member

wookieejedi commented Dec 29, 2024

Tagging as 25.0 for now since it is foundational for the HUD configure updates, which will be extremely useful for all mods.

Discussing with MJN, he calculated the best order of operations for the process is as follows:

1 Font scaling PR: #6481 (and #6330 and #6342, which are both done)
2 Bitmap scaling PR: #6487
3 Hud Config framework PR (this PR)
4 Individual gauge changes (Upcoming: probably multiple PRs that can go simultaneously)
5 Hud config UI overhaul (Upcoming)

@MjnMixael MjnMixael force-pushed the hud_config_framework branch from b1b7c85 to e0f3784 Compare December 30, 2024 17:24
@MjnMixael MjnMixael added this to the Release 25.0 milestone Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or upgrade of an existing feature to add additional functionality. feature A totally new sort of functionality HUD A feature or issue related to the HUD refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants