Batch #1665 by ragnarok-clanker: 0 byte-identical, 70 confirmed by peer review. - fn_10904 UIEditCtrl::UpdateLinks: logic confirmed by peer review - fn_10905 EditViewport::Synchronize: logic confirmed by peer review - fn_10950 UIBalloonText::SetText: logic confirmed by peer review - fn_11216 ItemLinkDisplay::Convert: logic confirmed by peer review - fn_11326 UIListBox::Slot15: logic confirmed by peer review (already on main) - fn_11327 UIListBoxEx::Slot15: logic confirmed by peer review (already on main) - fn_11366 UIListBox::Paint: logic confirmed by peer review - fn_11367 UIListBoxEx::Paint: logic confirmed by peer review - fn_11392 UITextButton::Paint: logic confirmed by peer review - fn_11394 UITextViewer::Paint: logic confirmed by peer review - fn_11445 UITextButton::Slot31: logic confirmed by peer review (already on main) - fn_11471 UITextButton::Slot27: logic confirmed by peer review (already on main) - fn_11494 UITextButton::Slot33: logic confirmed by peer review (already on main) - fn_11562 UITextViewer::SendMsg: logic confirmed by peer review (already on main) - fn_11721 UICntWnd::DrawBorder: logic confirmed by peer review (already on main) - fn_11760 UIBank_NewWnd::Paint: logic confirmed by peer review (already on main) - fn_11761 UIChatRoomWnd::Paint: logic confirmed by peer review (already on main) - fn_11767 UIMerInfoWnd::Paint: logic confirmed by peer review (already on main) - fn_12680 ShortcutPainting::Paint: logic confirmed by peer review - fn_13829 WrapPlainText: logic confirmed by peer review - fn_13833 WrapRichText: logic confirmed by peer review - fn_16941 UIWindow::DrawAmount: logic confirmed by peer review - fn_16971 UIWindow::TextHeight: logic confirmed by peer review - fn_16972 UIWindow::VerticalTextHeight: logic confirmed by peer review - fn_16973 UIWindow::TextSize: logic confirmed by peer review - fn_16974 UIWindow::VerticalTextSize: logic confirmed by peer review - fn_16975 UIWindow::TextWidth: logic confirmed by peer review - fn_16993 WrapPixelText: logic confirmed by peer review - fn_17007 FitText: logic confirmed by peer review - fn_17009 UIWindow::DrawTextAt: logic confirmed by peer review - fn_17013 DrawOutlinedColoredText: logic confirmed by peer review - fn_17014 DrawStyledColoredText: logic confirmed by peer review - fn_17015 DrawColoredText: logic confirmed by peer review - fn_17016 DrawOutlinedText: logic confirmed by peer review - fn_17136 BrowserFactory::Create: logic confirmed by peer review - fn_18376 LookupMessage: logic confirmed by peer review - fn_01934 TextContext::TextContext: logic confirmed by peer review - fn_01957 TextContext::Marker: logic confirmed by peer review - fn_01961 TextContext::Measure: logic confirmed by peer review - fn_01966 TextContext::SetFont: logic confirmed by peer review - fn_01970 TextContext::DrawPair: logic confirmed by peer review - fn_01971 TextContext::Draw: logic confirmed by peer review - fn_01983 TextContext::MeasurePart: logic confirmed by peer review - fn_01984 TextContext::DrawPart: logic confirmed by peer review - fn_21788 ReceivePartyJoinResult: logic confirmed by peer review - fn_24191 EmotionHotkeys::LoadDefaults: logic confirmed by peer review - fn_03664 CAdventurerAgencyMgr::CompletePartyInfo: logic confirmed by peer review - fn_03666 CAdventurerAgencyMgr::CompleteRegistration: logic confirmed by peer review - fn_03668 CAdventurerAgencyMgr::CompleteStopRecruiting: logic confirmed by peer review - fn_03976 CEmblemDataMgr::CompleteUpload: logic confirmed by peer review - fn_04239 CMCStoreInfoBackup::CompleteSave: logic confirmed by peer review - fn_04262 CPlayerNameDictionary::Lookup: logic confirmed by peer review - fn_06581 ItemNaming::DisplayName: logic confirmed by peer review (already on main) - fn_06583 ItemNamingContext::Element: logic confirmed by peer review (already on main) - fn_06584 ItemNamingContext::Star: logic confirmed by peer review (already on main) - fn_06585 ItemNaming::Creator: logic confirmed by peer review (already on main) - fn_06586 ItemNamingContext::Apprentice: logic confirmed by peer review (already on main) - fn_06587 ItemNaming::Suffixes: logic confirmed by peer review (already on main) - fn_06588 ItemNaming::Prefixes: logic confirmed by peer review (already on main) - fn_09299 UIApplyForPartyWnd::Slot15: logic confirmed by peer review - fn_09300 UIRegisterPartyWnd::Slot15: logic confirmed by peer review - fn_09301 UIRequestJoinPartyWnd::Slot15: logic confirmed by peer review - fn_09303 UIApplyForPartyWnd::Paint: logic confirmed by peer review - fn_09304 UIPartyInfoWnd::Paint: logic confirmed by peer review - fn_10748 UIEditCtrl::RemoveInvalidLink: logic confirmed by peer review - fn_10758 UIEditCtrl::DrawSelectionAt: logic confirmed by peer review (already on main) - fn_10759 UIEditCtrl::DrawSelection: logic confirmed by peer review (already on main) - fn_10794 UIBasicButton::Paint: logic confirmed by peer review - fn_10799 UIBmpTextButton::Paint: logic confirmed by peer review - fn_10823 UITransBalloonText::Paint: logic confirmed by peer review Reviewed-by: ragnarok-clanker
212 lines
6.7 KiB
C++
212 lines
6.7 KiB
C++
#include "Client/Input/TextInputBuffer.h"
|
|
#include "UI/Window/InputFocus.h"
|
|
#include "UI/Text/NavigationLink.h"
|
|
#include "UI/Text/TextFitting.h"
|
|
#include "UI/Buttons/UIButton.h"
|
|
#include "UI/Edit/UIEditCtrl.h"
|
|
#include "UI/Buttons/UINaviLinkButton.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
#include <mbstring.h>
|
|
|
|
// OFFSET: 0x00854470
|
|
// FUNCTION: fn_10748
|
|
bool UIEditCtrl::RemoveInvalidLink(std::list<UIWindow*>::iterator& entry) {
|
|
auto* button = static_cast<UINaviLinkButton*>(*entry);
|
|
const std::string name = FormatNavigationLink(button->link, false);
|
|
std::string remaining = this->text;
|
|
|
|
if (name.empty()) {
|
|
return true;
|
|
}
|
|
|
|
const std::string fitted = FitText(*this->geometry.surface, name, this->geometry.width / 2);
|
|
std::size_t found = remaining.find(fitted);
|
|
|
|
if (found == std::string::npos) {
|
|
this->RemoveChild(button, 1);
|
|
entry = this->links.erase(entry);
|
|
return true;
|
|
}
|
|
|
|
std::size_t absolute = found;
|
|
const std::size_t bytes = fitted.size();
|
|
|
|
while (found != std::string::npos) {
|
|
const bool left = found > 0 && remaining[found - 1] == '<';
|
|
const bool right = found + bytes < remaining.size() && remaining[found + bytes] == '>';
|
|
|
|
if (left && right) {
|
|
return false;
|
|
}
|
|
|
|
if (left != right) {
|
|
const bool allowed = !this->m_edit->linkInputRestricted || this->m_edit->permittedLinkInput == this->m_edit->focus.window;
|
|
const auto boundary = left ? absolute + bytes : absolute;
|
|
|
|
if (allowed && boundary == static_cast<unsigned>(this->m_edit->input.cursor)) {
|
|
const auto begin = left ? absolute - 1 : absolute;
|
|
const auto end = absolute + bytes + (right ? 1 : 0);
|
|
remaining = this->text.substr(0, begin) + this->text.substr(end);
|
|
this->m_edit->input.CancelComposition();
|
|
this->m_edit->input.Insert(remaining.c_str());
|
|
this->RemoveChild(button, 1);
|
|
entry = this->links.erase(entry);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
remaining = remaining.substr(found + bytes);
|
|
const auto previous = found;
|
|
found = remaining.find(fitted);
|
|
|
|
if (found != std::string::npos) {
|
|
absolute = bytes + (absolute == previous ? absolute : absolute + previous);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x008550E0
|
|
// FUNCTION: fn_10750
|
|
void UIEditCtrl::SnapLinkSelection(std::size_t prefix, std::size_t bytes) {
|
|
if (this->m_edit->linkInputRestricted && this->m_edit->permittedLinkInput != this->m_edit->focus.window) {
|
|
return;
|
|
}
|
|
|
|
const auto cursor = static_cast<unsigned>(this->m_edit->input.cursor);
|
|
const auto end = prefix + bytes + 2;
|
|
|
|
if (cursor > prefix && cursor < end) {
|
|
const auto target = prefix + bytes / 2 + 1 <= cursor ? prefix : end;
|
|
this->m_edit->input.Select(static_cast<int>(target), static_cast<int>(target));
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x008624B0
|
|
// FUNCTION: fn_10904
|
|
void UIEditCtrl::UpdateLinks() {
|
|
if (std::none_of(this->links.begin(), this->links.end(), [](const UIWindow* window) { return window->geometry.id == 438; })) {
|
|
return;
|
|
}
|
|
|
|
this->linkedText.clear();
|
|
std::string prefix;
|
|
std::string remaining = this->text;
|
|
|
|
for (auto entry = this->links.begin(); entry != this->links.end();) {
|
|
if (this->RemoveInvalidLink(entry)) {
|
|
remaining.assign(this->m_edit->input.text.c_str());
|
|
break;
|
|
}
|
|
|
|
auto* button = static_cast<UINaviLinkButton*>(*entry);
|
|
const std::string name = FormatNavigationLink(button->link, false);
|
|
const std::string fitted = FitText(*this->geometry.surface, name, this->geometry.width / 2);
|
|
const std::string display = "<" + fitted + ">";
|
|
const auto found = remaining.find(display);
|
|
|
|
if (found != std::string::npos) {
|
|
const std::string head = remaining.substr(0, found);
|
|
prefix += head;
|
|
const auto end = prefix.size() - 1;
|
|
std::string visible;
|
|
|
|
if (end >= static_cast<unsigned>(this->firstVisible)) {
|
|
visible = prefix.substr(static_cast<unsigned>(this->firstVisible));
|
|
} else {
|
|
visible = prefix.substr(end, 1);
|
|
}
|
|
|
|
if (this->firstVisible != 0 && prefix.size() <= static_cast<unsigned>(this->firstVisible)) {
|
|
button->Move(1000, this->textY - 1);
|
|
} else {
|
|
button->Move(this->TextWidth(this->m_edit->buttons.fonts, this->m_edit->buttons.locale, visible.c_str(), 0, 0, 12, 0, 0) + 2, this->textY - 1);
|
|
}
|
|
|
|
this->SnapLinkSelection(prefix.size(), fitted.size());
|
|
this->linkedText += head;
|
|
this->linkedText += button->link;
|
|
remaining = remaining.substr(found + display.size());
|
|
prefix += display;
|
|
}
|
|
|
|
++entry;
|
|
}
|
|
|
|
this->linkedText += remaining;
|
|
}
|
|
|
|
// INLINED
|
|
void UIEditCtrl::InsertLink(const char* value) {
|
|
const std::string name = FormatNavigationLink(value, false);
|
|
|
|
FitText(*this->geometry.surface, name, this->geometry.width / 2);
|
|
const std::string display = "<" + name + ">";
|
|
std::string before;
|
|
bool removed = false;
|
|
std::size_t position = std::string::npos;
|
|
std::size_t oldBytes = 0;
|
|
|
|
for (auto entry = this->links.begin(); entry != this->links.end();) {
|
|
UIWindow* window = *entry;
|
|
|
|
if (window->geometry.id == 438) {
|
|
removed = true;
|
|
const auto* button = static_cast<const UINaviLinkButton*>(window);
|
|
const std::string fitted = FitText(
|
|
*this->geometry.surface, FormatNavigationLink(button->link, false), this->geometry.width / 2
|
|
);
|
|
const std::string old = "<" + fitted + ">";
|
|
|
|
oldBytes = old.size();
|
|
position = this->text.find(old);
|
|
|
|
if (position != std::string::npos) {
|
|
before = this->text.substr(0, position);
|
|
}
|
|
|
|
this->RemoveChild(window, 1);
|
|
entry = this->links.erase(entry);
|
|
} else {
|
|
++entry;
|
|
}
|
|
}
|
|
|
|
if (!_mbsstr(reinterpret_cast<const unsigned char*>(value), reinterpret_cast<const unsigned char*>("<NAVIL>")) &&
|
|
!_mbsstr(reinterpret_cast<const unsigned char*>(value), reinterpret_cast<const unsigned char*>("</NAVIL>"))) {
|
|
this->SetText(value);
|
|
return;
|
|
}
|
|
|
|
std::string transformed;
|
|
DisplayNavigationLink(transformed, value);
|
|
const std::string prospective = this->text + transformed;
|
|
|
|
if (static_cast<unsigned>(this->maximum) < prospective.size()) {
|
|
return;
|
|
}
|
|
|
|
if (removed) {
|
|
if (position != std::string::npos) {
|
|
this->text = before + display + this->text.substr(position + oldBytes);
|
|
}
|
|
} else {
|
|
this->text += transformed;
|
|
}
|
|
|
|
this->SetText(this->text.c_str());
|
|
this->anchor = this->cursor = static_cast<int>(this->text.size());
|
|
this->m_edit->input.Select(this->cursor, this->cursor);
|
|
|
|
auto* button = new UINaviLinkButton(*this->m_context, this->m_edit->buttons, this->m_edit->navigation);
|
|
|
|
button->Configure(display.c_str(), 0x009E68F0, 0, 12, 0, 0);
|
|
button->SetId(438);
|
|
ExtractNavigationLink(button->link, value);
|
|
this->AddChild(button);
|
|
this->links.push_back(button);
|
|
}
|