Example #1
0
void dskSinglePlayer::Msg_ButtonClick(const unsigned int ctrl_id)
{
    switch(ctrl_id)
    {
        case 3: // "Letztes Spiel fortsetzen"
        {
            std::list<std::string> liste;
            std::string tmp = GetFilePath(FILE_PATHS[85]);

            tmp += "*.sav";
            ListDir(tmp.c_str(), false, NULL, NULL, &liste);

            std::string path;
            unser_time_t recent = 0;
            for(std::list<std::string>::iterator it = liste.begin(); it != liste.end(); ++it)
            {
                Savegame save;

                // Datei öffnen
                if (!save.Load(*it, false, false))
                    continue;

                if (save.save_time > recent)
                {
                    recent = save.save_time;
                    path = *it;
                }
            }

            if (recent != 0)
            {
                // Dateiname noch rausextrahieren aus dem Pfad
                size_t pos = path.find_last_of('/');
                if(pos == std::string::npos)
                    return;
                std::string extracted_filename = path.substr(pos + 1);

                // ".sav" am Ende weg
                assert(extracted_filename.length() >= 4);
                extracted_filename.erase(extracted_filename.length() - 4);

                // Server info
                CreateServerInfo csi;

                csi.gamename = extracted_filename;
                csi.password = "******";
                csi.port = 3665;
                csi.type = NP_LOCAL;
                csi.ipv6 = false;
                csi.use_upnp = false;

                WindowManager::inst().Switch(new dskSelectMap(csi));

                if(GAMESERVER.TryToStart(csi, path, MAPTYPE_SAVEGAME))
                {
                    WindowManager::inst().Draw();
                    WindowManager::inst().Show(new iwPleaseWait);
                }
                else
                {
                    WindowManager::inst().Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), this, MSB_OK, MSB_EXCLAMATIONRED));
                }
            }
            else
            {
                WindowManager::inst().Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), this, MSB_OK, MSB_EXCLAMATIONRED));
            }

            liste.clear();
        } break;
        case 4: // "Replay abspielen"
        {
            WindowManager::inst().Show(new iwPlayReplay);
        } break;
        case 5: // "Kampagne"
        {
            /// @todo Hier dann Auswahl zwischen Kampagne(n) und "Freies Spiel"
            WindowManager::inst().Show(new iwMsgbox(_("Not available"), _("Please use \'Unlimited Play\' to create a Singleplayer game."), this, MSB_OK, MSB_EXCLAMATIONGREEN));
        } break;
        case 6: // "Freies Spiel"
        {
            PrepareSinglePlayerServer();
        } break;
        case 7: // "Spiel laden"
        {
            PrepareLoadGame();
        } break;
        case 8: // "Zurück"
        {
            WindowManager::inst().Switch(new dskMainMenu);
        } break;
    }
}
Example #2
0
void dskSinglePlayer::Msg_ButtonClick(const unsigned int ctrl_id)
{
    switch(ctrl_id)
    {
        case 3: // "Letztes Spiel fortsetzen"
        {
            std::vector<std::string> savFiles = ListDir(GetFilePath(FILE_PATHS[85]), "sav");

            bfs::path path;
            unser_time_t recent = 0;
            for(std::vector<std::string>::iterator it = savFiles.begin(); it != savFiles.end(); ++it)
            {
                Savegame save;

                // Datei öffnen
                if (!save.Load(*it, false, false))
                    continue;

                if (save.save_time > recent)
                {
                    recent = save.save_time;
                    path = *it;
                }
            }

            if (recent != 0)
            {
                // Dateiname noch rausextrahieren aus dem Pfad
                if(!path.has_filename())
                    return;
                bfs::path fileName = path.filename();

                // ".sav" am Ende weg
                RTTR_Assert(fileName.has_extension());
                fileName.replace_extension();

                // Server info
                CreateServerInfo csi;

                csi.gamename = fileName.string();
                csi.password = "******";
                csi.port = 3665;
                csi.type = ServerType::LOCAL;
                csi.ipv6 = false;
                csi.use_upnp = false;

                WINDOWMANAGER.Switch(new dskSelectMap(csi));

                if(GAMESERVER.TryToStart(csi, path.string(), MAPTYPE_SAVEGAME))
                    WINDOWMANAGER.ShowAfterSwitch(new iwPleaseWait);
                else
                    WINDOWMANAGER.Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), NULL, MSB_OK, MSB_EXCLAMATIONRED));
            }
            else
                WINDOWMANAGER.Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), NULL, MSB_OK, MSB_EXCLAMATIONRED));

        } break;
        case 4: // "Replay abspielen"
        {
            WINDOWMANAGER.Show(new iwPlayReplay);
        } break;
        case 5: // "Kampagne"
        {
            /// @todo Hier dann Auswahl zwischen Kampagne(n) und "Freies Spiel"
            WINDOWMANAGER.Show(new iwMsgbox(_("Not available"), _("Please use \'Unlimited Play\' to create a Singleplayer game."), this, MSB_OK, MSB_EXCLAMATIONGREEN));
        } break;
        case 6: // "Freies Spiel"
        {
            PrepareSinglePlayerServer();
        } break;
        case 7: // "Spiel laden"
        {
            PrepareLoadGame();
        } break;
        case 8: // "Zurück"
        {
            WINDOWMANAGER.Switch(new dskMainMenu);
        } break;
    }
}