void tickMenu(int menu){ switch(menu){ case MENU_SETTINGS: if(!bindOpt){ if(!selBut){ if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=21;} if (k_down.clicked){ ++currentSelection; if(currentSelection > 21)currentSelection=0;} if (k_left.clicked){ left = true;} if (k_right.clicked){ left = false;} } else { if (k_left.clicked){ if(left)switchGameBut(true,keys[currentSelection]); else switchMenuBut(true,keys[currentSelection]); } else if (k_right.clicked) { if(left)switchGameBut(false,keys[currentSelection]); else switchMenuBut(false,keys[currentSelection]); } } if (k_accept.clicked) selBut = !selBut; if (k_decline.clicked){ bindOpt = true; curSaveSel = 0; } } else { if (k_up.clicked){ --curSaveSel; if(curSaveSel < 0)curSaveSel=2;} if (k_down.clicked){ ++curSaveSel; if(curSaveSel > 2)curSaveSel=0;} if (k_decline.clicked){ bindOpt = false; errorBut = -1; } if (k_accept.clicked){ switch(curSaveSel){ case 0: // Exit and save if(checkPropButtons() == -1){ k_up.input = keyProp[0]; k_down.input = keyProp[1]; k_left.input = keyProp[2]; k_right.input = keyProp[3]; k_attack.input = keyProp[4]; k_menu.input = keyProp[5]; k_pause.input = keyProp[6]; k_accept.input = keyProp[7]; k_decline.input = keyProp[8]; k_delete.input = keyProp[9]; FILE *fs=fopen("btnSave.bin","wb"); fwrite(keyProp,sizeof(int),9,fs); fclose(fs); currentSelection = 2; currentMenu = MENU_TITLE; errorBut = -1; } else errorBut = checkPropButtons(); break; case 1: // Exit and DON'T save currentSelection = 2; currentMenu = MENU_TITLE; errorBut = -1; break; case 2: // reset defaults keyProp[0] = KEY_DUP | KEY_CPAD_UP | KEY_CSTICK_UP; keyProp[1] = KEY_DDOWN | KEY_CPAD_DOWN | KEY_CSTICK_DOWN; keyProp[2] = KEY_DLEFT | KEY_CPAD_LEFT | KEY_CSTICK_LEFT; keyProp[3] = KEY_DRIGHT | KEY_CPAD_RIGHT | KEY_CSTICK_RIGHT; keyProp[4] = KEY_A | KEY_B | KEY_L | KEY_ZR; keyProp[5] = KEY_X | KEY_Y | KEY_R | KEY_ZL; keyProp[6] = KEY_START; keyProp[7] = KEY_A; keyProp[8] = KEY_B; keyProp[9] = KEY_X; bindOpt = false; errorBut = -1; break; } } } break; case MENU_PAUSED: if(!areYouSure && !areYouSureSave){ if(pauseSaveDisplayTimer > 0) --pauseSaveDisplayTimer; if (k_pause.clicked) currentMenu = MENU_NONE; if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=2;} if (k_down.clicked){ ++currentSelection; if(currentSelection > 2)currentSelection=0;} if (k_accept.clicked){ switch(currentSelection){ case 0: currentMenu = MENU_NONE; break; case 1: areYouSureSave = true; break; case 2: areYouSure = true; break; } } } else if(areYouSureSave) { if (k_accept.clicked){ pauseSaveDisplayTimer = 60; saveCurrentWorld(currentFileName, &eManager, &player, (u8*)map, (u8*)data); areYouSureSave = false; areYouSure = false; } else if (k_decline.clicked){ areYouSureSave = false; areYouSure = false; } } else { if (k_accept.clicked){ areYouSure = false; areYouSureSave = false; sf2d_set_clear_color(0xFF); currentSelection = 0; currentMenu = MENU_TITLE; } else if (k_decline.clicked){ areYouSure = false; areYouSureSave = false; } } break; case MENU_INVENTORY: if (k_menu.clicked || k_decline.clicked){ currentMenu = MENU_NONE; player.p.activeItem = &noItem; player.p.isCarrying = false; } if (k_accept.clicked){ // Select item from inventory if(player.p.inv->lastSlot!=0){ median = player.p.inv->items[curInvSel]; // create copy of item. removeItemFromInventory(curInvSel, player.p.inv); // remove original pushItemToInventoryFront(median, player.p.inv); // add copy to front player.p.activeItem = &player.p.inv->items[0]; // active item = copy. if(player.p.activeItem->id > 27) player.p.isCarrying = true; else player.p.isCarrying = false; } currentMenu = MENU_NONE; } if (k_up.clicked){ --curInvSel; if(curInvSel < 0)curInvSel=player.p.inv->lastSlot-1;} if (k_down.clicked){ ++curInvSel; if(curInvSel > player.p.inv->lastSlot-1)curInvSel=0;} break; case MENU_CRAFTING: if (k_menu.clicked || k_decline.clicked) currentMenu = MENU_NONE; if (k_accept.clicked){ int newslot = player.p.activeItem->slotNum + 1; if(craftItem(currentRecipes, ¤tRecipes->recipes[curInvSel], player.p.inv)){ playSound(snd_craft); if(player.p.activeItem != &noItem)player.p.activeItem = &player.p.inv->items[newslot]; } } if (k_up.clicked){ --curInvSel; if(curInvSel < 0)curInvSel=currentRecipes->size-1;} if (k_down.clicked){ ++curInvSel; if(curInvSel > currentRecipes->size-1)curInvSel=0;} break; case MENU_WIN: if (k_accept.clicked){ sf2d_set_clear_color(0xFF); currentMenu = MENU_TITLE; saveCurrentWorld(currentFileName, &eManager, &player, (u8*)map, (u8*)data); } break; case MENU_LOSE: if (k_accept.clicked){ sf2d_set_clear_color(0xFF); currentMenu = MENU_TITLE; } break; case MENU_ABOUT: if (k_decline.clicked) currentMenu = MENU_TITLE; break; case MENU_CONTAINER: if (k_menu.clicked || k_decline.clicked)currentMenu = MENU_NONE; if (k_left.clicked) { curChestEntity->entityFurniture.r = 0; int tmp = curInvSel; curInvSel = curChestEntity->entityFurniture.oSel; curChestEntity->entityFurniture.oSel = tmp; } if (k_right.clicked) { curChestEntity->entityFurniture.r = 1; int tmp = curInvSel; curInvSel = curChestEntity->entityFurniture.oSel; curChestEntity->entityFurniture.oSel = tmp; } Inventory* i1 = curChestEntity->entityFurniture.r == 1 ? player.p.inv : curChestEntity->entityFurniture.inv; Inventory* i2 = curChestEntity->entityFurniture.r == 0 ? player.p.inv : curChestEntity->entityFurniture.inv; int len = i1->lastSlot; if (curInvSel < 0) curInvSel = 0; if (curInvSel >= len) curInvSel = len - 1; if (k_up.clicked) --curInvSel; if (k_down.clicked) ++curInvSel; if (len == 0) curInvSel = 0; if (curInvSel < 0) curInvSel += len; if (curInvSel >= len) curInvSel -= len; if(k_accept.clicked && len > 0){ Item* pullItem = &i1->items[curInvSel]; Item pushItem = newItem(pullItem->id,pullItem->countLevel); pushItem.chestPtr = pullItem->chestPtr; pushItemToInventoryFront(pushItem, i2); if(i2 == player.p.inv){ int newslot = player.p.activeItem->slotNum + 1; player.p.activeItem = &player.p.inv->items[newslot]; } else if(pullItem == player.p.activeItem){ player.p.activeItem = &noItem; } removeItemFromCurrentInv(pullItem); if (curInvSel >= i1->lastSlot) curInvSel = i1->lastSlot - 1; } break; case MENU_LOADGAME: if(!enteringName && !areYouSure){ // World select if (k_decline.clicked){ currentMenu = MENU_TITLE; currentSelection = 0; } if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection = worldFileCount;} if (k_down.clicked){ ++currentSelection; if(currentSelection > worldFileCount)currentSelection=0;} if(k_delete.clicked){ if(currentSelection < worldFileCount) areYouSure = true; } if(k_accept.clicked){ if(currentSelection == worldFileCount){ enteringName = true; } else { memset(¤tFileName, 0, 255); // reset currentFileName sprintf(currentFileName,"%s.wld",fileNames[currentSelection]); playSound(snd_test); initGame = 1; currentMenu = MENU_NONE; } } } else if (areYouSure){ if (k_decline.clicked || k_delete.clicked) areYouSure = false; if (k_accept.clicked){ sprintf(currentFileName,"%s.wld",fileNames[currentSelection]); remove(currentFileName); readFiles(); enteringName = false; areYouSure = false; memset(¤tFileName, 0, 255); // reset currentFileName } }else { // Enter new world name. if(k_decline.clicked) enteringName = false; if(k_accept.clicked && errorFileName == 0){ errorFileName = checkFileNameForErrors(); if(errorFileName == 0){ // If no errors are found with the filename, then start a new game! memset(¤tFileName, 0, 255); // reset currentFileName sprintf(currentFileName,"%s.wld",fileNames[worldFileCount]); currentMenu = MENU_NONE; playSound(snd_test); initGame = 2; ++worldFileCount; } } touchPosition touch; hidTouchRead(&touch); if((touch.px != 0 || touch.py != 0) && touchDelay == 0){ if(!isTouching)doTouchButton(touch); } else if(touch.px == 0 || touch.py == 0) isTouching = false; if(touchDelay > 0) --touchDelay; } break; case MENU_TITLE: if (k_up.clicked){ --currentSelection; if(currentSelection < 0)currentSelection=4;} if (k_down.clicked){ ++currentSelection; if(currentSelection > 4)currentSelection=0;} if(k_accept.clicked){ switch(currentSelection){ case 0: currentMenu = MENU_LOADGAME; readFiles(); currentSelection = 0; enteringName = false; areYouSure = false; break; case 2: keyProp[0] = k_up.input; keyProp[1] = k_down.input; keyProp[2] = k_left.input; keyProp[3] = k_right.input; keyProp[4] = k_attack.input; keyProp[5] = k_menu.input; keyProp[6] = k_pause.input; keyProp[7] = k_accept.input; keyProp[8] = k_decline.input; keyProp[9] = k_delete.input; left = true; selBut = false; bindOpt = false; currentSelection = 0; currentMenu = MENU_SETTINGS; break; case 3: currentMenu = MENU_ABOUT; break; case 4: quitGame = true; break; } } break; } }
void UCraftingSystemComponent::onCraftButtonClicked() { craftItem(selectedRecipe); }