mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 19:34:01 +02:00
Better names for sort, allow showing own saves
This commit is contained in:
@@ -201,6 +201,7 @@ tpt.partsdata = nil");
|
|||||||
{
|
{
|
||||||
lua_el_mode[i] = 0;
|
lua_el_mode[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScriptInterface::Tick()
|
void LuaScriptInterface::Tick()
|
||||||
@@ -216,7 +217,65 @@ int LuaScriptInterface::Command(std::string command)
|
|||||||
|
|
||||||
std::string LuaScriptInterface::FormatCommand(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() {
|
LuaScriptInterface::~LuaScriptInterface() {
|
||||||
|
@@ -137,7 +137,7 @@ std::string TPTScriptInterface::FormatCommand(std::string command)
|
|||||||
currentWord = ++currentCommand;
|
currentWord = ++currentCommand;
|
||||||
}
|
}
|
||||||
words.push_back(std::string(currentWord));
|
words.push_back(std::string(currentWord));
|
||||||
|
free(rawCommand);
|
||||||
while(!words.empty())
|
while(!words.empty())
|
||||||
{
|
{
|
||||||
ValueType cType = testType(words.front());
|
ValueType cType = testType(words.front());
|
||||||
@@ -160,41 +160,6 @@ std::string TPTScriptInterface::FormatCommand(std::string command)
|
|||||||
outputData += words.front() + " ";
|
outputData += words.front() + " ";
|
||||||
words.pop_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;
|
return outputData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -469,7 +469,7 @@ std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
|
|||||||
return commentArray;
|
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 = "";
|
lastError = "";
|
||||||
resultCount = 0;
|
resultCount = 0;
|
||||||
@@ -489,6 +489,12 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
|
|||||||
urlStream << URLEscape(" ");
|
urlStream << URLEscape(" ");
|
||||||
urlStream << URLEscape("sort:") << URLEscape(sort);
|
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);
|
data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
|
||||||
|
@@ -52,7 +52,7 @@ public:
|
|||||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||||
LoginStatus Login(string username, string password, User & user);
|
LoginStatus Login(string username, string password, User & user);
|
||||||
void ClearThumbnailRequests();
|
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);
|
std::vector<Comment*> * GetComments(int saveID, int start, int count);
|
||||||
Thumbnail * GetPreview(int saveID, int saveDate);
|
Thumbnail * GetPreview(int saveID, int saveDate);
|
||||||
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "SearchView.h"
|
#include "SearchView.h"
|
||||||
#include "interface/Panel.h"
|
#include "interface/Panel.h"
|
||||||
#include "preview/PreviewController.h"
|
#include "preview/PreviewController.h"
|
||||||
|
#include "client/Client.h"
|
||||||
|
|
||||||
class SearchController::OpenCallback: public ControllerCallback
|
class SearchController::OpenCallback: public ControllerCallback
|
||||||
{
|
{
|
||||||
@@ -106,19 +107,22 @@ void SearchController::NextPage()
|
|||||||
|
|
||||||
void SearchController::ChangeSort()
|
void SearchController::ChangeSort()
|
||||||
{
|
{
|
||||||
if(searchModel->GetSort() == "date")
|
if(searchModel->GetSort() == "new")
|
||||||
{
|
{
|
||||||
searchModel->SetSort("votes");
|
searchModel->SetSort("best");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
searchModel->SetSort("date");
|
searchModel->SetSort("new");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::ShowOwn(bool show)
|
void SearchController::ShowOwn(bool show)
|
||||||
{
|
{
|
||||||
//TODO: Implement
|
if(Client::Ref().GetAuthUser().ID)
|
||||||
|
searchModel->SetShowOwn(show);
|
||||||
|
else
|
||||||
|
searchModel->SetShowOwn(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::OpenSave(int saveID)
|
void SearchController::OpenSave(int saveID)
|
||||||
|
@@ -4,12 +4,14 @@
|
|||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
|
||||||
SearchModel::SearchModel():
|
SearchModel::SearchModel():
|
||||||
currentSort("votes"),
|
currentSort("best"),
|
||||||
showOwn(false),
|
showOwn(false),
|
||||||
loadedSave(NULL),
|
loadedSave(NULL),
|
||||||
updateSaveListWorking(false),
|
updateSaveListWorking(false),
|
||||||
updateSaveListFinished(false),
|
updateSaveListFinished(false),
|
||||||
saveListLoaded(false)
|
saveListLoaded(false),
|
||||||
|
currentPage(1),
|
||||||
|
resultCount(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ void * SearchModel::updateSaveListTHelper(void * obj)
|
|||||||
|
|
||||||
void * SearchModel::updateSaveListT()
|
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;
|
updateSaveListFinished = true;
|
||||||
return tempSaveList;
|
return tempSaveList;
|
||||||
}
|
}
|
||||||
|
@@ -47,7 +47,7 @@ public:
|
|||||||
std::string GetLastQuery() { return lastQuery; }
|
std::string GetLastQuery() { return lastQuery; }
|
||||||
void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
|
void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
|
||||||
string GetSort() { return currentSort; }
|
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; }
|
bool GetShowOwn() { return showOwn; }
|
||||||
void SetLoadedSave(Save * save);
|
void SetLoadedSave(Save * save);
|
||||||
Save * GetLoadedSave();
|
Save * GetLoadedSave();
|
||||||
|
@@ -27,7 +27,7 @@ SearchView::SearchView():
|
|||||||
v->doSearch();
|
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->SetAlignment(AlignLeft, AlignBottom);
|
||||||
searchField->SetActionCallback(new SearchAction(this));
|
searchField->SetActionCallback(new SearchAction(this));
|
||||||
|
|
||||||
@@ -41,9 +41,9 @@ SearchView::SearchView():
|
|||||||
v->c->ChangeSort();
|
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->SetActionCallback(new SortAction(this));
|
||||||
sortButton->SetAlignment(AlignLeft, AlignBottom);
|
sortButton->SetAlignment(AlignCentre, AlignBottom);
|
||||||
AddComponent(sortButton);
|
AddComponent(sortButton);
|
||||||
|
|
||||||
class MyOwnAction : public ui::ButtonAction
|
class MyOwnAction : public ui::ButtonAction
|
||||||
@@ -56,10 +56,12 @@ SearchView::SearchView():
|
|||||||
v->c->ShowOwn(sender->GetToggleState());
|
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->SetTogglable(true);
|
||||||
ownButton->SetActionCallback(new MyOwnAction(this));
|
ownButton->SetActionCallback(new MyOwnAction(this));
|
||||||
ownButton->SetAlignment(AlignLeft, AlignBottom);
|
if(!Client::Ref().GetAuthUser().ID)
|
||||||
|
ownButton->Enabled = false;
|
||||||
|
ownButton->SetAlignment(AlignCentre, AlignBottom);
|
||||||
AddComponent(ownButton);
|
AddComponent(ownButton);
|
||||||
|
|
||||||
class NextPageAction : public ui::ButtonAction
|
class NextPageAction : public ui::ButtonAction
|
||||||
@@ -110,12 +112,12 @@ SearchView::~SearchView()
|
|||||||
|
|
||||||
void SearchView::NotifySortChanged(SearchModel * sender)
|
void SearchView::NotifySortChanged(SearchModel * sender)
|
||||||
{
|
{
|
||||||
sortButton->SetText("Sort: "+sender->GetSort());
|
sortButton->SetText("Show "+sender->GetSort());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
|
void SearchView::NotifyShowOwnChanged(SearchModel * sender)
|
||||||
{
|
{
|
||||||
sortButton->SetToggleState(sender->GetShowOwn());
|
ownButton->SetToggleState(sender->GetShowOwn());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchView::NotifyPageChanged(SearchModel * sender)
|
void SearchView::NotifyPageChanged(SearchModel * sender)
|
||||||
|
Reference in New Issue
Block a user