From c88079d084f2f3b7ec891da22f8c497cd2652853 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Sun, 8 Apr 2012 00:11:21 +0100 Subject: Element sampling HUD thingy (No very good with MVC) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index dfdc12d..40d7501 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -348,6 +348,12 @@ void GameController::Tick() void GameController::Update() { + ui::Point pos = gameView->GetMousePosition(); + if(pos.X >= 0 && pos.Y >= 0 && pos.X < XRES && pos.Y < YRES) + { + gameView->SetSample(gameModel->GetSimulation()->Get(pos.X, pos.Y)); + } + gameModel->GetSimulation()->update_particles(); if(renderOptions && renderOptions->HasExited) { @@ -558,4 +564,8 @@ void GameController::ReloadSim() gameModel->GetSimulation()->Load(gameModel->GetSave()->GetData(), gameModel->GetSave()->GetDataLength()); } +std::string GameController::ElementResolve(int type) +{ + return std::string(gameModel->GetSimulation()->ptypes[type].name); +} diff --git a/src/game/GameController.h b/src/game/GameController.h index fffe26a..b9629ed 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -90,6 +90,7 @@ public: void ShowConsole(); void FrameStep(); ui::Point PointTranslate(ui::Point point); + std::string ElementResolve(int type); }; #endif // GAMECONTROLLER_H diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index bd4bd7a..e6e6445 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -1,4 +1,5 @@ #include +#include #include "Config.h" #include "GameView.h" @@ -29,7 +30,8 @@ GameView::GameView(): selectPoint1(0, 0), selectPoint2(0, 0), stampThumb(NULL), - clipboardThumb(NULL) + clipboardThumb(NULL), + mousePosition(0, 0) { int currentX = 1; //Set up UI @@ -282,6 +284,16 @@ void GameView::NotifyMenuListChanged(GameModel * sender) } } +void GameView::SetSample(Particle sample) +{ + this->sample = sample; +} + +ui::Point GameView::GetMousePosition() +{ + return mousePosition; +} + void GameView::NotifyActiveToolsChanged(GameModel * sender) { for(int i = 0; i < toolButtons.size(); i++) @@ -469,6 +481,7 @@ void GameView::NotifyBrushChanged(GameModel * sender) void GameView::OnMouseMove(int x, int y, int dx, int dy) { + mousePosition = c->PointTranslate(ui::Point(x, y)); if(selectMode!=SelectNone) { if(selectMode==PlaceStamp || selectMode==PlaceClipboard) @@ -837,9 +850,9 @@ void GameView::changeColour() void GameView::OnDraw() { + Graphics * g = ui::Engine::Ref().g; if(ren) { - Graphics * g = ui::Engine::Ref().g; ren->draw_air(); ren->render_parts(); ren->render_fire(); @@ -925,10 +938,19 @@ void GameView::OnDraw() { string message = (*iter); startY -= 13; - g->fillrect(startX-3, startY-3, Graphics::textwidth((char*)message.c_str())+6, 14, 0, 0, 0, 100); + g->fillrect(startX-3, startY-3, Graphics::textwidth((char*)message.c_str())+6 , 14, 0, 0, 0, 100); g->drawtext(startX, startY, message.c_str(), 255, 255, 255, startAlpha); startAlpha-=14; } } } + + std::stringstream sampleInfo; + sampleInfo.precision(2); + if(sample.type) + sampleInfo << c->ElementResolve(sample.type) << ", Temp: " << std::fixed << sample.temp -273.15f; + else + sampleInfo << "Empty"; + + g->drawtext(XRES+BARSIZE-(10+Graphics::textwidth((char*)sampleInfo.str().c_str())), 5, (const char*)sampleInfo.str().c_str(), 255, 255, 255, 255); } diff --git a/src/game/GameView.h b/src/game/GameView.h index 9843743..85f60ed 100644 --- a/src/game/GameView.h +++ b/src/game/GameView.h @@ -71,12 +71,21 @@ private: ui::Point selectPoint1; ui::Point selectPoint2; + ui::Point mousePosition; + Thumbnail * clipboardThumb; Thumbnail * stampThumb; + Particle sample; + void changeColour(); public: GameView(); + + //Breaks MVC, but any other way is going to be more of a mess. + ui::Point GetMousePosition(); + void SetSample(Particle sample); + void AttachController(GameController * _c){ c = _c; } void NotifyRendererChanged(GameModel * sender); void NotifySimulationChanged(GameModel * sender); diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp index 5db7acc..b2769cc 100644 --- a/src/interface/Component.cpp +++ b/src/interface/Component.cpp @@ -148,4 +148,6 @@ void Component::OnMouseWheelInside(int localx, int localy, int d) Component::~Component() { + if(GetParentWindow()->IsFocused(this)) + GetParentWindow()->FocusComponent(NULL); } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 7b1dca8..b52907b 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -120,6 +120,15 @@ int Simulation::flood_prop(int x, int y, size_t propoffset, void * propvalue, in return 0; } +Particle Simulation::Get(int x, int y) +{ + if(pmap[y][x]) + return parts[pmap[y][x]>>8]; + if(photons[y][x]) + return parts[photons[y][x]>>8]; + return Particle(); +} + int Simulation::flood_parts(int x, int y, int fullc, int cm, int bm, int flags) { int c = fullc&0xFF; diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index dd86953..3139b77 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -210,6 +210,7 @@ public: int Load(int x, int y, unsigned char * data, int dataLength); unsigned char * Save(int & dataLength); unsigned char * Save(int x1, int y1, int x2, int y2, int & dataLength); + Particle Get(int x, int y); inline int is_blocking(int t, int x, int y); inline int is_boundary(int pt, int x, int y); inline int find_next_boundary(int pt, int *x, int *y, int dm, int *em); -- cgit v0.9.2-21-gd62e