void OnClickLoad(std::string filename) { std::string fullname = join_path(GetFullSavefileDirPath().c_str(), filename.c_str(), 0); if (Pi::IsGameStarted()) Pi::EndGame(); Pi::UninitGame(); Pi::InitGame(); try { Serializer::LoadGame(fullname.c_str()); } catch (SavedGameCorruptException) { Gui::Screen::ShowBadError(Lang::GAME_LOAD_CORRUPT); Pi::UninitGame(); Pi::InitGame(); Pi::SetView(Pi::gameMenuView); // Pi::currentView is unset, set it back to the gameMenuView return; } catch (CouldNotOpenFileException) { Gui::Screen::ShowBadError(Lang::GAME_LOAD_CANNOT_OPEN); Pi::UninitGame(); Pi::InitGame(); Pi::SetView(Pi::gameMenuView); // Pi::currentView is unset, set it back to the gameMenuView return; } Pi::StartGame(); // Pi::currentView is unset, but this view is still shown, so // must un-show it Pi::SetView(Pi::gameMenuView); Pi::SetView(Pi::worldView); }
void ShowAll() { DeleteAllChildren(); PackEnd(new Gui::Label(m_title)); m_tentry = new Gui::TextEntry(); PackEnd(m_tentry); std::list<std::string> files; GetDirectoryContents(GetFullSavefileDirPath().c_str(), files); Gui::HBox *hbox = new Gui::HBox(); PackEnd(hbox); Gui::HBox *buttonBox = new Gui::HBox(); buttonBox->SetSpacing(5.0f); Gui::Button *b = new Gui::LabelButton(new Gui::Label(m_type == SAVE ? Lang::SAVE : Lang::LOAD)); b->onClick.connect(sigc::mem_fun(this, &FileDialog::OnClickAction)); buttonBox->PackEnd(b); b = new Gui::LabelButton(new Gui::Label(Lang::CANCEL)); b->onClick.connect(sigc::mem_fun(this, &FileDialog::OnClickCancel)); buttonBox->PackEnd(b); PackEnd(buttonBox); Gui::VScrollBar *scroll = new Gui::VScrollBar(); Gui::VScrollPortal *portal = new Gui::VScrollPortal(390); portal->SetTransparency(false); scroll->SetAdjustment(&portal->vscrollAdjust); hbox->PackEnd(portal); hbox->PackEnd(scroll); Gui::Box *vbox = new Gui::VBox(); for (std::list<std::string>::iterator i = files.begin(); i!=files.end(); ++i) { b = new SimpleLabelButton(new Gui::Label(*i)); b->onClick.connect(sigc::bind(sigc::mem_fun(this, &FileDialog::OnClickFile), *i)); vbox->PackEnd(b); } portal->Add(vbox); Gui::VBox::ShowAll(); }
void Pi::HandleEvents() { SDL_Event event; Pi::mouseMotion[0] = Pi::mouseMotion[1] = 0; while (SDL_PollEvent(&event)) { Gui::HandleSDLEvent(&event); switch (event.type) { case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) { // only accessible once game started if (currentView != 0) { if (currentView != gameMenuView) { RequestTimeAccel(0); SetTimeAccel(0); SetView(gameMenuView); } else RequestTimeAccel(1); } break; } // special keys. LCTRL+turd if ((KeyState(SDLK_LCTRL) || (KeyState(SDLK_RCTRL)))) { if (event.key.keysym.sym == SDLK_q) Pi::Quit(); if (event.key.keysym.sym == SDLK_s) { Render::ToggleShaders(); } if (event.key.keysym.sym == SDLK_h) { Render::ToggleHDR(); } if (event.key.keysym.sym == SDLK_i) Pi::showDebugInfo = !Pi::showDebugInfo; if (event.key.keysym.sym == SDLK_p) { Sint64 crime, fine; Polit::GetCrime(&crime, &fine); printf("Criminal record: %llx, $%lld\n", crime, fine); Polit::AddCrime(0x1, 100); Polit::GetCrime(&crime, &fine); printf("Criminal record now: %llx, $%lld\n", crime, fine); } if (event.key.keysym.sym == SDLK_PRINT) { char buf[256]; const time_t t = time(0); struct tm *_tm = localtime(&t); strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%H%M%S.tga", _tm); Screendump(buf); fprintf(stderr, "Screendump to %s\n", buf); } #ifdef DEBUG if (event.key.keysym.sym == SDLK_m) { Pi::player->SetMoney(Pi::player->GetMoney() + 10000000); } if (event.key.keysym.sym == SDLK_F12) { matrix4x4d m; Pi::player->GetRotMatrix(m); vector3d dir = m*vector3d(0,0,-1); /* add test object */ if (KeyState(SDLK_RSHIFT)) { Missile *missile = new Missile(ShipType::MISSILE_GUIDED, Pi::player, Pi::player->GetCombatTarget()); missile->SetRotMatrix(m); missile->SetFrame(Pi::player->GetFrame()); missile->SetPosition(Pi::player->GetPosition()+50.0*dir); missile->SetVelocity(Pi::player->GetVelocity()); Space::AddBody(missile); } else if (KeyState(SDLK_LSHIFT)) { SpaceStation *s = static_cast<SpaceStation*>(Pi::player->GetNavTarget()); if (s) { int port = s->GetFreeDockingPort(); if (port != -1) { printf("Putting ship into station\n"); // Make police ship intent on killing the player Ship *ship = new Ship(ShipType::LADYBIRD); ship->AIKill(Pi::player); ship->SetFrame(Pi::player->GetFrame()); ship->SetDockedWith(s, port); Space::AddBody(ship); } else { printf("No docking ports free dude\n"); } } else { printf("Select a space station...\n"); } } else { Ship *ship = new Ship(ShipType::LADYBIRD); ship->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::PULSECANNON_1MW); ship->AIKill(Pi::player); ship->SetFrame(Pi::player->GetFrame()); ship->SetPosition(Pi::player->GetPosition()+100.0*dir); ship->SetVelocity(Pi::player->GetVelocity()); ship->m_equipment.Add(Equip::DRIVE_CLASS2); ship->m_equipment.Add(Equip::RADAR_MAPPER); ship->m_equipment.Add(Equip::SCANNER); ship->m_equipment.Add(Equip::SHIELD_GENERATOR); ship->m_equipment.Add(Equip::HYDROGEN, 10); Space::AddBody(ship); } } #endif /* DEBUG */ // XXX only works on X11 //if (event.key.keysym.sym == SDLK_F11) SDL_WM_ToggleFullScreen(Pi::scrSurface); if (event.key.keysym.sym == SDLK_F10) Pi::SetView(Pi::objectViewerView); if (event.key.keysym.sym == SDLK_F9) { std::string name = join_path(GetFullSavefileDirPath().c_str(), "_quicksave", 0); Serializer::SaveGame(name.c_str()); Pi::cpan->MsgLog()->Message("", "Game saved to "+name); } } Pi::keyState[event.key.keysym.sym] = 1; Pi::keyModState = event.key.keysym.mod; Pi::onKeyPress.emit(&event.key.keysym); break; case SDL_KEYUP: Pi::keyState[event.key.keysym.sym] = 0; Pi::keyModState = event.key.keysym.mod; Pi::onKeyRelease.emit(&event.key.keysym); break; case SDL_MOUSEBUTTONDOWN: Pi::mouseButton[event.button.button] = 1; Pi::onMouseButtonDown.emit(event.button.button, event.button.x, event.button.y); break; case SDL_MOUSEBUTTONUP: Pi::mouseButton[event.button.button] = 0; Pi::onMouseButtonUp.emit(event.button.button, event.button.x, event.button.y); break; case SDL_MOUSEMOTION: Pi::mouseMotion[0] += event.motion.xrel; Pi::mouseMotion[1] += event.motion.yrel; // SDL_GetRelativeMouseState(&Pi::mouseMotion[0], &Pi::mouseMotion[1]); break; case SDL_JOYAXISMOTION: if (joysticks[event.jaxis.which].joystick == NULL) break; if (event.jaxis.value == -32768) joysticks[event.jaxis.which].axes[event.jaxis.axis] = 1.f; else joysticks[event.jaxis.which].axes[event.jaxis.axis] = -event.jaxis.value / 32767.f; break; case SDL_JOYBUTTONUP: case SDL_JOYBUTTONDOWN: if (joysticks[event.jaxis.which].joystick == NULL) break; joysticks[event.jbutton.which].buttons[event.jbutton.button] = event.jbutton.state != 0; break; case SDL_JOYHATMOTION: if (joysticks[event.jaxis.which].joystick == NULL) break; joysticks[event.jhat.which].hats[event.jhat.hat] = event.jhat.value; break; case SDL_QUIT: Pi::Quit(); break; } } }
void OnClickSave(std::string filename) { std::string fullname = join_path(GetFullSavefileDirPath().c_str(), filename.c_str(), 0); Serializer::SaveGame(fullname.c_str()); Pi::cpan->MsgLog()->Message("", Lang::GAME_SAVED_TO+fullname); m_fileDialog->ShowAll(); }