Add 2 More Slots for Power Discs on Emulated Base

This commit is contained in:
deReeperJosh 2024-05-11 17:10:15 +01:00 committed by Joshua de Reeper
parent 0cc1d4c62d
commit a87ea694a9
7 changed files with 74 additions and 40 deletions

View File

@ -80,7 +80,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
private var infinityFigureData = Figure(-1, "Position") private var infinityFigureData = Figure(-1, "Position")
private var skylanderSlot = -1 private var skylanderSlot = -1
private var infinityPosition = -1 private var infinityPosition = -1
private var infinityListPosition = -1
private lateinit var skylandersBinding: DialogNfcFiguresManagerBinding private lateinit var skylandersBinding: DialogNfcFiguresManagerBinding
private lateinit var infinityBinding: DialogNfcFiguresManagerBinding private lateinit var infinityBinding: DialogNfcFiguresManagerBinding
@ -140,12 +139,14 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
if (infinityFigures.isEmpty()) { if (infinityFigures.isEmpty()) {
infinityFigures.apply { infinityFigures.apply {
add(FigureSlot(getString(R.string.infinity_hexagon_label), 0)) add(FigureSlot(getString(R.string.infinity_hexagon_label), 0))
add(FigureSlot(getString(R.string.infinity_p1_label), 1)) add(FigureSlot(getString(R.string.infinity_power_hex_two_label), 1))
add(FigureSlot(getString(R.string.infinity_p1a1_label), 3)) add(FigureSlot(getString(R.string.infinity_power_hex_three_label), 2))
add(FigureSlot(getString(R.string.infinity_p1_label), 3))
add(FigureSlot(getString(R.string.infinity_p1a1_label), 4))
add(FigureSlot(getString(R.string.infinity_p1a2_label), 5)) add(FigureSlot(getString(R.string.infinity_p1a2_label), 5))
add(FigureSlot(getString(R.string.infinity_p2_label), 2)) add(FigureSlot(getString(R.string.infinity_p2_label), 6))
add(FigureSlot(getString(R.string.infinity_p2a1_label), 4)) add(FigureSlot(getString(R.string.infinity_p2a1_label), 7))
add(FigureSlot(getString(R.string.infinity_p2a2_label), 6)) add(FigureSlot(getString(R.string.infinity_p2a2_label), 8))
} }
} }
} }
@ -164,7 +165,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
putInt(EXTRA_SKYLANDER_VAR, skylanderData.variant) putInt(EXTRA_SKYLANDER_VAR, skylanderData.variant)
putString(EXTRA_SKYLANDER_NAME, skylanderData.name) putString(EXTRA_SKYLANDER_NAME, skylanderData.name)
putInt(EXTRA_INFINITY_POSITION, infinityPosition) putInt(EXTRA_INFINITY_POSITION, infinityPosition)
putInt(EXTRA_INFINITY_LIST_POSITION, infinityListPosition)
putLong(EXTRA_INFINITY_NUM, infinityFigureData.number) putLong(EXTRA_INFINITY_NUM, infinityFigureData.number)
putString(EXTRA_INFINITY_NAME, infinityFigureData.name) putString(EXTRA_INFINITY_NAME, infinityFigureData.name)
} }
@ -183,7 +183,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
savedInstanceState.getString(EXTRA_SKYLANDER_NAME)!! savedInstanceState.getString(EXTRA_SKYLANDER_NAME)!!
) )
infinityPosition = savedInstanceState.getInt(EXTRA_INFINITY_POSITION) infinityPosition = savedInstanceState.getInt(EXTRA_INFINITY_POSITION)
infinityListPosition = savedInstanceState.getInt(EXTRA_INFINITY_LIST_POSITION)
infinityFigureData = Figure( infinityFigureData = Figure(
savedInstanceState.getLong(EXTRA_INFINITY_NUM), savedInstanceState.getLong(EXTRA_INFINITY_NUM),
savedInstanceState.getString(EXTRA_INFINITY_NAME)!! savedInstanceState.getString(EXTRA_INFINITY_NAME)!!
@ -297,11 +296,10 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
} else if (requestCode == REQUEST_INFINITY_FIGURE_FILE) { } else if (requestCode == REQUEST_INFINITY_FIGURE_FILE) {
val label = InfinityConfig.loadFigure(infinityPosition, result!!.data.toString()) val label = InfinityConfig.loadFigure(infinityPosition, result!!.data.toString())
if (label != null && label != "Unknown Figure") { if (label != null && label != "Unknown Figure") {
clearInfinityFigure(infinityListPosition) clearInfinityFigure(infinityPosition)
infinityFigures[infinityListPosition].label = label infinityFigures[infinityPosition].label = label
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityListPosition) infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1 infinityPosition = -1
infinityListPosition = -1
infinityFigureData = Figure.BLANK_FIGURE infinityFigureData = Figure.BLANK_FIGURE
} else { } else {
MaterialAlertDialogBuilder(this) MaterialAlertDialogBuilder(this)
@ -317,11 +315,10 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
result!!.data.toString(), result!!.data.toString(),
infinityPosition infinityPosition
) )
clearInfinityFigure(infinityListPosition) clearInfinityFigure(infinityPosition)
infinityFigures[infinityListPosition].label = label!! infinityFigures[infinityPosition].label = label!!
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityListPosition) infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1 infinityPosition = -1
infinityListPosition = -1
infinityFigureData = Figure.BLANK_FIGURE infinityFigureData = Figure.BLANK_FIGURE
} }
} }
@ -906,18 +903,19 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
fun setInfinityFigureData(num: Long, name: String, position: Int, listPosition: Int) { fun setInfinityFigureData(num: Long, name: String, position: Int, listPosition: Int) {
infinityFigureData = Figure(num, name) infinityFigureData = Figure(num, name)
infinityPosition = position infinityPosition = position
infinityListPosition = listPosition
} }
fun clearInfinityFigure(position: Int) { fun clearInfinityFigure(position: Int) {
when (position) { when (position) {
0 -> infinityFigures[position].label = getString(R.string.infinity_hexagon_label) 0 -> infinityFigures[position].label = getString(R.string.infinity_hexagon_label)
1 -> infinityFigures[position].label = getString(R.string.infinity_p1_label) 1 -> infinityFigures[position].label = getString(R.string.infinity_power_hex_two_label)
2 -> infinityFigures[position].label = getString(R.string.infinity_p1a1_label) 2 -> infinityFigures[position].label = getString(R.string.infinity_power_hex_three_label)
3 -> infinityFigures[position].label = getString(R.string.infinity_p1a2_label) 3 -> infinityFigures[position].label = getString(R.string.infinity_p1_label)
4 -> infinityFigures[position].label = getString(R.string.infinity_p2_label) 4 -> infinityFigures[position].label = getString(R.string.infinity_p1a1_label)
5 -> infinityFigures[position].label = getString(R.string.infinity_p2a1_label) 5 -> infinityFigures[position].label = getString(R.string.infinity_p1a2_label)
6 -> infinityFigures[position].label = getString(R.string.infinity_p2a2_label) 6 -> infinityFigures[position].label = getString(R.string.infinity_p2_label)
7 -> infinityFigures[position].label = getString(R.string.infinity_p2a1_label)
8 -> infinityFigures[position].label = getString(R.string.infinity_p2a2_label)
} }
infinityBinding.figureManager.adapter?.notifyItemChanged(position) infinityBinding.figureManager.adapter?.notifyItemChanged(position)
} }

