Textbox in the stamp browser also
This commit is contained in:
parent
efaa32363f
commit
cd9fa0c85a
@ -131,6 +131,12 @@ void LocalBrowserController::PrevPage()
|
||||
browserModel->UpdateSavesList(browserModel->GetPageNum()-1);
|
||||
}
|
||||
|
||||
void LocalBrowserController::SetPage(int page)
|
||||
{
|
||||
if (page != browserModel->GetPageNum() && page > 0 && page <= browserModel->GetPageCount())
|
||||
browserModel->UpdateSavesList(page);
|
||||
}
|
||||
|
||||
void LocalBrowserController::Update()
|
||||
{
|
||||
if(browserModel->GetSave())
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
void SetMoveToFront(bool move);
|
||||
void NextPage();
|
||||
void PrevPage();
|
||||
void SetPage(int page);
|
||||
void Update();
|
||||
void Exit();
|
||||
virtual ~LocalBrowserController();
|
||||
|
@ -31,6 +31,7 @@ void LocalBrowserModel::notifySavesListChanged()
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifySavesListChanged(this);
|
||||
observers[i]->NotifyPageChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
std::stringstream pageInfo;
|
||||
pageInfo << "Page " << sender->GetPageNum() << " of " << sender->GetPageCount();
|
||||
infoLabel->SetText(pageInfo.str());
|
||||
pageCount = sender->GetPageCount();
|
||||
if (!sender->GetSavesList().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;
|
||||
@ -216,6 +275,4 @@ void LocalBrowserView::OnKeyRelease(int key, Uint16 character, bool shift, bool
|
||||
c->SetMoveToFront(true);
|
||||
}
|
||||
|
||||
LocalBrowserView::~LocalBrowserView() {
|
||||
}
|
||||
|
||||
LocalBrowserView::~LocalBrowserView() { }
|
||||
|
@ -7,6 +7,7 @@
|
||||
namespace ui
|
||||
{
|
||||
class Label;
|
||||
class Textbox;
|
||||
class Button;
|
||||
class SaveButton;
|
||||
}
|
||||
@ -19,8 +20,15 @@ class LocalBrowserView: public ui::Window {
|
||||
ui::Button * undeleteButton;
|
||||
ui::Button * previousButton;
|
||||
ui::Button * nextButton;
|
||||
ui::Label * infoLabel;
|
||||
ui::Label * pageLabel;
|
||||
ui::Label * pageCountLabel;
|
||||
ui::Textbox * pageTextbox;
|
||||
ui::Button * removeSelected;
|
||||
|
||||
void textChanged();
|
||||
bool changed;
|
||||
int lastChanged;
|
||||
int pageCount;
|
||||
public:
|
||||
LocalBrowserView();
|
||||
//virtual void OnDraw();
|
||||
|
Reference in New Issue
Block a user