diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index 3591d3d0c..f007a9f7a 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 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 f7584386d..a3f468cce 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 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 112bdf1d8..1fbff93ed 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -469,7 +469,7 @@ std::vector * Client::GetComments(int saveID, int start, int count) return commentArray; } -std::vector * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount) +std::vector * Client::SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount) { lastError = ""; resultCount = 0; @@ -489,6 +489,12 @@ std::vector * 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 46c18483a..084866bd2 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 * SearchSaves(int start, int count, string query, string sort, int & resultCount); + std::vector * SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount); std::vector * 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 6fa974846..1449f9ad4 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 e40c4b0db..4a410c386 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 * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort, resultCount); + vector * 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 d52529d0c..2587c0340 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 584b7e37c..5bcbe065e 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)