ko4life-net / ko

Open source development of the game Knight Online. This is a reversed engineered old version of the game aiming to replicate the nostalgic experience we all once had <3
https://github.com/ko4life-net/ko
MIT License
55 stars 22 forks source link

Overlapped texts fix UISkillTreeDlg.cpp #239

Open UTengine opened 4 months ago

UTengine commented 4 months ago

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

Description

This fixes the overlapping texts of the following strings: "img_class_1-3". Result: image Before: image

💔Thank you!

JanekCode commented 4 months ago

Good job

UTengine commented 4 months ago

image

  case NATION_KARUS:
    AllClearImageByName("hunter", false);
    AllClearImageByName("berserker", false);
    AllClearImageByName("sorcerer", false);
    AllClearImageByName("shaman", false);
    AllClearImageByName("Shadow Knight", false);  // Master Class
    AllClearImageByName("Elemental Lord", false); // Master Class
    AllClearImageByName("Shadow Bane", false);    // Master Class
    AllClearImageByName("Berserker Hero", false); // Master Class

case NATION_ELMORAD:
    AllClearImageByName("ranger", false);
    AllClearImageByName("blade", false);
    AllClearImageByName("mage", false);
    AllClearImageByName("cleric", false);
    AllClearImageByName("Paladin", false);      // Master Class
    AllClearImageByName("Arc Mage", false);     // Master Class
    AllClearImageByName("kasar hood", false);   // Master Class
    AllClearImageByName("Blade Master", false); // Master Class
KiraAmora61 commented 4 months ago