View File

@ -75,6 +75,11 @@ class FigureSlotAdapter(
} }
1, 2 -> { 1, 2 -> {
// Hexagon Power Discs
validFigures.filter { (_, value) -> value in 4000000..4999999 }
}
3, 6 -> {
// Characters // Characters
validFigures.filter { (_, value) -> value in 1000000..1999999 } validFigures.filter { (_, value) -> value in 1000000..1999999 }
} }

View File

@ -914,6 +914,8 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="infinity_number">Figure Number</string> <string name="infinity_number">Figure Number</string>
<string name="invalid_infinity_figure">Invalid Figure Selection</string> <string name="invalid_infinity_figure">Invalid Figure Selection</string>
<string name="infinity_hexagon_label">Power Disc/Play Set</string> <string name="infinity_hexagon_label">Power Disc/Play Set</string>
<string name="infinity_power_hex_two_label">Power Disc Two</string>
<string name="infinity_power_hex_three_label">Power Disc Three</string>
<string name="infinity_p1_label">Player One</string> <string name="infinity_p1_label">Player One</string>
<string name="infinity_p2_label">Player Two</string> <string name="infinity_p2_label">Player Two</string>
<string name="infinity_p1a1_label">P1 Ability One</string> <string name="infinity_p1a1_label">P1 Ability One</string>

View File

