Skip to content

Commit

Permalink
Merge branch 'PKSM.cpp' into i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoGiordano authored Dec 9, 2018
2 parents 4acb6fe + 080e9af commit 179fb8a
Show file tree
Hide file tree
Showing 20 changed files with 173 additions and 99 deletions.
5 changes: 3 additions & 2 deletions assets/romfs/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"version": 2,
"language": 2,
"autoBackup": true,
"storageSize": 150,
Expand All @@ -19,5 +19,6 @@
},
"extraSaves": {
},
"writeFileSave": false
"writeFileSave": false,
"useSaveInfo": false
}
14 changes: 13 additions & 1 deletion include/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Configuration
{
public:
static constexpr int CURRENT_VERSION = 1;
static constexpr int CURRENT_VERSION = 2;

static Configuration& getInstance(void)
{
Expand Down Expand Up @@ -116,6 +116,11 @@ class Configuration
return mJson["writeFileSave"];
}

bool useSaveInfo(void)
{
return mJson["useSaveInfo"];
}

void language(Language lang)
{
mJson["language"] = lang;
Expand Down Expand Up @@ -191,6 +196,11 @@ class Configuration
mJson["writeFileSave"] = write;
}

void useSaveInfo(bool saveInfo)
{
mJson["useSaveInfo"] = saveInfo;
}

void save(void);

private:
Expand All @@ -200,6 +210,8 @@ class Configuration
Configuration(Configuration const&) = delete;
void operator=(Configuration const&) = delete;

void loadFromRomfs(void);

nlohmann::json mJson;

size_t oldSize = 0;
Expand Down
2 changes: 2 additions & 0 deletions include/gui/screen/BagScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class BagScreen : public Screen
876, 877, 878, 885, 886, 887, 888, 889, 890, 891,
892, 893, 894, 895, 896
};

bool justSwitched = true;
};

#endif
1 change: 1 addition & 0 deletions include/gui/screen/ConfigScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ConfigScreen : public Screen
int currentTab = 0;
int oldStorage;
void back(void);
bool justSwitched = true;
};

#endif
1 change: 1 addition & 0 deletions include/gui/screen/EditSelectorScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class EditSelectorScreen : public Screen
std::shared_ptr<PKX> moveMon = nullptr;
int cursorPos = 0;
int box = 0;
bool justSwitched = true;
};

#endif
1 change: 1 addition & 0 deletions include/gui/screen/EditorScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class EditorScreen : public Screen
int origPartyLevel;
int origPartyCurrHP;
int origPartyCP;
bool justSwitched = true;
};

#endif
1 change: 1 addition & 0 deletions include/gui/screen/HexEditScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class HexEditScreen : public Screen
if (!isClicked && clicked(touch))
{
key = key == ui_sheet_emulated_toggle_green_idx ? ui_sheet_emulated_toggle_red_idx : ui_sheet_emulated_toggle_green_idx;
isClicked = clicked(touch);
return noArg();
}
else
Expand Down
1 change: 1 addition & 0 deletions include/gui/screen/MainMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MainMenu : public Screen
ScreenType type() const override { return ScreenType::MAINMENU; }
private:
std::array<MainMenuButton*, 6> buttons = {NULL};
bool justSwitched = true;
};

#endif
1 change: 1 addition & 0 deletions include/gui/screen/StorageScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class StorageScreen : public Screen
std::unique_ptr<ViewerScreen> viewer;
std::shared_ptr<PKX> moveMon = nullptr;
int partyNum = -1;
bool justSwitched = true;
// Storage implementation
};

Expand Down
1 change: 0 additions & 1 deletion include/utils/scripthelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "picoc.h"
#include "3ds/types.h"

void gui_fpsCheck(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs);
void gui_warn(struct ParseState*, struct Value*, struct Value**, int);
void gui_choice(struct ParseState*, struct Value*, struct Value**, int);
void gui_menu6x5(struct ParseState*, struct Value*, struct Value**, int);
Expand Down
28 changes: 24 additions & 4 deletions source/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ Configuration::Configuration()

if (R_FAILED(stream.result()))
{
std::ifstream istream("romfs:/config.json");
istream >> mJson;
istream.close();
save();
loadFromRomfs();
}
else
{
Expand All @@ -49,6 +46,21 @@ Configuration::Configuration()
stream.close();
mJson = nlohmann::json::parse(jsonData);
delete[] jsonData;

if (mJson.find("version") == mJson.end())
{
loadFromRomfs();
}
else if (mJson["version"].get<int>() != CURRENT_VERSION)
{
if (mJson["version"].get<int>() < 2)
{
mJson["useSaveInfo"] = false;
}

mJson["version"] = CURRENT_VERSION;
save();
}
}
}

Expand Down Expand Up @@ -105,4 +117,12 @@ void Configuration::extraSaves(std::string id, std::pair<std::vector<std::string
{
mJson["extraSaves"][id]["files"] = value.second;
}
}

void Configuration::loadFromRomfs()
{
std::ifstream istream("romfs:/config.json");
istream >> mJson;
istream.close();
save();
}
11 changes: 11 additions & 0 deletions source/gui/screen/BagScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ void BagScreen::draw() const

