Merge branch 'master' of github.com:FacialTurd/The-Powder-Toy

This commit is contained in:
Simon Robertshaw 2012-12-16 16:38:29 +00:00
commit 0c5e99aef6
10 changed files with 82 additions and 45 deletions

1
.gitignore vendored
View File

@ -32,6 +32,7 @@ Makefile.me
*.manifest.res *.manifest.res
*manifest.rc *manifest.rc
*res.res *res.res
*.idb
*.obj *.obj
*.tlog *.tlog
*.lib *.lib

View File

@ -431,7 +431,9 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str
findFileHandle = _findfirst(fileMatch.c_str(), &currentFile); findFileHandle = _findfirst(fileMatch.c_str(), &currentFile);
if (findFileHandle == -1L) if (findFileHandle == -1L)
{ {
#ifdef DEBUG
printf("Unable to open directory\n"); printf("Unable to open directory\n");
#endif
return std::vector<std::string>(); return std::vector<std::string>();
} }
do do
@ -1308,7 +1310,7 @@ RequestStatus Client::AddComment(int saveID, std::string comment)
if(status!=1) if(status!=1)
{ {
lastError = ((json::Number)objDocument["Error"]).Value(); lastError = ((json::String)objDocument["Error"]).Value();
} }
if(status!=1) if(status!=1)
@ -1480,7 +1482,10 @@ RequestStatus Client::UnpublishSave(int saveID)
int status = ((json::Number)objDocument["Status"]).Value(); int status = ((json::Number)objDocument["Status"]).Value();
if(status!=1) if(status!=1)
{
lastError = ((json::String)objDocument["Error"]).Value();
goto failure; goto failure;
}
} }
catch (json::Exception &e) catch (json::Exception &e)
{ {
@ -1828,7 +1833,7 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate)
//Check active requests for any "forgotten" requests //Check active requests for any "forgotten" requests
for(i = 0; i < IMGCONNS; i++) for(i = 0; i < IMGCONNS; i++)
{ {
//If the request is active, and we've recieved a response //If the request is active, and we've received a response
if(activeThumbRequests[i] && http_async_req_status(activeThumbRequests[i])) if(activeThumbRequests[i] && http_async_req_status(activeThumbRequests[i]))
{ {
//If we haven't already, mark the request as completed //If we haven't already, mark the request as completed

View File

@ -817,16 +817,27 @@ void GameView::NotifySaveChanged(GameModel * sender)
reloadButton->Enabled = true; reloadButton->Enabled = true;
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0); upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1) if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 200, 40, 100)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 108, 10, 255));
else else
upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
downVoteButton->Enabled = upVoteButton->Enabled; downVoteButton->Enabled = upVoteButton->Enabled;
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==-1) if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==-1)
downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(200, 40, 40, 100)); downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(108, 0, 10, 255));
else else
downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
if (sender->GetUser().ID)
{
upVoteButton->Appearance.BorderDisabled = upVoteButton->Appearance.BorderInactive;
downVoteButton->Appearance.BorderDisabled = downVoteButton->Appearance.BorderInactive;
}
else
{
upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
}
tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID); tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID);
if(sender->GetSave()->GetID()) if(sender->GetSave()->GetID())
{ {
@ -862,9 +873,11 @@ void GameView::NotifySaveChanged(GameModel * sender)
saveSimulationButton->SetText(sender->GetSaveFile()->GetDisplayName()); saveSimulationButton->SetText(sender->GetSaveFile()->GetDisplayName());
reloadButton->Enabled = true; reloadButton->Enabled = true;
upVoteButton->Enabled = false; upVoteButton->Enabled = false;
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
downVoteButton->Enabled = false; downVoteButton->Enabled = false;
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100);
tagSimulationButton->Enabled = false; tagSimulationButton->Enabled = false;
tagSimulationButton->SetText("[no tags set]"); tagSimulationButton->SetText("[no tags set]");
currentSaveType = 2; currentSaveType = 2;
@ -875,9 +888,11 @@ void GameView::NotifySaveChanged(GameModel * sender)
saveSimulationButton->SetText("[untitled simulation]"); saveSimulationButton->SetText("[untitled simulation]");
reloadButton->Enabled = false; reloadButton->Enabled = false;
upVoteButton->Enabled = false; upVoteButton->Enabled = false;
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100),
downVoteButton->Enabled = false; downVoteButton->Enabled = false;
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0));
downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100),
tagSimulationButton->Enabled = false; tagSimulationButton->Enabled = false;
tagSimulationButton->SetText("[no tags set]"); tagSimulationButton->SetText("[no tags set]");
currentSaveType = 0; currentSaveType = 0;
@ -942,9 +957,9 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
if(selectMode!=SelectNone) if(selectMode!=SelectNone)
{ {
if(selectMode==PlaceSave) if(selectMode==PlaceSave)
selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint1 = c->PointTranslate(ui::Point(x, y));
if(selectPoint1.X!=-1) if(selectPoint1.X!=-1)
selectPoint2 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint2 = c->PointTranslate(ui::Point(x, y));
return; return;
} }
currentMouse = ui::Point(x, y); currentMouse = ui::Point(x, y);
@ -963,7 +978,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
{ {
if(button==BUTTON_LEFT) if(button==BUTTON_LEFT)
{ {
selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); selectPoint1 = c->PointTranslate(ui::Point(x, y));
selectPoint2 = selectPoint1; selectPoint2 = selectPoint1;
} }
return; return;
@ -1023,15 +1038,12 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y;
int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X; int x1 = (selectPoint2.X<selectPoint1.X)?selectPoint2.X:selectPoint1.X;
int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y; int y1 = (selectPoint2.Y<selectPoint1.Y)?selectPoint2.Y:selectPoint1.Y;
if(x2-x1>0 && y2-y1>0) if(selectMode==SelectCopy)
{ c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2));
if(selectMode==SelectCopy) else if(selectMode==SelectCut)
c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2));
else if(selectMode==SelectCut) else if(selectMode==SelectStamp)
c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2)); c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
else if(selectMode==SelectStamp)
c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2));
}
} }
} }
currentMouse = ui::Point(x, y); currentMouse = ui::Point(x, y);

