Better names for sort, allow showing own saves

This commit is contained in:
Simon Robertshaw 2012-02-12 16:47:01 +00:00
parent d25384c36c
commit afe9e061e1
8 changed files with 92 additions and 54 deletions

View File

@ -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() {

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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;
}

View File

@ -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();

View File

@ -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)