From 0fd86e994afb7edb4fb923f7b46da77ad423acc2 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 14:28:23 -0500 Subject: [PATCH 1/8] make the comment box always multiline. Fixing pasting large amounts of text into it. --- src/preview/PreviewView.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index d6c444858..0e8c43cf2 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -208,7 +208,6 @@ void PreviewView::commentBoxAutoHeight() int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str()); if(textWidth+15 > Size.X-(XRES/2)-48) { - addCommentBox->SetMultiline(true); addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignTop; int oldSize = addCommentBox->Size.Y; @@ -225,7 +224,6 @@ void PreviewView::commentBoxAutoHeight() else { commentBoxHeight = 20; - addCommentBox->SetMultiline(false); addCommentBox->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; commentBoxPositionX = (XRES/2)+4; @@ -467,6 +465,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->SetActionCallback(new AutoCommentSizeAction(this)); addCommentBox->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; + addCommentBox->SetMultiline(true); AddComponent(addCommentBox); submitCommentButton = new ui::Button(ui::Point(Size.X-40, Size.Y-19), ui::Point(40, 19), "Submit"); submitCommentButton->SetActionCallback(new SubmitCommentAction(this)); From a623959a314e544f092c85f037d8b564adc2af45 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Thu, 4 Oct 2012 10:42:09 -0400 Subject: [PATCH 2/8] save stamps on 1 pixel grid (works exactly like in tpt now), delete signs with Ctrl+X, also fixes stamps on very bottom/right edge and other edge cases --- src/game/GameView.cpp | 21 +++++++++------------ src/simulation/Simulation.cpp | 34 +++++++++++++++++++++------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 9d900bae5..a1c7f70ee 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -942,9 +942,9 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy) if(selectMode!=SelectNone) { if(selectMode==PlaceSave) - selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint1 = c->PointTranslate(ui::Point(x, y)); if(selectPoint1.X!=-1) - selectPoint2 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint2 = c->PointTranslate(ui::Point(x, y)); return; } currentMouse = ui::Point(x, y); @@ -963,7 +963,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button) { if(button==BUTTON_LEFT) { - selectPoint1 = c->NormaliseBlockCoord(c->PointTranslate(ui::Point(x, y))); + selectPoint1 = c->PointTranslate(ui::Point(x, y)); selectPoint2 = selectPoint1; } return; @@ -1023,15 +1023,12 @@ void GameView::OnMouseUp(int x, int y, unsigned button) int y2 = (selectPoint1.Y>selectPoint2.Y)?selectPoint1.Y:selectPoint2.Y; int x1 = (selectPoint2.X0 && y2-y1>0) - { - if(selectMode==SelectCopy) - c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - else if(selectMode==SelectCut) - c->CutRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - else if(selectMode==SelectStamp) - c->StampRegion(ui::Point(x1, y1), ui::Point(x2, y2)); - } + if(selectMode==SelectCopy) + c->CopyRegion(ui::Point(x1, y1), ui::Point(x2, y2)); + else if(selectMode==SelectCut) + c->CutRegion(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); diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index f016112e0..21f810938 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -167,7 +167,7 @@ int Simulation::Load(int fullX, int fullY, GameSave * 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) @@ -192,14 +192,14 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) blockX = fullX/CELL; blockY = fullY/CELL; - blockX2 = fullX2/CELL; - blockY2 = fullY2/CELL; + blockX2 = (fullX2+CELL)/CELL; + blockY2 = (fullY2+CELL)/CELL; - fullX = blockX*CELL; - fullY = blockY*CELL; + //fullX = blockX*CELL; + //fullY = blockY*CELL; - fullX2 = blockX2*CELL; - fullY2 = blockY2*CELL; + //fullX2 = blockX2*CELL; + //fullY2 = blockY2*CELL; blockW = blockX2-blockX; blockH = blockY2-blockY; @@ -216,11 +216,11 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2) int x, y; x = int(parts[i].x + 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]; - tempPart.x -= fullX; - tempPart.y -= fullY; + tempPart.x -= blockX*CELL; + tempPart.y -= blockY*CELL; if(elements[tempPart.type].Enabled) { *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++) { - 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]; - tempSign.x -= fullX; - tempSign.y -= fullY; + tempSign.x -= blockX*CELL; + tempSign.y -= blockY*CELL; *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) gravWallChanged = true; 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); } } + 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) From e4907d18815b72bb811e4ef981c8cdff4a880a1b Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sun, 16 Dec 2012 00:16:05 +0000 Subject: [PATCH 3/8] Copy dcolour when MERC expands, to let people make coloured mercury thermometers --- src/simulation/elements/MERC.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/simulation/elements/MERC.cpp b/src/simulation/elements/MERC.cpp index 1fec32a99..655a8b9b1 100644 --- a/src/simulation/elements/MERC.cpp +++ b/src/simulation/elements/MERC.cpp @@ -80,13 +80,14 @@ int Element_MERC::update(UPDATE_FUNC_ARGS) r = pmap[y+ry][x+rx]; if (parts[i].tmp<=maxtmp) 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); if (np<0) continue; parts[i].tmp--; parts[np].temp = parts[i].temp; parts[np].tmp = 0; + parts[np].dcolour = parts[i].dcolour; } } for ( trade = 0; trade<4; trade ++) @@ -118,4 +119,4 @@ int Element_MERC::update(UPDATE_FUNC_ARGS) } -Element_MERC::~Element_MERC() {} \ No newline at end of file +Element_MERC::~Element_MERC() {} From c62ef2cb359f31f305b87e49d230f0786df28007 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 20:34:00 -0500 Subject: [PATCH 4/8] fix upvote buttons still having colored background after clearing the save, make them look more like from in tpt --- .gitignore | 1 + src/game/GameView.cpp | 23 +++++++++++++++++------ src/graphics/Graphics.cpp | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 49eb84797..04f321699 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ Makefile.me *.manifest.res *manifest.rc *res.res +*.idb *.obj *.tlog *.lib diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index a1c7f70ee..be79b5c2d 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -817,16 +817,27 @@ void GameView::NotifySaveChanged(GameModel * sender) reloadButton->Enabled = true; upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0); 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 upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Enabled = upVoteButton->Enabled; 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 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(10, 10, 10); + downVoteButton->Appearance.BorderDisabled = ui::Colour(10, 10, 10); + } + tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID); if(sender->GetSave()->GetID()) { @@ -862,9 +873,9 @@ void GameView::NotifySaveChanged(GameModel * sender) saveSimulationButton->SetText(sender->GetSaveFile()->GetDisplayName()); reloadButton->Enabled = true; upVoteButton->Enabled = false; - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Enabled = false; - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); tagSimulationButton->Enabled = false; tagSimulationButton->SetText("[no tags set]"); currentSaveType = 2; @@ -875,9 +886,9 @@ void GameView::NotifySaveChanged(GameModel * sender) saveSimulationButton->SetText("[untitled simulation]"); reloadButton->Enabled = false; upVoteButton->Enabled = false; - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Enabled = false; - upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); tagSimulationButton->Enabled = false; tagSimulationButton->SetText("[no tags set]"); currentSaveType = 0; diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index c3a5acac6..974a16999 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -824,9 +824,9 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve break; case IconVoteUp: if(invert) - drawchar(x, y, 0xCB, 0, 100, 0, alpha); + drawchar(x, y+1, 0xCB, 0, 100, 0, alpha); else - drawchar(x, y, 0xCB, 0, 187, 18, alpha); + drawchar(x, y+1, 0xCB, 0, 187, 18, alpha); break; case IconVoteDown: if(invert) From 1ef507d9e60348ed03f2edcd9c8d78d28d8d9d6f Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 20:42:30 -0500 Subject: [PATCH 5/8] fix colors slightly from last commit --- src/game/GameView.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index be79b5c2d..4caad247a 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -834,8 +834,8 @@ void GameView::NotifySaveChanged(GameModel * sender) } else { - upVoteButton->Appearance.BorderDisabled = ui::Colour(10, 10, 10); - downVoteButton->Appearance.BorderDisabled = ui::Colour(10, 10, 10); + upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); + downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); } tagSimulationButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID); @@ -874,8 +874,10 @@ void GameView::NotifySaveChanged(GameModel * sender) reloadButton->Enabled = true; upVoteButton->Enabled = false; upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); downVoteButton->Enabled = false; upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); tagSimulationButton->Enabled = false; tagSimulationButton->SetText("[no tags set]"); currentSaveType = 2; @@ -887,8 +889,10 @@ void GameView::NotifySaveChanged(GameModel * sender) reloadButton->Enabled = false; upVoteButton->Enabled = false; upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + upVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100), downVoteButton->Enabled = false; upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); + downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100), tagSimulationButton->Enabled = false; tagSimulationButton->SetText("[no tags set]"); currentSaveType = 0; From 462bd7bdf914b2663c7e574a0bf4de6d4a8a723c Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 22:55:53 -0500 Subject: [PATCH 6/8] fix comments being deleted when hitting enter and opening a save or getting an error when commenting --- src/preview/PreviewController.cpp | 7 +++++-- src/preview/PreviewController.h | 2 +- src/preview/PreviewView.cpp | 13 ++++++++++--- src/preview/PreviewView.h | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index 89e3ca620..37561b7b5 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -84,24 +84,27 @@ void PreviewController::Update() } } -void PreviewController::SubmitComment(std::string comment) +bool PreviewController::SubmitComment(std::string comment) { if(comment.length() < 4) { new ErrorMessage("Error", "Comment is too short"); + return false; } else { RequestStatus status = Client::Ref().AddComment(saveId, comment); if(status != RequestOkay) { - new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); + new ErrorMessage("Error Submitting comment", Client::Ref().GetLastError()); + return false; } else { previewModel->UpdateComments(1); } } + return true; } void PreviewController::ShowLogin() diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h index c8c3f8e36..2d8e35a1b 100644 --- a/src/preview/PreviewController.h +++ b/src/preview/PreviewController.h @@ -41,7 +41,7 @@ public: PreviewView * GetView() { return previewView; } void Update(); void FavouriteSave(); - void SubmitComment(std::string comment); + bool SubmitComment(std::string comment); void NextCommentPage(); void PrevCommentPage(); diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 0e8c43cf2..fca7fa005 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -19,6 +19,7 @@ #include "search/Thumbnail.h" #include "client/Client.h" #include "interface/ScrollPanel.h" +#include "interface/Keys.h" class PreviewView::LoginAction: public ui::ButtonAction { @@ -121,7 +122,6 @@ PreviewView::PreviewView(): openButton->SetIcon(IconOpen); openButton->SetActionCallback(new OpenAction(this)); AddComponent(openButton); - SetOkayButton(openButton); class BrowserOpenAction: public ui::ButtonAction { @@ -363,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) { SaveInfo * save = sender->GetSave(); @@ -429,10 +435,11 @@ void PreviewView::submitComment() std::string comment = std::string(addCommentBox->GetText()); submitCommentButton->Enabled = false; 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); - c->SubmitComment(comment); + if (!c->SubmitComment(comment)) + addCommentBox->SetText(comment); addCommentBox->SetPlaceholder("Add comment"); submitCommentButton->Enabled = true; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 2dc667bf9..c5931af49 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -72,6 +72,7 @@ public: virtual void OnTick(float dt); virtual void OnTryExit(ExitMethod method); virtual void OnMouseWheel(int x, int y, int d); + virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt); virtual ~PreviewView(); }; From a85526bfac04f033337edcd31aa53e8e33554ec1 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 15 Dec 2012 23:12:54 -0500 Subject: [PATCH 7/8] fix comment error messages not showing --- src/client/Client.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index f46222bd6..326bb055a 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1308,7 +1308,7 @@ RequestStatus Client::AddComment(int saveID, std::string comment) if(status!=1) { - lastError = ((json::Number)objDocument["Error"]).Value(); + lastError = ((json::String)objDocument["Error"]).Value(); } if(status!=1) @@ -1480,7 +1480,10 @@ RequestStatus Client::UnpublishSave(int saveID) int status = ((json::Number)objDocument["Status"]).Value(); if(status!=1) + { + lastError = ((json::String)objDocument["Error"]).Value(); goto failure; + } } catch (json::Exception &e) { @@ -1828,7 +1831,7 @@ Thumbnail * Client::GetThumbnail(int saveID, int saveDate) //Check active requests for any "forgotten" requests 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 we haven't already, mark the request as completed From 06f8f88374a1b9e288da30d754ba4bf02768d863 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 16 Dec 2012 11:38:12 -0500 Subject: [PATCH 8/8] fix output appearing in stdout without DEBUG defined --- src/client/Client.cpp | 2 ++ src/client/GameSave.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 326bb055a..4ec929c12 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -431,7 +431,9 @@ std::vector Client::DirectorySearch(std::string directory, std::str findFileHandle = _findfirst(fileMatch.c_str(), ¤tFile); if (findFileHandle == -1L) { +#ifdef DEBUG printf("Unable to open directory\n"); +#endif return std::vector(); } do diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 2e1a880cc..fbb982951 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1097,7 +1097,9 @@ void GameSave::readPSv(char * data, int dataLength) } dataLength = i; +#ifdef DEBUG std::cout << "Parsing " << dataLength << " bytes of data, version " << ver << std::endl; +#endif if (dataLength < bw*bh) throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)");