View File

@ -824,9 +824,9 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve
break; break;
case IconVoteUp: case IconVoteUp:
if(invert) if(invert)
drawchar(x, y, 0xCB, 0, 100, 0, alpha); drawchar(x, y+1, 0xCB, 0, 100, 0, alpha);
else else
drawchar(x, y, 0xCB, 0, 187, 18, alpha); drawchar(x, y+1, 0xCB, 0, 187, 18, alpha);
break; break;
case IconVoteDown: case IconVoteDown:
if(invert) if(invert)

View File

@ -84,24 +84,27 @@ void PreviewController::Update()
} }
} }
void PreviewController::SubmitComment(std::string comment) bool PreviewController::SubmitComment(std::string comment)
{ {
if(comment.length() < 4) if(comment.length() < 4)
{ {
new ErrorMessage("Error", "Comment is too short"); new ErrorMessage("Error", "Comment is too short");
return false;
} }
else else
{ {
RequestStatus status = Client::Ref().AddComment(saveId, comment); RequestStatus status = Client::Ref().AddComment(saveId, comment);
if(status != RequestOkay) if(status != RequestOkay)
{ {
new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError());
return false;
} }
else else
{ {
previewModel->UpdateComments(1); previewModel->UpdateComments(1);
} }
} }
return true;
} }
void PreviewController::ShowLogin() void PreviewController::ShowLogin()

View File

@ -41,7 +41,7 @@ public:
PreviewView * GetView() { return previewView; } PreviewView * GetView() { return previewView; }
void Update(); void Update();
void FavouriteSave(); void FavouriteSave();
void SubmitComment(std::string comment); bool SubmitComment(std::string comment);
void NextCommentPage(); void NextCommentPage();
void PrevCommentPage(); void PrevCommentPage();

View File