void CUISkillTreeDlg::CheckButtonTooltipRenderEnable()
{
#define IN_RECT(a, b)    ((a.left < b.x) && (a.right > b.x) && (a.top < b.y) && (a.bottom > b.y))

    RECT rect[MAX_SKILL_KIND_OF];
    memset(rect, 0, sizeof(RECT) * MAX_SKILL_KIND_OF);

    rect[SKILL_DEF_BASIC] = ((CN3UIButton*)GetChildByID("btn_public"))->GetClickRect();
    rect[SKILL_DEF_SPECIAL3] = ((CN3UIButton*)GetChildByID("btn_master"))->GetClickRect();

    switch (CGameBase::g_pPlayer->m_InfoBase.eNation)
    {
        case NATION_KARUS:
        {
            PrintChildIDs();
            rect[SKILL_DEF_SPECIAL0] = ((CN3UIButton*)GetChildByID("btn_berserker0"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL1] = ((CN3UIButton*)GetChildByID("btn_berserker1"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL2] = ((CN3UIButton*)GetChildByID("btn_berserker2"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL3] = ((CN3UIButton*)GetChildByID("btn_berserker3"))->GetClickRect();
        }
        break;
        case NATION_ELMORAD:
        {
            PrintChildIDs();
            rect[SKILL_DEF_SPECIAL0] = ((CN3UIButton*)GetChildByID("btn_blade0"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL1] = ((CN3UIButton*)GetChildByID("btn_blade1"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL2] = ((CN3UIButton*)GetChildByID("btn_blade2"))->GetClickRect();
            rect[SKILL_DEF_SPECIAL3] = ((CN3UIButton*)GetChildByID("btn_blade3"))->GetClickRect();
        }
        break;
    }

    POINT ptCur = CGameProcedure::g_pLocalInput->MouseGetPos();
    for (int i = 0; i < MAX_SKILL_KIND_OF; i++)
    {
        if (IN_RECT(rect[i], ptCur))
            ButtonTooltipRender(i);
    }
}

void CUISkillTreeDlg::PageButtonInitialize()
{
    SetPageInIconRegion(0, 0);
    SetPageInCharRegion();

    // Define the IDs and their corresponding m_iSkillInfo indices
    const std::vector<std::string> skillStringIDs = 
    {
        "string_skillpoint", "string_0", "string_1", "string_2",
        "string_3", "string_4", "string_5", "string_6", "string_7"
    };

    // Iterate over the IDs and set the strings accordingly
    for (size_t i = 0; i < skillStringIDs.size(); ++i)
    {
        CN3UIString* pStrName = static_cast<CN3UIString*>(GetChildByID(skillStringIDs[i]));
        if (pStrName)
        {
            pStrName->SetStringAsInt(m_iSkillInfo[i]);
        }
    }
    ButtonVisibleStateSet();
}

void CUISkillTreeDlg::ButtonVisibleStateSet()
{
    // Capture 'this' and 'm_iCurKindOf' in the lambda functions
    auto SetButtonState = [this](CN3UIButton* pButton, bool visible, bool downState = false)
    {
        if (!pButton)
            return;

        pButton->SetVisible(visible);
        if (downState)
            pButton->SetState(UI_STATE_BUTTON_DOWN);
        else
            pButton->SetState(UI_STATE_BUTTON_NORMAL);
    };

    auto HideButtons = [this, &SetButtonState](const std::vector<std::string>& buttonIDs)
    {
        for (const auto& id : buttonIDs)
        {
            CN3UIButton* pButton = static_cast<CN3UIButton*>(GetChildByID(id));
            SetButtonState(pButton, false);
        }
    };

    auto ShowButtons = [this, &SetButtonState](const std::vector<std::string>& buttonIDs)
    {
        for (size_t i = 0; i < buttonIDs.size(); ++i)
        {
            CN3UIButton* pButton = static_cast<CN3UIButton*>(GetChildByID(buttonIDs[i]));
            SetButtonState(pButton, true, (m_iCurKindOf == static_cast<int>(i + 1)));
        }
    };

    // Initial button setup
    CN3UIButton* pButton = static_cast<CN3UIButton*>(GetChildByID("btn_public"));
    SetButtonState(pButton, true);

    // Define button IDs for Elmorad and Karus
    std::vector<std::string> elmoradButtons = 
    {
        "btn_ranger0", "btn_ranger1", "btn_ranger2", "btn_blade0", "btn_blade1",
        "btn_blade2", "btn_mage0", "btn_mage1", "btn_mage2", "btn_cleric0",
        "btn_cleric1", "btn_cleric2"
    };

    std::vector<std::string> karusButtons = 
    {
        "btn_hunter0", "btn_hunter1", "btn_hunter2", "btn_berserker0", "btn_berserker1",
        "btn_berserker2", "btn_sorcerer0", "btn_sorcerer1", "btn_sorcerer2", "btn_shaman0",
        "btn_shaman1", "btn_shaman2"
    };

    // Hide all buttons based on nation
    switch (CGameBase::g_pPlayer->m_InfoBase.eNation) 
    {
        case NATION_ELMORAD:HideButtons(elmoradButtons);break;
        case NATION_KARUS:HideButtons(karusButtons);break;
    }

    // Set the "public" button state if needed
    if (m_iCurKindOf == 0) 
    {
        pButton = static_cast<CN3UIButton*>(GetChildByID("btn_public"));
        SetButtonState(pButton, true, true);
    }

    // Show and set state of buttons based on class
    switch (CGameBase::g_pPlayer->m_InfoBase.eClass)
    {
    case KARUS_JOB_CHANGE_WARRIOR:
        ShowButtons({ "btn_berserker0", "btn_berserker1", "btn_berserker2" });
        break;
    case KARUS_JOB_CHANGE_ROGUE:
        ShowButtons({ "btn_hunter0", "btn_hunter1", "btn_hunter2" });
        break;
    case KARUS_JOB_CHANGE_RIEST:
        ShowButtons({ "btn_shaman0", "btn_shaman1", "btn_shaman2" });
        break;
    case KARUS_JOB_CHANGE_MAGE:
        ShowButtons({ "btn_sorcerer0", "btn_sorcerer1", "btn_sorcerer2" });
        break;
    case ELMORAD_JOB_CHANGE_WARRIOR:
        ShowButtons({ "btn_blade0", "btn_blade1", "btn_blade2" });
        break;
    case ELMORAD_JOB_CHANGE_ROGUE:
        ShowButtons({ "btn_ranger0", "btn_ranger1", "btn_ranger2" });
        break;
    case ELMORAD_JOB_CHANGE_RIEST:
        ShowButtons({ "btn_cleric0", "btn_cleric1", "btn_cleric2" });
        break;
    case ELMORAD_JOB_CHANGE_MAGE:
        ShowButtons({ "btn_mage0", "btn_mage1", "btn_mage2" });
        break;
    }
}

bu şekilde kullanabilirsin iyi günler. !

stevewgr commented 3 months ago

@UTengine thanks for this fix! lgtm to me visually 🚀, but give me some time and I'll eventually properly review this in comparison to the disassembled official code. Once I have feedback, I'll get back to you or merge this.

UTengine commented 3 months ago

yes there is an issue with line 1620

UTengine commented 3 months ago

those 3 need to be fixed correctly