From 162a8ecba57a3cea84149aa89d6eee742c1e2cea Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 8 Jan 2013 22:00:45 -0500 Subject: [PATCH] readd tpt.hud and tpt.set_console commands --- src/cat/LegacyLuaAPI.cpp | 23 ++++++++++++----------- src/cat/LuaScriptHelper.h | 1 + src/cat/LuaScriptInterface.cpp | 2 ++ src/game/GameController.cpp | 16 +++++++++++++++- src/game/GameController.h | 2 ++ src/game/GameView.cpp | 5 +++++ src/game/GameView.h | 1 + 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index 8c52bfe05..c6a41e167 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -12,7 +12,7 @@ #include "dialogues/ErrorMessage.h" #include "dialogues/InformationMessage.h" #include "dialogues/TextPrompt.h" -#include "dialogues/ConfirmPrompt.h" +#include "dialogues/ConfirmPrompt.h" #include "simulation/Simulation.h" #include "game/GameModel.h" @@ -803,11 +803,12 @@ int luatpt_togglewater(lua_State* l) int luatpt_setconsole(lua_State* l) { - /*int consolestate; + int consolestate; consolestate = luaL_optint(l, 1, 0); - console_mode = (consolestate==0?0:1); - return 0;*/ - //TODO IMPLEMENT + if (consolestate) + luacon_controller->ShowConsole(); + else + luacon_controller->HideConsole(); return 0; } @@ -1640,12 +1641,12 @@ int luatpt_getPartIndex(lua_State* l) } int luatpt_hud(lua_State* l) { - /*int hudstate; - hudstate = luaL_optint(l, 1, 0); - hud_enable = (hudstate==0?0:1); - return 0;*/ - //TODO IMPLEMENT - return 0; + int hudstate = luaL_optint(l, 1, 0); + if (hudstate) + luacon_controller->SetHudEnable(1); + else + luacon_controller->SetHudEnable(0); + return 0; } int luatpt_gravity(lua_State* l) { diff --git a/src/cat/LuaScriptHelper.h b/src/cat/LuaScriptHelper.h index 1b771e485..b55329f87 100644 --- a/src/cat/LuaScriptHelper.h +++ b/src/cat/LuaScriptHelper.h @@ -9,6 +9,7 @@ #define LUASCRIPTHELPER_H_ extern GameModel * luacon_model; +extern GameController * luacon_controller; extern Simulation * luacon_sim; extern LuaScriptInterface * luacon_ci; extern Graphics * luacon_g; diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 8cf35c359..b529255c8 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -55,6 +55,7 @@ extern "C" } GameModel * luacon_model; +GameController * luacon_controller; Simulation * luacon_sim; LuaScriptInterface * luacon_ci; Graphics * luacon_g; @@ -91,6 +92,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): luacon_mousedown(false) { luacon_model = m; + luacon_controller = c; luacon_sim = m->GetSimulation(); luacon_g = ui::Engine::Ref().g; luacon_ren = m->GetRenderer(); diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 2ec2cfc5f..3b9a64e50 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -892,6 +892,11 @@ void GameController::ShowGravityGrid() gameModel->UpdateQuickOptions(); } +void GameController::SetHudEnable(bool hudState) +{ + gameView->SetHudEnable(hudState); +} + void GameController::SetActiveColourPreset(int preset) { gameModel->SetActiveColourPreset(preset); @@ -1107,7 +1112,16 @@ void GameController::ShowConsole() { if(!console) console = new ConsoleController(NULL, commandInterface); - ui::Engine::Ref().ShowWindow(console->GetView()); + if (console->GetView() != ui::Engine::Ref().GetWindow()) + ui::Engine::Ref().ShowWindow(console->GetView()); +} + +void GameController::HideConsole() +{ + if(!console) + return; + if (console->GetView() == ui::Engine::Ref().GetWindow()) + ui::Engine::Ref().CloseWindow(); } void GameController::OpenRenderOptions() diff --git a/src/game/GameController.h b/src/game/GameController.h index 2e02b2575..a3057d231 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -96,6 +96,7 @@ public: void SetDecoration(bool decorationState); void SetDecoration(); void ShowGravityGrid(); + void SetHudEnable(bool hudState); void SetActiveMenu(Menu * menu); void SetActiveTool(int toolSelection, Tool * tool); void SetActiveColourPreset(int preset); @@ -123,6 +124,7 @@ public: void Vote(int direction); void ChangeBrush(); void ShowConsole(); + void HideConsole(); void FrameStep(); void TranslateSave(ui::Point point); void TransformSave(matrix2d transform); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 5118d17c5..d6f519cf7 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -564,6 +564,11 @@ void GameView::SetSample(SimulationSample sample) this->sample = sample; } +void GameView::SetHudEnable(bool hudState) +{ + showHud = hudState; +} + ui::Point GameView::GetMousePosition() { return mousePosition; diff --git a/src/game/GameView.h b/src/game/GameView.h index e17279f1a..7474da0e5 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -126,6 +126,7 @@ public: //Breaks MVC, but any other way is going to be more of a mess. ui::Point GetMousePosition(); void SetSample(SimulationSample sample); + void SetHudEnable(bool hudState); bool CtrlBehaviour(){ return ctrlBehaviour; } bool ShiftBehaviour(){ return shiftBehaviour; } void ExitPrompt();