Skip to content

Commit

Permalink
Merge pull request #98 from t3knomanzer/fix-game-mode-continuous-scroll
Browse files Browse the repository at this point in the history
Fix game mode continuous scroll
  • Loading branch information
t3knomanzer authored Jul 25, 2020
2 parents bfa1439 + e7b0b43 commit ca28a15
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions Embedded/MaxMix/MaxMix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -197,24 +197,23 @@ bool ProcessPackage()
index = itemCount - 1;
}
else
{
UpdateItemCommand(decodeBuffer, items, index);
}

// Switch to newly added item.
if(settings.displayNewSession)
{
itemIndex = index;
if(mode == MODE_APPLICATION)
stateApplication = STATE_APPLICATION_NAVIGATE;

return true;
}
}
else if(command == MSG_COMMAND_REMOVE)
{
// Check if there are any existing items first.
if(itemCount == 0)
return;
return false;

// Check if item to be removed exists.
uint32_t id = GetIdFromPackage(decodeBuffer);
Expand All @@ -223,30 +222,28 @@ bool ProcessPackage()
return false;

RemoveItemCommand(decodeBuffer, items, &itemCount, index);

bool isItemActive = IsItemActive(index);

// Return to Navigate state if active application is removed
if(IsItemActive(index) && mode == MODE_APPLICATION)
stateApplication = STATE_APPLICATION_NAVIGATE;

// Make sure current menu index is not out of bounds after removing item.
itemIndex = GetNextIndex(itemIndex, itemCount, 0, settings.continuousScroll);
itemIndexA = GetNextIndex(itemIndexA, itemCount, 0, settings.continuousScroll);
itemIndexB = GetNextIndex(itemIndexB, itemCount, 0, settings.continuousScroll);

// TODO: Game mode
// If the removed item was itemIndexA or itemIndexB
// set those index to -1 so the user needs to select a new
// application for the channel.
// If the index of the removed item was higher, no need to do anything.
// If it was lower, just decrease the the index by 1.
if(isItemActive)
{
if(mode == MODE_APPLICATION)
stateApplication = STATE_APPLICATION_NAVIGATE;

return true;
}
}
else if(command == MSG_COMMAND_UPDATE_VOLUME)
{
// Check that the item exists.
uint32_t id = GetIdFromPackage(decodeBuffer);
int8_t index = FindItem(id);
if(index == -1)
return;
return false;

UpdateItemVolumeCommand(decodeBuffer, items, index);

Expand All @@ -255,13 +252,15 @@ bool ProcessPackage()
// call a method here to rebalance.

if(IsItemActive(index))
return true;
return true;

}
else if(command == MSG_COMMAND_SETTINGS)
{
UpdateSettingsCommand(decodeBuffer, &settings);
return true;
}

return false;
}

Expand Down Expand Up @@ -418,27 +417,36 @@ void UpdateDisplay()
return;
}

uint8_t scrollLeft = CanScrollLeft(itemIndex, itemCount, settings.continuousScroll);
uint8_t scrollRight = CanScrollRight(itemIndex, itemCount, settings.continuousScroll);

if(mode == MODE_MASTER)
{
DisplayMasterSelectScreen(display, items[0].volume, mode, MODE_COUNT);
}
else if(mode == MODE_APPLICATION)
{
if(stateApplication == STATE_APPLICATION_NAVIGATE)
{
uint8_t scrollLeft = CanScrollLeft(itemIndex, itemCount, settings.continuousScroll);
uint8_t scrollRight = CanScrollRight(itemIndex, itemCount, settings.continuousScroll);
DisplayApplicationSelectScreen(display, items[itemIndex].name, items[itemIndex].volume, scrollLeft, scrollRight, mode, MODE_COUNT);
}

else if(stateApplication == STATE_APPLICATION_EDIT)
DisplayApplicationEditScreen(display, items[itemIndex].name, items[itemIndex].volume, mode, MODE_COUNT);
}
else if(mode == MODE_GAME)
{
if(stateGame == STATE_GAME_SELECT_A)
{
uint8_t scrollLeft = CanScrollLeft(itemIndexA, itemCount, settings.continuousScroll);
uint8_t scrollRight = CanScrollRight(itemIndexA, itemCount, settings.continuousScroll);
DisplayGameSelectScreen(display, items[itemIndexA].name, items[itemIndexA].volume, "A", scrollLeft, scrollRight, mode, MODE_COUNT);
}
else if(stateGame == STATE_GAME_SELECT_B)
{
uint8_t scrollLeft = CanScrollLeft(itemIndexB, itemCount, settings.continuousScroll);
uint8_t scrollRight = CanScrollRight(itemIndexB, itemCount, settings.continuousScroll);
DisplayGameSelectScreen(display, items[itemIndexB].name, items[itemIndexB].volume, "B", scrollLeft, scrollRight, mode, MODE_COUNT);
}
else if(stateGame == STATE_GAME_EDIT)
DisplayGameEditScreen(display, items[itemIndexA].name, items[itemIndexB].name, items[itemIndexA].volume, items[itemIndexB].volume, mode, MODE_COUNT);
}
Expand Down Expand Up @@ -557,6 +565,7 @@ bool IsItemActive(int8_t index)
{
return true;
}

return false;
}

Expand Down

0 comments on commit ca28a15

Please sign in to comment.