void BagScreen::update(touchPosition* touch)
{
if (justSwitched)
{
if (keysHeld() & KEY_TOUCH)
{
return;
}
else
{
justSwitched = false;
}
}
static int timer = 0;
u32 downKeys = hidKeysDown();
u32 heldKeys = hidKeysHeld();
Expand Down
14 changes: 14 additions & 0 deletions source/gui/screen/ConfigScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ ConfigScreen::ConfigScreen() : oldStorage(Configuration::getInstance().storageSi
tabButtons[2].push_back(new ClickButton(237, 87, 15, 12, [](){ Configuration::getInstance().fixSectors(!Configuration::getInstance().fixSectors()); return true; }, ui_sheet_button_info_detail_editor_light_idx, "", 0.0f, 0));
tabButtons[2].push_back(new ClickButton(237, 111, 15, 12, [](){ Configuration::getInstance().transferEdit(!Configuration::getInstance().transferEdit()); return true; }, ui_sheet_button_info_detail_editor_light_idx, "", 0.0f, 0));
tabButtons[2].push_back(new ClickButton(237, 135, 15, 12, [](){ Configuration::getInstance().writeFileSave(!Configuration::getInstance().writeFileSave()); return true; }, ui_sheet_button_info_detail_editor_light_idx, "", 0.0f, 0));
tabButtons[2].push_back(new ClickButton(237, 159, 15, 12, [](){ Configuration::getInstance().useSaveInfo(!Configuration::getInstance().useSaveInfo()); return true; }, ui_sheet_button_info_detail_editor_light_idx, "", 0.0f, 0));
}

void ConfigScreen::draw() const
Expand Down Expand Up @@ -240,6 +241,7 @@ void ConfigScreen::draw() const
Gui::staticText(i18n::localize("CONFIG_BAD_SECTORS"), 19, 84, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(i18n::localize("CONFIG_EDIT_TRANSFERS"), 19, 108, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(i18n::localize("CONFIG_BACKUP_INJECTION"), 19, 132, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(i18n::localize("CONFIG_SAVE_INFO"), 19, 156, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);

for (Button* button : tabButtons[currentTab])
{
Expand All @@ -251,11 +253,23 @@ void ConfigScreen::draw() const
Gui::staticText(Configuration::getInstance().fixSectors() ? i18n::localize("YES") : i18n::localize("NO"), 260, 84, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(Configuration::getInstance().transferEdit() ? i18n::localize("YES") : i18n::localize("NO"), 260, 108, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(Configuration::getInstance().writeFileSave() ? i18n::localize("YES") : i18n::localize("NO"), 260, 132, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
Gui::staticText(Configuration::getInstance().useSaveInfo() ? i18n::localize("YES") : i18n::localize("NO"), 260, 156, FONT_SIZE_14, FONT_SIZE_14, COLOR_WHITE);
}
}

void ConfigScreen::update(touchPosition* touch)
{
if (justSwitched)
{
if (keysHeld() & KEY_TOUCH)
{
return;
}
else
{
justSwitched = false;
}
}
Screen::update();
if (hidKeysDown() & KEY_B)
{
Expand Down
11 changes: 11 additions & 0 deletions source/gui/screen/EditSelectorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,17 @@ void EditSelectorScreen::draw() const

void EditSelectorScreen::update(touchPosition* touch)
{
if (justSwitched)
{
if (keysHeld() & KEY_TOUCH)
{
return;
}
else
{
justSwitched = false;
}
}
static bool sleep = true;
static int sleepTimer = 10;

Expand Down
40 changes: 25 additions & 15 deletions source/gui/screen/EditorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ EditorScreen::EditorScreen(std::shared_ptr<ViewerScreen> viewer, std::shared_ptr
if (!pkm || pkm->species() == 0)
{
pkm = TitleLoader::save->emptyPkm()->clone();
pkm->TID(Configuration::getInstance().defaultTID());
pkm->SID(Configuration::getInstance().defaultSID());
pkm->otName(Configuration::getInstance().defaultOT().c_str());
if (Configuration::getInstance().useSaveInfo())
{
pkm->TID(TitleLoader::save->TID());
pkm->SID(TitleLoader::save->SID());
pkm->otName(TitleLoader::save->otName().c_str());
}
else
{
pkm->TID(Configuration::getInstance().defaultTID());
pkm->SID(Configuration::getInstance().defaultSID());
pkm->otName(Configuration::getInstance().defaultOT().c_str());
}
pkm->ball(4);
pkm->encryptionConstant((u32)rand());
pkm->version(TitleLoader::save->version());
Expand Down Expand Up @@ -287,6 +296,17 @@ void EditorScreen::draw() const

void EditorScreen::update(touchPosition* touch)
{
if (justSwitched)
{
if (keysHeld() & KEY_TOUCH)
{
return;
}
else
{
justSwitched = false;
}
}
if (!selector)
{
u32 downKeys = keysDown();
Expand Down Expand Up @@ -415,12 +435,7 @@ bool EditorScreen::togglePokerus()
void EditorScreen::setOT()
{
SwkbdState state;
bool first = true;
if (first)
{
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN ? 12 : (8 - 1));
first = false;
}
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN ? 12 : (8 - 1));
swkbdSetHintText(&state, i18n::localize("OT_NAME").c_str());
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[25] = {0};
Expand All @@ -435,12 +450,7 @@ void EditorScreen::setOT()
void EditorScreen::setNick()
{
SwkbdState state;
bool first = true;
if (first)
{
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN ? 12 : (11 - 1));
first = false;
}
swkbdInit(&state, SWKBD_TYPE_NORMAL, 2, pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN ? 12 : (11 - 1));
swkbdSetHintText(&state, i18n::localize("NICKNAME").c_str());
swkbdSetValidation(&state, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char input[25] = {0};
Expand Down
Loading

0 comments on commit 179fb8a

Please sign in to comment.