by rollingcrow » Sun Feb 10, 2019 7:44 pm
I modified CommanderZ's code to support more resolutions in a slightly less hardcoded way awhile back, though I don't know how easily this could be adapted into something usable by Project MSX. It should support any(?) 4:3, 16:9, 16:10, or 17:10 resolution.
Code: Select all
/*
Heavily modified version of CommanderZ's old widescreen HUDMessage script.
Now supports any supported aspect ratio rather than hardcoded resolutions.
*/
int res4to3 = 1.33333333333;
//int res5to4 = 1.25;
int res16to9a = 1.77777777778;
int res16to9b = 1.77864583; // For 1366x768
int res16to10 = 1.6;
int res17to10 = 1.7;
function void HudMessageStr(int type, int id, int imageWidth, int imageHeight, int time, int fadeTime, int alpha)
{
int hudScreenWidth = imageHeight * 4 / 3 * imageWidth / imageHeight;
int hudScreenHeight = imageHeight;
if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res4to3)
{
hudScreenWidth = hudScreenWidth / 4 * 3;
}
/*
if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res5to4)
{
hudScreenWidth = hudScreenWidth / 5 * 4;
Log(s:"Sorry, unsupported resolution!");
}
*/
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to9a)
{
hudScreenWidth = hudScreenWidth / 16 * 9;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to9b)
{
hudScreenWidth = hudScreenWidth / 16 * 9;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to10)
{
hudScreenWidth = hudScreenWidth / 16 * 10;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res17to10)
{
hudScreenWidth = hudScreenWidth / 17 * 10;
}
else
{
Log(s:"Sorry, unsupported resolution!");
}
// ---
SetHudSize(hudScreenWidth, hudScreenHeight, 1);
HudMessage(s:"a"; type, id, CR_Untranslated, (hudScreenWidth / 2) * 65536, (hudScreenHeight / 2) * 65536, time, fadeTime, alpha);
}
Sample use:
Code: Select all
Script "PlayerFatigue" ENTER
{
SetFont("BlkVig");
if (CheckInventory("Fatigue") <= 10000)
{
HudMessageStr(HUDMSG_ALPHA | HUDMSG_FADEOUT | HUDMSG_LAYER_UNDERHUD | HUDMSG_NOTWITHFULLMAP, 101, 1920, 1080, 0.0, 1.0, 1.0);
}
// snip
}
I modified CommanderZ's code to support more resolutions in a slightly less hardcoded way awhile back, though I don't know how easily this could be adapted into something usable by Project MSX. It should support any(?) 4:3, 16:9, 16:10, or 17:10 resolution.
[code]/*
Heavily modified version of CommanderZ's old widescreen HUDMessage script.
Now supports any supported aspect ratio rather than hardcoded resolutions.
*/
int res4to3 = 1.33333333333;
//int res5to4 = 1.25;
int res16to9a = 1.77777777778;
int res16to9b = 1.77864583; // For 1366x768
int res16to10 = 1.6;
int res17to10 = 1.7;
function void HudMessageStr(int type, int id, int imageWidth, int imageHeight, int time, int fadeTime, int alpha)
{
int hudScreenWidth = imageHeight * 4 / 3 * imageWidth / imageHeight;
int hudScreenHeight = imageHeight;
if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res4to3)
{
hudScreenWidth = hudScreenWidth / 4 * 3;
}
/*
if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res5to4)
{
hudScreenWidth = hudScreenWidth / 5 * 4;
Log(s:"Sorry, unsupported resolution!");
}
*/
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to9a)
{
hudScreenWidth = hudScreenWidth / 16 * 9;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to9b)
{
hudScreenWidth = hudScreenWidth / 16 * 9;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res16to10)
{
hudScreenWidth = hudScreenWidth / 16 * 10;
}
else if ((FixedDiv(GetScreenWidth(), GetScreenHeight())) == res17to10)
{
hudScreenWidth = hudScreenWidth / 17 * 10;
}
else
{
Log(s:"Sorry, unsupported resolution!");
}
// ---
SetHudSize(hudScreenWidth, hudScreenHeight, 1);
HudMessage(s:"a"; type, id, CR_Untranslated, (hudScreenWidth / 2) * 65536, (hudScreenHeight / 2) * 65536, time, fadeTime, alpha);
}[/code]
Sample use:
[code]
Script "PlayerFatigue" ENTER
{
SetFont("BlkVig");
if (CheckInventory("Fatigue") <= 10000)
{
HudMessageStr(HUDMSG_ALPHA | HUDMSG_FADEOUT | HUDMSG_LAYER_UNDERHUD | HUDMSG_NOTWITHFULLMAP, 101, 1920, 1080, 0.0, 1.0, 1.0);
}
// snip
}
[/code]