From 913b374f9baa4ff7ee9e4ec401025f71883bd4ce Mon Sep 17 00:00:00 2001 From: GenericHeroGuy <86008856+GenericHeroGuy@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:16:54 +0100 Subject: [PATCH] Lua functions for colorization, offsets, drawing HUD items Introduce drawinfo_t to pass coords/flags to both hardcode and Lua * v.getDrawInfo: return X/Y/flags for the given HUD item * v.drawItemBox: draw the item box, with support for all effects * v.drawItemMul: draw multi sticker, for convenience * v.getHudColor: return HUD color * v.useColorHud: return true if colorization is enabled * hud.getOffsets: return xoffset/yoffset for the given HUD item --- LUASTUFF.md | 35 ++++++- src/k_kart.c | 259 +++++++++++++++++++++++++++-------------------- src/k_kart.h | 14 +++ src/lua_hudlib.c | 133 ++++++++++++++++++++++++ 4 files changed, 327 insertions(+), 114 deletions(-) diff --git a/LUASTUFF.md b/LUASTUFF.md index 2ccd71dcb..13d4cea8f 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -2,7 +2,7 @@ ## mobj.localskin and player.localskin fields -Allow reading and assigning localskins to players. Local skins for other objects aren't supported currently. +Allow reading and assigning localskins. ## mobj.rollsum field @@ -20,9 +20,40 @@ Changes vote background texture prefix (game looks for PREFIX + "W" or "C" (depe ## hud.add(fn, "vote") and hud.add(fn, "intermission") Hud hooks for vote screen and intermission screen. They only get drawer (`v`) as argument. -To check if those hooks are available, check if globals FEATURE\_VOTEHUD and FEATURE\_INERMISSIONHUD +To check if those hooks are available, check if globals FEATURE\_VOTEHUD and FEATURE\_INTERMISSIONHUD exist. +## x, y = hud.getOffsets(item) + +Returns the values of the given HUD item's `xoffset`/`yoffset` cvars, or nil if unsupported. +Uses the same strings as `hud.enabled`. + +## x, y, flags = v.getDrawInfo(item) + +Returns the X, Y and flags where the given HUD item will be drawn for the current displayplayer. +Available for `item`, `gametypeinfo` and `minimap`. + +## v.drawItemBox(x, y, flags, small, dark, colormap) + +Draws an item box at the given coordinates. +`small`: true to draw small item box, false to draw large item box. +`dark`: true if item box should be darkened. +`colormap`: Colormap to draw the item box with. If nil, use displayplayer's HUD colormap. + +## v.drawItemMul(x, y, flags, small, colormap) + +Draws a multi-item sticker at the given coordinates. +`small`: true to draw small sticker, false to draw large sticker. +`colormap`: Colormap to draw the sticker with. If nil, use displayplayer's HUD colormap. + +## hudcolor = v.getHudColor() + +Returns the displayplayer's HUD color. + +## colorize = v.useColorHud() + +Returns true if colorization is enabled, false otherwise. + ## mobj.spritexscale, mobj.spriteyscale, mobj.spritexoffset, mobj.spriteyoffset, mobj.rollangle, mobj.sloperoll, mobj.rollmodel fields Same fields as in SRB2 2.2 diff --git a/src/k_kart.c b/src/k_kart.c index 920a607fb..40d519025 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7500,7 +7500,7 @@ static void K_initKartHUD(void) ITEM2_X = BASEVIDWIDTH-39 + cv_item_xoffset.value; ITEM2_Y = -8 + cv_item_yoffset.value; - LAPS2_X = BASEVIDWIDTH-40 + cv_laps_xoffset.value; + LAPS2_X = BASEVIDWIDTH-3 + cv_laps_xoffset.value; LAPS2_Y = (BASEVIDHEIGHT/2)-13 + cv_laps_yoffset.value; POSI2_X = BASEVIDWIDTH -4 + cv_posi_xoffset.value; @@ -7567,6 +7567,97 @@ INT32 K_calcSplitFlags(INT32 snapflags) return (splitflags|snapflags); } +drawinfo_t K_getItemBoxDrawinfo(void) +{ + INT32 fx, fy, fflags; + drawinfo_t info; + + // pain and suffering defined below + if (splitscreen < 2) // don't change shit for THIS splitscreen. + { + fx = ITEM_X; + fy = ITEM_Y; + fflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); + } + else // now we're having a fun game. + { + if (!(stplyrnum & 1)) // If we are P1 or P3... + { + fx = ITEM_X; + fy = ITEM_Y; + fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P3 to the bottom. + } + else // else, that means we're P2 or P4. + { + fx = ITEM2_X; + fy = ITEM2_Y; + fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P4 to the bottom + } + } + + info.x = fx; + info.y = fy; + info.flags = fflags; + return info; +} + +drawinfo_t K_getLapsDrawinfo(void) +{ + INT32 fx, fy, fflags; + drawinfo_t info; + + // pain and suffering defined below + if (splitscreen < 2) // don't change shit for THIS splitscreen. + { + fx = LAPS_X; + fy = LAPS_Y; + fflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); + } + else + { + if (!(stplyrnum & 1)) // If we are P1 or P3... + { + fx = LAPS_X; + fy = LAPS_Y; + fflags = V_SNAPTOLEFT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. + } + else // else, that means we're P2 or P4. + { + fx = LAPS2_X; + fy = LAPS2_Y; + fflags = V_SNAPTORIGHT|(stplyrnum & 2 ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom + } + } + + info.x = fx; + info.y = fy; + info.flags = fflags; + return info; +} + +drawinfo_t K_getMinimapDrawinfo(void) +{ + INT32 fx = MINI_X, fy = MINI_Y, fflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split) + drawinfo_t info; + + info.x = fx; + info.y = fy; + info.flags = fflags; + return info; +} + +patch_t *K_getItemBoxPatch(boolean small, boolean dark) +{ + UINT8 ofs = (cv_darkitembox.value && dark ? 1 : 0) + (small ? 2 : 0); + return (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[ofs] : kp_itembg[ofs]; +} + +patch_t *K_getItemMulPatch(boolean small) +{ + UINT8 ofs = small ? 1 : 0; + return K_UseColorHud() ? kp_itemmulstickerclr[ofs] : kp_itemmulsticker[ofs]; +} + static void K_drawKartStats(void) { INT32 x, y, spdoffset, flags; @@ -7692,12 +7783,8 @@ static void K_drawKartItem(void) const UINT8 offset = ((splitscreen > 1) ? 1 : 0); patch_t *localpatch = kp_nodraw; patch_t *localbg; - - if (cv_colorizeditembox.value && K_UseColorHud()) - localbg = ((offset) ? kp_itembgclr[2] : kp_itembgclr[0]); - else - localbg = ((offset) ? kp_itembg[2] : kp_itembg[0]); - + boolean dark = false; + patch_t *localinv = ((offset) ? kp_invincibility[((leveltime % (6*3)) / 3) + 7] : kp_invincibility[(leveltime % (7*3)) / 3]); INT32 fx = 0, fy = 0, fflags = 0; // final coords for hud and flags... //INT32 splitflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); @@ -7708,9 +7795,9 @@ static void K_drawKartItem(void) UINT8 localcolor = SKINCOLOR_NONE; SINT8 colormode = TC_RAINBOW; UINT8 *colmap = NULL; - UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - - boolean flipamount = false; // Used for 3P/4P splitscreen to flip item amount stuff + UINT8 *colormap = NULL; + + boolean flipamount = splitscreen > 1 && stplyrnum & 1; // Used for 3P/4P splitscreen to flip item amount stuff if (stplyr->kartstuff[k_itemroulette]) { @@ -7857,8 +7944,7 @@ static void K_drawKartItem(void) break; case KITEM_INVINCIBILITY: localpatch = localinv; - if (cv_darkitembox.value) - localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; + dark = true; break; case KITEM_BANANA: localpatch = kp_banana[offset]; @@ -7880,8 +7966,7 @@ static void K_drawKartItem(void) break; case KITEM_SPB: localpatch = kp_selfpropelledbomb[offset]; - if (cv_darkitembox.value) - localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; + dark = true; break; case KITEM_GROW: localpatch = kp_grow[offset]; @@ -7891,8 +7976,7 @@ static void K_drawKartItem(void) break; case KITEM_THUNDERSHIELD: localpatch = kp_thundershield[offset]; - if (cv_darkitembox.value) - localbg = (cv_colorizeditembox.value && K_UseColorHud()) ? kp_itembgclr[offset + 1] : kp_itembg[offset + 1]; + dark = true; break; case KITEM_HYUDORO: localpatch = kp_hyudoro[offset]; @@ -7933,47 +8017,24 @@ static void K_drawKartItem(void) } } - // pain and suffering defined below - if (splitscreen < 2) // don't change shit for THIS splitscreen. - { - fx = ITEM_X; - fy = ITEM_Y; - fflags = K_calcSplitFlags(V_SNAPTOTOP|V_SNAPTOLEFT); - } - else // now we're having a fun game. - { - if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3... - { - fx = ITEM_X; - fy = ITEM_Y; - fflags = V_SNAPTOLEFT|((stplyr == &players[displayplayers[2]]) ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - fx = ITEM2_X; - fy = ITEM2_Y; - fflags = V_SNAPTORIGHT|((stplyr == &players[displayplayers[3]]) ? V_SPLITSCREEN : V_SNAPTOTOP); // flip P4 to the bottom - flipamount = true; - } - } + localbg = K_getItemBoxPatch((boolean)offset, dark); + drawinfo_t info = K_getItemBoxDrawinfo(); + fx = info.x; + fy = info.y; + fflags = info.flags; if (localcolor != SKINCOLOR_NONE) colmap = R_GetTranslationColormap(colormode, localcolor, GTC_CACHE); + if (K_UseColorHud()) + colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - - if (cv_colorizeditembox.value && K_UseColorHud()) - V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, localbg,colormap); - else - V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, localbg); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, localbg, cv_colorizeditembox.value ? colormap : NULL); // Then, the numbers: if (stplyr->kartstuff[k_itemamount] >= numberdisplaymin && !stplyr->kartstuff[k_itemroulette]) { - if (!K_UseColorHud()) - V_DrawScaledPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulsticker[offset]); - else //Colourized hud - V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), kp_itemmulstickerclr[offset], colormap); // flip this graphic for p2 and p4 in split and shift it. - + localbg = K_getItemMulPatch((boolean)offset); + V_DrawMappedPatch(fx + (flipamount ? 48 : 0), fy, V_HUDTRANS|fflags|(flipamount ? V_FLIP : 0), localbg, colormap); // flip this graphic for p2 and p4 in split and shift it. V_DrawFixedPatch(fx< 1 && stplyrnum & 1; // used for 3p or 4p INT32 stringw = 0; // used with the above - + + drawinfo_t info = K_getLapsDrawinfo(); + fx = info.x; + fy = info.y; + fflags = info.flags; + if (splitscreen > 1) { - // pain and suffering defined below - if (splitscreen < 2) // don't change shit for THIS splitscreen. - { - fx = LAPS_X; - fy = LAPS_Y; - fflags = splitflags; - } - else - { - if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3... - { - fx = LAPS_X; - fy = LAPS_Y; - fflags = V_SNAPTOLEFT|((stplyr == &players[displayplayers[2]]) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - fx = LAPS2_X; - fy = LAPS2_Y; - fflags = V_SNAPTORIGHT|((stplyr == &players[displayplayers[3]]) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom - flipstring = true; // make the string right aligned and other shit - } - } - if (stplyr->exiting) // draw stuff as god intended. { V_DrawScaledPatch(fx, fy, V_HUDTRANS|fflags, kp_splitlapflag); @@ -8617,8 +8659,8 @@ static void K_drawKartLaps(void) { stringw = V_StringWidth(va("%d/%d", stplyr->laps+1, cv_numlaps.value), 0); - V_DrawScaledPatch(BASEVIDWIDTH-stringw-16, fy, V_HUDTRANS|fflags, kp_splitlapflag); - V_DrawRightAlignedString(BASEVIDWIDTH-3, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->laps+1, cv_numlaps.value)); + V_DrawScaledPatch(fx-stringw-13, fy, V_HUDTRANS|fflags, kp_splitlapflag); + V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->laps+1, cv_numlaps.value)); } else // draw stuff NORMALLY. { @@ -8631,23 +8673,23 @@ static void K_drawKartLaps(void) if (!K_UseColorHud()) { if (K_BigLapSticker()) - V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig)); + V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2 : kp_lapstickerbig)); else - V_DrawScaledPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapsticker); + V_DrawScaledPatch(fx, fy, V_HUDTRANS|splitflags, kp_lapsticker); } else //Colourized hud { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); if (K_BigLapSticker()) - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr), colormap); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, ((stplyr->laps + 1 > 9) ? kp_lapstickerbig2clr : kp_lapstickerbigclr), colormap); else - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, kp_lapstickerclr, colormap); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|splitflags, kp_lapstickerclr, colormap); } if (stplyr->exiting) - V_DrawKartString(LAPS_X+33, LAPS_Y+3, V_HUDTRANS|splitflags, "FIN"); + V_DrawKartString(fx+33, fy+3, V_HUDTRANS|splitflags, "FIN"); else - V_DrawKartString(LAPS_X+33, LAPS_Y+3, V_HUDTRANS|splitflags, va("%d/%d", stplyr->laps+1, cv_numlaps.value)); + V_DrawKartString(fx+33, fy+3, V_HUDTRANS|splitflags, va("%d/%d", stplyr->laps+1, cv_numlaps.value)); } } @@ -8799,31 +8841,21 @@ static void K_drawKartSpeedometer(void) static void K_drawKartBumpersOrKarma(void) { UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); - INT32 splitflags = K_calcSplitFlags(V_SNAPTOBOTTOM|V_SNAPTOLEFT); - INT32 fx = 0, fy = 0, fflags = 0; - boolean flipstring = false; // same as laps, used for splitscreen + INT32 fx, fy, fflags; + boolean flipstring = splitscreen > 1 && stplyrnum & 1; // same as laps, used for splitscreen INT32 stringw = 0; // used with the above + drawinfo_t info = K_getLapsDrawinfo(); + fx = info.x; + fy = info.y; + fflags = info.flags; + if (splitscreen > 1) { - // we will reuse lap coords here since it's essentially the same shit. - - if (stplyr == &players[displayplayers[0]] || stplyr == &players[displayplayers[2]]) // If we are P1 or P3... - { - fx = LAPS_X; - fy = LAPS_Y; - fflags = V_SNAPTOLEFT|((stplyr == &players[displayplayers[2]]) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P3 to the bottom. - } - else // else, that means we're P2 or P4. - { - fx = LAPS2_X; - fy = LAPS2_Y; - fflags = V_SNAPTORIGHT|((stplyr == &players[displayplayers[3]]) ? V_SPLITSCREEN|V_SNAPTOBOTTOM : 0); // flip P4 to the bottom - flipstring = true; - } - if (stplyr->kartstuff[k_bumper] <= 0) { + if (flipstring) + fx -= 37; V_DrawMappedPatch(fx, fy-1, V_HUDTRANS|fflags, kp_splitkarmabomb, colormap); V_DrawString(fx+13, fy+1, V_HUDTRANS|fflags, va("%d/2", stplyr->kartstuff[k_comebackpoints])); } @@ -8833,8 +8865,8 @@ static void K_drawKartBumpersOrKarma(void) { stringw = V_StringWidth(va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value), 0); - V_DrawMappedPatch(BASEVIDWIDTH-stringw-16, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); - V_DrawRightAlignedString(BASEVIDWIDTH-3, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); + V_DrawMappedPatch(fx-stringw-13, fy-1, V_HUDTRANS|fflags, kp_rankbumper, colormap); + V_DrawRightAlignedString(fx, fy+1, V_HUDTRANS|fflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); } else // draw bumpers normally. { @@ -8847,17 +8879,17 @@ static void K_drawKartBumpersOrKarma(void) { if (stplyr->kartstuff[k_bumper] <= 0) { - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_karmastickerclr : kp_karmasticker), colormap); - V_DrawKartString(LAPS_X+47, LAPS_Y+3, V_HUDTRANS|splitflags, va("%d/2", stplyr->kartstuff[k_comebackpoints])); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, (K_UseColorHud() ? kp_karmastickerclr : kp_karmasticker), colormap); + V_DrawKartString(fx+47, fy+3, V_HUDTRANS|fflags, va("%d/2", stplyr->kartstuff[k_comebackpoints])); } else { if (stplyr->kartstuff[k_bumper] > 9 && cv_kartbumpers.value > 9) - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_bumperstickerwideclr : kp_bumperstickerwide), colormap); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, (K_UseColorHud() ? kp_bumperstickerwideclr : kp_bumperstickerwide), colormap); else - V_DrawMappedPatch(LAPS_X, LAPS_Y, V_HUDTRANS|splitflags, (K_UseColorHud() ? kp_bumperstickerclr : kp_bumpersticker), colormap); + V_DrawMappedPatch(fx, fy, V_HUDTRANS|fflags, (K_UseColorHud() ? kp_bumperstickerclr : kp_bumpersticker), colormap); - V_DrawKartString(LAPS_X+47, LAPS_Y+3, V_HUDTRANS|splitflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); + V_DrawKartString(fx+47, fy+3, V_HUDTRANS|fflags, va("%d/%d", stplyr->kartstuff[k_bumper], cv_kartbumpers.value)); } } } @@ -9120,7 +9152,7 @@ static void K_drawKartMinimap(void) patch_t *AutomapPic; INT32 i = 0; INT32 x, y; - INT32 minimaptrans, splitflags = (splitscreen == 3 ? 0 : V_SNAPTORIGHT); // flags should only be 0 when it's centered (4p split) + INT32 minimaptrans, splitflags; SINT8 localplayers[4]; SINT8 numlocalplayers = 0; @@ -9139,8 +9171,11 @@ static void K_drawKartMinimap(void) else return; // no pic, just get outta here - x = MINI_X - (AutomapPic->width/2); - y = MINI_Y - (AutomapPic->height/2); + drawinfo_t info = K_getMinimapDrawinfo(); + x = info.x - (AutomapPic->width/2); + y = info.y - (AutomapPic->height/2); + splitflags = info.flags; + if (timeinmap > 105) { diff --git a/src/k_kart.h b/src/k_kart.h index 803594790..861d00991 100644 --- a/src/k_kart.h +++ b/src/k_kart.h @@ -18,6 +18,7 @@ void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor); void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local); UINT8 K_GetKartColorByName(const char *name); UINT8 K_GetHudColor(void); +boolean K_UseColorHud(void); void K_RegisterKartStuff(void); @@ -96,5 +97,18 @@ void K_drawKartHUD(void); void K_drawKartFreePlay(UINT32 flashtime); void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT16 emblemmap, UINT8 mode); +typedef struct +{ + INT32 x; + INT32 y; + INT32 flags; +} drawinfo_t; + +patch_t *K_getItemBoxPatch(boolean small, boolean dark); +patch_t *K_getItemMulPatch(boolean small); +drawinfo_t K_getItemBoxDrawinfo(void); +drawinfo_t K_getLapsDrawinfo(void); +drawinfo_t K_getMinimapDrawinfo(void); + // ========================================================================= #endif // __K_KART__ diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index c7b1ec38e..a6dee3188 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -24,6 +24,7 @@ #include "v_video.h" #include "w_wad.h" #include "z_zone.h" +#include "k_kart.h" #include "lua_script.h" #include "lua_libs.h" @@ -744,6 +745,67 @@ static int libd_drawStretched(lua_State *L) return 0; } +static int libd_drawItemBox(lua_State *L) +{ + HUDONLY + INT32 x = luaL_checkinteger(L, 1); + INT32 y = luaL_checkinteger(L, 2); + INT32 flags = luaL_optinteger(L, 3, 0); + boolean small = lua_optboolean(L, 4); + boolean dark = lua_optboolean(L, 5); + UINT8 *colormap = NULL; + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + if (!lua_isnoneornil(L, 6)) + colormap = *((UINT8 **)luaL_checkudata(L, 6, META_COLORMAP)); + else if (cv_colorizeditembox.value && K_UseColorHud()) + colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + + patch_t *localbg = K_getItemBoxPatch(small, dark); + + lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); + huddrawlist_h list = (huddrawlist_h) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (LUA_HUD_IsDrawListValid(list)) + LUA_HUD_AddDraw(list, x, y, localbg, flags, colormap); + else + V_DrawMappedPatch(x, y, flags, localbg, colormap); + + return 0; +} + +static int libd_drawItemMul(lua_State *L) +{ + HUDONLY + INT32 x = luaL_checkinteger(L, 1); + INT32 y = luaL_checkinteger(L, 2); + INT32 flags = luaL_optinteger(L, 3, 0); + boolean small = lua_optboolean(L, 4); + UINT8 *colormap = NULL; + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + if (!lua_isnoneornil(L, 5)) + colormap = *((UINT8 **)luaL_checkudata(L, 5, META_COLORMAP)); + else if (K_UseColorHud()) + colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE); + + patch_t *patch = K_getItemMulPatch(small); + + lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); + huddrawlist_h list = (huddrawlist_h) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (LUA_HUD_IsDrawListValid(list)) + LUA_HUD_AddDraw(list, x, y, patch, flags, colormap); + else + V_DrawMappedPatch(x, y, flags, patch, colormap); + + return 0; +} + static int libd_drawNum(lua_State *L) { @@ -1007,6 +1069,21 @@ static int libd_getColormap(lua_State *L) return 1; } +static int libd_getHudColor(lua_State *L) +{ + HUDONLY + lua_pushinteger(L, K_GetHudColor()); + return 1; +} + +static int libd_useColorHud(lua_State *L) +{ + HUDONLY + lua_pushboolean(L, K_UseColorHud()); + return 1; +} + + static int libd_width(lua_State *L) { HUDONLY @@ -1057,6 +1134,26 @@ static int libd_getlocaltransflag(lua_State *L) return 1; } +static int libd_getDrawInfo(lua_State *L) +{ + HUDONLY + enum hud option = luaL_checkoption(L, 1, NULL, hud_disable_options); + drawinfo_t info; + + switch(option) { + case hud_item: info = K_getItemBoxDrawinfo(); break; + case hud_gametypeinfo: info = K_getLapsDrawinfo(); break; + case hud_minimap: info = K_getMinimapDrawinfo(); break; + default: + return 0; // not available + } + + lua_pushinteger(L, info.x); + lua_pushinteger(L, info.y); + lua_pushinteger(L, info.flags); + return 3; +} + static luaL_Reg lib_draw[] = { {"patchExists", libd_patchExists}, {"cachePatch", libd_cachePatch}, @@ -1080,6 +1177,11 @@ static luaL_Reg lib_draw[] = { {"renderer", libd_renderer}, {"localTransFlag", libd_getlocaltransflag}, {"drawOnMinimap", libd_drawOnMinimap}, + {"drawItemBox", libd_drawItemBox}, + {"drawItemMul", libd_drawItemMul}, + {"getDrawInfo", libd_getDrawInfo}, + {"getHudColor", libd_getHudColor}, + {"useColorHud", libd_useColorHud}, {NULL, NULL} }; @@ -1170,12 +1272,43 @@ static int lib_hudsetvotebackground(lua_State *L) return 0; } +static int lib_hudgetoffsets(lua_State *L) +{ + enum hud option = luaL_checkoption(L, 1, NULL, hud_disable_options); + INT32 ofx, ofy; + +#define OFS(x, y) ofx = x.value; ofy = y.value; break; +#define OFY(y) ofx = 0; ofy = y.value; break; + switch(option) { + case hud_item: OFS(cv_item_xoffset, cv_item_yoffset) + case hud_time: OFS(cv_time_xoffset, cv_time_yoffset) + case hud_gametypeinfo: OFS(cv_laps_xoffset, cv_laps_yoffset) + //case TODO: OFS(cv_dnft_xoffset, cv_dnft_yoffset) + case hud_speedometer: OFS(cv_speed_xoffset, cv_speed_yoffset) + case hud_position: OFS(cv_posi_xoffset, cv_posi_yoffset) + case hud_minirankings: OFS(cv_face_xoffset, cv_face_yoffset) + //case TODO: OFS(cv_stcd_xoffset, cv_stcd_yoffset) + case hud_check: OFY(cv_chek_yoffset); + case hud_minimap: OFS(cv_mini_xoffset, cv_mini_yoffset) + case hud_wanted: OFS(cv_want_xoffset, cv_want_yoffset) + case hud_statdisplay: OFS(cv_stat_xoffset, cv_stat_yoffset) + default: + return 0; // not available + } +#undef OFS + + lua_pushinteger(L, ofx); + lua_pushinteger(L, ofy); + return 2; +} + static luaL_Reg lib_hud[] = { {"enable", lib_hudenable}, {"disable", lib_huddisable}, {"enabled", lib_hudenabled}, {"add", lib_hudadd}, {"setVoteBackground", lib_hudsetvotebackground}, + {"getOffsets", lib_hudgetoffsets}, {NULL, NULL} };