From 6bd068713e8c81ead150edfa23458a58e4548bfb Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 4 Sep 2017 14:06:28 -0400 Subject: [PATCH] recording improvements remove 'r' record shortcut add tpt.record function. Still gives the user a confirm prompt recordings now go into recordings//, where timestamp is the time the recording was started. is returned by the tpt.record function. Each new recording starts the filenames over at 0 again. you probably still need a lua script to use the recording feature, this should make it easier for those --- .gitignore | 1 + src/gui/game/GameController.cpp | 5 ++++ src/gui/game/GameController.h | 1 + src/gui/game/GameView.cpp | 41 ++++++++++++++++++--------------- src/gui/game/GameView.h | 5 ++-- src/lua/LegacyLuaAPI.cpp | 10 ++++++++ src/lua/LuaScriptHelper.h | 1 + src/lua/LuaScriptInterface.cpp | 1 + 8 files changed, 44 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 959e7c104..872032ba9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ Saves/* scripts/* generated/* includes/* +recordings/ font/* generate Makefile.me diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 572a5dec5..6182c8197 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -1571,6 +1571,11 @@ std::string GameController::WallName(int type) return ""; } +int GameController::Record(bool record) +{ + return gameView->Record(record); +} + void GameController::NotifyAuthUserChanged(Client * sender) { User newUser = sender->GetAuthUser(); diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 42df4f6f6..79d850449 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -149,6 +149,7 @@ public: std::string ElementResolve(int type, int ctype); bool IsValidElement(int type); std::string WallName(int type); + int Record(bool record); void ResetAir(); void ResetSpark(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 1a94ca578..088480529 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -186,8 +186,9 @@ GameView::GameView(): introTextMessage(introTextData), doScreenshot(false), - recording(false), screenshotIndex(0), + recording(false), + recordingFolder(0), recordingIndex(0), currentPoint(ui::Point(0, 0)), lastPoint(ui::Point(0, 0)), @@ -1044,28 +1045,31 @@ void GameView::screenshot() doScreenshot = true; } -void GameView::record() +int GameView::Record(bool record) { - if(recording) + if (!record) { recording = false; + recordingIndex = 0; + recordingFolder = 0; } - else + else if (!recording) { - class RecordingConfirmation: public ConfirmDialogueCallback { - public: - GameView * v; - RecordingConfirmation(GameView * v): v(v) {} - virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) { - if (result == ConfirmPrompt::ResultOkay) - { - v->recording = true; - } - } - virtual ~RecordingConfirmation() { } - }; - new ConfirmPrompt("Recording", "You're about to start recording all drawn frames. This may use a load of hard disk space.", new RecordingConfirmation(this)); + // block so that the return value is correct + bool record = ConfirmPrompt::Blocking("Recording", "You're about to start recording all drawn frames. This will use a load of disk space."); + if (record) + { + time_t startTime = time(NULL); + recordingFolder = startTime; + std::stringstream recordingDir; + recordingDir << "recordings" << PATH_SEP << recordingFolder; + Client::Ref().MakeDirectory("recordings"); + Client::Ref().MakeDirectory(recordingDir.str().c_str()); + recording = true; + recordingIndex = 0; + } } + return recordingFolder; } void GameView::updateToolButtonScroll() @@ -1496,8 +1500,6 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool case 'r': if (ctrl) c->ReloadSim(); - else - record(); break; case 'e': c->OpenElementSearch(); @@ -2233,6 +2235,7 @@ void GameView::OnDraw() std::vector data = format::VideoBufferToPPM(screenshot); std::stringstream filename; + filename << "recordings" << PATH_SEP << recordingFolder << PATH_SEP; filename << "frame_"; filename << std::setfill('0') << std::setw(6) << (recordingIndex++); filename << ".ppm"; diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index c66d28ff4..2d87cf228 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -66,8 +66,9 @@ private: std::string introTextMessage; bool doScreenshot; - bool recording; int screenshotIndex; + bool recording; + int recordingFolder; int recordingIndex; ui::Point currentPoint, lastPoint; @@ -117,7 +118,6 @@ private: void SetSaveButtonTooltips(); void screenshot(); - void record(); void enableShiftBehaviour(); void disableShiftBehaviour(); @@ -147,6 +147,7 @@ public: void ExitPrompt(); SelectMode GetSelectMode() { return selectMode; } void BeginStampSelection(); + int Record(bool record); //all of these are only here for one debug lines bool GetMouseDown() { return isMouseDown; } diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 1379ae455..adcb49914 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -2032,4 +2032,14 @@ int luatpt_screenshot(lua_State* l) return 1; } +int luatpt_record(lua_State* l) +{ + if (!lua_isboolean(l, -1)) + return luaL_typerror(l, 1, lua_typename(l, LUA_TBOOLEAN)); + bool record = lua_toboolean(l, -1); + int recordingFolder = luacon_controller->Record(record); + lua_pushinteger(l, recordingFolder); + return 1; +} + #endif diff --git a/src/lua/LuaScriptHelper.h b/src/lua/LuaScriptHelper.h index dd3ae9914..85e3730cd 100644 --- a/src/lua/LuaScriptHelper.h +++ b/src/lua/LuaScriptHelper.h @@ -131,6 +131,7 @@ int luatpt_getscript(lua_State* l); int luatpt_setwindowsize(lua_State* l); int luatpt_screenshot(lua_State* l); +int luatpt_record(lua_State* l); #endif /* LUASCRIPTHELPER_H_ */ diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 4c4a284dc..0aca14767 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -202,6 +202,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): {"setwindowsize",&luatpt_setwindowsize}, {"watertest",&luatpt_togglewater}, {"screenshot",&luatpt_screenshot}, + {"record",&luatpt_record}, {"element",&luatpt_getelement}, {"element_func",&luatpt_element_func}, {"graphics_func",&luatpt_graphics_func},