HD Cursor

This commit is contained in:
Kae 2023-06-26 18:39:40 +10:00
parent 32411daa67
commit 4b9b02783f
10 changed files with 44 additions and 14 deletions

View File

@ -0,0 +1,5 @@
{
"frameGrid" : {
"size" : [32, 32]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -0,0 +1,3 @@
{
"scale" : 1
}

View File

@ -0,0 +1,3 @@
{
"scale" : 1
}

View File

@ -0,0 +1,3 @@
{
"scale" : 1
}

View File

@ -76,11 +76,13 @@ void ErrorScreen::renderCursor() {
Vec2I cursorPos = m_cursorScreenPos; Vec2I cursorPos = m_cursorScreenPos;
Vec2I cursorSize = m_cursor.size(); Vec2I cursorSize = m_cursor.size();
Vec2I cursorOffset = m_cursor.offset(); Vec2I cursorOffset = m_cursor.offset();
unsigned int cursorScale = m_cursor.scale(interfaceScale());
Drawable cursorDrawable = m_cursor.drawable();
cursorPos[0] -= cursorOffset[0] * interfaceScale(); cursorPos[0] -= cursorOffset[0] * cursorScale;
cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * interfaceScale(); cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * cursorScale;
if (!m_guiContext->trySetCursor(m_cursor.drawable(), cursorOffset, interfaceScale())) if (!m_guiContext->trySetCursor(cursorDrawable, cursorOffset, cursorScale))
m_guiContext->drawDrawable(m_cursor.drawable(), Vec2F(cursorPos), interfaceScale()); m_guiContext->drawDrawable(cursorDrawable, Vec2F(cursorPos), cursorScale);
} }
float ErrorScreen::interfaceScale() const { float ErrorScreen::interfaceScale() const {

View File

@ -36,6 +36,8 @@ void InterfaceCursor::setCursor(String const& configFile) {
m_drawable = Animation(config.get("animation"), "/interface"); m_drawable = Animation(config.get("animation"), "/interface");
m_size = Vec2I(m_drawable.get<Animation>().drawable(1.0f).boundBox(false).size()); m_size = Vec2I(m_drawable.get<Animation>().drawable(1.0f).boundBox(false).size());
} }
m_scale = config.getUInt("scale", 0);
} }
Drawable InterfaceCursor::drawable() const { Drawable InterfaceCursor::drawable() const {
@ -53,6 +55,10 @@ Vec2I InterfaceCursor::offset() const {
return m_offset; return m_offset;
} }
unsigned int InterfaceCursor::scale(unsigned int interfaceScale) const {
return m_scale ? m_scale : interfaceScale;
}
void InterfaceCursor::update(float dt) { void InterfaceCursor::update(float dt) {
if (m_drawable.is<Animation>()) { if (m_drawable.is<Animation>()) {
m_drawable.get<Animation>().update(dt); m_drawable.get<Animation>().update(dt);

View File

@ -20,6 +20,7 @@ public:
Drawable drawable() const; Drawable drawable() const;
Vec2I size() const; Vec2I size() const;
Vec2I offset() const; Vec2I offset() const;
unsigned int scale(unsigned int interfaceScale = 0) const;
void update(float dt); void update(float dt);
@ -27,6 +28,7 @@ private:
String m_configFile; String m_configFile;
Vec2I m_offset; Vec2I m_offset;
Vec2I m_size; Vec2I m_size;
unsigned int m_scale;
MVariant<String, Animation> m_drawable; MVariant<String, Animation> m_drawable;
}; };

View File

@ -1375,10 +1375,13 @@ void MainInterface::renderCursor() {
Vec2I cursorPos = m_cursorScreenPos; Vec2I cursorPos = m_cursorScreenPos;
Vec2I cursorSize = m_cursor.size(); Vec2I cursorSize = m_cursor.size();
Vec2I cursorOffset = m_cursor.offset(); Vec2I cursorOffset = m_cursor.offset();
cursorPos[0] -= cursorOffset[0] * interfaceScale(); unsigned int cursorScale = m_cursor.scale(interfaceScale());
cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * interfaceScale(); Drawable cursorDrawable = m_cursor.drawable();
if (!m_guiContext->trySetCursor(m_cursor.drawable(), cursorOffset, interfaceScale()))
m_guiContext->drawDrawable(m_cursor.drawable(), Vec2F(cursorPos), interfaceScale()); cursorPos[0] -= cursorOffset[0] * cursorScale;
cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * cursorScale;
if (!m_guiContext->trySetCursor(cursorDrawable, cursorOffset, cursorScale))
m_guiContext->drawDrawable(cursorDrawable, Vec2F(cursorPos), cursorScale);
if (m_cursorTooltip) { if (m_cursorTooltip) {
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
@ -1388,7 +1391,7 @@ void MainInterface::renderCursor() {
auto rawCursorOffset = jsonToVec2I(assets->json("/interface.config:cursorTooltip.offset")); auto rawCursorOffset = jsonToVec2I(assets->json("/interface.config:cursorTooltip.offset"));
Vec2I tooltipSize = Vec2I(imgDb->imageSize(backgroundImage)) * interfaceScale(); Vec2I tooltipSize = Vec2I(imgDb->imageSize(backgroundImage)) * interfaceScale();
Vec2I cursorOffset = (Vec2I{0, -m_cursor.size().y()} + rawCursorOffset) * interfaceScale(); Vec2I cursorOffset = (Vec2I{0, -m_cursor.size().y()} + rawCursorOffset) * cursorScale;
Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset; Vec2I tooltipOffset = m_cursorScreenPos + cursorOffset;
size_t fontSize = assets->json("/interface.config:cursorTooltip.fontSize").toUInt(); size_t fontSize = assets->json("/interface.config:cursorTooltip.fontSize").toUInt();
String font = assets->json("/interface.config:cursorTooltip.font").toString(); String font = assets->json("/interface.config:cursorTooltip.font").toString();
@ -1404,7 +1407,7 @@ void MainInterface::renderCursor() {
VerticalAnchor::VMidAnchor)); VerticalAnchor::VMidAnchor));
} }
m_cursorItem->setPosition(m_cursorScreenPos / interfaceScale() + m_config->inventoryItemMouseOffset); m_cursorItem->setPosition(m_cursorScreenPos / cursorScale + m_config->inventoryItemMouseOffset);
if (auto swapItem = m_client->mainPlayer()->inventory()->swapSlotItem()) if (auto swapItem = m_client->mainPlayer()->inventory()->swapSlotItem())
m_cursorItem->setItem(swapItem); m_cursorItem->setItem(swapItem);

View File

@ -414,11 +414,14 @@ void TitleScreen::renderCursor() {
Vec2I cursorPos = m_cursorScreenPos; Vec2I cursorPos = m_cursorScreenPos;
Vec2I cursorSize = m_cursor.size(); Vec2I cursorSize = m_cursor.size();
Vec2I cursorOffset = m_cursor.offset(); Vec2I cursorOffset = m_cursor.offset();
unsigned int cursorScale = m_cursor.scale(interfaceScale());
Drawable cursorDrawable = m_cursor.drawable();
cursorPos[0] -= cursorOffset[0] * interfaceScale(); cursorPos[0] -= cursorOffset[0] * cursorScale;
cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * interfaceScale(); cursorPos[1] -= (cursorSize[1] - cursorOffset[1]) * cursorScale;
if (!m_guiContext->trySetCursor(m_cursor.drawable(), cursorOffset, interfaceScale()))
m_guiContext->drawDrawable(m_cursor.drawable(), Vec2F(cursorPos), interfaceScale()); if (!m_guiContext->trySetCursor(cursorDrawable, cursorOffset, cursorScale))
m_guiContext->drawDrawable(cursorDrawable, Vec2F(cursorPos), cursorScale);
} }
float TitleScreen::interfaceScale() const { float TitleScreen::interfaceScale() const {