Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
583 changes: 292 additions & 291 deletions CMake/Assets.cmake

Large diffs are not rendered by default.

2,099 changes: 1,050 additions & 1,049 deletions Source/CMakeLists.txt

Large diffs are not rendered by default.

81 changes: 67 additions & 14 deletions Source/control/control_infobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "engine/render/primitive_render.hpp"
#include "inv.h"
#include "levels/trigs.h"
#include "lua/lua_global.hpp"
#include "lua/modules/infobox.hpp"
#include "panels/partypanel.hpp"
#include "qol/stash.h"
#include "qol/xpbar.h"
Expand Down Expand Up @@ -44,12 +46,14 @@ void PrintInfo(const Surface &out)

SpeakText(InfoString);

DrawString(out, InfoString, infoBox,
{
.flags = InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::KerningFitSpacing,
.spacing = 2,
.lineHeight = lineHeight,
});
if (!DrawInfoBoxTextWithColors(out, InfoString, infoBox, UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::KerningFitSpacing, 2, lineHeight)) {
DrawString(out, InfoString, infoBox,
{
.flags = InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter | UiFlags::KerningFitSpacing,
.spacing = 2,
.lineHeight = lineHeight,
});
}
}

Rectangle GetFloatingInfoRect(const int lineHeight, const int textSpacing)
Expand Down Expand Up @@ -211,6 +215,26 @@ int ClampAboveOrBelow(int anchorY, int spriteH, int boxH, int pad, int linePad)
return (yAbove >= 0) ? yAbove : yBelow;
}

const Item *GetHoveredInventoryOrStashItem()
{
if (pcursinvitem >= INVITEM_HEAD && pcursinvitem < INVITEM_INV_FIRST) {
const int slot = pcursinvitem - INVITEM_HEAD;
return &InspectPlayer->InvBody[slot];
}
if (pcursinvitem >= INVITEM_INV_FIRST && pcursinvitem < INVITEM_INV_FIRST + InventoryGridCells) {
const int itemIdx = pcursinvitem - INVITEM_INV_FIRST;
return &InspectPlayer->InvList[itemIdx];
}
if (pcursinvitem >= INVITEM_BELT_FIRST && pcursinvitem < INVITEM_BELT_FIRST + MaxBeltItems) {
const int itemIdx = pcursinvitem - INVITEM_BELT_FIRST;
return &InspectPlayer->SpdList[itemIdx];
}
if (pcursstashitem != StashStruct::EmptyCell) {
return &Stash.stashList[pcursstashitem];
}
return nullptr;
}

void PrintFloatingInfo(const Surface &out)
{
if (ChatFlag)
Expand All @@ -234,6 +258,7 @@ void PrintFloatingInfo(const Surface &out)

// Prevent the floating info box from going off-screen vertically
floatingInfoBox.position.y = ClampAboveOrBelow(anchorY, spriteH, floatingInfoBox.size.height, vPadding, verticalSpacing);
SetLastFloatingInfoBoxRect(floatingInfoBox);

SpeakText(FloatingInfoString);

Expand All @@ -244,12 +269,16 @@ void PrintFloatingInfo(const Surface &out)
DrawHalfTransparentHorizontalLine(out, { floatingInfoBox.position.x - hPadding, floatingInfoBox.position.y - vPadding - 1 }, floatingInfoBox.size.width + (hPadding * 2), PAL16_GRAY + 10);
DrawHalfTransparentHorizontalLine(out, { floatingInfoBox.position.x - hPadding, floatingInfoBox.position.y + vPadding + floatingInfoBox.size.height }, floatingInfoBox.size.width + (hPadding * 2), PAL16_GRAY + 10);

DrawString(out, FloatingInfoString, floatingInfoBox,
{
.flags = InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter,
.spacing = textSpacing,
.lineHeight = lineHeight,
});
if (!DrawInfoBoxTextWithColors(out, FloatingInfoString, floatingInfoBox, UiFlags::AlignCenter | UiFlags::VerticalCenter, textSpacing, lineHeight)) {
DrawString(out, FloatingInfoString, floatingInfoBox,
{
.flags = InfoColor | UiFlags::AlignCenter | UiFlags::VerticalCenter,
.spacing = textSpacing,
.lineHeight = lineHeight,
});
}

LuaEvent("AfterFloatingInfoBoxDraw");
}

} // namespace
Expand Down Expand Up @@ -355,6 +384,8 @@ void CheckPanelInfo()

