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)
|
void GameSave::setSize(int newWidth, int newHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::cout << "GameSave::setSize(" << newWidth << ", " << newHeight << ")";
|
|
||||||
|
|
||||||
this->blockWidth = newWidth;
|
this->blockWidth = newWidth;
|
||||||
this->blockHeight = newHeight;
|
this->blockHeight = newHeight;
|
||||||
|
|
||||||
|
@ -275,12 +275,8 @@ void GameModel::SetSave(SaveInfo * newSave)
|
|||||||
currentSave = newSave;
|
currentSave = newSave;
|
||||||
if(currentSave)
|
if(currentSave)
|
||||||
{
|
{
|
||||||
int returnVal = sim->Load(currentSave->GetGameSave());
|
sim->clear_sim();
|
||||||
if(returnVal){
|
sim->Load(currentSave->GetGameSave());
|
||||||
delete currentSave;
|
|
||||||
currentSave = NULL;
|
|
||||||
throw GameModelException(returnVal==2?"Save from newer version":"Save data corrupt");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
notifySaveChanged();
|
notifySaveChanged();
|
||||||
notifyPausedChanged();
|
notifyPausedChanged();
|
||||||
|
@ -39,6 +39,10 @@ void PreviewController::Update()
|
|||||||
Exit();
|
Exit();
|
||||||
new ErrorMessage("Error", e.what());
|
new ErrorMessage("Error", e.what());
|
||||||
}
|
}
|
||||||
|
if(previewModel->GetDoOpen() && previewModel->GetSave() && previewModel->GetSave()->GetGameSave())
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveInfo * PreviewController::GetSave()
|
SaveInfo * PreviewController::GetSave()
|
||||||
|
@ -11,11 +11,13 @@
|
|||||||
#include "simulation/SaveRenderer.h"
|
#include "simulation/SaveRenderer.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
|
#include "Style.h"
|
||||||
#include "search/Thumbnail.h"
|
#include "search/Thumbnail.h"
|
||||||
|
|
||||||
PreviewView::PreviewView():
|
PreviewView::PreviewView():
|
||||||
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+200, (YRES/2)+150)),
|
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
|
class OpenAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
@ -25,7 +27,6 @@ PreviewView::PreviewView():
|
|||||||
virtual void ActionCallback(ui::Button * sender)
|
virtual void ActionCallback(ui::Button * sender)
|
||||||
{
|
{
|
||||||
v->c->DoOpen();
|
v->c->DoOpen();
|
||||||
v->c->Exit();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
openButton = new ui::Button(ui::Point(0, Size.Y-19), ui::Point(51, 19), "Open");
|
openButton = new ui::Button(ui::Point(0, Size.Y-19), ui::Point(51, 19), "Open");
|
||||||
@ -109,6 +110,18 @@ PreviewView::PreviewView():
|
|||||||
AddComponent(authorDateLabel);
|
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()
|
void PreviewView::OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
@ -128,16 +141,16 @@ 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);
|
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;
|
float factor;
|
||||||
if(!votesUp && !votesDown)
|
if(!(!votesUp && !votesDown))
|
||||||
return;
|
{
|
||||||
else
|
|
||||||
factor = (float)(((float)(XRES/2)-2)/((float)(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, (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);
|
g->fillrect(1+Position.X, 2+Position.Y+YRES/2, (int)(((float)votesUp)*factor), 9, 50, 200, 50, 255);
|
||||||
g->fillrect(1+Position.X, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100);
|
g->fillrect(1+Position.X, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100);
|
||||||
g->fillrect(Position.X+(XRES/2)-15, 2+Position.Y+(YRES/2), 14, 9, 0, 0, 0, 100);
|
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(1+Position.X+2, Position.Y+(YRES/2)+4, IconVoteUp);
|
||||||
g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown);
|
g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2)+1, IconVoteDown);
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; i < commentTextComponents.size(); i++)
|
for(int i = 0; i < commentTextComponents.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -33,12 +33,14 @@ class PreviewView: public ui::Window {
|
|||||||
std::vector<ui::Component*> commentTextComponents;
|
std::vector<ui::Component*> commentTextComponents;
|
||||||
int votesUp;
|
int votesUp;
|
||||||
int votesDown;
|
int votesDown;
|
||||||
|
bool doOpen;
|
||||||
public:
|
public:
|
||||||
void AttachController(PreviewController * controller) { c = controller;}
|
void AttachController(PreviewController * controller) { c = controller;}
|
||||||
PreviewView();
|
PreviewView();
|
||||||
void NotifySaveChanged(PreviewModel * sender);
|
void NotifySaveChanged(PreviewModel * sender);
|
||||||
void NotifyCommentsChanged(PreviewModel * sender);
|
void NotifyCommentsChanged(PreviewModel * sender);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
|
virtual void DoDraw();
|
||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
virtual ~PreviewView();
|
virtual ~PreviewView();
|
||||||
|
@ -19,7 +19,7 @@ int Simulation::Load(GameSave * save)
|
|||||||
|
|
||||||
int Simulation::Load(int fullX, int fullY, GameSave * save)
|
int Simulation::Load(int fullX, int fullY, GameSave * save)
|
||||||
{
|
{
|
||||||
int blockX, blockY;
|
int blockX, blockY, x, y, r;
|
||||||
|
|
||||||
if(!save) return 0;
|
if(!save) return 0;
|
||||||
|
|
||||||
@ -32,15 +32,27 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
|
|||||||
int i;
|
int i;
|
||||||
for(int n = 0; n < NPART && n < save->particlesCount; n++)
|
for(int n = 0; n < NPART && n < save->particlesCount; n++)
|
||||||
{
|
{
|
||||||
if (pfree == -1)
|
Particle tempPart = save->particles[n];
|
||||||
break;
|
tempPart.x += (float)fullX;
|
||||||
i = pfree;
|
tempPart.y += (float)fullY;
|
||||||
pfree = parts[i].life;
|
x = int(tempPart.x + 0.5f);
|
||||||
if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
|
y = int(tempPart.y + 0.5f);
|
||||||
|
|
||||||
parts[i] = save->particles[n];
|
if(r = pmap[y][x])
|
||||||
parts[i].x += (float)fullX;
|
{
|
||||||
parts[i].y += (float)fullY;
|
//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] = tempPart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
parts_lastActiveIndex = NPART-1;
|
parts_lastActiveIndex = NPART-1;
|
||||||
for(int i = 0; i < save->signs.size() && signs.size() < MAXSIGNS; i++)
|
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;
|
tempSign.y += fullY;
|
||||||
signs.push_back(tempSign);
|
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])
|
if(save->blockMap[saveBlockY][saveBlockX])
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user