For reference, here's a similar solution that I came up with:
Code: Select all
class OptionMenuItemExtendedSlider : OptionMenuItemSlider
{
void DrawExtendedSlider (int x, int y, double min, double max, double cur, int fracdigits, int indent)
{
/* same snip out of duplicate code that Nash talked about above */
if (!mSliderShort)
{
DrawElement(x, cy, "Slider_L", g_inactivecolor);
for (int s = 1; s < 11; s++) { DrawElement(x + s * 8 * CleanXFac_1, cy, "Slider_M", g_inactivecolor); }
DrawElement(x + 11 * 8 * CleanXFac_1, cy, "Slider_R", g_inactivecolor);
DrawElement(x + int((5 + ((ccur * 78) / range)) * CleanXfac_1), cy, "Slider_H", g_altcolor);
}
else
{
// On 320x200 we need a shorter slider
DrawElement(x, cy, "Slider_L", g_inactivecolor);
for (int s = 1; s < 6; s++) { DrawElement(x + s * 8 * CleanXFac_1, cy, "Slider_M", g_inactivecolor); }
DrawElement(x + 6 * 8 * CleanXFac_1, cy, "Slider_R", g_inactivecolor);
DrawElement(x + int((5 + ((ccur * 38) / range)) * CleanXfac_1), cy, "Slider_H", g_altcolor);
right -= 5*8*CleanXfac_1;
}
if (fracdigits >= 0 && right + maxlen <= screen.GetWidth())
{
textbuf = String.format(formater, cur);
screen.DrawText(SmallFont, Font.CR_DARKGRAY, right, y, textbuf, DTA_CleanNoMove_1, true);
}
}
/* more snip */
void DrawElement(double x, double y, String pic, int clr = 0)
{
let tex = TexMan.CheckForTexture (pic, TexMan.Type_MiscPatch);
if (tex.isValid())
{
screen.DrawTexture(tex, true, int(x), int(y), DTA_DestWidth, 8 * CleanXFac_1, DTA_DestHeight, 8 * CleanYFac_1);
if (clr > 0) { screen.DrawTexture(tex, true, int(x), int(y), DTA_DestWidth, 8 * CleanXFac_1, DTA_DestHeight, 8 * CleanYFac_1, DTA_FillColor, clr, DTA_Alpha, 0.5); }
}
}
}
The major difference is that I didn't bother with a separate font definition; I re-worked everything to draw a set of square textures scaled to 8x8, via the DrawElement function that you can see here. This implementation also has the benefit of (hackily) applying color overlays to graphics to allow the appearance of translations on .pngs - I used cvars (set in CVARNIFO) to set the color values. This lets you have something like
this... The base graphics for the sliders are all grayscale, with the green as an alpha stencil overlay.
Getting this to work with the default menus means copy/pasting the entirety of MENUDEFS and replacing the slider entries with my custom slider.
(One oddity that I noticed just now is that if I bump the zscript version to 2.5, this breaks... hmm...)