page textbox in browser (go to any page)
also fix page count (add one for front page), and make page count invisible until the saves actually load
This commit is contained in:
parent
b3b852249b
commit
efaa32363f
@ -12,6 +12,7 @@
|
||||
#include "BitmapBrush.h"
|
||||
#include "client/Client.h"
|
||||
#include "client/GameSave.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "gui/game/DecorationTool.h"
|
||||
#include "QuickOptions.h"
|
||||
#include "GameModelException.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "simulation/SaveRenderer.h"
|
||||
#include "simulation/SimulationData.h"
|
||||
#include "gui/dialogues/ConfirmPrompt.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "Format.h"
|
||||
#include "QuickOptions.h"
|
||||
#include "IntroText.h"
|
||||
|
@ -121,16 +121,22 @@ void SearchController::DoSearch(std::string query, bool now)
|
||||
|
||||
void SearchController::PrevPage()
|
||||
{
|
||||
if(searchModel->GetPageNum()>1)
|
||||
if (searchModel->GetPageNum()>1)
|
||||
searchModel->UpdateSaveList(searchModel->GetPageNum()-1, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::NextPage()
|
||||
{
|
||||
if(searchModel->GetPageNum() < searchModel->GetPageCount())
|
||||
if (searchModel->GetPageNum() < searchModel->GetPageCount())
|
||||
searchModel->UpdateSaveList(searchModel->GetPageNum()+1, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::SetPage(int page)
|
||||
{
|
||||
if (page != searchModel->GetPageNum() && page > 0 && page <= searchModel->GetPageCount())
|
||||
searchModel->UpdateSaveList(page, searchModel->GetLastQuery());
|
||||
}
|
||||
|
||||
void SearchController::ChangeSort()
|
||||
{
|
||||
if(searchModel->GetSort() == "new")
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void DoSearch(std::string query, bool now = false);
|
||||
void NextPage();
|
||||
void PrevPage();
|
||||
void SetPage(int page);
|
||||
void ChangeSort();
|
||||
void ShowOwn(bool show);
|
||||
void ShowFavourite(bool show);
|
||||
|
@ -64,7 +64,7 @@ public:
|
||||
int GetPageCount()
|
||||
{
|
||||
if (!showOwn && !showFavourite && currentSort == "best" && lastQuery == "")
|
||||
return max(1, (int)(ceil((resultCount+5)/20.0f)));
|
||||
return max(1, (int)(ceil((resultCount+5)/20.0f))+1); //add one for front page (front page saves are repeated twice)
|
||||
else
|
||||
return max(1, (int)(ceil(resultCount/20.0f)));
|
||||
}
|
||||
|
@ -4,26 +4,52 @@
|
||||
#include "client/Client.h"
|
||||
#include "gui/interface/Keys.h"
|
||||
#include "gui/interface/SaveButton.h"
|
||||
#include "gui/interface/Button.h"
|
||||
#include "gui/interface/Label.h"
|
||||
#include "gui/interface/RichLabel.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "gui/interface/Spinner.h"
|
||||
#include "Misc.h"
|
||||
#include "Format.h"
|
||||
|
||||
SearchView::SearchView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)),
|
||||
saveButtons(vector<ui::SaveButton*>()),
|
||||
errorLabel(NULL),
|
||||
c(NULL)
|
||||
c(NULL),
|
||||
changed(true),
|
||||
lastChanged(0),
|
||||
pageCount(0)
|
||||
{
|
||||
|
||||
Client::Ref().AddListener(this);
|
||||
|
||||
nextButton = new ui::Button(ui::Point(WINDOWW-52, WINDOWH-18), ui::Point(50, 16), "Next \x95");
|
||||
previousButton = new ui::Button(ui::Point(1, WINDOWH-18), ui::Point(50, 16), "\x96 Prev");
|
||||
infoLabel = new ui::Label(ui::Point(260, WINDOWH-18), ui::Point(WINDOWW-520, 16), "Page 1 of 1");
|
||||
tagsLabel = new ui::Label(ui::Point(270, WINDOWH-18), ui::Point(WINDOWW-540, 16), "\boPopular Tags:");
|
||||
motdLabel = new ui::RichLabel(ui::Point(51, WINDOWH-18), ui::Point(WINDOWW-102, 16), Client::Ref().GetMessageOfTheDay());
|
||||
|
||||
class PageNumAction : public ui::TextboxAction
|
||||
{
|
||||
SearchView * v;
|
||||
public:
|
||||
PageNumAction(SearchView * _v) { v = _v; }
|
||||
void TextChangedCallback(ui::Textbox * sender)
|
||||
{
|
||||
v->textChanged();
|
||||
}
|
||||
};
|
||||
pageTextbox = new ui::Textbox(ui::Point(283, WINDOWH-18), ui::Point(41, 16), "");
|
||||
pageTextbox->SetActionCallback(new PageNumAction(this));
|
||||
pageTextbox->SetInputType(ui::Textbox::Number);
|
||||
pageLabel = new ui::Label(ui::Point(0, WINDOWH-18), ui::Point(30, 16), "Page"); //page [TEXTBOX] of y
|
||||
pageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
||||
pageCountLabel = new ui::Label(ui::Point(WINDOWW/2+6, WINDOWH-18), ui::Point(50, 16), "");
|
||||
pageCountLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
AddComponent(pageLabel);
|
||||
AddComponent(pageCountLabel);
|
||||
AddComponent(pageTextbox);
|
||||
|
||||
class SearchAction : public ui::TextboxAction
|
||||
{
|
||||
SearchView * v;
|
||||
@ -131,6 +157,7 @@ SearchView::SearchView():
|
||||
nextButton->SetActionCallback(new NextPageAction(this));
|
||||
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
|
||||
nextButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
nextButton->Visible = false;
|
||||
class PrevPageAction : public ui::ButtonAction
|
||||
{
|
||||
SearchView * v;
|
||||
@ -144,10 +171,10 @@ SearchView::SearchView():
|
||||
previousButton->SetActionCallback(new PrevPageAction(this));
|
||||
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
previousButton->Visible = false;
|
||||
AddComponent(nextButton);
|
||||
AddComponent(previousButton);
|
||||
AddComponent(searchField);
|
||||
AddComponent(infoLabel);
|
||||
|
||||
loadingSpinner = new ui::Spinner(ui::Point((WINDOWW/2)-12, (WINDOWH/2)+12), ui::Point(24, 24));
|
||||
AddComponent(loadingSpinner);
|
||||
@ -235,13 +262,23 @@ void SearchView::doSearch()
|
||||
c->DoSearch(searchField->GetText());
|
||||
}
|
||||
|
||||
|
||||
void SearchView::clearSearch()
|
||||
{
|
||||
searchField->SetText("");
|
||||
c->DoSearch(searchField->GetText(), true);
|
||||
}
|
||||
|
||||
void SearchView::textChanged()
|
||||
{
|
||||
int num = format::StringToNumber<int>(pageTextbox->GetText());
|
||||
if (num < 0) //0 is allowed so that you can backspace the 1
|
||||
pageTextbox->SetText("1");
|
||||
else if (num > pageCount)
|
||||
pageTextbox->SetText(format::NumberToString(pageCount));
|
||||
changed = true;
|
||||
lastChanged = SDL_GetTicks()+600;
|
||||
}
|
||||
|
||||
void SearchView::OnTryOkay(OkayMethod method)
|
||||
{
|
||||
c->DoSearch(searchField->GetText(), true);
|
||||
@ -252,7 +289,14 @@ SearchView::~SearchView()
|
||||
Client::Ref().RemoveListener(this);
|
||||
RemoveComponent(nextButton);
|
||||
RemoveComponent(previousButton);
|
||||
RemoveComponent(infoLabel);
|
||||
RemoveComponent(pageTextbox);
|
||||
RemoveComponent(pageLabel);
|
||||
RemoveComponent(pageCountLabel);
|
||||
delete nextButton;
|
||||
delete previousButton;
|
||||
delete pageTextbox;
|
||||
delete pageLabel;
|
||||
delete pageCountLabel;
|
||||
|
||||
for(int i = 0; i < saveButtons.size(); i++)
|
||||
{
|
||||
@ -260,10 +304,6 @@ SearchView::~SearchView()
|
||||
delete saveButtons[i];
|
||||
}
|
||||
saveButtons.clear();
|
||||
|
||||
delete nextButton;
|
||||
delete previousButton;
|
||||
delete infoLabel;
|
||||
}
|
||||
|
||||
void SearchView::Search(std::string query)
|
||||
@ -330,9 +370,28 @@ void SearchView::NotifyShowFavouriteChanged(SearchModel * sender)
|
||||
|
||||
void SearchView::NotifyPageChanged(SearchModel * sender)
|
||||
{
|
||||
std::stringstream pageInfo;
|
||||
pageInfo << "Page " << sender->GetPageNum() << " of " << sender->GetPageCount();
|
||||
infoLabel->SetText(pageInfo.str());
|
||||
pageCount = sender->GetPageCount();
|
||||
if (!sender->GetSaveList().size()) //no saves
|
||||
{
|
||||
pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream pageInfo;
|
||||
pageInfo << "of " << pageCount;
|
||||
pageCountLabel->SetText(pageInfo.str());
|
||||
int width = Graphics::textwidth(pageInfo.str().c_str());
|
||||
|
||||
pageLabel->Position.X = WINDOWW/2-width-20;
|
||||
pageTextbox->Position.X = WINDOWW/2-width+11;
|
||||
pageTextbox->Size.X = width-4;
|
||||
//pageCountLabel->Position.X = WINDOWW/2+6;
|
||||
pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = true;
|
||||
|
||||
pageInfo.str("");
|
||||
pageInfo << sender->GetPageNum();
|
||||
pageTextbox->SetText(pageInfo.str());
|
||||
}
|
||||
if(sender->GetPageNum() == 1)
|
||||
{
|
||||
previousButton->Visible = false;
|
||||
@ -700,6 +759,11 @@ void SearchView::NotifySelectedChanged(SearchModel * sender)
|
||||
void SearchView::OnTick(float dt)
|
||||
{
|
||||
c->Update();
|
||||
if (changed && lastChanged < SDL_GetTicks())
|
||||
{
|
||||
changed = false;
|
||||
c->SetPage(std::max(format::StringToNumber<int>(pageTextbox->GetText()), 0));
|
||||
}
|
||||
}
|
||||
|
||||
void SearchView::OnMouseWheel(int x, int y, int d)
|
||||
|
@ -3,11 +3,6 @@
|
||||
|
||||
#include <vector>
|
||||
#include "SearchController.h"
|
||||
#include "gui/interface/SaveButton.h"
|
||||
#include "gui/interface/Button.h"
|
||||
#include "gui/interface/Label.h"
|
||||
#include "gui/interface/Spinner.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "client/ClientListener.h"
|
||||
|
||||
using namespace std;
|
||||
@ -36,7 +31,9 @@ private:
|
||||
ui::Button * previousButton;
|
||||
ui::Label * errorLabel;
|
||||
ui::Textbox * searchField;
|
||||
ui::Label * infoLabel;
|
||||
ui::Textbox * pageTextbox;
|
||||
ui::Label * pageLabel;
|
||||
ui::Label * pageCountLabel;
|
||||
ui::Label * tagsLabel;
|
||||
ui::RichLabel * motdLabel;
|
||||
ui::Button * sortButton;
|
||||
@ -49,6 +46,10 @@ private:
|
||||
ui::Button * clearSelection;
|
||||
void clearSearch();
|
||||
void doSearch();
|
||||
void textChanged();
|
||||
bool changed;
|
||||
int lastChanged;
|
||||
int pageCount;
|
||||
public:
|
||||
void NotifyTagListChanged(SearchModel * sender);
|
||||
void NotifySaveListChanged(SearchModel * sender);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "gui/game/Tool.h"
|
||||
#include "LuaScriptHelper.h"
|
||||
#include "client/HTTP.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "Misc.h"
|
||||
#include "PowderToy.h"
|
||||
|
||||
|
Reference in New Issue
Block a user