rodecomp/Source/UI/UIChooseSellBuyWnd.cpp
2026-10-24 00:35:19 +00:00

148 lines
4.7 KiB
C++

#include "Client/ModeEvents.h"
#include "Client/ReplayPacketRecorder.h"
#include "Resource/BitmapResource.h"
#include "Resource/ResourceMgr.h"
#include "UI/UIBitmapButton.h"
#include "UI/UIJoinPartyAcceptWnd.h"
#include "UI/UITextViewer.h"
#include "UI/WindowManagerWindows.h"
#include <bit>
#include <cstring>
namespace {
constexpr char prefix[] = "\xC0\xAF\xC0\xFA\xC0\xCE\xC5\xCD\xC6\xE4\xC0\xCC\xBD\xBA\\";
}
// OFFSET: 0x008C73C0
UIChooseSellBuyWnd::UIChooseSellBuyWnd(
UIWindowContext& windows,
UIFrameContext& frames,
UIAcceptanceContext& acceptance
)
: UIFrameWnd(windows, frames, 0), identity(0), m_acceptance(&acceptance) {
}
// OFFSET: 0x008CC430
// FUNCTION: fn_12010
UIChooseSellBuyWnd::~UIChooseSellBuyWnd() = default;
void UIChooseSellBuyWnd::AddChoice(const char* name, int id, int x, int y) {
auto* button = new UIBitmapButton(*this->m_context, this->m_acceptance->text.buttons);
const char* suffixes[] = {"", "_a", "_b"};
for (int state = 0; state < 3; ++state) {
const std::string path = std::string(prefix) + name + suffixes[state] + ".bmp";
button->SetBitmap(path.c_str(), state, 0);
}
button->SetSize(button->BitmapWidth(), button->BitmapHeight());
button->Move(x, y);
button->SetId(id);
this->AddChild(button);
}
void UIChooseSellBuyWnd::CreateViewer(int width, int height) {
auto& text = this->m_acceptance->text;
this->viewer = new UITextViewer(*this->m_context, text);
this->viewer->Configure(10, 22, width - 20, height - 55, 0);
const std::string chip = std::string(prefix) + "colorchip.bmp";
const auto* bitmap = static_cast<CBitmapRes*>(text.buttons.resources.Load(chip.c_str()));
const auto& image = bitmap->image;
const std::uint32_t pixel = image.width > 2 && image.height > 2 ? image.pixels[2 + 2 * image.width] : 0x00FF0000u;
this->viewer->textColor = 0xFF000000u | ((pixel & 255) << 16) | (pixel & 0xFF00) | ((pixel >> 16) & 255);
this->viewer->Invalidate();
this->AddChild(this->viewer);
}
// OFFSET: 0x008DD290
// FUNCTION: fn_12162
void UIChooseSellBuyWnd::Slot15(int width, int height) {
this->AddChoice("btn_buy", 224, 144, 96);
this->AddChoice("btn_sell", 223, 189, 96);
this->AddChoice("btn_cancel", 185, 234, 96);
this->m_message0 = 224;
this->CreateViewer(width, height);
this->viewer->SendMsg(
nullptr, 29, reinterpret_cast<std::intptr_t>(this->m_acceptance->text.buttons.services.MessageText(92)), 38, 0, 0
);
}
// OFFSET: 0x008ED130
// FUNCTION: fn_12214
void UIChooseSellBuyWnd::Paint() {
const std::string path = std::string(prefix) + "win_msgbox.bmp";
const auto* bitmap = static_cast<CBitmapRes*>(this->m_acceptance->text.buttons.resources.Load(path.c_str()));
this->DrawBitmap(0, 0, bitmap ? &bitmap->image : nullptr, false);
}
// OFFSET: 0x008F8860
// FUNCTION: fn_12332
int UIChooseSellBuyWnd::SendMsg(
UIWindow* sender,
int message,
std::intptr_t a,
std::intptr_t b,
std::intptr_t c,
std::intptr_t d
) {
if (message == 6) {
const int response = std::bit_cast<int>(static_cast<unsigned>(a));
this->m_acceptance->recorder.Record(this->geometry.id, response, b, c, d);
if (this->geometry.visible != 0) {
if (response == 185) {
this->m_context->mode->SendModeMessage(40, 0, 0, 0, 0);
this->m_frameContext->windows.CloseWindow(25);
} else if (response == 223 || response == 224) {
this->m_context->mode->SendModeMessage(response == 223 ? 37 : 38, this->identity, 0, 0, 0);
this->m_frameContext->windows.LookupWindow(25)->Show(0);
} else {
return 0;
}
this->m_acceptance->firstShopItems.clear();
this->m_acceptance->secondShopItems.clear();
this->m_acceptance->thirdShopItems.clear();
}
return 0;
}
if (message == 28) {
this->identity = static_cast<std::uint32_t>(a);
return 0;
}
if (message == 123) {
const auto* bytes = reinterpret_cast<const unsigned char*>(a);
std::uint16_t marker;
std::memcpy(&marker, bytes, sizeof(marker));
unsigned offset = 6;
if (marker == 20850) {
while (static_cast<unsigned>(b) > offset) {
std::uint16_t kind;
std::uint32_t size;
std::memcpy(&kind, bytes + offset, sizeof(kind));
std::memcpy(&size, bytes + offset + 2, sizeof(size));
offset += 6;
if (kind == 20851) {
this->m_acceptance->replayShopState = 1;
this->SendMsg(nullptr, 28, 0, 0, 0, 0);
this->m_frameContext->windows.CloseWindow(22);
this->m_frameContext->windows.CloseWindow(23);
this->m_frameContext->windows.CloseWindow(24);
return 0;
}
offset += size;
}
}
return 0;
}
return this->UIFrameWnd::SendMsg(sender, message, a, b, c, d);
}