Skip to content

Commit

Permalink
Rudimentary tri-state marking editing
Browse files Browse the repository at this point in the history
  • Loading branch information
piepie62 committed Jan 23, 2019
1 parent 296ad5d commit ba0acc6
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 15 deletions.
2 changes: 2 additions & 0 deletions include/gui/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
#define ui_sheet_emulated_button_plus_small_black_idx 522
#define ui_sheet_emulated_button_minus_small_black_idx 523
#define ui_sheet_emulated_box_search_idx 524
#define ui_sheet_emulated_toggle_gray_idx 525
#define ui_sheet_emulated_toggle_blue_idx 526

// colors
#define COLOR_WHITE C2D_Color32(255, 255, 255, 255)
Expand Down
58 changes: 54 additions & 4 deletions include/gui/screen/HexEditScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class HexEditScreen : public Screen
bool editNumber(bool high, bool up);
bool checkValue(void);
void drawMeaning(void) const;
bool rotateMark(u8 mark);
std::pair<std::string, SecurityLevel> selectedDescription;
std::vector<int> selectBytes;
std::shared_ptr<PKX> pkm;
Expand All @@ -76,8 +77,8 @@ class HexEditScreen : public Screen
class HexEditButton : public Button
{
public:
HexEditButton(int x, int y, int w, int h, std::function<bool()> callback, int image, std::string text, bool toggle, u8 bit)
: Button(x, y, w, h, callback, image, text, FONT_SIZE_11, COLOR_WHITE), toggle(toggle), bitVal(bit) {}
HexEditButton(int x, int y, int w, int h, std::function<bool()> callback, int image, std::string text, bool toggle, u8 bit, bool mark = false)
: Button(x, y, w, h, callback, image, text, FONT_SIZE_11, COLOR_WHITE), toggle(toggle), mark(mark), bitVal(bit) {}
void draw() const override
{
Gui::sprite(key, xPos, yPos);
Expand All @@ -89,7 +90,20 @@ 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;
key = key == ui_sheet_emulated_toggle_green_idx ? ui_sheet_emulated_toggle_gray_idx : ui_sheet_emulated_toggle_green_idx;
isClicked = clicked(touch);
return noArg();
}
else
{
isClicked = clicked(touch);
}
}
else if (mark)
{
if (!isClicked && clicked(touch))
{
rotateColor();
isClicked = clicked(touch);
return noArg();
}
Expand Down Expand Up @@ -126,18 +140,54 @@ class HexEditScreen : public Screen
}
void setToggled(bool flag)
{
key = flag ? ui_sheet_emulated_toggle_green_idx : ui_sheet_emulated_toggle_red_idx;
key = flag ? ui_sheet_emulated_toggle_green_idx : ui_sheet_emulated_toggle_gray_idx;
}
bool isToggle()
{
return toggle;
}
bool isMark()
{
return mark;
}
void rotateColor()
{
switch (key)
{
case ui_sheet_emulated_toggle_gray_idx:
key = ui_sheet_emulated_toggle_blue_idx;
break;
case ui_sheet_emulated_toggle_blue_idx:
key = ui_sheet_emulated_toggle_red_idx;
break;
case ui_sheet_emulated_toggle_red_idx:
default:
key = ui_sheet_emulated_toggle_gray_idx;
break;
}
}
void setColor(u8 val)
{
switch (val)
{
case 0:
default:
key = ui_sheet_emulated_toggle_gray_idx;
break;
case 1:
key = ui_sheet_emulated_toggle_blue_idx;
break;
case 2:
key = ui_sheet_emulated_toggle_red_idx;
}
}
u8 bit()
{
return bitVal;
}
private:
bool toggle;
bool mark;
u8 bitVal;
int clickedTime;
bool isClicked = false;
Expand Down
8 changes: 8 additions & 0 deletions source/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,14 @@ void Gui::sprite(int key, int x, int y)