void DrawInfoBox(const Surface &out)
{
const Item *infoBoxItem = nullptr;

DrawPanelBox(out, MakeSdlRect(InfoBoxRect.position.x, InfoBoxRect.position.y + PanelPaddingHeight, InfoBoxRect.size.width, InfoBoxRect.size.height), GetMainPanel().position + Displacement { InfoBoxRect.position.x, InfoBoxRect.position.y });
if (!MainPanelFlag && !trigflag && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && !SpellSelectFlag && pcurs != CURSOR_HOURGLASS) {
InfoString = StringOrView {};
Expand All @@ -364,6 +395,7 @@ void DrawInfoBox(const Surface &out)
if (SpellSelectFlag || trigflag || pcurs == CURSOR_HOURGLASS) {
InfoColor = UiFlags::ColorWhite;
} else if (!myPlayer.HoldItem.isEmpty()) {
infoBoxItem = &myPlayer.HoldItem;
if (myPlayer.HoldItem._itype == ItemType::Gold) {
const int nGold = myPlayer.HoldItem._ivalue;
InfoString = fmt::format(fmt::runtime(ngettext("{:s} gold piece", "{:s} gold pieces", nGold)), FormatInteger(nGold));
Expand All @@ -374,8 +406,10 @@ void DrawInfoBox(const Surface &out)
InfoColor = myPlayer.HoldItem.getTextColor();
}
} else {
if (pcursitem != -1)
if (pcursitem != -1) {
GetItemStr(Items[pcursitem]);
infoBoxItem = &Items[pcursitem];
}
else if (ObjectUnderCursor != nullptr)
GetObjectStr(*ObjectUnderCursor);
if (pcursmonst != -1) {
Expand Down Expand Up @@ -407,6 +441,17 @@ void DrawInfoBox(const Surface &out)
AddInfoBoxString(_("Right click to inspect"));
}
}
if (infoBoxItem == nullptr)
infoBoxItem = GetHoveredInventoryOrStashItem();

if (infoBoxItem != nullptr) {
PrepareInfoBoxColors(infoBoxItem, false);
if (FloatingInfoBoxColors.hasCustomColors())
InfoColor = FloatingInfoBoxColors.getLineColor(0);
} else {
FloatingInfoBoxColors.clear();
}

if (!InfoString.empty())
PrintInfo(out);
}
Expand All @@ -416,10 +461,18 @@ void DrawFloatingInfoBox(const Surface &out)
if (pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell) {
FloatingInfoString = StringOrView {};
InfoColor = UiFlags::ColorWhite;
ClearLastFloatingInfoBoxRect();
}

if (!FloatingInfoString.empty())
if (!FloatingInfoString.empty()) {
const Item *hoveredItem = GetHoveredInventoryOrStashItem();
PrepareInfoBoxColors(hoveredItem, true);
if (FloatingInfoBoxColors.hasCustomColors())
InfoColor = FloatingInfoBoxColors.getLineColor(0);
PrintFloatingInfo(out);
} else {
ClearLastFloatingInfoBoxRect();
}
}

} // namespace devilution
4 changes: 3 additions & 1 deletion Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,9 @@ void DrawView(const Surface &out, Point startPosition)
}
DrawLevelButton(out);
if (ShowUniqueItemInfoBox) {
DrawUniqueInfo(out);
LuaEvent("BeforeUniqueInfoBoxDraw");
if (ShowUniqueItemInfoBox)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be truthy right?

DrawUniqueInfo(out);
}
if (qtextflag) {
DrawQText(out);
Expand Down
32 changes: 32 additions & 0 deletions Source/lua/lua_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "lua/modules/player.hpp"
#include "lua/modules/render.hpp"
#include "lua/modules/system.hpp"
#include "lua/modules/infobox.hpp"
#include "lua/modules/towners.hpp"
#include "monster.h"
#include "options.h"
Expand Down Expand Up @@ -291,6 +292,7 @@ void LuaInitialize()
"devilutionx.towners", LuaTownersModule(lua),
"devilutionx.hellfire", LuaHellfireModule(lua),
"devilutionx.system", LuaSystemModule(lua),
"devilutionx.infobox", LuaInfoBoxModule(lua),
"devilutionx.floatingnumbers", LuaFloatingNumbersModule(lua),
"devilutionx.message", [](std::string_view text) { EventPlrMsg(text, UiFlags::ColorRed); },
// This package is loaded without a sandbox:
Expand Down Expand Up @@ -355,6 +357,36 @@ void LuaEvent(std::string_view name, const Player *player, uint32_t arg1)
CallLuaEvent(name, player, arg1);
}

void LuaEvent(std::string_view name, const Item *item)
{
CallLuaEvent(name, item);
}

void LuaEvent(std::string_view name, const Item *item, bool arg1)
{
CallLuaEvent(name, item, arg1);
}

bool LuaEventHasHandlers(std::string_view name)
{
if (!CurrentLuaState.has_value()) {
return false;
}

const auto hasHandlers = CurrentLuaState->events.traverse_get<std::optional<sol::object>>(name, "hasHandlers");
if (!hasHandlers.has_value() || !hasHandlers->is<sol::protected_function>()) {
return false;
}

const sol::protected_function fn = hasHandlers->as<sol::protected_function>();
sol::object result = SafeCallResult(fn(), /*optional=*/true);
if (!result.valid() || result.get_type() != sol::type::boolean) {
return false;
}

return result.as<bool>();
}

sol::state &GetLuaState()
{
return CurrentLuaState->sol;
Expand Down
4 changes: 4 additions & 0 deletions Source/lua/lua_global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace devilution {

struct Player;
struct Monster;
struct Item;

void LuaInitialize();
void LuaReloadActiveMods();
Expand All @@ -19,6 +20,9 @@ void LuaEvent(std::string_view name, std::string_view arg);
void LuaEvent(std::string_view name, const Player *player, int arg1, int arg2);
void LuaEvent(std::string_view name, const Monster *monster, int arg1, int arg2);
void LuaEvent(std::string_view name, const Player *player, uint32_t arg1);
void LuaEvent(std::string_view name, const Item *item);
void LuaEvent(std::string_view name, const Item *item, bool arg1);
bool LuaEventHasHandlers(std::string_view name);
sol::state &GetLuaState();
sol::environment CreateLuaSandbox();
sol::object SafeCallResult(sol::protected_function_result result, bool optional);
Expand Down
Loading