JustPaste.it

#include "IFUFUQManager.h"
#include "IFTitleManager.h"
#include <NetProcessIn.h>
#include <ICPlayer.h>
#include "GInterface.h"
#include "TextStringManager.h"
#include "IFSystemMessage.h"
#include "Game.h"
#include "IFMainMenu.h"
#include <ctime>
#include <algorithm>

#define REFRESH_CLICKID 0
GFX_IMPLEMENT_DYNCREATE(CIFUQManager, CIFMainFrame)
GFX_BEGIN_MESSAGE_MAP(CIFUQManager, CIFMainFrame)
ONG_COMMAND(REFRESH_CLICKID, &CIFUQManager::OnRefreshClicked)
ONG_COMMAND(8, &CIFUQManager::OnSearchClicked)
ONG_COMMAND(9, &CIFUQManager::OnViewClicked)
ONG_COMMAND(10, &CIFUQManager::OnOptionChanged)
ONG_COMMAND(12, &CIFUQManager::OnOptionChanged)
ONG_COMMAND(14, &CIFUQManager::OnOptionChanged)

GFX_END_MESSAGE_MAP()
std::vector<CIFUQManager::UniqueHashMapStruct> CIFUQManager::UQlist;


bool CIFUQManager::OnCreate(long ln)
{
    //printf("> " __FUNCTION__ "(%d)\n", ln);

    // Populate inherited members
    CIFMainFrame::OnCreate(ln);
    SetText(L"Unique History (F6)");
    TB_Func_13("interface\\frame\\mframe_wnd_", 0, 0);
    wnd_rect sz;
    sz.pos.x = 10;
    sz.pos.y = 40;
    sz.size.width = 607;
    sz.size.height = 315;
    m_Frame = (CIFFrame*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFFrame), sz, 1, 1);
    m_Frame->TB_Func_13("interface\\inventory\\int_window_", 0, 0);
    m_Frame->BringToFront();

    sz.pos.x = 18;
    sz.pos.y = 46;
    sz.size.width = 592;
    sz.size.height = 305;
    BG_Tile = (CIFNormalTile*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFNormalTile), sz, 2, 1);
    BG_Tile->TB_Func_13("interface\\ifcommon\\bg_tile\\com_bg_tile_b.ddj", 0, 0);
    BG_Tile->BringToFront();

    sz.pos.x = 21;
    sz.pos.y = 102;
    sz.size.width = 184;
    sz.size.height = 24;
    bars[1] = (CIFBarWnd*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFBarWnd), sz, 3, 0);
    bars[1]->TB_Func_13("interface\\ifcommon\\com_bar02_", 1, 1);
    bars[1]->SetText(L"Unique Name");
    bars[1]->BringToFront();

    sz.pos.x = bars[1]->GetBounds().pos.x + bars[1]->GetSize().width;
    sz.pos.y = 102;
    sz.size.width = 70;
    sz.size.height = 24;
    bars[2] = (CIFBarWnd*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFBarWnd), sz, 3, 0);
    bars[2]->TB_Func_13("interface\\ifcommon\\com_bar02_", 1, 1);
    bars[2]->SetText(L"Status");
    bars[2]->BringToFront();

    sz.pos.x = bars[2]->GetBounds().pos.x + bars[2]->GetSize().width;
    sz.pos.y = 102;
    sz.size.width = 132;
    sz.size.height = 24;
    bars[3] = (CIFBarWnd*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFBarWnd), sz, 3, 0);
    bars[3]->TB_Func_13("interface\\ifcommon\\com_bar02_", 1, 1);
    bars[3]->SetText(L"Last Slayer");
    bars[3]->BringToFront();

    sz.pos.x = bars[3]->GetBounds().pos.x + bars[3]->GetSize().width;
    sz.pos.y = 102;
    sz.size.width = 185;
    sz.size.height = 24;
    bars[4] = (CIFBarWnd*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFBarWnd), sz, 3, 0);
    bars[4]->TB_Func_13("interface\\ifcommon\\com_bar02_", 1, 1);
    bars[4]->SetText(L"Elapsed Time (ago)");
    bars[4]->BringToFront();


    sz.pos.x = bars[4]->GetBounds().pos.x + bars[4]->GetSize().width;
    sz.pos.y = 102;
    sz.size.width = 16;
    sz.size.height = 24;
    labels[1] = (CIFStatic*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStatic), sz, 4, 0);
    labels[1]->TB_Func_13("interface\\guild\\gil_shape.ddj", 1, 1);
    labels[1]->BringToFront();

    sz.pos.x = 200;
    sz.pos.y = 43;
    sz.size.width = 16;
    sz.size.height = 24;
    labels[2] = (CIFStatic*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStatic), sz, 6, 0);
    labels[2]->BringToFront();
    labels[2]->SetText(L"Look For a Unique:");
    labels[2]->SetTextColor(0xDBC99B);

    sz.pos.x = 261;
    sz.pos.y = 46;
    sz.size.width = 16;
    sz.size.height = 24;
    UQEdit = (CIFEdit*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFEdit), sz, 7, 0);
    UQEdit->SetGWndSize(175, 20);
    UQEdit->TB_Func_13("interface\\exchange\\exc_box.ddj", 0, 0);
    UQEdit->TB_Func_5(1);
    UQEdit->TB_Func_6(1);
    UQEdit->m_FontTexture.sub_8B4400(1, 0);
    UQEdit->m_FontTexture.sub_8B4750(1);
    UQEdit->BringToFront();
    UQEdit->FUN_00634f80(30);


    sz.pos.x = labels[1]->GetBounds().pos.x + labels[1]->GetSize().width - 580;
    sz.pos.y = labels[1]->GetBounds().pos.y + labels[1]->GetSize().height - 3;
    sz.size.width = 572;
    sz.size.height = 224;
    m_scroll = (CIFScrollManager*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFScrollManager), sz, 5, 0);
    

    sz.pos.x = 20;//20
    sz.pos.y = 124;//72
    sz.size.width = 550;
    sz.size.height = 24;
    for (int i = 0; i < 99; i++) {
        RECT m_Slots = { 20,124,560,24 };
        m_Slots.top += 22 * i;
        m_slots[i] = (CIFUQManagerList*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFUQManagerList), m_Slots, 101, 0);
        m_slots[i]->BringToFront();
    }
    for (int i = 0; i < 10; i++)
        m_slots[i]->ShowGWnd(true);
    for (int i = 0; i < 99; i++)
        m_slots[i]->m_ufbar01->BringToFront();
    for (int i = 0; i < 99; i++)
        m_slots[i]->m_ufbar02->BringToFront();
    for (int i = 0; i < 99; i++)
        m_slots[i]->m_ufbar03->BringToFront();
    sz.pos.x = 19;
    sz.pos.y = 101;
    sz.size.width = 574;
    sz.size.height = 248;
    blacksquare = (CIFStretchWnd*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStretchWnd), sz, 109, 0);
    blacksquare->SetEdgeTextures("interface\\ifcommon\\com_blacksquare_right_side.ddj", "interface\\ifcommon\\com_blacksquare_left_up.ddj",
        "interface\\ifcommon\\com_blacksquare_right_side.ddj", "interface\\ifcommon\\com_blacksquare_right_side.ddj");
    blacksquare->BringToFront();

    for (int i = 1; i <= 4; i++)
        bars[i]->BringToFront();

    m_scroll->m_verticalScroll->SetUniqueID(10);
    m_scroll->sub_008124F0(0);
    m_scroll->sub_008124C0(0x16);
    m_scroll->sub_008123F0(10);
    m_scroll->sub_00812500(0);
    m_scroll->sub_00812420(-8, 0);
    m_scroll->BringToFront();

    sz.pos.x = 146;
    sz.pos.y = 72;
    sz.size.width = 90;
    sz.size.height = 24;
    RefreshClick[0] = (CIFButton*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFButton), sz, REFRESH_CLICKID, 0);
    RefreshClick[0]->SetText(L"Refresh");
    RefreshClick[0]->BringToFront();
    RefreshClick[0]->TB_Func_13("interface\\ifcommon\\com_button.ddj", 0, 0);

    sz.pos.x = 250;
    sz.pos.y = 72;
    sz.size.width = 90;
    sz.size.height = 24;
    RefreshClick[1] = (CIFButton*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFButton), sz, 8, 0);
    RefreshClick[1]->SetText(L"Search");
    RefreshClick[1]->BringToFront();
    RefreshClick[1]->TB_Func_13("interface\\ifcommon\\com_button.ddj", 0, 0);

    sz.pos.x = 354;
    sz.pos.y = 72;
    sz.size.width = 90;
    sz.size.height = 24;
    RefreshClick[2] = (CIFButton*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFButton), sz, 9, 0);
    RefreshClick[2]->SetText(L"View Data");
    RefreshClick[2]->BringToFront();
    RefreshClick[2]->TB_Func_13("interface\\ifcommon\\com_button.ddj", 0, 0);
    BYTE ix = 0;
    int sCount = 99;
    while (ix < sCount && sCount > 0) {
        m_scroll->AddItem(m_slots[ix], 1, 0);
        ix++;
    }
    RECT rect = { 0,0,0,0 };
    ShowOnlyDeadUqsBox = (CIFCheckBox*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFCheckBox), rect, 10, 0);
    ShowOnlyDeadUqsDESC = (CIFStatic*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStatic), rect, 11, 0);
    ShowOnlyDeadUqsBox->BringToFront();
    ShowOnlyDeadUqsBox->MoveGWnd(480, 45);//kant 28
    ShowOnlyDeadUqsBox->SetGWndSize(16, 16);
    ShowOnlyDeadUqsBox->TB_Func_13("interface\\ifcommon\\ifcommon\\com_checkbutton.ddj", 0, 0);
    ShowOnlyDeadUqsDESC->MoveGWnd(ShowOnlyDeadUqsBox->GetBounds().pos.x + 19, ShowOnlyDeadUqsBox->GetBounds().pos.y + 1);
    ShowOnlyDeadUqsDESC->SetText(L"Show Only Dead");
    ShowOnlyDeadUqsDESC->TB_Func_5(0);
    ShowOnlyDeadUqsDESC->TB_Func_6(0);
    ShowOnlyDeadUqsDESC->BringToFront();

    ShowOnlyAliveUqsBox = (CIFCheckBox*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFCheckBox), rect, 12, 0);
    ShowOnlyAliveUqsDESC = (CIFStatic*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStatic), rect, 13, 0);
    ShowOnlyAliveUqsBox->BringToFront();
    ShowOnlyAliveUqsBox->MoveGWnd(480, 65);//kant 28
    ShowOnlyAliveUqsBox->SetGWndSize(16, 16);
    ShowOnlyAliveUqsBox->TB_Func_13("interface\\ifcommon\\ifcommon\\com_checkbutton.ddj", 0, 0);
    ShowOnlyAliveUqsDESC->MoveGWnd(ShowOnlyAliveUqsBox->GetBounds().pos.x + 19, ShowOnlyAliveUqsBox->GetBounds().pos.y + 1);
    ShowOnlyAliveUqsDESC->SetText(L"Show Only Alive");
    ShowOnlyAliveUqsDESC->TB_Func_5(0);
    ShowOnlyAliveUqsDESC->TB_Func_6(0);
    ShowOnlyAliveUqsDESC->BringToFront();

    ShowOnlyMyKillsUqsBox = (CIFCheckBox*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFCheckBox), rect, 14, 0);
    ShowOnlyMyKillsUqsDESC = (CIFStatic*)CGWnd::CreateInstance(this, GFX_RUNTIME_CLASS(CIFStatic), rect, 15, 0);
    ShowOnlyMyKillsUqsBox->BringToFront();
    ShowOnlyMyKillsUqsBox->MoveGWnd(480, 85);//kant 28
    ShowOnlyMyKillsUqsBox->SetGWndSize(16, 16);
    ShowOnlyMyKillsUqsBox->TB_Func_13("interface\\ifcommon\\ifcommon\\com_checkbutton.ddj", 0, 0);
    ShowOnlyMyKillsUqsDESC->MoveGWnd(ShowOnlyMyKillsUqsBox->GetBounds().pos.x + 19, ShowOnlyMyKillsUqsBox->GetBounds().pos.y + 1);
    ShowOnlyMyKillsUqsDESC->SetText(L"Show Only MyKills");
    ShowOnlyMyKillsUqsDESC->TB_Func_5(0);
    ShowOnlyMyKillsUqsDESC->TB_Func_6(0);
    ShowOnlyMyKillsUqsDESC->BringToFront();
    ShowOnlyDeadUqsBox->FUN_00656d50(false);
    ShowOnlyAliveUqsBox->FUN_00656d50(false);
    ShowOnlyMyKillsUqsBox->FUN_00656d50(false);

    this->ShowGWnd(false);
    UpdateMenuSize();
    return true;

}
void CIFUQManager::ClearDDJ() {
    for (int i = 0; i < 99; ++i)
        m_slots[i]->ClearDDJ();
}
void CIFUQManager::Clear()
{
    int sCount = 99;
    BYTE ix = 0;
    while (ix < sCount && sCount > 0) {
        m_slots[ix]->m_UQName->SetText(L"");
        m_slots[ix]->m_State->SetText(L"");
        m_slots[ix]->m_Slayer->SetText(L"");
        m_slots[ix]->m_agoTime->SetText(L"");
        ix++;
    }
}
void CIFUQManager::UpdateMenuSize()
{
    screenCenterPoint.x = theApp.GetClientDimensionStuff().width * 0.5;
    screenCenterPoint.y = theApp.GetClientDimensionStuff().height * 0.5;

    USHORT PosX = 0, PosY = 165;
    PosX = CLIENT_SCREEN_WIDTH - 750;
    this->MoveGWnd((screenCenterPoint.x - 500 * 0.5), (screenCenterPoint.y - 500 * 0.5));
}
void CIFUQManager::OnRefreshClicked()
{
    CMsgStreamBuffer buf(0x2A17);
    SendMsg(buf);
    UpdateLog();
}
void CIFUQManager::OnSearchClicked()
{
    if (UQEdit->GetNText().length() > 0)
    {
        CMsgStreamBuffer buf(0x2A17);
        SendMsg(buf);
        UpdateLogForSearchBtn();
    }
}
void CIFUQManager::OnViewClicked()
{
    if (RefObjID.length() > 0)
    {
        CMsgStreamBuffer buf(0x2A15);
        buf << std::n_string(TO_NSTRING(CIFMainMenu::UqManagerW->RefObjID).c_str());
        SendMsg(buf);
        const ClientResolutonData& res = CGame::GetClientDimensionStuff();
        CIFMainMenu::DpsW->MoveGWnd(((res.width - GetSize().width) + 320), GetPos().y + 60);
        CIFMainMenu::DpsW->BringToFront();

    }
}
void CIFUQManager::OnOptionChanged()
{
    if (ShowOnlyDeadUqsBox->GetCheckedState_MAYBE())
    {
        ShowOnlyAliveUqsBox->FUN_00656d50(false);
        ShowOnlyMyKillsUqsBox->FUN_00656d50(false);
    }
    if (ShowOnlyAliveUqsBox->GetCheckedState_MAYBE())
    {
        ShowOnlyDeadUqsBox->FUN_00656d50(false);
        ShowOnlyMyKillsUqsBox->FUN_00656d50(false);
    }
    if (ShowOnlyMyKillsUqsBox->GetCheckedState_MAYBE())
    {
        ShowOnlyDeadUqsBox->FUN_00656d50(false);
        ShowOnlyAliveUqsBox->FUN_00656d50(false);
    }
}
void  CIFUQManager::UpdateLog()
{
    Clear();
        int count = 0;
        for (std::vector<CIFUQManager::UniqueHashMapStruct>::iterator it = CIFUQManager::UQlist.begin(); it != CIFUQManager::UQlist.end(); ++it)
        {
            if (!ShowOnlyMyKillsUqsBox->GetCheckedState_MAYBE() && !ShowOnlyDeadUqsBox->GetCheckedState_MAYBE() && !ShowOnlyAliveUqsBox->GetCheckedState_MAYBE())
            {
                m_slots[count]->UpdateItems((*it).UqName.c_str(), (*it).LifeState.c_str(), (*it).Killer.c_str(), (*it).agoTime.c_str(), (*it).RefObjID);
                count++;
            }
            else 
            {
                if (ShowOnlyMyKillsUqsBox->GetCheckedState_MAYBE())
                {
                    if (wcscmp((*it).Killer.c_str(), g_pCICPlayer->GetCharName().c_str()) == 0)
                    {
                        m_slots[count]->UpdateItems((*it).UqName.c_str(), (*it).LifeState.c_str(), (*it).Killer.c_str(), (*it).agoTime.c_str(), (*it).RefObjID);
                        count++;
                    }
                }
                if (ShowOnlyDeadUqsBox->GetCheckedState_MAYBE())
                {
                    if (wcscmp((*it).LifeState.c_str(), L"Dead") == 0)
                    {
                        m_slots[count]->UpdateItems((*it).UqName.c_str(), (*it).LifeState.c_str(), (*it).Killer.c_str(), (*it).agoTime.c_str(), (*it).RefObjID);
                        count++;
                    }
                }
                if (ShowOnlyAliveUqsBox->GetCheckedState_MAYBE())
                {
                    if (wcscmp((*it).LifeState.c_str(), L"Alive") == 0)
                    {
                        m_slots[count]->UpdateItems((*it).UqName.c_str(), (*it).LifeState.c_str(), (*it).Killer.c_str(), (*it).agoTime.c_str(), (*it).RefObjID);
                        count++;
                    }
                }
            }
        }
}

void CIFUQManager::UpdateLogForSearchBtn()
{
    Clear();
    int count = 0;
    std::wstring SearchSTR = UQEdit->GetNText().c_str();
    std::transform(SearchSTR.begin(), SearchSTR.end(), SearchSTR.begin(), ::tolower);
    // Use std::wstring instead of std::string for uqName
    for (std::vector<CIFUQManager::UniqueHashMapStruct>::iterator it = CIFUQManager::UQlist.begin(); it != CIFUQManager::UQlist.end(); ++it)
    {
        std::wstring uqName = (*it).UqName;
        std::transform(uqName.begin(), uqName.end(), uqName.begin(), ::tolower);
        // Use std::wstring::find instead of std::string::find
        if (uqName.find(SearchSTR.c_str()) != std::wstring::npos)
        {
            m_slots[count]->UpdateItems((*it).UqName.c_str(), (*it).LifeState.c_str(), (*it).Killer.c_str(), (*it).agoTime.c_str(), (*it).RefObjID);
            count++;
        }
    }
}

void CIFUQManager::OnUpdate()
{
}