|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include "client/Client.h"
|
|
|
|
|
#include "Format.h"
|
|
|
|
|
#include "LocalBrowserView.h"
|
|
|
|
|
|
|
|
|
|
#include "gui/interface/Button.h"
|
|
|
|
@@ -15,17 +16,39 @@
|
|
|
|
|
#include "LocalBrowserModelException.h"
|
|
|
|
|
|
|
|
|
|
LocalBrowserView::LocalBrowserView():
|
|
|
|
|
ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH))
|
|
|
|
|
ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)),
|
|
|
|
|
changed(false),
|
|
|
|
|
lastChanged(0),
|
|
|
|
|
pageCount(0)
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
undeleteButton = new ui::Button(ui::Point(WINDOWW-122, WINDOWH-18), ui::Point(60, 16), "Rescan");
|
|
|
|
|
infoLabel = new ui::Label(ui::Point(51, WINDOWH-18), ui::Point(WINDOWW-102, 16), "Loading...");
|
|
|
|
|
AddComponent(infoLabel);
|
|
|
|
|
AddComponent(nextButton);
|
|
|
|
|
AddComponent(previousButton);
|
|
|
|
|
AddComponent(undeleteButton);
|
|
|
|
|
|
|
|
|
|
class PageNumAction : public ui::TextboxAction
|
|
|
|
|
{
|
|
|
|
|
LocalBrowserView * v;
|
|
|
|
|
public:
|
|
|
|
|
PageNumAction(LocalBrowserView * _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 NextPageAction : public ui::ButtonAction
|
|
|
|
|
{
|
|
|
|
|
LocalBrowserView * v;
|
|
|
|
@@ -83,16 +106,52 @@ LocalBrowserView::LocalBrowserView():
|
|
|
|
|
AddComponent(removeSelected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalBrowserView::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 LocalBrowserView::OnTick(float dt)
|
|
|
|
|
{
|
|
|
|
|
c->Update();
|
|
|
|
|
if (changed && lastChanged < SDL_GetTicks())
|
|
|
|
|
{
|
|
|
|
|
changed = false;
|
|
|
|
|
c->SetPage(std::max(format::StringToNumber<int>(pageTextbox->GetText()), 0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender)
|
|
|
|
|
{
|
|
|
|
|
pageCount = sender->GetPageCount();
|
|
|
|
|
if (!sender->GetSavesList().size()) //no saves
|
|
|
|
|
{
|
|
|
|
|
pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::stringstream pageInfo;
|
|
|
|
|
pageInfo << "Page " << sender->GetPageNum() << " of " << sender->GetPageCount();
|
|
|
|
|
infoLabel->SetText(pageInfo.str());
|
|
|
|
|
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;
|
|
|
|
@@ -216,6 +275,4 @@ void LocalBrowserView::OnKeyRelease(int key, Uint16 character, bool shift, bool
|
|
|
|
|
c->SetMoveToFront(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalBrowserView::~LocalBrowserView() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LocalBrowserView::~LocalBrowserView() { }
|
|
|
|
|