Skip to content

Commit

Permalink
Update handling of race selection
Browse files Browse the repository at this point in the history
Make the race selection dialog no longer use an hardcoded max amount of checkboxes and update its drawing so that all the options are put one after the other rather than having big gaps between the available ones.
  • Loading branch information
edo9300 committed Apr 20, 2023
1 parent 33be212 commit 933c0c4
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 33 deletions.
15 changes: 15 additions & 0 deletions gframe/client_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <IGUIScrollBar.h>
#include <IGUIListBox.h>
#include <IGUIEditBox.h>
#include <IGUICheckBox.h>
#include <IVideoDriver.h>
#include <ICameraSceneNode.h>
#include "game.h"
Expand Down Expand Up @@ -1157,6 +1158,20 @@ bool ClientField::CheckSelectSum() {
return ret;
}
}
void ClientField::ShowSelectRace(uint64_t race) {
uint64_t filter = 0x1;
auto selected = 0;
for(auto i = 0u; i < sizeofarr(mainGame->chkRace); ++i, filter <<= 1) {
auto* checkBox = mainGame->chkRace[i];
checkBox->setChecked(false);
auto checked = (filter & race) != 0;
checkBox->setVisible(checked);
if(checked) {
checkBox->setRelativePosition(mainGame->Scale<irr::s32>(10 + (selected % 3) * 120, (selected / 3) * 25, 150 + (selected % 3) * 120, 25 + (selected / 3) * 25));
++selected;
}
}
}
bool ClientField::check_min(const std::set<ClientCard*>& left, std::set<ClientCard*>::const_iterator index, int min, int max) {
if (index == left.end())
return false;
Expand Down
1 change: 1 addition & 0 deletions gframe/client_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ClientField: public irr::IEventReceiver {
void FadeCard(ClientCard* pcard, float alpha, float frame);
bool ShowSelectSum();
bool CheckSelectSum();
void ShowSelectRace(uint64_t race);
bool check_min(const std::set<ClientCard*>& left, std::set<ClientCard*>::const_iterator index, int min, int max);
bool check_sel_sum_s(const std::set<ClientCard*>& left, size_t index, int acc);
void check_sel_sum_t(const std::set<ClientCard*>& left, int acc);
Expand Down
8 changes: 7 additions & 1 deletion gframe/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@
#define RACE_CREATORGOD 0x400000
#define RACE_WYRM 0x800000
#define RACE_CYBERSE 0x1000000
#define RACE_CYBORG 0x2000000
#define RACE_ILLUSIONIST 0x2000000
#define RACE_CYBORG 0x4000000
#define RACE_MAGICALKNIGHT 0x8000000
#define RACE_HIGHDRAGON 0x10000000
#define RACE_OMEGAPSYCHIC 0x20000000
#define RACE_CELESTIALWARRIOR 0x40000000
#define RACE_GALAXY 0x80000000

//Reasons
#define REASON_DESTROY 0x1
Expand Down
13 changes: 2 additions & 11 deletions gframe/data_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,11 @@ static std::wstring FormatSkill(uint64_t skill_type) {
std::wstring DataManager::FormatRace(uint64_t race, bool isSkill) const {
if(isSkill) return FormatSkill(race);
std::wstring res;
uint32_t i = 1020;
for(; race && i <= 1049; race >>= 1, ++i) {
for(uint32_t i = 0; race; race >>= 1, ++i) {
if(race & 0x1u) {
if(!res.empty())
res += L'|';
appendstring(res, GetSysString(i));
}
}
//strings 1050 above are already used, read the rest from this other range
for(i = 2500; race; race >>= 1, ++i) {
if(race & 0x1u) {
if(!res.empty())
res += L'|';
appendstring(res, GetSysString(i));
appendstring(res, GetSysString(GetRaceStringIndex(i)));
}
}
if(res.empty())
Expand Down
7 changes: 7 additions & 0 deletions gframe/data_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <unordered_map>
#include <cstdint>
#include <memory>
#include "common.h"
#include "text_types.h"
#include "utils.h"

Expand Down Expand Up @@ -138,6 +139,12 @@ class DataManager {
inline epro::wstringview GetSetName(uint32_t code) const {
return _setnameStrings.GetLocale(code, L"");
}
inline uint32_t GetRaceStringIndex(uint32_t race_idx) const {
if(race_idx < 30)
return 1020 + race_idx;
//strings 1050 above are already used, read the rest from this other range
return (2500 - 30) + race_idx;
}
std::vector<uint16_t> GetSetCode(const std::vector<std::wstring>& setname) const;
std::wstring GetNumString(size_t num, bool bracket = false) const;
epro::wstringview FormatLocation(uint32_t location, int sequence) const;
Expand Down
15 changes: 4 additions & 11 deletions gframe/duelclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3834,14 +3834,8 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
/*const auto player = */mainGame->LocalPlayer(BufferIO::Read<uint8_t>(pbuf));
mainGame->dField.announce_count = BufferIO::Read<uint8_t>(pbuf);
const auto available = CompatRead<uint32_t, uint64_t>(pbuf);
uint64_t filter = 0x1;
for(int i = 0; i < 25; ++i, filter <<= 1) {
mainGame->chkRace[i]->setChecked(false);
if(filter & available)
mainGame->chkRace[i]->setVisible(true);
else mainGame->chkRace[i]->setVisible(false);
}
std::unique_lock<epro::mutex> lock(mainGame->gMutex);
mainGame->dField.ShowSelectRace(available);
mainGame->wANRace->setText(gDataManager->GetDesc(select_hint ? select_hint : 563, mainGame->dInfo.compat_mode).data());
mainGame->PopupElement(mainGame->wANRace);
select_hint = 0;
Expand All @@ -3851,11 +3845,10 @@ int DuelClient::ClientAnalyze(const uint8_t* msg, uint32_t len) {
/*const auto player = */mainGame->LocalPlayer(BufferIO::Read<uint8_t>(pbuf));
mainGame->dField.announce_count = BufferIO::Read<uint8_t>(pbuf);
const auto available = BufferIO::Read<uint32_t>(pbuf);
for(int i = 0, filter = 0x1; i < 7; ++i, filter <<= 1) {
uint32_t filter = 0x1;
for(auto i = 0u; i < sizeofarr(mainGame->chkAttribute); ++i, filter <<= 1) {
mainGame->chkAttribute[i]->setChecked(false);
if(filter & available)
mainGame->chkAttribute[i]->setVisible(true);
else mainGame->chkAttribute[i]->setVisible(false);
mainGame->chkAttribute[i]->setVisible((filter& available) != 0);
}
std::unique_lock<epro::mutex> lock(mainGame->gMutex);
mainGame->wANAttribute->setText(gDataManager->GetDesc(select_hint ? select_hint : 562, mainGame->dInfo.compat_mode).data());
Expand Down
2 changes: 1 addition & 1 deletion gframe/event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
}
case CHECK_RACE: {
uint64_t rac = 0, filter = 0x1, count = 0;
for(int i = 0; i < 25; ++i, filter <<= 1) {
for(int i = 0; i < sizeofarr(mainGame->chkRace); ++i, filter <<= 1) {
if(mainGame->chkRace[i]->isChecked()) {
rac |= filter;
count++;
Expand Down
19 changes: 11 additions & 8 deletions gframe/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,15 @@ void Game::Initialize() {
defaultStrings.emplace_back(wANRace, 563);
wANRace->getCloseButton()->setVisible(false);
wANRace->setVisible(false);
for(int i = 0; i < 25; ++i) {
chkRace[i] = env->addCheckBox(false, Scale(10 + (i % 4) * 90, 25 + (i / 4) * 25, 100 + (i % 4) * 90, 50 + (i / 4) * 25),
wANRace, CHECK_RACE, gDataManager->GetSysString(1020 + i).data());
defaultStrings.emplace_back(chkRace[i], 1020 + i);
{
auto tmpPanel = irr::gui::Panel::addPanel(env, wANRace, -1, wANRace->getClientRect(), true, false);
auto crPanel = tmpPanel->getSubpanel();
for(int i = 0; i < static_cast<int>(sizeofarr(chkRace)); ++i) {
auto string = gDataManager->GetRaceStringIndex(i);
chkRace[i] = env->addCheckBox(false, Scale(10 + (i % 3) * 120, (i / 3) * 25, 150 + (i % 3) * 120, 25 + (i / 3) * 25),
crPanel, CHECK_RACE, gDataManager->GetSysString(string).data());
defaultStrings.emplace_back(chkRace[i], string);
}
}
//selection hint
stHintMsg = env->addStaticText(L"", Scale(500, 60, 820, 90), true, false, 0, -1, false);
Expand Down Expand Up @@ -3425,10 +3430,8 @@ void Game::ReloadCBRace() {
//currently corresponding to RACE_GALAXY
static constexpr auto RACE_MAX = UINT64_C(0x80000000);
uint64_t filter = 0x1;
for(uint32_t i = 1020; i <= 1049 && filter <= RACE_MAX; i++, filter <<= 1)
cbRace->addItem(gDataManager->GetSysString(i).data(), filter);
for(uint32_t i = 2500; filter <= RACE_MAX; i++, filter <<= 1)
cbRace->addItem(gDataManager->GetSysString(i).data(), filter);
for(uint32_t i = 0; filter <= RACE_MAX; i++, filter <<= 1)
cbRace->addItem(gDataManager->GetSysString(gDataManager->GetRaceStringIndex(i)).data(), filter);
}
void Game::ReloadCBFilterRule() {
cbFilterRule->clear();
Expand Down
2 changes: 1 addition & 1 deletion gframe/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ class Game {
irr::gui::IGUICheckBox* chkAttribute[7];
//announce race
irr::gui::IGUIWindow* wANRace;
irr::gui::IGUICheckBox* chkRace[25];
irr::gui::IGUICheckBox* chkRace[64];
//cmd menu
irr::gui::IGUIWindow* wCmdMenu;
irr::gui::IGUIButton* btnActivate;
Expand Down

0 comments on commit 933c0c4

Please sign in to comment.