void GameStateCutscene::logic() { if (!initialized) { if (settings->music_volume > 0 && !music.empty()) { // restart music so that game devs can sync with cutscene playback snd->stopMusic(); snd->loadMusic(music); } initialized = true; } if (scenes.empty() || scene_index >= scenes.size()) { if (game_slot != -1) { showLoading(); GameStatePlay *gsp = new GameStatePlay(); gsp->resetGame(); save_load->setGameSlot(game_slot); save_load->loadGame(); setRequestedGameState(gsp); return; } // return to previous gamestate showLoading(); setRequestedGameState(previous_gamestate); return; } // status is processed after we render this scene if (scene_index < scenes.size()) status = scenes[scene_index]->logic(); }
void GameStateConfigBase::logicAccept() { if (setMods()) { snd->unloadMusic(); reload_music = true; reload_backgrounds = true; delete mods; mods = new ModManager(NULL); loadTilesetSettings(); PREV_SAVE_SLOT = -1; } delete msg; msg = new MessageEngine(); inpt->saveKeyBindings(); inpt->setKeybindNames(); loadMiscSettings(); setStatNames(); refreshFont(); if ((ENABLE_JOYSTICK) && (inpt->getNumJoysticks() > 0)) { inpt->initJoystick(); } cleanup(); showLoading(); // need to delete the "Loading..." message here, as we're recreating our render context if (loading_tip) { delete loading_tip; loading_tip = NULL; } render_device->createContext(); saveSettings(); setRequestedGameState(new GameStateTitle()); }
void GameStateLoad::logicLoading() { // load an existing game inpt->lock_all = true; delete_items = false; showLoading(); GameStatePlay* play = new GameStatePlay(); play->resetGame(); save_load->setGameSlot(game_slots[selected_slot]->id); save_load->loadGame(); loaded = true; loading = false; setRequestedGameState(play); }
void GameStateConfigBase::logicCancel() { inpt->lock[CANCEL] = true; loadSettings(); inpt->loadKeyBindings(); delete msg; msg = new MessageEngine(); loadMiscSettings(); setStatNames(); update(); cleanup(); render_device->windowResize(); render_device->updateTitleBar(); showLoading(); setRequestedGameState(new GameStateTitle()); }
void GameStateLoad::logic() { if (inpt->window_resized) refreshWidgets(); for (size_t i = 0; i < game_slots.size(); ++i) { if (static_cast<int>(i) == selected_slot) { if (game_slots[i]->preview_turn_ticks > 0) game_slots[i]->preview_turn_ticks--; if (game_slots[i]->preview_turn_ticks == 0) { game_slots[i]->preview_turn_ticks = GAMESLOT_PREVIEW_TURN_DURATION; game_slots[i]->stats.direction++; if (game_slots[i]->stats.direction > 7) game_slots[i]->stats.direction = 0; } } game_slots[i]->preview.logic(); } if (!confirm->visible) { tablist.logic(true); if (button_exit->checkClick() || (inpt->pressing[CANCEL] && !inpt->lock[CANCEL])) { inpt->lock[CANCEL] = true; showLoading(); setRequestedGameState(new GameStateTitle()); } if (loading_requested) { loading = true; loading_requested = false; logicLoading(); } bool outside_scrollbar = true; if (button_new->checkClick()) { // create a new game showLoading(); GameStateNew* newgame = new GameStateNew(); newgame->game_slot = (game_slots.empty() ? 1 : game_slots.back()->id+1); delete_items = false; setRequestedGameState(newgame); } else if (button_load->checkClick()) { loading_requested = true; } else if (button_delete->checkClick()) { // Display pop-up to make sure save should be deleted confirm->visible = true; confirm->render(); } else if (game_slots.size() > 0) { Rect scroll_area = slot_pos[0]; scroll_area.h = slot_pos[0].h * game_slot_max; if (isWithinRect(scroll_area, inpt->mouse)) { if (inpt->pressing[MAIN1] && !inpt->lock[MAIN1]) { for (int i=0; i<visible_slots; ++i) { if (isWithinRect(slot_pos[i], inpt->mouse)) { inpt->lock[MAIN1] = true; setSelectedSlot(i + scroll_offset); updateButtons(); break; } } } else if (inpt->scroll_up) { scrollUp(); } else if (inpt->scroll_down) { scrollDown(); } } else if (has_scroll_bar) { switch (scrollbar->checkClick(inpt->mouse.x, inpt->mouse.y)) { case 1: scrollUp(); outside_scrollbar = false; break; case 2: scrollDown(); outside_scrollbar = false; break; case 3: scroll_offset = scrollbar->getValue(); if (scroll_offset >= static_cast<int>(game_slots.size()) - visible_slots) { scroll_offset = static_cast<int>(game_slots.size()) - visible_slots; } outside_scrollbar = false; break; default: break; } } if (outside_scrollbar && inpt->pressing[MAIN1] && !inpt->lock[MAIN1]) { inpt->lock[MAIN1] = true; setSelectedSlot(-1); updateButtons(); } // Allow characters to be navigateable via up/down keys if (inpt->pressing[UP] && !inpt->lock[UP]) { inpt->lock[UP] = true; setSelectedSlot((selected_slot - 1 < 0) ? static_cast<int>(game_slots.size()) - 1 : selected_slot - 1); scroll_offset = std::min(static_cast<int>(game_slots.size()) - visible_slots, selected_slot); updateButtons(); } else if (inpt->pressing[DOWN] && !inpt->lock[DOWN]) { inpt->lock[DOWN] = true; setSelectedSlot((selected_slot + 1 == static_cast<int>(game_slots.size())) ? 0 : selected_slot + 1); scroll_offset = std::max(0, selected_slot-visible_slots+1); updateButtons(); } } } else if (confirm->visible) { confirm->logic(); if (confirm->confirmClicked) { removeSaveDir(game_slots[selected_slot]->id); delete game_slots[selected_slot]; game_slots[selected_slot] = NULL; game_slots.erase(game_slots.begin()+selected_slot); visible_slots = (game_slot_max > static_cast<int>(game_slots.size()) ? static_cast<int>(game_slots.size()) : game_slot_max); setSelectedSlot(-1); while (scroll_offset + visible_slots > static_cast<int>(game_slots.size())) { scroll_offset--; } updateButtons(); confirm->visible = false; confirm->confirmClicked = false; } } }