C2D_DrawRectSolid(x + 20, y + 17, 0.5f, 144, 1, COLOR_WHITE);
}
else if (key == ui_sheet_emulated_toggle_gray_idx)
{
C2D_DrawRectSolid(x, y, 0.5f, 13, 13, C2D_Color32(0x80, 0x80, 0x80, 0xFF));
}
else if (key == ui_sheet_emulated_toggle_blue_idx)
{
C2D_DrawRectSolid(x, y, 0.5f, 13, 13, C2D_Color32(0x00, 0x00, 0xFF, 0xFF));
}
// standard case
else
{
Expand Down
82 changes: 71 additions & 11 deletions source/gui/screen/HexEditScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,14 @@ std::pair<std::string, HexEditScreen::SecurityLevel> HexEditScreen::describe(int
case 0x15:
return std::make_pair(i18n::localize("ABILITY_NUMBER"), OPEN);
case 0x16 ... 0x17:
return std::make_pair(i18n::localize("TRAINING_BAG_HITS_LEFT"), NORMAL);
if (pkm->generation() == Generation::SIX)
{
return std::make_pair(i18n::localize("TRAINING_BAG_HITS_LEFT"), NORMAL);
}
else
{
return std::make_pair(i18n::localize("MARKINGS"), NORMAL);
}
case 0x18 ... 0x1B:
return std::make_pair(i18n::localize("PID"), NORMAL);
case 0x1C:
Expand Down Expand Up @@ -645,7 +652,11 @@ std::pair<std::string, HexEditScreen::SecurityLevel> HexEditScreen::describe(int
return std::make_pair(i18n::localize("CONTEST_VALUE_SHEEN"), NORMAL);
}
case 0x2A:
return std::make_pair(i18n::localize("MARKINGS"), NORMAL);
if (pkm->generation() == Generation::SIX)
{
return std::make_pair(i18n::localize("MARKINGS"), NORMAL);
}
return UNUSED;
case 0x2B:
return std::make_pair(i18n::localize("POKERUS"), NORMAL);
case 0x2C ... 0x2F:
Expand Down Expand Up @@ -1193,15 +1204,22 @@ HexEditScreen::HexEditScreen(std::shared_ptr<PKX> pkm) : pkm(pkm), hid(240, 16)
editNumber(high, up);
for (size_t j = 4; j < buttons[i].size(); j++)
{
buttons[i][j]->setToggled((this->pkm->rawData()[i] >> buttons[i][j]->bit()) & 0x1);
if (buttons[i][j]->isToggle())
{
buttons[i][j]->setToggled((this->pkm->rawData()[i] >> buttons[i][j]->bit()) & 0x1);
}
else if (buttons[i][j]->isMark())
{
buttons[i][j]->setColor((*(u16*)(this->pkm->rawData() + 0x16) >> buttons[i][j]->bit()) & 0x3);
}
}
return true;
};
buttons[i].push_back(new HexEditButton(145, 33, 13, 13, [edit](){ return edit(true, true); }, ui_sheet_button_plus_small_idx, "", false, 0));
buttons[i].push_back(new HexEditButton(161, 33, 13, 13, [edit](){ return edit(false, true); }, ui_sheet_button_plus_small_idx, "", false, 0));
buttons[i].push_back(new HexEditButton(145, 75, 13, 13, [edit](){ return edit(true, false); }, ui_sheet_button_minus_small_idx, "", false, 0));
buttons[i].push_back(new HexEditButton(161, 75, 13, 13, [edit](){ return edit(false, false); }, ui_sheet_button_minus_small_idx, "", false, 0));
if (pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN)
if (pkm->generation() == Generation::SIX || pkm->generation() == Generation::SEVEN || pkm->generation() == Generation::LGPE)
{
switch (i)
{
Expand All @@ -1211,16 +1229,35 @@ HexEditScreen::HexEditScreen(std::shared_ptr<PKX> pkm) : pkm(pkm), hid(240, 16)
buttons[i].back()->setToggled(pkm->rawData()[i] & 0x1);
break;
// Markings
case 0x2A:
for (int j = 0; j < 4; j++)
case 0x16 ... 0x17:
if (pkm->generation() != Generation::SIX)
{
delete buttons[i].back();
buttons[i].pop_back();
for (int j = 0; j < 4; j++)
{
delete buttons[i].back();
buttons[i].pop_back();
}
for (int j = 0; j < (i == 0x16 ? 4 : 2); j++)
{
u8 currentMark = i == 0x16 ? j : j + 4;
buttons[i].push_back(new HexEditButton(30, 90 + j * 16, 13, 13, [this, currentMark](){ return this->rotateMark(currentMark); }, ui_sheet_emulated_toggle_gray_idx, i18n::localize(std::string(marks[currentMark])), false, currentMark, true));
buttons[i].back()->setColor((pkm->rawData()[i] >> (j * 2)) & 0x3);
}
}
for (int j = 0; j < 6; j++)
break;
case 0x2A:
if (pkm->generation() == Generation::SIX)
{
buttons[i].push_back(new HexEditButton(30, 90 + j * 16, 13, 13, [this, i, j](){ return this->toggleBit(i, j); }, ui_sheet_emulated_toggle_green_idx, i18n::localize(std::string(marks[j])), true, j));
buttons[i].back()->setToggled((pkm->rawData()[i] >> j) & 0x1);
for (int j = 0; j < 4; j++)
{
delete buttons[i].back();
buttons[i].pop_back();
}
for (int j = 0; j < 6; j++)
{
buttons[i].push_back(new HexEditButton(30, 90 + j * 16, 13, 13, [this, i, j](){ return this->toggleBit(i, j); }, ui_sheet_emulated_toggle_green_idx, i18n::localize(std::string(marks[j])), true, j));
buttons[i].back()->setToggled((pkm->rawData()[i] >> j) & 0x1);
}
}
break;
// Super Training Flags
Expand Down Expand Up @@ -1719,4 +1756,27 @@ void HexEditScreen::drawMeaning() const
default:
break;
}
}

bool HexEditScreen::rotateMark(u8 mark)
{
u16 markData = *(u16*)(pkm->rawData() + 0x16);
switch ((markData >> (mark * 2)) & 0x3)
{
case 0:
markData &= (0xFFFF ^ (0x3 << (mark * 2)));
markData |= 0x1 << (mark * 2);
break;
case 1:
markData &= (0xFFFF ^ (0x3 << (mark * 2)));
markData |= 0x2 << (mark * 2);
break;
case 2:
default:
markData &= (0xFFFF ^ (0x3 << (mark * 2)));
// markData |= 0x0 << (mark * 2);
break;
}
*(u16*)(pkm->rawData() + 0x16) = markData;
return false;
}

0 comments on commit ba0acc6

Please sign in to comment.