Skip to content

Commit

Permalink
Initial type matchup support
Browse files Browse the repository at this point in the history
  • Loading branch information
zaksabeast committed Apr 4, 2020
1 parent 054f60c commit 774bf54
Show file tree
Hide file tree
Showing 17 changed files with 1,301 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CaptureSight/include/ui/MainApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ui/views/MainMenuLayout.hpp>
#include <ui/views/PokemonListLayout.hpp>
#include <ui/views/PokemonSummaryLayout.hpp>
#include <ui/views/PokemonTypeLayout.hpp>
#include <ui/views/RaidSearchResultLayout.hpp>
#include <ui/views/RaidSearchSettingsLayout.hpp>
#include <ui/views/WarningLayout.hpp>
Expand All @@ -32,6 +33,7 @@ class MainApplication : public pu::ui::Application {
std::vector<std::shared_ptr<csight::raid::Den>> m_dens;
bool m_isShowingExtraDetail = false;
PokemonSummaryLayout::Ref m_pokemonSummaryLayout;
PokemonTypeLayout::Ref m_pokemonTypeLayout;
MainMenuLayout::Ref m_mainMenuLayout;
PokemonListLayout::Ref m_pokemonListLayout;
RaidSearchResultLayout::Ref m_raidSearchResultLayout;
Expand All @@ -48,7 +50,9 @@ class MainApplication : public pu::ui::Application {
void OnInputRaidSearchResultLayout(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
void OnInputDenList(u64 seed);
void OnInputPokemonListLayout(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
void OnInputDenMenuLayout(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
void OnInputRaidSearchSettingsLayout(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
void ShowPKMTypeMatchUps(std::shared_ptr<csight::PKM> pkm);
void SelectPokemonSlot(u32 slot);
void IncreaseSlot(u32 slotIncrease);
void DecreaseSlot(u32 slotDecrease);
Expand Down
1 change: 1 addition & 0 deletions CaptureSight/include/ui/views/DenMenuLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DenMenuLayout : public pu::ui::Layout {
void UpdateValues(std::vector<std::shared_ptr<csight::raid::Den>> dens);
void SetOnInputMenuItem(std::function<void(u64)> onInput);
void ClickMenuItem(u64 seed);
s32 GetSelectedIndex();

private:
pu::ui::elm::Menu::Ref m_menu;
Expand Down
2 changes: 2 additions & 0 deletions CaptureSight/include/ui/views/PokemonListLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class PokemonListLayout : public pu::ui::Layout {
void UpdateValues(std::vector<std::shared_ptr<csight::PK8>> pk8s, std::function<std::string(u32)> GetTitle);
void SetOnInputMenuItem(std::function<void(u32)> onInput);
void SetSelectedIndex(u32 index);
s32 GetSelectedIndex();

private:
pu::ui::elm::Menu::Ref m_menu;
std::function<void(u32)> m_onMenuItemInput;
pu::ui::elm::TextBlock::Ref m_instructionTextBlock;
pu::ui::elm::MenuItem::Ref CreateMenuItem(std::shared_ptr<csight::PK8> pk8, u32 slot, std::string title);
void ClickMenuItem(u32 slot);
};
17 changes: 17 additions & 0 deletions CaptureSight/include/ui/views/PokemonTypeLayout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <csight/core>
#include <pu/Plutonium>
#include <vector>

class PokemonTypeLayout : public pu::ui::Layout {
public:
PU_SMART_CTOR(PokemonTypeLayout)
void SetTypeMatchUps(std::vector<csight::type::TypeMultiplier> defensiveMatchUps,
std::vector<csight::type::TypeMultiplier> offensiveMatchUps);

private:
void AddMatchUpBlock(std::vector<csight::type::TypeMultiplier> matchUps, std::string header, std::string firstMatchUpName,
std::string secondMatchUpName, u32 baseX);
void AddMatchUpText(std::vector<csight::type::TypeMultiplier> matchUps, std::string matchUpName, u32 x, u32 y);
};
24 changes: 24 additions & 0 deletions CaptureSight/source/ui/MainApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void MainApplication::OnLoad() {
m_pokemonSummaryLayout->SetOnInput(std::bind(&MainApplication::OnInputPokemonSummaryLayout, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));

SETUP_LAYOUT(PokemonTypeLayout, m_pokemonTypeLayout);

SETUP_LAYOUT(MainMenuLayout, m_mainMenuLayout);
m_mainMenuLayout->SetOnInputMenuItem(std::bind(&MainApplication::SetViewMode, this, std::placeholders::_1));
m_mainMenuLayout->Add(m_versionTextBlock);
Expand All @@ -71,6 +73,9 @@ void MainApplication::OnLoad() {

SETUP_LAYOUT(DenMenuLayout, m_denMenuLayout);
m_denMenuLayout->SetOnInputMenuItem(std::bind(&MainApplication::OnInputDenList, this, std::placeholders::_1));
m_denMenuLayout->UpdateValues(m_dens);
m_denMenuLayout->SetOnInput(std::bind(&MainApplication::OnInputDenMenuLayout, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));

SETUP_LAYOUT(RaidSearchSettingsLayout, m_raidSearchSettingsLayout);
m_raidSearchSettingsLayout->SetOnInput(std::bind(&MainApplication::OnInputRaidSearchSettingsLayout, this, std::placeholders::_1,
Expand Down Expand Up @@ -113,9 +118,28 @@ void MainApplication::OnInputPokemonListLayout(u64 Down, u64 Up, u64 Held, pu::u
this->DecreaseSlot(30);
} else if (Down & KEY_R) {
this->IncreaseSlot(30);
} else if (Down & KEY_Y) {
auto slot = m_pokemonListLayout->GetSelectedIndex();
auto pkm = m_pkms[slot];
this->ShowPKMTypeMatchUps(pkm);
}
}

void MainApplication::OnInputDenMenuLayout(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos) {
if (Down & KEY_Y) {
auto slot = m_denMenuLayout->GetSelectedIndex();
auto pkm = m_dens[slot]->GetPKM();
this->ShowPKMTypeMatchUps(pkm);
}
}

void MainApplication::ShowPKMTypeMatchUps(std::shared_ptr<csight::PKM> pkm) {
auto weaknesses = pkm->GetTypeMatchUps(true);
auto strengths = pkm->GetTypeMatchUps(false);
m_pokemonTypeLayout->SetTypeMatchUps(weaknesses, strengths);
this->NavigateTo(m_pokemonTypeLayout);
}

void MainApplication::SelectPokemonSlot(u32 slot) {
this->SetSlot(slot);
this->NavigateTo(m_pokemonSummaryLayout);
Expand Down
15 changes: 7 additions & 8 deletions CaptureSight/source/ui/views/DenMenuLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extern Settings gsets;
extern std::shared_ptr<I18N> i18n;

DenMenuLayout::DenMenuLayout() : Layout::Layout() {
m_headerTextBlock = pu::ui::elm::TextBlock::New(50, 50, "", 25);
m_headerTextBlock
= pu::ui::elm::TextBlock::New(50, 50, i18n->Translate("View upcoming advances (A), View type matches (Y)"), 25);
m_headerTextBlock->SetColor(gsets.GetTheme().text.light);

m_menu = pu::ui::elm::Menu::New(0, 120, SCREEN_MAX_WIDTH, gsets.GetTheme().active.dark, 150, 4);

this->Add(m_menu);
Expand All @@ -24,8 +24,7 @@ DenMenuLayout::DenMenuLayout() : Layout::Layout() {
void DenMenuLayout::UpdateValues(std::vector<std::shared_ptr<csight::raid::Den>> dens) {
m_menu->ClearItems();

for (auto denIterator = dens.begin(); denIterator != end(dens); ++denIterator) {
auto den = *(denIterator);
for (auto den : dens) {
auto pkm = den->GetPKM();
auto formattedIVs = csight::utils::joinNums(pkm->GetIVs(), "/");
auto stars = std::to_string(den->GetDisplayStars());
Expand All @@ -41,10 +40,6 @@ void DenMenuLayout::UpdateValues(std::vector<std::shared_ptr<csight::raid::Den>>
}

m_menu->SetSelectedIndex(0);

auto headerText = i18n->Translate("View upcoming advances (A)");

m_headerTextBlock->SetText(headerText);
}

void DenMenuLayout::ClickMenuItem(u64 seed) {
Expand All @@ -54,3 +49,7 @@ void DenMenuLayout::ClickMenuItem(u64 seed) {
void DenMenuLayout::SetOnInputMenuItem(std::function<void(u64)> onInput) {
m_onMenuItemInput = onInput;
}

s32 DenMenuLayout::GetSelectedIndex() {
return m_menu->GetSelectedIndex();
}
26 changes: 16 additions & 10 deletions CaptureSight/source/ui/views/PokemonListLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ extern std::shared_ptr<I18N> i18n;

PokemonListLayout::PokemonListLayout() : Layout::Layout() {
m_menu = pu::ui::elm::Menu::New(0, 120, SCREEN_MAX_WIDTH, gsets.GetTheme().active.dark, 150, 4);
m_instructionTextBlock = pu::ui::elm::TextBlock::New(50, 50, "View details (A), View type matches (Y)", 25);
m_instructionTextBlock->SetColor(gsets.GetTheme().text.light);
this->Add(m_menu);
this->Add(m_instructionTextBlock);
}

void PokemonListLayout::UpdateValues(std::vector<std::shared_ptr<csight::PK8>> pk8s, std::function<std::string(u32)> GetTitle) {
m_menu->ClearItems();

for (auto pk8 = pk8s.begin(); pk8 != end(pk8s); ++pk8) {
auto pkm = *(pk8);
auto formattedIVs = csight::utils::joinNums(pkm->GetIVs(), "/");
u32 slot = std::distance(pk8s.begin(), pk8);
std::string species = i18n->Translate("species", pkm->GetSpeciesString());
std::string shinyTranslationKey = pkm->GetIsShiny() ? "Shiny" : "Not Shiny";
std::string title = pkm->GetIsValid()
? species + " - " + formattedIVs + " - " + i18n->Translate(shinyTranslationKey) + " - " + GetTitle(slot)
: i18n->Translate("Empty") + " - " + GetTitle(slot);
auto menuItem = this->CreateMenuItem(pkm, slot, title);
for (u32 i = 0; i < pk8s.size(); i++) {
auto pk8 = pk8s[i];
auto formattedIVs = csight::utils::joinNums(pk8->GetIVs(), "/");
std::string species = i18n->Translate("species", pk8->GetSpeciesString());
std::string shinyTranslationKey = pk8->GetIsShiny() ? "Shiny" : "Not Shiny";
std::string title = pk8->GetIsValid()
? species + " - " + formattedIVs + " - " + i18n->Translate(shinyTranslationKey) + " - " + GetTitle(i)
: i18n->Translate("Empty") + " - " + GetTitle(i);
auto menuItem = this->CreateMenuItem(pk8, i, title);

m_menu->AddItem(menuItem);
}
Expand Down Expand Up @@ -57,4 +59,8 @@ void PokemonListLayout::SetOnInputMenuItem(std::function<void(u32)> onInput) {

void PokemonListLayout::SetSelectedIndex(u32 index) {
m_menu->SetSelectedIndex(index);
}

s32 PokemonListLayout::GetSelectedIndex() {
return m_menu->GetSelectedIndex();
}
62 changes: 62 additions & 0 deletions CaptureSight/source/ui/views/PokemonTypeLayout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <csight/core>
#include <functional>
#include <ui/MainApplication.hpp>
#include <ui/PokemonSprite.hpp>
#include <ui/elements/RoundedRectangle.hpp>
#include <ui/views/PokemonTypeLayout.hpp>
#include <utils/Constants.hpp>
#include <utils/I18N.hpp>
#include <utils/Settings.hpp>

extern MainApplication::Ref mainApp;
extern Settings gsets;
extern std::shared_ptr<I18N> i18n;

void PokemonTypeLayout::SetTypeMatchUps(std::vector<csight::type::TypeMultiplier> defensiveMatchUps,
std::vector<csight::type::TypeMultiplier> offensiveMatchUps) {
this->Clear();
this->AddMatchUpBlock(defensiveMatchUps, "Defense", "Weakness", "Resistance", 50);
this->AddMatchUpBlock(offensiveMatchUps, "Offense", "Strength", "Resistance", 650);
}

void PokemonTypeLayout::AddMatchUpBlock(std::vector<csight::type::TypeMultiplier> matchUps, std::string header,
std::string firstMatchUpName, std::string secondMatchUpName, u32 baseX) {
u32 baseY = 50;
u32 headerY = baseY + 25;
u32 matchUpY = headerY + 40;
u32 matchUpX = baseX + 25;
auto theme = gsets.GetTheme();
auto secondMatchUpStart
= std::find_if(matchUps.begin(), matchUps.end(), [](auto typeMatchUp) { return typeMatchUp.multiplier < 1; });
std::vector<csight::type::TypeMultiplier> firstMatchUp(matchUps.begin(), secondMatchUpStart);
std::vector<csight::type::TypeMultiplier> secondMatchUp(secondMatchUpStart, matchUps.end());
auto background = RoundedRectangle::New(baseX, baseY, 550, 600, theme.background.light, 5);
auto headerTextBlock = pu::ui::elm::TextBlock::New(matchUpX, headerY, header, 35);
headerTextBlock->SetColor(theme.text.light);

this->Add(background);
this->Add(headerTextBlock);
this->AddMatchUpText(firstMatchUp, firstMatchUpName, matchUpX, matchUpY);
this->AddMatchUpText(secondMatchUp, secondMatchUpName, matchUpX + 250, matchUpY);
}

void PokemonTypeLayout::AddMatchUpText(std::vector<csight::type::TypeMultiplier> matchUps, std::string matchUpName, u32 x,
u32 y) {
auto matchUpNameY = y + 25;
auto matchUpYOffset = matchUpNameY + 60;
auto theme = gsets.GetTheme();
auto matchUpNameTextBlock = pu::ui::elm::TextBlock::New(x, matchUpNameY, matchUpName, 26);
matchUpNameTextBlock->SetColor(theme.text.light);

this->Add(matchUpNameTextBlock);

for (u32 i = 0; i < matchUps.size(); i++) {
auto matchUp = matchUps[i];
auto typeName = csight::utils::getTypeName(matchUp.type);
auto matchUpText = typeName + " " + csight::utils::convertFloatWithPrecision(matchUp.multiplier, 2);
u32 matchUpY = matchUpYOffset + (i * 40);
auto matchUpTextBlock = pu::ui::elm::TextBlock::New(x, matchUpY, matchUpText, 20);
matchUpTextBlock->SetColor(theme.text.light);
this->Add(matchUpTextBlock);
}
}
12 changes: 7 additions & 5 deletions libcsight/include/csight/PK8.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <csight/PKM.hpp>
#include <csight/lookups/Types.hpp>
#include <future>
#include <string>
#include <switch.h>
#include <vector>

namespace csight {
class PK8 {
class PK8 : public PKM {
public:
PK8(u8 *data);
~PK8();
Expand All @@ -24,10 +26,9 @@ namespace csight {
u8 GetEV(u8 stat);
std::vector<u8> GetEVs();
bool GetIsShiny();
u8 GetAbility();
ability::Ability GetAbility();
std::string GetAbilityString();
u32 GetTSV();
u32 GetPSV();
u32 GetPID();
u16 GetSID();
u16 GetTID();
Expand All @@ -48,8 +49,9 @@ namespace csight {
u8 GetHTFriendship();
u8 GetOTFriendship();
u8 GetCurrentFriendship();
ulong GetRaidSeed();
std::future<ulong> GetRaidSeedAsync();
u64 GetRaidSeed();
std::future<u64> GetRaidSeedAsync();
u8 GetForm();

private:
u8 *m_data = new u8[0x148];
Expand Down
46 changes: 46 additions & 0 deletions libcsight/include/csight/PKM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <algorithm>
#include <csight/Utils.hpp>
#include <csight/lookups/Types.hpp>
#include <future>
#include <string>
#include <switch.h>
#include <vector>

namespace csight {
class PKM {
public:
virtual u16 GetSpecies() = 0;
virtual std::string GetSpeciesString() = 0;
virtual std::vector<u8> GetIVs() = 0;
virtual bool GetIsShiny() = 0;
virtual ability::Ability GetAbility() = 0;
virtual std::string GetAbilityString() = 0;
virtual u32 GetPID() = 0;
virtual u64 GetRaidSeed() = 0;
virtual u8 GetForm() = 0;
u32 GetPSV() {
u32 pid = this->GetPID();
return ((pid >> 16 ^ (pid & 0xFFFF)) >> 4);
}
std::pair<type::PokemonType, type::PokemonType> GetTypes() {
auto form = this->GetForm();
auto species = this->GetSpecies();
auto resultIterator = std::find_if(type::PokemonTypeList.begin(), type::PokemonTypeList.end(),
[species, form](auto type) { return type.species == species && type.form == form; });
auto result = resultIterator[0];

return std::make_pair(result.type1, result.type2);
}
std::vector<type::TypeMultiplier> GetTypeMatchUps(bool shouldGetWeakness) {
auto types = this->GetTypes();
auto calculateTypeMatchUps = shouldGetWeakness ? utils::calculateWeakness : utils::calculateStrengths;
auto typeMatchUps = calculateTypeMatchUps(types.first, types.second);
std::sort(typeMatchUps.begin(), typeMatchUps.end(),
[](auto type1, auto type2) { return type1.multiplier > type2.multiplier; });

return typeMatchUps;
}
};
} // namespace csight
6 changes: 5 additions & 1 deletion libcsight/include/csight/RaidPokemon.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include <csight/Ability.hpp>
#include <csight/PKM.hpp>
#include <csight/Shiny.hpp>
#include <switch.h>
#include <vector>

namespace csight::raid {
class RaidPokemon {
class RaidPokemon : public PKM {
public:
RaidPokemon(u64 seed, u32 flawlessIvs, u16 species, ability::raid::AbilityRaidSetting abilitySetting);
u32 GetEC();
Expand All @@ -18,8 +19,11 @@ namespace csight::raid {
std::vector<u8> GetIVs();
ability::Ability GetAbility();
std::string GetAbilityString();
u64 GetRaidSeed();
u8 GetForm();

private:
u64 m_seed;
u32 m_EC;
u32 m_PID;
u16 m_species;
Expand Down
Loading

0 comments on commit 774bf54

Please sign in to comment.