@ -628,6 +628,11 @@ InfinityBase::LoadFigure(const std::array<u8, INFINITY_NUM_BLOCKS * INFINITY_BLO
order_added = figure.order_added; order_added = figure.order_added;
position = DeriveFigurePosition(position); position = DeriveFigurePosition(position);
if (position == 0)
{
ERROR_LOG_FMT(IOS_USB, "Invalid Position for Infinity Figure");
return "Unknown Figure";
}
std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, order_added, 0x00}; std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, order_added, 0x00};
figure_change_response[6] = GenerateChecksum(figure_change_response, 6); figure_change_response[6] = GenerateChecksum(figure_change_response, 6);
@ -649,9 +654,14 @@ void InfinityBase::RemoveFigure(u8 position)
if (figure.present) if (figure.present)
{ {
figure.present = false;
position = DeriveFigurePosition(position); position = DeriveFigurePosition(position);
if (position == 0)
{
ERROR_LOG_FMT(IOS_USB, "Invalid Position for Infinity Figure");
return;
}
figure.present = false;
std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, figure.order_added, std::array<u8, 32> figure_change_response = {0xab, 0x04, position, 0x09, figure.order_added,
0x01}; 0x01};
@ -744,14 +754,28 @@ std::string InfinityBase::FindFigure(u32 number) const
u8 InfinityBase::DeriveFigurePosition(u8 position) u8 InfinityBase::DeriveFigurePosition(u8 position)
{ {
// In the added/removed response, position needs to be 1 for the hexagon, 2 for Player 1 and // In the added/removed response, position needs to be 1 for the hexagon, 2 for Player 1 and
// Player 1's abilities, and 3 for Player 2 and Player 2's abilities. Abilities are in positions // Player 1's abilities, and 3 for Player 2 and Player 2's abilities. In the UI, positions 0, 1
// > 2 in the UI (3/5 for player 1, 4/6 for player 2) so decrement the position until < 2. // and 2 represent the hexagon slot, 3, 4 and 5 represent Player 1's slot and 6, 7 and 8 represent
// Player 2's slot.
while (position > 2) switch (position)
position -= 2; {
case 0:
case 1:
case 2:
return 1;
case 3:
case 4:
case 5:
return 2;
case 6:
case 7:
case 8:
return 3;
position++; default:
return position; return 0;
}
} }
InfinityFigure& InfinityBase::GetFigureByOrder(u8 order_added) InfinityFigure& InfinityBase::GetFigureByOrder(u8 order_added)

View File

@ -89,7 +89,7 @@ public:
protected: protected:
std::mutex m_infinity_mutex; std::mutex m_infinity_mutex;
std::array<InfinityFigure, 7> m_figures; std::array<InfinityFigure, 9> m_figures;
private: private:
InfinityFigure& GetFigureByOrder(u8 order_added); InfinityFigure& GetFigureByOrder(u8 order_added);

View File

@ -79,17 +79,21 @@ void InfinityBaseWindow::CreateMainWindow()
AddFigureSlot(vbox_group, tr("Play Set/Power Disc"), 0); AddFigureSlot(vbox_group, tr("Play Set/Power Disc"), 0);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player One"), 1); AddFigureSlot(vbox_group, tr("Power Disc Two"), 1);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player One Ability One"), 3); AddFigureSlot(vbox_group, tr("Power Disc Three"), 2);
add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player One"), 3);
add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player One Ability One"), 4);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player One Ability Two"), 5); AddFigureSlot(vbox_group, tr("Player One Ability Two"), 5);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player Two"), 2); AddFigureSlot(vbox_group, tr("Player Two"), 6);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player Two Ability One"), 4); AddFigureSlot(vbox_group, tr("Player Two Ability One"), 7);
add_line(vbox_group); add_line(vbox_group);
AddFigureSlot(vbox_group, tr("Player Two Ability Two"), 6); AddFigureSlot(vbox_group, tr("Player Two Ability Two"), 8);
m_group_figures->setLayout(vbox_group); m_group_figures->setLayout(vbox_group);
scroll_area->setWidget(m_group_figures); scroll_area->setWidget(m_group_figures);
@ -203,8 +207,9 @@ CreateFigureDialog::CreateFigureDialog(QWidget* parent, u8 slot) : QDialog(paren
// Only display entry if it is a piece appropriate for the slot // Only display entry if it is a piece appropriate for the slot
if ((slot == 0 && if ((slot == 0 &&
((figure > 0x1E8480 && figure < 0x2DC6BF) || (figure > 0x3D0900 && figure < 0x4C4B3F))) || ((figure > 0x1E8480 && figure < 0x2DC6BF) || (figure > 0x3D0900 && figure < 0x4C4B3F))) ||
((slot == 1 || slot == 2) && figure < 0x1E847F) || ((slot == 1 || slot == 2) && (figure > 0x3D0900 && figure < 0x4C4B3F)) ||
((slot == 3 || slot == 4 || slot == 5 || slot == 6) && ((slot == 3 || slot == 6) && figure < 0x1E847F) ||
((slot == 4 || slot == 5 || slot == 7 || slot == 8) &&
(figure > 0x2DC6C0 && figure < 0x3D08FF))) (figure > 0x2DC6C0 && figure < 0x3D08FF)))
{ {
const auto figure_name = QString::fromStdString(entry.first); const auto figure_name = QString::fromStdString(entry.first);

View File

@ -28,7 +28,7 @@ public:
~InfinityBaseWindow() override; ~InfinityBaseWindow() override;
protected: protected:
std::array<QLineEdit*, 7> m_edit_figures; std::array<QLineEdit*, 9> m_edit_figures;
private: private:
void CreateMainWindow(); void CreateMainWindow();