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
KOTOR: HUD Scaling #312
KOTOR: HUD Scaling #312
Conversation
src/engines/kotor/gui/ingame/hud.cpp
Outdated
scaleWidgetToLowerMid(getWidget("BTN_CLEARONE2"), wHeight); | ||
} | ||
|
||
void HUD::scaleWidgetToUpperLeftEdge(Widget *widget, int wWidth, int wHeight) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check for widget != 0 in all of these here. It shouldn't crash if the widget is not available. For example, the Xbox version doesn't have a lot of these.
src/engines/kotor/gui/ingame/hud.cpp
Outdated
@@ -91,12 +92,17 @@ HUD::HUD(Module &module, Engines::Console *console) | |||
resString += Common::UString::format("%dx%d", it->width, it->height); | |||
} | |||
|
|||
foundRes = &kResolution[0]; | |||
scale = true; | |||
warning("TODO: Add scaling for custom resolutions. Supported resolutions are %s", resString.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That warning needs to go then too, if you're implementing scaling with this PR
src/engines/kotor/gui/ingame/hud.cpp
Outdated
@@ -207,6 +213,138 @@ void HUD::setPartyMember2(Creature *creature) { | |||
setPortrait(3, creature != 0, creature ? creature->getPortrait() : ""); | |||
} | |||
|
|||
void HUD::scaleWidgets(unsigned int wWidth, unsigned int wHeight) { | |||
scaleWidgetToUpperLeftEdge(getWidget("LBL_MAPVIEW"), wWidth, wHeight); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, a lot of code duplication there. And duplicating the widget names partially.
Maybe instead this big chunk, we should rather have a static array of structs with the names of all widgets, their visibility status from the start (taking over the list on lines 106ff) and their relative position.
Something like
enum Position {
kPositionUpperLeft,
kPositionMidLeft,
...
kPositionUnknown
};
struct KnownWidget {
const *name;
bool visible;
Position position
};
static const KnownWidget kKnownWidgets[] = {
{ "LBL_MAPBORDER", true, kPositionUpperLeft },
{ "LBL_LEVELUP1", false, kPositionUpperLeft },
...
};
Then in HUD::HUD()
, we're iterating over kKnownWidgets, setting them invisible if necessary, and scaling them if necessary and a position is given. Any other property we need there?
4953f97
to
de3fa21
Compare
I reworked the scaling code as you suggested. |
That's better, yes. Works great, mostly. One thing, though: the Xbox GUI is called "mi8x6", not "mipc28x6", so just taking kResolution[0] won't work. You need to take the first available one, not the first of all possible ones. |
c9d0f99
to
9056d32
Compare
The code should now look after mipc28x6 and mi8x6 with a preference to mipc28x6 |
src/engines/kotor/gui/ingame/hud.cpp
Outdated
|
||
resString += Common::UString::format("%dx%d", it->width, it->height); | ||
// Search for an existing interface with 800x600 resolution with preference to the pc interface. | ||
if (Common::UString(it->gui) == "mipc28x6" || (Common::UString(it->gui) == "mi8x6" && !foundRes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you comparing the name instead width and height directly?
You can also just break when one is found, instead of checking that foundRes is not assigned yet.
I.e. I think that
if ((it->width == 800) && (it->height == 600)) {
foundRes = &*it;
break;
}
would be way clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In C++11, I'd even say that's a std::find() with a lambda checking width and height, but that's future talk :P)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the pc version of kotor also contains the gui file for the xbox ui, i wanted to prefer the pc ui and the only way of doing this, is by comparing their names. Maybe later you can add a command line switch for forcing the xbox ui. Also i wanted to make sure, that in the case of both being found and supported, the pc version is used since that would be what a normal pc user would expect first and, as far as i know, the pc ui is not contained in the xbox game but the xbox ui is contained in the pc game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why availableRes is a std::set, operator<() only checks the dimensions, and the PC version is checked first. availableRes doesn't contain the xbox GUI file in PC version, even though the file is theoretically available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Yes, that's a bit of a hack in either case, I know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, i will correct this
9056d32
to
a56e2ab
Compare
i changed the code now as you suggested. |
Merged, thanks! :) Can you move that over to KotOR2, too, please? |
This PR adds the ability to scale the hud of no proper resolution is found.