Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CJK fixes for 1.5 #6905

Merged
merged 3 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Source/.clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BasedOnStyle: webkit
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
PointerAlignment: Right
TabWidth: 4
UseTab: ForIndentation
Expand Down
4 changes: 2 additions & 2 deletions Source/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void PrintInfo(const Surface &out)
return;

const int space[] = { 18, 12, 6, 3, 0 };
Rectangle infoArea { GetMainPanel().position + Displacement { 177, 46 }, { 288, 60 } };
Rectangle infoArea { GetMainPanel().position + InfoBoxTopLeft, InfoBoxSize };

const int newLineCount = std::count(InfoString.str().begin(), InfoString.str().end(), '\n');
const int spaceIndex = std::min(4, newLineCount);
Expand Down Expand Up @@ -1161,7 +1161,7 @@ void FreeControlPan()

void DrawInfoBox(const Surface &out)
{
DrawPanelBox(out, { 177, 62, 288, 63 }, GetMainPanel().position + Displacement { 177, 46 });
DrawPanelBox(out, { 177, 62, InfoBoxSize.width, InfoBoxSize.height }, GetMainPanel().position + InfoBoxTopLeft);
if (!panelflag && !trigflag && pcursinvitem == -1 && pcursstashitem == StashStruct::EmptyCell && !spselflag) {
InfoString = {};
InfoColor = UiFlags::ColorWhite;
Expand Down
6 changes: 6 additions & 0 deletions Source/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#include "DiabloUI/ui_flags.hpp"
#include "engine.h"
#include "engine/displacement.hpp"
#include "engine/point.hpp"
#include "engine/rectangle.hpp"
#include "engine/render/text_render.hpp"
#include "engine/size.hpp"
#include "panels/ui_panels.hpp"
#include "spelldat.h"
#include "spells.h"
Expand All @@ -32,6 +34,10 @@ namespace devilution {

constexpr Size SidePanelSize { 320, 352 };

// Info box displacement of the top-left corner relative to GetMainPanel().position.
constexpr Displacement InfoBoxTopLeft { 177, 46 };
constexpr Size InfoBoxSize { 288, 64 };

extern bool dropGoldFlag;
extern bool chrbtn[4];
extern bool lvlbtndown;
Expand Down
3 changes: 2 additions & 1 deletion Source/engine/render/scrollrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,8 @@ void DrawMain(const Surface &out, int dwHgt, bool drawDesc, bool drawHp, bool dr
// When chat input is displayed, the belt is hidden and the chat moves up.
DoBlitScreen(mainPanelPosition.x + 171, mainPanelPosition.y + 6, 298, 116);
} else {
DoBlitScreen(mainPanelPosition.x + 176, mainPanelPosition.y + 46, 288, 63);
DoBlitScreen(mainPanelPosition.x + InfoBoxTopLeft.deltaX, mainPanelPosition.y + InfoBoxTopLeft.deltaY,
InfoBoxSize.width, InfoBoxSize.height);
}
}
if (drawMana) {
Expand Down
31 changes: 20 additions & 11 deletions Source/qol/itemlabels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ bool highlightKeyPressed = false;
bool isLabelHighlighted = false;
std::array<std::optional<int>, ITEMTYPES> labelCenterOffsets;

const int BorderX = 4; // minimal horizontal space between labels
const int BorderY = 2; // minimal vertical space between labels
const int MarginX = 2; // horizontal margins between text and edges of the label
const int MarginY = 1; // vertical margins between text and edges of the label
const int Height = 11 + MarginY * 2; // going above 13 scatters labels of items that are next to each other
const int BorderX = 4; // minimal horizontal space between labels
const int BorderY = 2; // minimal vertical space between labels
const int MarginX = 2; // horizontal margins between text and edges of the label

// Vertical space between the text and the edges of the label.
int TextMarginTop() { return IsSmallFontTall() ? 1 : -1; }
int TextMarginBottom() { return IsSmallFontTall() ? 1 : 3; }

// The total height of the label box.
int LabelHeight() { return (IsSmallFontTall() ? 16 : 11) + TextMarginBottom() + TextMarginTop(); }

/**
* @brief The set of used X coordinates for a certain Y coordinate.
Expand Down Expand Up @@ -121,7 +126,7 @@ void AddItemToLabelQueue(int id, Point position)
position *= 2;
}
position.x -= nameWidth / 2;
position.y -= Height;
position.y -= LabelHeight();
labelQueue.push_back(ItemLabel { id, nameWidth, position, std::move(textOnGround) });
}

Expand Down Expand Up @@ -151,6 +156,8 @@ void DrawItemNameLabels(const Surface &out)
if (labelQueue.empty())
return;
UsedX usedX;
const int labelHeight = LabelHeight();
const int labelMarginTop = TextMarginTop();

for (unsigned i = 0; i < labelQueue.size(); ++i) {
usedX.clear();
Expand All @@ -161,7 +168,7 @@ void DrawItemNameLabels(const Surface &out)
for (unsigned j = 0; j < i; ++j) {
ItemLabel &a = labelQueue[i];
ItemLabel &b = labelQueue[j];
if (abs(b.pos.y - a.pos.y) < Height + BorderY) {
if (abs(b.pos.y - a.pos.y) < labelHeight + BorderY) {
const int widthA = a.width + BorderX + MarginX * 2;
const int widthB = b.width + BorderX + MarginX * 2;
int newpos = b.pos.x;
Expand All @@ -186,7 +193,8 @@ void DrawItemNameLabels(const Surface &out)
for (const ItemLabel &label : labelQueue) {
Item &item = Items[label.id];

if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y + MarginY && MousePosition.y < label.pos.y + MarginY + Height) {
if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width
&& MousePosition.y >= label.pos.y && MousePosition.y < label.pos.y + labelHeight) {
if (!gmenu_is_active()
&& PauseMode == 0
&& !MyPlayerIsDead
Expand All @@ -199,10 +207,11 @@ void DrawItemNameLabels(const Surface &out)
}
}
if (pcursitem == label.id && stextflag == TalkID::None)
FillRect(clippedOut, label.pos.x, label.pos.y + MarginY, label.width, Height, PAL8_BLUE + 6);
FillRect(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight, PAL8_BLUE + 6);
else
DrawHalfTransparentRectTo(clippedOut, label.pos.x, label.pos.y + MarginY, label.width, Height);
DrawString(clippedOut, label.text, { { label.pos.x + MarginX, label.pos.y }, { label.width, Height } }, item.getTextColor());
DrawHalfTransparentRectTo(clippedOut, label.pos.x, label.pos.y, label.width, labelHeight);
DrawString(clippedOut, label.text, { { label.pos.x + MarginX, label.pos.y + labelMarginTop }, { label.width, labelHeight } },
item.getTextColor());
}
labelQueue.clear();
}
Expand Down
3 changes: 2 additions & 1 deletion test/.clang-format
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BasedOnStyle: webkit
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: None
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
PointerAlignment: Right
TabWidth: 4
UseTab: ForIndentation
Expand Down
Loading