Preview: Wait for save to load before opening, Simulation: Correct block coords when reading wall data, replace existing particles when placing stamps on top, Game: Clear the simulation when loading a save
This commit is contained in:
parent
46614017c8
commit
c408e035fa
@ -69,9 +69,6 @@ GameSave::GameSave(char * data, int dataSize)
|
||||
|
||||
void GameSave::setSize(int newWidth, int newHeight)
|
||||
{
|
||||
|
||||
std::cout << "GameSave::setSize(" << newWidth << ", " << newHeight << ")";
|
||||
|
||||
this->blockWidth = newWidth;
|
||||
this->blockHeight = newHeight;
|
||||
|
||||
|
@ -275,12 +275,8 @@ void GameModel::SetSave(SaveInfo * newSave)
|
||||
currentSave = newSave;
|
||||
if(currentSave)
|
||||
{
|
||||
int returnVal = sim->Load(currentSave->GetGameSave());
|
||||
if(returnVal){
|
||||
delete currentSave;
|
||||
currentSave = NULL;
|
||||
throw GameModelException(returnVal==2?"Save from newer version":"Save data corrupt");
|
||||
}
|
||||
sim->clear_sim();
|
||||
sim->Load(currentSave->GetGameSave());
|
||||
}
|
||||
notifySaveChanged();
|
||||
notifyPausedChanged();
|
||||
|
@ -39,6 +39,10 @@ void PreviewController::Update()
|
||||
Exit();
|
||||
new ErrorMessage("Error", e.what());
|
||||
}
|
||||
if(previewModel->GetDoOpen() && previewModel->GetSave() && previewModel->GetSave()->GetGameSave())
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
}
|
||||
|
||||
SaveInfo * PreviewController::GetSave()
|
||||
|
@ -11,11 +11,13 @@
|
||||
#include "simulation/SaveRenderer.h"
|
||||
#include "interface/Point.h"
|
||||
#include "interface/Window.h"
|
||||
#include "Style.h"
|
||||
#include "search/Thumbnail.h"
|
||||
|
||||
PreviewView::PreviewView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
|
||||
savePreview(NULL)
|
||||
savePreview(NULL),
|
||||
doOpen(false)
|
||||
{
|
||||
class OpenAction: public ui::ButtonAction
|
||||
{
|
||||
@ -25,7 +27,6 @@ PreviewView::PreviewView():
|
||||
virtual void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->DoOpen();
|
||||
v->c->Exit();
|
||||
}
|
||||
};
|
||||
openButton = new ui::Button(ui::Point(0, Size.Y-19), ui::Point(51, 19), "Open");
|
||||
@ -109,6 +110,18 @@ PreviewView::PreviewView():
|
||||
AddComponent(authorDateLabel);
|
||||
}
|
||||
|
||||
void PreviewView::DoDraw()
|
||||
{
|
||||
Window::DoDraw();
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
if(c->GetDoOpen())
|
||||
{
|
||||
g->fillrect(Position.X+(Size.X/2)-101, Position.Y+(Size.Y/2)-26, 202, 52, 0, 0, 0, 210);
|
||||
g->drawrect(Position.X+(Size.X/2)-100, Position.Y+(Size.Y/2)-25, 200, 50, 255, 255, 255, 180);
|
||||
g->drawtext(Position.X+(Size.X/2)-(Graphics::textwidth("Loading save...")/2), Position.Y+(Size.Y/2)-5, "Loading save...", style::Colour::InformationTitle.Red, style::Colour::InformationTitle.Green, style::Colour::InformationTitle.Blue, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewView::OnDraw()
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
@ -128,9 +141,8 @@ void PreviewView::OnDraw()
|
||||
|
||||
g->draw_line(Position.X+1, Position.Y+12+YRES/2, Position.X-1+XRES/2, Position.Y+12+YRES/2, 100, 100, 100,255);
|
||||
float factor;
|
||||
if(!votesUp && !votesDown)
|
||||
return;
|
||||
else
|
||||
if(!(!votesUp && !votesDown))
|
||||
{
|
||||
factor = (float)(((float)(XRES/2)-2)/((float)(votesUp+votesDown)));
|
||||
g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (XRES/2)-2, 9, 200, 50, 50, 255);
|
||||
g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 9, 50, 200, 50, 255);
|
||||
@ -138,6 +150,7 @@ void PreviewView::OnDraw()
|
||||
g->fillrect(Position.X+(XRES/2)-15, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100);
|
||||
g->draw_icon(1+Position.X+2, Position.Y+(YRES/2)+4, IconVoteUp);
|
||||
g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown);
|
||||
}
|
||||
|
||||
for(int i = 0; i < commentTextComponents.size(); i++)
|
||||
{
|
||||
|
@ -33,12 +33,14 @@ class PreviewView: public ui::Window {
|
||||
std::vector<ui::Component*> commentTextComponents;
|
||||
int votesUp;
|
||||
int votesDown;
|
||||
bool doOpen;
|
||||
public:
|
||||
void AttachController(PreviewController * controller) { c = controller;}
|
||||
PreviewView();
|
||||
void NotifySaveChanged(PreviewModel * sender);
|
||||
void NotifyCommentsChanged(PreviewModel * sender);
|
||||
virtual void OnDraw();
|
||||
virtual void DoDraw();
|
||||
virtual void OnTick(float dt);
|
||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||
virtual ~PreviewView();
|
||||
|
@ -19,7 +19,7 @@ int Simulation::Load(GameSave * save)
|
||||
|
||||
int Simulation::Load(int fullX, int fullY, GameSave * save)
|
||||
{
|
||||
int blockX, blockY;
|
||||
int blockX, blockY, x, y, r;
|
||||
|
||||
if(!save) return 0;
|
||||
|
||||
@ -32,15 +32,27 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
||||
int i;
|
||||
for(int n = 0; n < NPART && n < save->particlesCount; n++)
|
||||
{
|
||||
Particle tempPart = save->particles[n];
|
||||
tempPart.x += (float)fullX;
|
||||
tempPart.y += (float)fullY;
|
||||
x = int(tempPart.x + 0.5f);
|
||||
y = int(tempPart.y + 0.5f);
|
||||
|
||||
if(r = pmap[y][x])
|
||||
{
|
||||
//Replace existing
|
||||
parts[r>>8] = tempPart;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Allocate new particle
|
||||
if (pfree == -1)
|
||||
break;
|
||||
i = pfree;
|
||||
pfree = parts[i].life;
|
||||
if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
|
||||
|
||||
parts[i] = save->particles[n];
|
||||
parts[i].x += (float)fullX;
|
||||
parts[i].y += (float)fullY;
|
||||
parts[i] = tempPart;
|
||||
}
|
||||
}
|
||||
parts_lastActiveIndex = NPART-1;
|
||||
for(int i = 0; i < save->signs.size() && signs.size() < MAXSIGNS; i++)
|
||||
@ -50,9 +62,9 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
||||
tempSign.y += fullY;
|
||||
signs.push_back(tempSign);
|
||||
}
|
||||
for(int saveBlockX = 0; saveBlockX < save->blockWidth/CELL; saveBlockX++)
|
||||
for(int saveBlockX = 0; saveBlockX < save->blockWidth; saveBlockX++)
|
||||
{
|
||||
for(int saveBlockY = 0; saveBlockY < save->blockHeight/CELL; saveBlockY++)
|
||||
for(int saveBlockY = 0; saveBlockY < save->blockHeight; saveBlockY++)
|
||||
{
|
||||
if(save->blockMap[saveBlockY][saveBlockX])
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user