From 8d5fe459fe4e0b9d398d9eb6d273b71da1a77eec Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 15 Jul 2013 13:09:19 -0400 Subject: [PATCH] 'n' to toggle Newtonian Gravity, quickoption tooltips show which keys you need to press to toggle them --- src/client/GameSave.cpp | 2 +- src/graphics/Graphics.cpp | 12 ++++++++++++ src/gui/game/GameController.cpp | 9 +++++++++ src/gui/game/GameController.h | 1 + src/gui/game/GameView.cpp | 16 +++++++++++----- src/gui/game/QuickOptions.h | 10 +++++----- src/simulation/elements/STKM.cpp | 1 - 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 3d271a2eb..52ad64bf2 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -434,7 +434,7 @@ void GameSave::readOPS(char * data, int dataLength) unsigned char * inputData = (unsigned char*)data, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL; unsigned int inputDataLen = dataLength, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, soapLinkDataLen; unsigned partsCount = 0, *partsSimIndex = NULL; - int i, freeIndicesCount, x, y, j; + int i, x, y, j; int *freeIndices = NULL; int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; int savedVersion = inputData[4]; diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index 09da9363c..0b7e502ba 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -573,7 +573,19 @@ int Graphics::textwidth(const char *s) { int x = 0; for (; *s; s++) + { + if(((char)*s)=='\b') + { + if(!s[1]) break; + s++; + continue; + } else if(*s == '\x0F') { + if(!s[1] || !s[2] || !s[3]) break; + s+=3; + continue; + } x += font_data[font_ptrs[(int)(*(unsigned char *)s)]]; + } return x-1; } diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 815c7a41a..6a6702d51 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -823,6 +823,15 @@ void GameController::ToggleAHeat() gameModel->SetAHeatEnable(!gameModel->GetAHeatEnable()); } +void GameController::ToggleNewtonianGravity() +{ + if (gameModel->GetSimulation()->grav->ngrav_enable) + gameModel->GetSimulation()->grav->stop_grav_async(); + else + gameModel->GetSimulation()->grav->start_grav_async(); + gameModel->UpdateQuickOptions(); +} + void GameController::LoadRenderPreset(int presetNum) { diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index a037e946e..2e1014c3e 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -143,6 +143,7 @@ public: void SwitchGravity(); void SwitchAir(); void ToggleAHeat(); + void ToggleNewtonianGravity(); void LoadClipboard(); void LoadStamp(); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index b1d46d256..3aac3fc74 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -1395,6 +1395,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool case 'u': c->ToggleAHeat(); break; + case 'n': + c->ToggleNewtonianGravity(); case '=': if(ctrl) c->ResetSpark(); @@ -2021,7 +2023,11 @@ void GameView::OnDraw() else if(showHud) { //Draw info about simulation under cursor - int wavelengthGfx = 0; + int wavelengthGfx = 0, alpha = 255; + if (toolTipPosition.Y < 120) + alpha = 255-toolTipPresence*3; + if (alpha < 50) + alpha = 50; std::stringstream sampleInfo; sampleInfo.precision(2); if(sample.particle.type) @@ -2081,8 +2087,8 @@ void GameView::OnDraw() } int textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str()); - g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); - g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255*0.75); + g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5f); + g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 255, 255, alpha*0.75f); #ifndef OGLI if(wavelengthGfx) @@ -2134,8 +2140,8 @@ void GameView::OnDraw() sampleInfo << " GX: " << sample.GravityVelocityX << " GY: " << sample.GravityVelocityY; textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str()); - g->fillrect(XRES-20-textWidth, 26, textWidth+8, 15, 0, 0, 0, 255*0.5); - g->drawtext(XRES-16-textWidth, 30, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255*0.75); + g->fillrect(XRES-20-textWidth, 26, textWidth+8, 15, 0, 0, 0, alpha*0.5f); + g->drawtext(XRES-16-textWidth, 30, (const char*)sampleInfo.str().c_str(), 255, 255, 255, alpha*0.75f); } } diff --git a/src/gui/game/QuickOptions.h b/src/gui/game/QuickOptions.h index 7c31f9c51..e6900aaed 100644 --- a/src/gui/game/QuickOptions.h +++ b/src/gui/game/QuickOptions.h @@ -23,7 +23,7 @@ class DrawGravOption: public QuickOption { public: DrawGravOption(GameModel * m): - QuickOption("G", "Draw gravity field", m, Toggle) + QuickOption("G", "Draw gravity field \bg(g)", m, Toggle) { } @@ -41,7 +41,7 @@ class DecorationsOption: public QuickOption { public: DecorationsOption(GameModel * m): - QuickOption("D", "Draw decorations", m, Toggle) + QuickOption("D", "Draw decorations \bg(ctrl+b)", m, Toggle) { } @@ -59,7 +59,7 @@ class NGravityOption: public QuickOption { public: NGravityOption(GameModel * m): - QuickOption("N", "Newtonian Gravity", m, Toggle) + QuickOption("N", "Newtonian Gravity \bg(n)", m, Toggle) { } @@ -86,7 +86,7 @@ class AHeatOption: public QuickOption { public: AHeatOption(GameModel * m): - QuickOption("A", "Ambient heat", m, Toggle) + QuickOption("A", "Ambient heat \bg(u)", m, Toggle) { } @@ -105,7 +105,7 @@ class ConsoleShowOption: public QuickOption GameController * c; public: ConsoleShowOption(GameModel * m, GameController * c_): - QuickOption("C", "Show Console", m, Toggle) + QuickOption("C", "Show Console \bg(~)", m, Toggle) { c = c_; } diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index d576637a5..709a1184b 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -144,7 +144,6 @@ int Element_STKM::run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { rby = 1.0f; tmp = 1.0f; } - float rbx1 = rbx/tmp, rby1 = rby/tmp;// scale so that the largest is 1.0 tmp = 1.0f/sqrtf(rbx*rbx+rby*rby); rbx *= tmp;// scale to a unit vector rby *= tmp;