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/palette.h"
00028 #include "graphics/scaler.h"
00029 #include "graphics/thumbnail.h"
00030 #include "common/translation.h"
00031 #include "gui/widgets/list.h"
00032 #include "gui/editrecorddialog.h"
00033 #include "gui/EventRecorder.h"
00034 #include "gui/message.h"
00035 #include "common/system.h"
00036 #include "gui/ThemeEval.h"
00037 #include "gui/gui-manager.h"
00038 #include "recorderdialog.h"
00039 
00040 #define MAX_RECORDS_NAMES 0xFF
00041 
00042 namespace GUI {
00043 
00044 enum {
00045     kRecordCmd = 'RCRD',
00046     kPlaybackCmd = 'PBCK',
00047     kDeleteCmd = 'DEL ',
00048     kNextScreenshotCmd = 'NEXT',
00049     kPrevScreenshotCmd = 'PREV',
00050     kEditRecordCmd = 'EDIT'
00051 };
00052 
00053 RecorderDialog::RecorderDialog() : Dialog("RecorderDialog"), _list(nullptr), _currentScreenshot(0) {
00054     _firstScreenshotUpdate = false;
00055     _screenShotsCount = 0;
00056     _currentScreenshotText = nullptr;
00057     _authorText = nullptr;
00058     _notesText = nullptr;
00059 
00060     _backgroundType = ThemeEngine::kDialogBackgroundSpecial;
00061 
00062     new StaticTextWidget(this, "RecorderDialog.Title", _("Recorder or Playback Gameplay"));
00063 
00064     _list = new GUI::ListWidget(this, "RecorderDialog.List");
00065     _list->setNumberingMode(GUI::kListNumberingOff);
00066 
00067     _deleteButton = new GUI::ButtonWidget(this, "RecorderDialog.Delete", _("Delete"), nullptr, kDeleteCmd);
00068     new GUI::ButtonWidget(this, "RecorderDialog.Cancel", _("Cancel"), nullptr, kCloseCmd);
00069     new GUI::ButtonWidget(this, "RecorderDialog.Record", _("Record"), nullptr, kRecordCmd);
00070     _playbackButton = new GUI::ButtonWidget(this, "RecorderDialog.Playback", _("Playback"), nullptr, kPlaybackCmd);
00071 
00072     _editButton = new GUI::ButtonWidget(this, "RecorderDialog.Edit", _("Edit"), nullptr, kEditRecordCmd);
00073 
00074     _editButton->setEnabled(false);
00075     _deleteButton->setEnabled(false);
00076     _playbackButton->setEnabled(false);
00077 
00078     _gfxWidget = new GUI::GraphicsWidget(this, 0, 0, 10, 10);
00079     _container = new GUI::ContainerWidget(this, "RecorderDialog.Thumbnail");
00080     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") == 1) {
00081         new GUI::ButtonWidget(this,"RecorderDialog.NextScreenShotButton", "<", nullptr, kPrevScreenshotCmd);
00082         new GUI::ButtonWidget(this, "RecorderDialog.PreviousScreenShotButton", ">", nullptr, kNextScreenshotCmd);
00083         _currentScreenshotText = new StaticTextWidget(this, "RecorderDialog.currentScreenshot", "0/0");
00084         _authorText = new StaticTextWidget(this, "RecorderDialog.Author", _("Author: "));
00085         _notesText = new StaticTextWidget(this, "RecorderDialog.Notes", _("Notes: "));
00086     }
00087     if (_gfxWidget)
00088         _gfxWidget->setGfx(nullptr);
00089 }
00090 
00091 
00092 void RecorderDialog::reflowLayout() {
00093     Dialog::reflowLayout();
00094 
00095     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") == 1) {
00096         int16 x, y;
00097         int16 w, h;
00098 
00099         if (!g_gui.xmlEval()->getWidgetData("RecorderDialog.Thumbnail", x, y, w, h)) {
00100             error("Error when loading position data for Recorder Thumbnails");
00101         }
00102 
00103         int thumbW = kThumbnailWidth;
00104         int thumbH = kThumbnailHeight2;
00105         int thumbX = x + (w >> 1) - (thumbW >> 1);
00106         int thumbY = y + kLineHeight;
00107 
00108         _container->resize(x, y, w, h);
00109         _gfxWidget->resize(thumbX, thumbY, thumbW, thumbH);
00110 
00111         _container->setVisible(true);
00112         _gfxWidget->setVisible(true);
00113         updateSelection(false);
00114     } else {
00115         _container->setVisible(false);
00116         _gfxWidget->setVisible(false);
00117     }
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         QualifiedGameDescriptor desc = EngineMan.findTarget(_target);
00170         g_system->getTimeAndDate(t);
00171         EditRecordDialog editDlg(_("Unknown Author"), Common::String::format("%.2d.%.2d.%.4d ", t.tm_mday, t.tm_mon, 1900 + t.tm_year) + desc.description, "");
00172         if (editDlg.runModal() != kOKCmd) {
00173             return;
00174         }
00175         _author = editDlg.getAuthor();
00176         _name = editDlg.getName();
00177         _notes = editDlg.getNotes();
00178         _filename = g_eventRec.generateRecordFileName(_target);
00179         setResult(kRecordDialogRecord);
00180         close();
00181         }
00182         break;
00183     case kPlaybackCmd:
00184         if (_list->getSelected() >= 0) {
00185             _filename = _fileHeaders[_list->getSelected()].fileName;
00186             setResult(kRecordDialogPlayback);
00187             close();
00188         }
00189         break;
00190     case kCloseCmd:
00191         setResult(kRecordDialogClose);
00192         // Fall through
00193     default:
00194         Dialog::handleCommand(sender, cmd, data);
00195     }
00196 }
00197 
00198 void RecorderDialog::updateList() {
00199     Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
00200     Common::String pattern(_target+".r??");
00201     Common::StringArray files = saveFileMan->listSavefiles(pattern);
00202     Common::PlaybackFile file;
00203     Common::StringArray namesList;
00204     _fileHeaders.clear();
00205     for (Common::StringArray::iterator i = files.begin(); i != files.end(); ++i) {
00206         if (file.openRead(*i)) {
00207             namesList.push_back(file.getHeader().name);
00208             _fileHeaders.push_back(file.getHeader());
00209         }
00210         file.close();
00211     }
00212     _list->setList(namesList);
00213     _list->markAsDirty();
00214 }
00215 
00216 int RecorderDialog::runModal(Common::String &target) {
00217     _target = target;
00218     updateList();
00219     return Dialog::runModal();
00220 }
00221 
00222 RecorderDialog::~RecorderDialog() {
00223 }
00224 
00225 void RecorderDialog::updateSelection(bool redraw) {
00226     if (_list->getSelected() >= 0) {
00227         _editButton->setEnabled(true);
00228         _deleteButton->setEnabled(true);
00229         _playbackButton->setEnabled(true);
00230     }
00231 
00232     if (g_gui.xmlEval()->getVar("Globals.RecorderDialog.ExtInfo.Visible") != 1)
00233         return;
00234 
00235     _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00236     _screenShotsCount = 0;
00237     _currentScreenshot = 0;
00238     updateScreenShotsText();
00239     if (_list->getSelected() >= 0) {
00240         _authorText->setLabel(_("Author: ") + _fileHeaders[_list->getSelected()].author);
00241         _notesText->setLabel(_("Notes: ") + _fileHeaders[_list->getSelected()].notes);
00242 
00243         _firstScreenshotUpdate = true;
00244         updateScreenshot();
00245         if ((_screenShotsCount) > 0) {
00246             _currentScreenshot = 1;
00247         }
00248         updateScreenshot();
00249     } else {
00250         _authorText->setLabel(_("Author: "));
00251         _notesText->setLabel(_("Notes: "));
00252         _screenShotsCount = -1;
00253         _currentScreenshot = 0;
00254         _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00255         _gfxWidget->markAsDirty();
00256         updateScreenShotsText();
00257     }
00258 }
00259 
00260 void RecorderDialog::updateScreenshot() {
00261     if (_list->getSelected() == -1) {
00262         return;
00263     }
00264     if (_currentScreenshot < 1) {
00265         _currentScreenshot = _screenShotsCount;
00266     }
00267     if (_currentScreenshot > _screenShotsCount) {
00268         _currentScreenshot = 1;
00269     }
00270     if (_firstScreenshotUpdate) {
00271         _playbackFile.openRead(_fileHeaders[_list->getSelected()].fileName);
00272         _screenShotsCount = _playbackFile.getScreensCount();
00273         _firstScreenshotUpdate = false;
00274     }
00275     Graphics::Surface *srcsf = _playbackFile.getScreenShot(_currentScreenshot);
00276     if (srcsf != nullptr) {
00277         Graphics::Surface *destsf = Graphics::scale(*srcsf, _gfxWidget->getWidth(), _gfxWidget->getHeight());
00278         _gfxWidget->setGfx(destsf);
00279         updateScreenShotsText();
00280         delete destsf;
00281         delete srcsf;
00282     } else {
00283         _gfxWidget->setGfx(-1, -1, 0, 0, 0);
00284     }
00285     _gfxWidget->markAsDirty();
00286 }
00287 
00288 void RecorderDialog::updateScreenShotsText() {
00289     if (_screenShotsCount == -1) {
00290         _currentScreenshotText->setLabel(Common::String::format("%d / ?", _currentScreenshot));
00291     } else {
00292         _currentScreenshotText->setLabel(Common::String::format("%d / %d", _currentScreenshot, _screenShotsCount));
00293     }
00294 }
00295 
00296 } // End of namespace GUI


Generated on Sat Jun 27 2020 05:00:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge