rodecomp/Source/UI/Text/ItemLinkDisplay.cpp
ragnarok-clanker 3659ac2f71 Maintenance: [forced, user-approved] Family D7 (resubmit of #10212, returned only for conflicts with newer main; regenerated on e6188
Batch #10213 by ragnarok-clanker: forced by an admin (38 lower score(s), 147 changed function(s)); checked with 352 compiled unit(s), including every includer of Source/Client/Mode/ModeDragState.h, Source/Client/Session.h, Source/Contents/Items/ItemDescription.h, Source/Contents/Items/ItemInfo.h, Source/Contents/Items/ItemLink.h, Source/Contents/Items/ItemResources.h, Source/UI/Shop/ItemDrawing.h, Source/UI/Shortcuts/ShortcutPainting.h, Source/UI/Shortcuts/ShortcutPress.h, Source/UI/Shortcuts/UIQuickSlotWnd.h, Source/UI/Text/TextWrapping.h, Source/UI/Text/UIBalloonText.h, Source/UI/UIStaticItem.h.
2026-11-02 23:43:46 +00:00

136 lines
3.3 KiB
C++

#include "Contents/Items/ItemInfo.h"
#include "Contents/Items/ItemLink.h"
#include "Contents/Items/ItemNaming.h"
#include "Contents/TipBoxTitles.h"
#include "UI/Lists/UIChatHisBox.h"
#include "UI/Text/TextFitting.h"
#include <mbstring.h>
// OFFSET: 0x008816E0
// FUNCTION: fn_11299
bool UIChatHisBox::Name(const std::string& encoded, std::string& output) {
if (encoded.substr(0, 6) == "00000T") {
const int id = ItemLinkMessageId(encoded);
if (g_itemTagOwner->unknown_0118 >= id) {
std::string abbreviated;
output = g_itemTagOwner->Title(id, &abbreviated, 17);
if (!abbreviated.empty()) {
output = abbreviated;
return true;
}
}
return false;
}
std::vector<std::int32_t> fields;
DecodeItemLinkFields(encoded, fields);
ITEM_INFO item;
if (ItemFromLinkFields(fields, item)) {
output = item.DisplayName(0);
return true;
}
return false;
}
// OFFSET: 0x0087FD70
// FUNCTION: fn_11275
bool UIChatHisBox::Next(std::string& remaining, std::string& encoded, unsigned& position, const char* original) {
constexpr std::size_t opening = 7;
constexpr std::size_t closing = 8;
auto close = remaining.find("</ITEML>");
if (close == std::string::npos) {
return false;
}
do {
remaining.resize(close);
auto begin = remaining.find("<ITEML>");
if (begin == std::string::npos) {
position += closing;
remaining = std::string(original).substr(position);
return true;
}
close = remaining.find("</ITEML>");
do {
position += static_cast<unsigned>(begin);
remaining = remaining.substr(begin + opening);
begin = remaining.find("<ITEML>");
close = remaining.find("</ITEML>");
if (begin != std::string::npos) {
position += opening;
}
} while (begin != std::string::npos);
encoded = remaining;
remaining = original;
std::string name;
const bool valid = this->Name(encoded, name);
const auto extent = static_cast<unsigned>(closing + opening + encoded.size());
const auto next = position + extent;
remaining = remaining.substr(next);
if (!valid) {
position = next;
return true;
}
} while (close != std::string::npos);
return true;
}
// OFFSET: 0x00879390
// FUNCTION: fn_11216
std::string UIChatHisBox::Convert(const std::string& text) {
if (!_mbsstr(reinterpret_cast<const unsigned char*>(text.c_str()), reinterpret_cast<const unsigned char*>("<ITEML>"))) {
return text;
}
std::string remaining = text;
std::string result;
unsigned position = 0;
unsigned previous = 0;
for (;;) {
std::string encoded;
if (!this->Next(remaining, encoded, position, text.c_str())) {
break;
}
result.append(text, previous, position - previous);
std::string name;
if (this->Name(encoded, name)) {
result += '<';
result += FitText(*this->geometry.surface, name, this->geometry.width / 2);
result += '>';
position += static_cast<unsigned>(15 + encoded.size());
}
previous = position;
}
result += remaining;
return result;
}
// OFFSET: 0x00884460
// FUNCTION: fn_11307
std::string UIChatHisBox::BracketName(const std::string& name) {
std::string result;
result += '<';
result += FitText(*this->geometry.surface, name, this->geometry.width / 2);
result += '>';
return result;
}