@ -19,6 +19,7 @@
#include "search/Thumbnail.h" #include "search/Thumbnail.h"
#include "client/Client.h" #include "client/Client.h"
#include "interface/ScrollPanel.h" #include "interface/ScrollPanel.h"
#include "interface/Keys.h"
class PreviewView::LoginAction: public ui::ButtonAction class PreviewView::LoginAction: public ui::ButtonAction
{ {
@ -121,7 +122,6 @@ PreviewView::PreviewView():
openButton->SetIcon(IconOpen); openButton->SetIcon(IconOpen);
openButton->SetActionCallback(new OpenAction(this)); openButton->SetActionCallback(new OpenAction(this));
AddComponent(openButton); AddComponent(openButton);
SetOkayButton(openButton);
class BrowserOpenAction: public ui::ButtonAction class BrowserOpenAction: public ui::ButtonAction
{ {
@ -208,7 +208,6 @@ void PreviewView::commentBoxAutoHeight()
int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str()); int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str());
if(textWidth+15 > Size.X-(XRES/2)-48) if(textWidth+15 > Size.X-(XRES/2)-48)
{ {
addCommentBox->SetMultiline(true);
addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop; addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop;
int oldSize = addCommentBox->Size.Y; int oldSize = addCommentBox->Size.Y;
@ -225,7 +224,6 @@ void PreviewView::commentBoxAutoHeight()
else else
{ {
commentBoxHeight = 20; commentBoxHeight = 20;
addCommentBox->SetMultiline(false);
addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
commentBoxPositionX = (XRES/2)+4; commentBoxPositionX = (XRES/2)+4;
@ -365,6 +363,12 @@ void PreviewView::OnMouseWheel(int x, int y, int d)
} }
void PreviewView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if ((key == KEY_ENTER || key == KEY_RETURN) && !addCommentBox->IsFocused())
openButton->DoAction();
}
void PreviewView::NotifySaveChanged(PreviewModel * sender) void PreviewView::NotifySaveChanged(PreviewModel * sender)
{ {
SaveInfo * save = sender->GetSave(); SaveInfo * save = sender->GetSave();
@ -431,10 +435,11 @@ void PreviewView::submitComment()
std::string comment = std::string(addCommentBox->GetText()); std::string comment = std::string(addCommentBox->GetText());
submitCommentButton->Enabled = false; submitCommentButton->Enabled = false;
addCommentBox->SetText(""); addCommentBox->SetText("");
addCommentBox->SetPlaceholder("Submitting comment"); addCommentBox->SetPlaceholder("Submitting comment"); //This doesn't appear to ever show since no separate thread is created
FocusComponent(NULL); FocusComponent(NULL);
c->SubmitComment(comment); if (!c->SubmitComment(comment))
addCommentBox->SetText(comment);
addCommentBox->SetPlaceholder("Add comment"); addCommentBox->SetPlaceholder("Add comment");
submitCommentButton->Enabled = true; submitCommentButton->Enabled = true;
@ -467,6 +472,7 @@ void PreviewView::NotifyCommentBoxEnabledChanged(PreviewModel * sender)
addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment"); addCommentBox = new ui::Textbox(ui::Point((XRES/2)+4, Size.Y-19), ui::Point(Size.X-(XRES/2)-48, 17), "", "Add Comment");
addCommentBox->SetActionCallback(new AutoCommentSizeAction(this)); addCommentBox->SetActionCallback(new AutoCommentSizeAction(this));
addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
addCommentBox->SetMultiline(true);
AddComponent(addCommentBox); AddComponent(addCommentBox);
submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit"); submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit");
submitCommentButton->SetActionCallback(new SubmitCommentAction(this)); submitCommentButton->SetActionCallback(new SubmitCommentAction(this));

View File

@ -72,6 +72,7 @@ public:
virtual void OnTick(float dt); virtual void OnTick(float dt);
virtual void OnTryExit(ExitMethod method); virtual void OnTryExit(ExitMethod method);
virtual void OnMouseWheel(int x, int y, int d); virtual void OnMouseWheel(int x, int y, int d);
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
virtual ~PreviewView(); virtual ~PreviewView();
}; };

View File

@ -167,7 +167,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
GameSave * Simulation::Save() GameSave * Simulation::Save()
{ {
return Save(0, 0, XRES, YRES); return Save(0, 0, XRES-1, YRES-1);
} }
GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
@ -192,14 +192,14 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
blockX = fullX/CELL; blockX = fullX/CELL;
blockY = fullY/CELL; blockY = fullY/CELL;
blockX2 = fullX2/CELL; blockX2 = (fullX2+CELL)/CELL;
blockY2 = fullY2/CELL; blockY2 = (fullY2+CELL)/CELL;
fullX = blockX*CELL; //fullX = blockX*CELL;
fullY = blockY*CELL; //fullY = blockY*CELL;
fullX2 = blockX2*CELL; //fullX2 = blockX2*CELL;
fullY2 = blockY2*CELL; //fullY2 = blockY2*CELL;
blockW = blockX2-blockX; blockW = blockX2-blockX;
blockH = blockY2-blockY; blockH = blockY2-blockY;
@ -216,11 +216,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
int x, y; int x, y;
x = int(parts[i].x + 0.5f); x = int(parts[i].x + 0.5f);
y = int(parts[i].y + 0.5f); y = int(parts[i].y + 0.5f);
if(parts[i].type && x >= fullX && y >= fullY && x < fullX2 && y < fullY2) if(parts[i].type && x >= fullX && y >= fullY && x <= fullX2 && y <= fullY2)
{ {
Particle tempPart = parts[i]; Particle tempPart = parts[i];
tempPart.x -= fullX; tempPart.x -= blockX*CELL;
tempPart.y -= fullY; tempPart.y -= blockY*CELL;
if(elements[tempPart.type].Enabled) if(elements[tempPart.type].Enabled)
{ {
*newSave << tempPart; *newSave << tempPart;
@ -243,11 +243,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
for(int i = 0; i < MAXSIGNS && i < signs.size(); i++) for(int i = 0; i < MAXSIGNS && i < signs.size(); i++)
{ {
if(signs[i].text.length() && signs[i].x >= fullX && signs[i].y >= fullY && signs[i].x < fullX2 && signs[i].y < fullY2) if(signs[i].text.length() && signs[i].x >= fullX && signs[i].y >= fullY && signs[i].x <= fullX2 && signs[i].y <= fullY2)
{ {
sign tempSign = signs[i]; sign tempSign = signs[i];
tempSign.x -= fullX; tempSign.x -= blockX*CELL;
tempSign.y -= fullY; tempSign.y -= blockY*CELL;
*newSave << tempSign; *newSave << tempSign;
} }
} }
@ -340,9 +340,17 @@ void Simulation::clear_area(int area_x, int area_y, int area_w, int area_h)
if(bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] == WL_GRAV) if(bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] == WL_GRAV)
gravWallChanged = true; gravWallChanged = true;
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0; bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
emap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
delete_part(cx+area_x, cy+area_y, 0); delete_part(cx+area_x, cy+area_y, 0);
} }
} }
for(int i = 0; i < MAXSIGNS && i < signs.size(); i++)
{
if(signs[i].text.length() && signs[i].x >= area_x && signs[i].y >= area_y && signs[i].x <= area_x+area_w && signs[i].y <= area_y+area_h)
{
signs.erase(signs.begin()+i);
}
}
} }
void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags) void Simulation::CreateBox(int x1, int y1, int x2, int y2, int c, int flags)

View File

@ -80,13 +80,14 @@ int Element_MERC::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx]; r = pmap[y+ry][x+rx];
if (parts[i].tmp<=maxtmp) if (parts[i].tmp<=maxtmp)
continue; continue;
if ((!r)&&parts[i].tmp>=1)//if nothing then create deut if ((!r)&&parts[i].tmp>=1)//if nothing then create MERC
{ {
np = sim->create_part(-1,x+rx,y+ry,PT_MERC); np = sim->create_part(-1,x+rx,y+ry,PT_MERC);
if (np<0) continue; if (np<0) continue;
parts[i].tmp--; parts[i].tmp--;
parts[np].temp = parts[i].temp; parts[np].temp = parts[i].temp;
parts[np].tmp = 0; parts[np].tmp = 0;
parts[np].dcolour = parts[i].dcolour;
} }
} }
for ( trade = 0; trade<4; trade ++) for ( trade = 0; trade<4; trade ++)
@ -118,4 +119,4 @@ int Element_MERC::update(UPDATE_FUNC_ARGS)
} }
Element_MERC::~Element_MERC() {} Element_MERC::~Element_MERC() {}