summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-02-12 16:47:01 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-02-12 16:47:01 (GMT)
commitafe9e061e1d173731d8a5122c397a2caf4fe61ab (patch)
treef045221d8718c44b8af516cb58bdb45c3c74114b /src
parentd25384c36c427d4afd71f87f8282b1a981c4b563 (diff)
downloadpowder-afe9e061e1d173731d8a5122c397a2caf4fe61ab.zip
powder-afe9e061e1d173731d8a5122c397a2caf4fe61ab.tar.gz
Better names for sort, allow showing own saves
Diffstat (limited to 'src')
-rw-r--r--src/cat/LuaScriptInterface.cpp61
-rw-r--r--src/cat/TPTScriptInterface.cpp37
-rw-r--r--src/client/Client.cpp8
-rw-r--r--src/client/Client.h2
-rw-r--r--src/search/SearchController.cpp12
-rw-r--r--src/search/SearchModel.cpp8
-rw-r--r--src/search/SearchModel.h2
-rw-r--r--src/search/SearchView.cpp16
8 files changed, 92 insertions, 54 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 3591d3d..f007a9f 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -201,6 +201,7 @@ tpt.partsdata = nil");
{
lua_el_mode[i] = 0;
}
+
}
void LuaScriptInterface::Tick()
@@ -216,7 +217,65 @@ int LuaScriptInterface::Command(std::string command)
std::string LuaScriptInterface::FormatCommand(std::string command)
{
- return command;
+ //char ** keywords = {"and", "break", "do", "else", "elseif", "end", "false", "for", "function", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while", NULL};
+ //char ** functions = {"_VERSION", "assert", "collectgarbage", "dofile", "error", "gcinfo", "loadfile", "loadstring", "print", "tonumber", "tostring", "type", "unpack", "_ALERT", "_ERRORMESSAGE", "_INPUT", "_PROMPT", "_OUTPUT", "_STDERR", "_STDIN", "_STDOUT", "call", "dostring", "foreach", "foreachi", "getn", "globals", "newtype", "rawget", "rawset", "require", "sort", "tinsert", "tremove", "_G", "getfenv", "getmetatable", "ipairs", "loadlib", "next", "pairs", "pcall", "rawegal", "rawget", "rawset", "require", "setfenv", "setmetatable", "xpcall", "string", "table", "math", "coroutine", "io", "os", "debug"};
+ char * rawText = (char*)command.c_str();
+ char * outputData = (char *)calloc(command.length()*6, 1);
+ char lastWord[command.length()];
+ int lastWordChar = 0;
+ lastWord[0] = 0;
+ int rawTextLoc = 0;
+ int outputDataLoc = 0;
+ std::stack<char> pstack;
+ while(rawText[rawTextLoc])
+ {
+ switch(rawText[rawTextLoc])
+ {
+ case '\\':
+ outputData[outputDataLoc++] = rawText[rawTextLoc++];
+ if(rawText[rawTextLoc])
+ outputData[outputDataLoc++] = rawText[rawTextLoc++];
+ break;
+ case '"':
+ if(pstack.size() && pstack.top() == '"')
+ {
+ pstack.pop();
+ outputData[outputDataLoc++] = rawText[rawTextLoc++];
+ outputData[outputDataLoc++] = '\b';
+ outputData[outputDataLoc++] = 'w';
+ }
+ else
+ {
+ pstack.push('"');
+ outputData[outputDataLoc++] = '\b';
+ outputData[outputDataLoc++] = 'o';
+ outputData[outputDataLoc++] = rawText[rawTextLoc++];
+ }
+ break;
+ case '(':
+ pstack.push('(');
+ outputData[outputDataLoc++] = '\b';
+ outputData[outputDataLoc++] = 't';
+ strcpy(outputData+(outputDataLoc++), lastWord);
+ outputData[outputDataLoc++] = '\b';
+ outputData[outputDataLoc++] = 'w';
+ lastWord[0] = 0;
+ lastWordChar = 0;
+ break;
+ default:
+ if(pstack.top()!='"')
+ {
+ lastWord[lastWordChar++] = rawText[rawTextLoc++];
+ lastWord[lastWordChar] = 0;
+ }
+ else
+ {
+ outputData[outputDataLoc++] = rawText[rawTextLoc++];
+ }
+ break;
+ }
+ }
+ return outputData;
}
LuaScriptInterface::~LuaScriptInterface() {
diff --git a/src/cat/TPTScriptInterface.cpp b/src/cat/TPTScriptInterface.cpp
index f758438..a3f468c 100644
--- a/src/cat/TPTScriptInterface.cpp
+++ b/src/cat/TPTScriptInterface.cpp
@@ -137,7 +137,7 @@ std::string TPTScriptInterface::FormatCommand(std::string command)
currentWord = ++currentCommand;
}
words.push_back(std::string(currentWord));
-
+ free(rawCommand);
while(!words.empty())
{
ValueType cType = testType(words.front());
@@ -160,41 +160,6 @@ std::string TPTScriptInterface::FormatCommand(std::string command)
outputData += words.front() + " ";
words.pop_front();
}
- /*char * rawText = (char*)command.c_str();
- char * outputData = (char *)calloc(command.length()*6, 1);
- int rawTextLoc = 0;
- int outputDataLoc = 0;
- std::stack<char> pstack;
- while(rawText[rawTextLoc])
- {
- switch(rawText[rawTextLoc])
- {
- case '\\':
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- if(rawText[rawTextLoc])
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- break;
- case '"':
- if(pstack.size() && pstack.top() == '"')
- {
- pstack.pop();
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- outputData[outputDataLoc++] = '\b';
- outputData[outputDataLoc++] = 'w';
- }
- else
- {
- pstack.push('"');
- outputData[outputDataLoc++] = '\b';
- outputData[outputDataLoc++] = 'o';
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- }
- break;
- default:
- outputData[outputDataLoc++] = rawText[rawTextLoc++];
- break;
- }
- }*/
return outputData;
}
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 112bdf1..1fbff93 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -469,7 +469,7 @@ std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
return commentArray;
}
-std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount)
+std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount)
{
lastError = "";
resultCount = 0;
@@ -489,6 +489,12 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
urlStream << URLEscape(" ");
urlStream << URLEscape("sort:") << URLEscape(sort);
}
+ if(showOwn && authUser.ID)
+ {
+ if(query.length())
+ urlStream << URLEscape(" ");
+ urlStream << URLEscape("user:") << URLEscape(authUser.Username);
+ }
}
data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
diff --git a/src/client/Client.h b/src/client/Client.h
index 46c1848..084866b 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -52,7 +52,7 @@ public:
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests();
- std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, int & resultCount);
+ std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount);
std::vector<Comment*> * GetComments(int saveID, int start, int count);
Thumbnail * GetPreview(int saveID, int saveDate);
Thumbnail * GetThumbnail(int saveID, int saveDate);
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 6fa9748..1449f9a 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -4,6 +4,7 @@
#include "SearchView.h"
#include "interface/Panel.h"
#include "preview/PreviewController.h"
+#include "client/Client.h"
class SearchController::OpenCallback: public ControllerCallback
{
@@ -106,19 +107,22 @@ void SearchController::NextPage()
void SearchController::ChangeSort()
{
- if(searchModel->GetSort() == "date")
+ if(searchModel->GetSort() == "new")
{
- searchModel->SetSort("votes");
+ searchModel->SetSort("best");
}
else
{
- searchModel->SetSort("date");
+ searchModel->SetSort("new");
}
}
void SearchController::ShowOwn(bool show)
{
- //TODO: Implement
+ if(Client::Ref().GetAuthUser().ID)
+ searchModel->SetShowOwn(show);
+ else
+ searchModel->SetShowOwn(false);
}
void SearchController::OpenSave(int saveID)
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index e40c4b0..4a410c3 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -4,12 +4,14 @@
#include "client/Client.h"
SearchModel::SearchModel():
- currentSort("votes"),
+ currentSort("best"),
showOwn(false),
loadedSave(NULL),
updateSaveListWorking(false),
updateSaveListFinished(false),
- saveListLoaded(false)
+ saveListLoaded(false),
+ currentPage(1),
+ resultCount(0)
{
}
@@ -20,7 +22,7 @@ void * SearchModel::updateSaveListTHelper(void * obj)
void * SearchModel::updateSaveListT()
{
- vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort, resultCount);
+ vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", showOwn, resultCount);
updateSaveListFinished = true;
return tempSaveList;
}
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index d52529d..2587c03 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -47,7 +47,7 @@ public:
std::string GetLastQuery() { return lastQuery; }
void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
string GetSort() { return currentSort; }
- void SetShowOwn(bool show) { showOwn = show; UpdateSaveList(1, lastQuery); notifyShowOwnChanged(); }
+ void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; UpdateSaveList(1, lastQuery); } notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; }
void SetLoadedSave(Save * save);
Save * GetLoadedSave();
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 584b7e3..5bcbe06 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -27,7 +27,7 @@ SearchView::SearchView():
v->doSearch();
}
};
- searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((50*2)+16+10+50+10), 16), "");
+ searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((60*2)+16+10+50+10), 16), "");
searchField->SetAlignment(AlignLeft, AlignBottom);
searchField->SetActionCallback(new SearchAction(this));
@@ -41,9 +41,9 @@ SearchView::SearchView():
v->c->ChangeSort();
}
};
- sortButton = new ui::Button(ui::Point(XRES+BARSIZE-50-50-16-10, 10), ui::Point(50, 16), "Sort");
+ sortButton = new ui::Button(ui::Point(XRES+BARSIZE-60-60-16-10+5, 10), ui::Point(60, 16), "Sort");
sortButton->SetActionCallback(new SortAction(this));
- sortButton->SetAlignment(AlignLeft, AlignBottom);
+ sortButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(sortButton);
class MyOwnAction : public ui::ButtonAction
@@ -56,10 +56,12 @@ SearchView::SearchView():
v->c->ShowOwn(sender->GetToggleState());
}
};
- ownButton = new ui::Button(ui::Point(XRES+BARSIZE-50-16-10, 10), ui::Point(50, 16), "My Own");
+ ownButton = new ui::Button(ui::Point(XRES+BARSIZE-60-16-10+10, 10), ui::Point(60, 16), "My Own");
ownButton->SetTogglable(true);
ownButton->SetActionCallback(new MyOwnAction(this));
- ownButton->SetAlignment(AlignLeft, AlignBottom);
+ if(!Client::Ref().GetAuthUser().ID)
+ ownButton->Enabled = false;
+ ownButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(ownButton);
class NextPageAction : public ui::ButtonAction
@@ -110,12 +112,12 @@ SearchView::~SearchView()
void SearchView::NotifySortChanged(SearchModel * sender)
{
- sortButton->SetText("Sort: "+sender->GetSort());
+ sortButton->SetText("Show "+sender->GetSort());
}
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
{
- sortButton->SetToggleState(sender->GetShowOwn());
+ ownButton->SetToggleState(sender->GetShowOwn());
}
void SearchView::NotifyPageChanged(SearchModel * sender)