ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

recorderdialog.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/algorithm.h"
00024 #include "common/bufferedstream.h"
00025 #include "common/savefile.h"
00026 #include "common/system.h"
00027 #include "graphics/colormasks.h"
00028 #include "graphics/palette.h"
00029 #include "graphics/scaler.h"
00030 #include "graphics/thumbnail.h"
00031 #include "common/translation.h"
00032 #include "gui/widgets/list.h"
00033 #include "gui/editrecorddialog.h"
00034 #include "gui/EventRecorder.h"
00035 #include "gui/message.h"
00036 #include "common/system.h"
00037 #include "gui/ThemeEval.h"
00038 #include "gui/gui-manager.h"
00039 #include "recorderdialog.h"
00040 
00041 #define MAX_RECORDS_NAMES 0xFF
00042 
00043 namespace GUI {
00044 
00045 enum {
00046     kRecordCmd = 'RCRD',
00047     kPlaybackCmd = 'PBCK',
00048     kDeleteCmd = 'DEL ',
00049     kNextScreenshotCmd = 'NEXT',
00050     kPrevScreenshotCmd = 'PREV',
00051     kEditRecordCmd = 'EDIT'
00052 };
00053 
00054 RecorderDialog::RecorderDialog() : Dialog("RecorderDialog"), _list(0), _currentScreenshot(0) {
00055     _firstScreenshotUpdate = false;
00056     _screenShotsCount = 0;
00057     _currentScreenshotText = 0;
00058     _authorText = 0;
00059     _notesText = 0;
00060 
00061     _backgroundType = ThemeEngine::kDialogBackgroundSpecial;
00062 
00063     new StaticTextWidget(this, "SaveLoadChooser.Title", _("Recorder or Playback Gameplay"));
00064 
00065     _list = new GUI::ListWidget(this, "RecorderDialog.List");
00066     _list->setNumberingMode(GUI::kListNumberingOff);
00067 
00068     _deleteButton = new GUI::ButtonWidget(this, "RecorderDialog.Delete", _("Delete"), 0, kDeleteCmd);
00069     new GUI::ButtonWidget(this, "RecorderDialog.Cancel", _("Cancel"), 0, kCloseCmd);
00070     new GUI::ButtonWidget(this, "RecorderDialog.Record", _("Record"), 0, kRecordCmd);
00071     _playbackButton = new GUI::ButtonWidget(this, "RecorderDialog.Playback", _("Playback"), 0, kPlaybackCmd);
00072 
00073     _editButton = new GUI::ButtonWidget(this, "RecorderDialog.Edit", _("Edit"), 0, kEditRecordCmd);
00074 
00075     _editButton->setEnabled(false);
00076     _deleteButton->setEnabled(false);
00077     _playbackButton->setEnabled(false);
00078 
00079     _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10);
00080     _container = new GUI::ContainerWidget(this, 0, 0, 10, 10);
00081     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") == 1) {
00082         new GUI::ButtonWidget(this,"RecorderDialog.NextScreenShotButton", "<", 0, kPrevScreenshotCmd);
00083         new GUI::ButtonWidget(this, "RecorderDialog.PreviousScreenShotButton", ">", 0, kNextScreenshotCmd);
00084         _currentScreenshotText = new StaticTextWidget(this, "RecorderDialog.currentScreenshot", "0/0");
00085         _authorText = new StaticTextWidget(this, "RecorderDialog.Author", _("Author: "));
00086         _notesText = new StaticTextWidget(this, "RecorderDialog.Notes", _("Notes: "));
00087     }
00088     if (_gfxWidget)
00089         _gfxWidget->setGfx(0);
00090 }
00091 
00092 
00093 void RecorderDialog::reflowLayout() {
00094     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") == 1) {
00095         int16 x, y;
00096         uint16 w, h;
00097 
00098         if (!g_gui.xmlEval()->getWidgetData("RecorderDialog.Thumbnail", x, y, w, h)) {
00099             error("Error when loading position data for Recorder Thumbnails");
00100         }
00101 
00102         int thumbW = kThumbnailWidth;
00103         int thumbH = kThumbnailHeight2;
00104         int thumbX = x + (w >> 1) - (thumbW >> 1);
00105         int thumbY = y + kLineHeight;
00106 
00107         _container->resize(x, y, w, h);
00108         _gfxWidget->resize(thumbX, thumbY, thumbW, thumbH);
00109 
00110         _container->setVisible(true);
00111         _gfxWidget->setVisible(true);
00112         updateSelection(false);
00113     } else {
00114         _container->setVisible(false);
00115         _gfxWidget->setVisible(false);
00116     }
00117     Dialog::reflowLayout();
00118 }
00119 
00120 
00121 
00122 void RecorderDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00123     switch(cmd) {
00124     case kEditRecordCmd: {
00125         if (_list->getSelected() >= 0) {
00126             EditRecordDialog editDlg(_fileHeaders[_list->getSelected()].author, _fileHeaders[_list->getSelected()].name, _fileHeaders[_list->getSelected()].notes);
00127             if (editDlg.runModal() != kOKCmd) {
00128                 return;
00129             }
00130             _playbackFile.openRead(_fileHeaders[_list->getSelected()].fileName);
00131             _playbackFile.getHeader().author = editDlg.getAuthor();
00132             _playbackFile.getHeader().name = editDlg.getName();
00133             _playbackFile.getHeader().notes = editDlg.getNotes();
00134             _playbackFile.updateHeader();
00135             _fileHeaders[_list->getSelected()] = _playbackFile.getHeader();
00136             int oldselection = _list->getSelected();
00137             updateList();
00138             _list->setSelected(oldselection);
00139             updateSelection(true);
00140             _playbackFile.close();
00141         }
00142     }
00143         break;
00144     case kNextScreenshotCmd:
00145         ++_currentScreenshot;
00146         updateScreenshot();
00147         break;
00148     case kPrevScreenshotCmd:
00149         --_currentScreenshot;
00150         updateScreenshot();
00151         break;
00152     case kDeleteCmd:
00153         if (_list->getSelected() >= 0) {
00154             MessageDialog alert(_("Do you really want to delete this record?"),
00155                 _("Delete"), _("Cancel"));
00156             if (alert.runModal() == GUI::kMessageOK) {
00157                 _playbackFile.close();
00158                 g_eventRec.deleteRecord(_fileHeaders[_list->getSelected()].fileName);
00159                 _list->setSelected(-1);
00160                 updateList();
00161             }
00162         }
00163         break;
00164     case GUI::kListSelectionChangedCmd:
00165         updateSelection(true);
00166         break;
00167     case kRecordCmd: {
00168         TimeDate t;
00169         Common::String gameId = ConfMan.get("gameid", _target);
00170         PlainGameDescriptor desc = EngineMan.findGame(gameId);
00171         g_system->getTimeAndDate(t);
00172         EditRecordDialog editDlg(_("Unknown Author"), Common::String::format("%.2d.%.2d.%.4d ", t.tm_mday, t.tm_mon, 1900 + t.tm_year) + desc.description, "");
00173         if (editDlg.runModal() != kOKCmd) {
00174             return;
00175         }
00176         _author = editDlg.getAuthor();
00177         _name = editDlg.getName();
00178         _notes = editDlg.getNotes();
00179         _filename = g_eventRec.generateRecordFileName(_target);
00180         setResult(kRecordDialogRecord);
00181         close();
00182         }
00183         break;
00184     case kPlaybackCmd:
00185         if (_list->getSelected() >= 0) {
00186             _filename = _fileHeaders[_list->getSelected()].fileName;
00187             setResult(kRecordDialogPlayback);
00188             close();
00189         }
00190         break;
00191     case kCloseCmd:
00192         setResult(kRecordDialogClose);
00193         // Fall through
00194     default:
00195         Dialog::handleCommand(sender, cmd, data);
00196     }
00197 }
00198 
00199 void RecorderDialog::updateList() {
00200     Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
00201     Common::String pattern(_target+".r??");
00202     Common::StringArray files = saveFileMan->listSavefiles(pattern);
00203     Common::PlaybackFile file;
00204     Common::StringArray namesList;
00205     _fileHeaders.clear();
00206     for (Common::StringArray::iterator i = files.begin(); i != files.end(); ++i) {
00207         if (file.openRead(*i)) {
00208             namesList.push_back(file.getHeader().name);
00209             _fileHeaders.push_back(file.getHeader());
00210         }
00211         file.close();
00212     }
00213     _list->setList(namesList);
00214     _list->markAsDirty();
00215 }
00216 
00217 int RecorderDialog::runModal(Common::String &target) {
00218     _target = target;
00219     updateList();
00220     return Dialog::runModal();
00221 }
00222 
00223 RecorderDialog::~RecorderDialog() {
00224 }
00225 
00226 void RecorderDialog::updateSelection(bool redraw) {
00227     if (_list->getSelected() >= 0) {
00228         _editButton->setEnabled(true);
00229         _deleteButton->setEnabled(true);
00230         _playbackButton->setEnabled(true);
00231     }
00232 
00233     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") != 1)
00234         return;
00235 
00236     _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00237     _screenShotsCount = 0;
00238     _currentScreenshot = 0;
00239     updateScreenShotsText();
00240     if (_list->getSelected() >= 0) {
00241         _authorText->setLabel(_("Author: ") + _fileHeaders[_list->getSelected()].author);
00242         _notesText->setLabel(_("Notes: ") + _fileHeaders[_list->getSelected()].notes);
00243 
00244         _firstScreenshotUpdate = true;
00245         updateScreenshot();
00246         if ((_screenShotsCount) > 0) {
00247             _currentScreenshot = 1;
00248         }
00249         updateScreenshot();
00250     } else {
00251         _authorText->setLabel(_("Author: "));
00252         _notesText->setLabel(_("Notes: "));
00253         _screenShotsCount = -1;
00254         _currentScreenshot = 0;
00255         _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00256         _gfxWidget->markAsDirty();
00257         updateScreenShotsText();
00258     }
00259 }
00260 
00261 void RecorderDialog::updateScreenshot() {
00262     if (_list->getSelected() == -1) {
00263         return;
00264     }
00265     if (_currentScreenshot < 1) {
00266         _currentScreenshot = _screenShotsCount;
00267     }
00268     if (_currentScreenshot > _screenShotsCount) {
00269         _currentScreenshot = 1;
00270     }
00271     if (_firstScreenshotUpdate) {
00272         _playbackFile.openRead(_fileHeaders[_list->getSelected()].fileName);
00273         _screenShotsCount = _playbackFile.getScreensCount();
00274         _firstScreenshotUpdate = false;
00275     }
00276     Graphics::Surface *srcsf = _playbackFile.getScreenShot(_currentScreenshot);
00277     if (srcsf != NULL) {
00278         Graphics::Surface *destsf = Graphics::scale(*srcsf, _gfxWidget->getWidth(), _gfxWidget->getHeight());
00279         _gfxWidget->setGfx(destsf);
00280         updateScreenShotsText();
00281         delete destsf;
00282         delete srcsf;
00283     } else {
00284         _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00285     }
00286     _gfxWidget->markAsDirty();
00287 }
00288 
00289 void RecorderDialog::updateScreenShotsText() {
00290     if (_screenShotsCount == -1) {
00291         _currentScreenshotText->setLabel(Common::String::format("%d / ?", _currentScreenshot));
00292     } else {
00293         _currentScreenshotText->setLabel(Common::String::format("%d / %d", _currentScreenshot, _screenShotsCount));
00294     }
00295 }
00296 
00297 } // End of namespace GUI


Generated on Sat Feb 16 2019 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge