summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-09-13 21:39:01 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-09-13 21:39:01 (GMT)
commit5b52ac3675f08f9f16f44f530df8877ad6c64f2e (patch)
treed1b087ac413010f4248ddb4f6cb07a9f3f7ebbe3 /src
parenta11cd592cb9b985298dd16be78dec10226bf3e47 (diff)
downloadpowder-5b52ac3675f08f9f16f44f530df8877ad6c64f2e.zip
powder-5b52ac3675f08f9f16f44f530df8877ad6c64f2e.tar.gz
Save history and new multiline formatter
Diffstat (limited to 'src')
-rw-r--r--src/client/Client.cpp11
-rw-r--r--src/client/SaveInfo.cpp13
-rw-r--r--src/client/SaveInfo.h4
-rw-r--r--src/graphics/Graphics.cpp5
-rw-r--r--src/graphics/Graphics.h1
-rw-r--r--src/interface/Label.cpp61
-rw-r--r--src/interface/SaveButton.cpp2
-rw-r--r--src/preview/PreviewController.cpp24
-rw-r--r--src/preview/PreviewController.h2
-rw-r--r--src/search/SearchController.cpp8
-rw-r--r--src/search/SearchController.h1
-rw-r--r--src/search/SearchView.cpp2
12 files changed, 111 insertions, 23 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 191cebb..051dfcd 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -1412,6 +1412,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
json::Boolean tempFavourite = objDocument["Favourite"];
json::Number tempComments = objDocument["Comments"];
json::Number tempViews = objDocument["Views"];
+ json::Number tempVersion = objDocument["Version"];
json::Array tagsArray = objDocument["Tags"];
std::vector<std::string> tempTags;
@@ -1437,6 +1438,7 @@ SaveInfo * Client::GetSave(int saveID, int saveDate)
tempSave->Comments = tempComments.Value();
tempSave->Favourite = tempFavourite.Value();
tempSave->Views = tempViews.Value();
+ tempSave->Version = tempVersion.Value();
return tempSave;
}
catch (json::Exception &e)
@@ -1643,16 +1645,17 @@ std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, std::string q
json::Number tempScoreDown = savesArray[j]["ScoreDown"];
json::String tempUsername = savesArray[j]["Username"];
json::String tempName = savesArray[j]["Name"];
- saveArray->push_back(
- new SaveInfo(
+ json::Number tempVersion = savesArray[j]["Version"];
+ SaveInfo * tempSaveInfo = new SaveInfo(
tempID.Value(),
tempDate.Value(),
tempScoreUp.Value(),
tempScoreDown.Value(),
tempUsername.Value(),
tempName.Value()
- )
- );
+ );
+ tempSaveInfo->Version = tempVersion.Value();
+ saveArray->push_back(tempSaveInfo);
}
}
catch (json::Exception &e)
diff --git a/src/client/SaveInfo.cpp b/src/client/SaveInfo.cpp
index c6cafb1..2d8fd52 100644
--- a/src/client/SaveInfo.cpp
+++ b/src/client/SaveInfo.cpp
@@ -12,7 +12,7 @@
SaveInfo::SaveInfo(SaveInfo & save) :
userName(save.userName), name(save.name), Description(save.Description), date(
save.date), Published(save.Published), id(save.id), votesUp(
- save.votesUp), votesDown(save.votesDown), gameSave(NULL), vote(save.vote), tags(save.tags), Comments(save.Comments), Views(save.Views) {
+ save.votesUp), votesDown(save.votesDown), gameSave(NULL), vote(save.vote), tags(save.tags), Comments(save.Comments), Views(save.Views), Version(save.Version) {
if(save.gameSave)
gameSave = new GameSave(*save.gameSave);
}
@@ -21,14 +21,14 @@ SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, std::string
std::string _name) :
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
_name), Description(""), date(_date), Published(
- true), gameSave(NULL), vote(0), tags(), Comments(0), Views(0) {
+ true), gameSave(NULL), vote(0), tags(), Comments(0), Views(0), Version(0) {
}
SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, std::string _userName,
std::string _name, std::string description_, bool published_, std::vector<std::string> tags_) :
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
_name), Description(description_), date(date_), Published(
- published_), gameSave(NULL), vote(_vote), tags(tags_), Views(0), Comments(0) {
+ published_), gameSave(NULL), vote(_vote), tags(tags_), Views(0), Comments(0), Version(0) {
}
SaveInfo::~SaveInfo()
@@ -99,6 +99,13 @@ int SaveInfo::GetVotesDown() {
return votesDown;
}
+void SaveInfo::SetVersion(int version) {
+ this->Version = version;
+}
+int SaveInfo::GetVersion() {
+ return Version;
+}
+
void SaveInfo::SetTags(std::vector<std::string> tags)
{
this->tags = tags;
diff --git a/src/client/SaveInfo.h b/src/client/SaveInfo.h
index 49057ac..3f52c25 100644
--- a/src/client/SaveInfo.h
+++ b/src/client/SaveInfo.h
@@ -18,6 +18,7 @@ public:
bool Favourite;
int Comments;
int Views;
+ int Version;
GameSave * gameSave;
@@ -64,6 +65,9 @@ public:
void SetVotesDown(int votesDown);
int GetVotesDown();
+ void SetVersion(int version);
+ int GetVersion();
+
void SetTags(std::vector<std::string> tags);
std::vector<std::string> GetTags();
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp
index fef4b45..dde2701 100644
--- a/src/graphics/Graphics.cpp
+++ b/src/graphics/Graphics.cpp
@@ -489,6 +489,11 @@ int Graphics::textwidth(const char *s)
return x-1;
}
+int Graphics::CharWidth(char c)
+{
+ return font_data[font_ptrs[(int)c]];
+}
+
int Graphics::textnwidth(char *s, int n)
{
int x = 0;
diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h
index a51ed02..0bb6cb6 100644
--- a/src/graphics/Graphics.h
+++ b/src/graphics/Graphics.h
@@ -129,6 +129,7 @@ public:
//Font/text metrics
static int CharIndexAtPosition(char *s, int positionX, int positionY);
static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY);
+ static int CharWidth(char c);
static int textnwidth(char *s, int n);
static void textnpos(char *s, int n, int w, int *cx, int *cy);
static int textwidthx(char *s, int w);
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index 96a8520..b823977 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -76,21 +76,59 @@ void Label::updateMultiline()
std::copy(text.begin(), text.end(), rawText);
rawText[text.length()] = 0;
- int currentWidth = 0;
+ char c, pc = 0;
+ int charIndex = 0;
+
+ int wordWidth = 0;
+ int lineWidth = 0;
+ char * wordStart = NULL;
+ while(c = rawText[charIndex++])
+ {
+ switch(c)
+ {
+ case ' ':
+ lineWidth += Graphics::CharWidth(c);
+ lineWidth += wordWidth;
+ wordWidth = 0;
+ break;
+ case '\n':
+ lineWidth = wordWidth = 0;
+ lines++;
+ break;
+ default:
+ if(pc == ' ')
+ {
+ wordStart = &rawText[charIndex-2];
+ }
+ wordWidth += Graphics::CharWidth(c);
+ if(lineWidth + wordWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right))
+ {
+ if(wordStart && *wordStart)
+ *wordStart = '\n';
+ else if(!wordStart)
+ rawText[charIndex-1] = '\n';
+ lineWidth = wordWidth = 0;
+ lines++;
+ }
+ break;
+ }
+ pc = c;
+ }
+ if(autoHeight)
+ {
+ Size.Y = lines*12;
+ }
+ textLines = std::string(rawText);
+ delete[] rawText;
+ /*int currentWidth = 0;
char * lastSpace = NULL;
char * currentWord = rawText;
char * nextSpace;
- char oldChar;
while(true)
{
nextSpace = strchr(currentWord+1, ' ');
- if(nextSpace > strchr(currentWord+1, '\n'))
- nextSpace = strchr(currentWord+1, '\n');
if(nextSpace)
- {
- oldChar = nextSpace[0];
nextSpace[0] = 0;
- }
int width = Graphics::textwidth(currentWord);
if(width+currentWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right))
{
@@ -101,15 +139,10 @@ void Label::updateMultiline()
lines++;
}
}
- else if(oldChar == '\n')
- {
- currentWidth = width;
- lines++;
- }
else
currentWidth += width;
if(nextSpace)
- nextSpace[0] = oldChar;
+ nextSpace[0] = ' ';
if(!currentWord[0] || !currentWord[1] || !(currentWord = strchr(currentWord+1, ' ')))
break;
}
@@ -118,7 +151,7 @@ void Label::updateMultiline()
Size.Y = lines*12;
}
textLines = std::string(rawText);
- delete[] rawText;
+ delete[] rawText;*/
}
else
{
diff --git a/src/interface/SaveButton.cpp b/src/interface/SaveButton.cpp
index b4e67bd..66a6e66 100644
--- a/src/interface/SaveButton.cpp
+++ b/src/interface/SaveButton.cpp
@@ -120,7 +120,7 @@ void SaveButton::Tick(float dt)
else if(save->GetID())
{
waitingForThumb = true;
- ThumbnailBroker::Ref().RetrieveThumbnail(save->GetID() , Size.X-3, Size.Y-25, this);
+ ThumbnailBroker::Ref().RetrieveThumbnail(save->GetID(), save->GetVersion(), Size.X-3, Size.Y-25, this);
}
}
else if(file && file->GetGameSave())
diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp
index 4b8bd80..89e3ca6 100644
--- a/src/preview/PreviewController.cpp
+++ b/src/preview/PreviewController.cpp
@@ -15,9 +15,33 @@
#include "login/LoginController.h"
#include "Controller.h"
+PreviewController::PreviewController(int saveID, int saveDate, ControllerCallback * callback):
+ HasExited(false),
+ saveId(saveID),
+ saveDate(saveDate),
+ loginWindow(NULL)
+{
+ previewModel = new PreviewModel();
+ previewView = new PreviewView();
+ previewModel->AddObserver(previewView);
+ previewView->AttachController(this);
+
+ previewModel->UpdateSave(saveID, saveDate);
+
+ if(Client::Ref().GetAuthUser().ID)
+ {
+ previewModel->SetCommentBoxEnabled(true);
+ }
+
+ Client::Ref().AddListener(this);
+
+ this->callback = callback;
+}
+
PreviewController::PreviewController(int saveID, ControllerCallback * callback):
HasExited(false),
saveId(saveID),
+ saveDate(0),
loginWindow(NULL)
{
previewModel = new PreviewModel();
diff --git a/src/preview/PreviewController.h b/src/preview/PreviewController.h
index c04a07f..c8c3f8e 100644
--- a/src/preview/PreviewController.h
+++ b/src/preview/PreviewController.h
@@ -19,6 +19,7 @@ class PreviewModel;
class PreviewView;
class PreviewController: public ClientListener {
int saveId;
+ int saveDate;
PreviewModel * previewModel;
PreviewView * previewView;
LoginController * loginWindow;
@@ -29,6 +30,7 @@ public:
bool HasExited;
PreviewController(int saveID, ControllerCallback * callback);
+ PreviewController(int saveID, int saveDate, ControllerCallback * callback);
void Exit();
void DoOpen();
void OpenInBrowser();
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 2c6b78f..7930b65 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -181,6 +181,14 @@ void SearchController::OpenSave(int saveID)
ui::Engine::Ref().ShowWindow(activePreview->GetView());
}
+void SearchController::OpenSave(int saveID, int saveDate)
+{
+ if(activePreview)
+ delete activePreview;
+ activePreview = new PreviewController(saveID, saveDate, new OpenCallback(this));
+ ui::Engine::Ref().ShowWindow(activePreview->GetView());
+}
+
void SearchController::ClearSelection()
{
searchModel->ClearSelected();
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index 32ca8b3..66d464a 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -38,6 +38,7 @@ public:
void ShowFavourite(bool show);
void Selected(int saveID, bool selected);
void OpenSave(int saveID);
+ void OpenSave(int saveID, int saveDate);
void Update();
void ClearSelection();
void RemoveSelected();
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 04654d6..256ef90 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -586,7 +586,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
SaveOpenAction(SearchView * _v) { v = _v; }
virtual void ActionCallback(ui::SaveButton * sender)
{
- v->c->OpenSave(sender->GetSave()->GetID());
+ v->c->OpenSave(sender->GetSave()->GetID(), sender->GetSave()->GetVersion());
}
virtual void SelectedCallback(ui::SaveButton * sender)
{