Vote view in save preview, better handling of controller destruction
This commit is contained in:
parent
680a36549a
commit
80aa7219a2
@ -75,7 +75,7 @@ int main(int argc, char * argv[])
|
||||
GameController * gameController = new GameController();
|
||||
engine->ShowWindow(gameController->GetView());
|
||||
|
||||
new ErrorMessage("Error", "This is a test error message");
|
||||
//new ErrorMessage("Error", "This is a test error message");
|
||||
|
||||
SDL_Event event;
|
||||
while(engine->Running())
|
||||
|
@ -68,23 +68,20 @@ GameController::~GameController()
|
||||
{
|
||||
if(search)
|
||||
{
|
||||
if(ui::Engine::Ref().GetWindow() == search->GetView())
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
delete search;
|
||||
}
|
||||
if(renderOptions)
|
||||
{
|
||||
if(ui::Engine::Ref().GetWindow() == renderOptions->GetView())
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
delete renderOptions;
|
||||
}
|
||||
if(loginWindow)
|
||||
{
|
||||
if(ui::Engine::Ref().GetWindow() == loginWindow->GetView())
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
delete loginWindow;
|
||||
}
|
||||
delete gameView;
|
||||
if(ui::Engine::Ref().GetWindow() == gameView)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
}
|
||||
delete gameModel;
|
||||
}
|
||||
|
||||
|
@ -9,36 +9,29 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
SaveButton::SaveButton(Window* parent_state, Save * save):
|
||||
Component(parent_state),
|
||||
save(save),
|
||||
thumbnail(NULL),
|
||||
isMouseInside(false),
|
||||
isButtonDown(false),
|
||||
actionCallback(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SaveButton::SaveButton(Point position, Point size, Save * save):
|
||||
Component(position, size),
|
||||
save(save),
|
||||
thumbnail(NULL),
|
||||
isMouseInside(false),
|
||||
isButtonDown(false),
|
||||
actionCallback(NULL)
|
||||
actionCallback(NULL),
|
||||
voteColour(255, 0, 0)
|
||||
{
|
||||
if(save->votesUp==0)
|
||||
voteRatio = 0.0f;
|
||||
else if(save->votesDown==0)
|
||||
voteRatio = 1.0f;
|
||||
else
|
||||
voteRatio = 1.0f-(float)(((float)(save->votesDown))/((float)(save->votesUp)));
|
||||
if(voteRatio < 0.0f)
|
||||
voteRatio = 0.0f;
|
||||
if(voteRatio > 1.0f) //Not possible, but just in case the server were to give a negative value or something
|
||||
voteRatio = 1.0f;
|
||||
|
||||
}
|
||||
|
||||
SaveButton::SaveButton(Save * save):
|
||||
Component(),
|
||||
save(save),
|
||||
thumbnail(NULL),
|
||||
isMouseInside(false),
|
||||
isButtonDown(false),
|
||||
actionCallback(NULL)
|
||||
{
|
||||
voteColour.Red = (1.0f-voteRatio)*255;
|
||||
voteColour.Green = voteRatio*255;
|
||||
|
||||
}
|
||||
|
||||
@ -68,9 +61,9 @@ void SaveButton::Tick(float dt)
|
||||
{
|
||||
scaleFactorY = ((float)(Size.Y-25))/((float)thumbnail->Size.Y);
|
||||
}
|
||||
if(thumbnail->Size.X > Size.X)
|
||||
if(thumbnail->Size.X > Size.X-3)
|
||||
{
|
||||
scaleFactorX = ((float)Size.X)/((float)thumbnail->Size.X);
|
||||
scaleFactorX = ((float)Size.X-3)/((float)thumbnail->Size.X);
|
||||
}
|
||||
if(scaleFactorY < 1.0f || scaleFactorX < 1.0f)
|
||||
{
|
||||
@ -90,16 +83,32 @@ void SaveButton::Draw(const Point& screenPos)
|
||||
{
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
float scaleFactor;
|
||||
ui::Point thumbBoxSize(0, 0);
|
||||
|
||||
if(thumbnail)
|
||||
{
|
||||
g->draw_image(thumbnail->Data, screenPos.X+(Size.X-thumbnail->Size.X)/2, screenPos.Y+((Size.Y-25)-thumbnail->Size.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
||||
g->drawrect(screenPos.X+(Size.X-thumbnail->Size.X)/2, screenPos.Y+((Size.Y-25)-thumbnail->Size.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 180, 180, 180, 255);
|
||||
thumbBoxSize = ui::Point(thumbnail->Size.X, thumbnail->Size.Y);
|
||||
if(save->id)
|
||||
g->draw_image(thumbnail->Data, screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-25-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
||||
else
|
||||
g->draw_image(thumbnail->Data, screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-25-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaleFactor = (Size.Y-25)/((float)YRES);
|
||||
g->drawrect(screenPos.X+(Size.X-((float)XRES)*scaleFactor)/2, screenPos.Y+((Size.Y-21)-((float)YRES)*scaleFactor)/2, ((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor, 180, 180, 180, 255);
|
||||
thumbBoxSize = ui::Point(((float)XRES)*scaleFactor, ((float)YRES)*scaleFactor);
|
||||
}
|
||||
if(save->id)
|
||||
{
|
||||
g->drawrect(screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
||||
g->drawrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, 6, thumbBoxSize.Y, 180, 180, 180, 255);
|
||||
|
||||
int voteBar = max(10.0f, ((float)(thumbBoxSize.Y))*voteRatio);
|
||||
g->fillrect(screenPos.X-3+thumbBoxSize.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(thumbBoxSize.Y-voteBar)+(Size.Y-21-thumbBoxSize.Y)/2, 6, voteBar, voteColour.Red, voteColour.Green, voteColour.Blue, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
||||
}
|
||||
|
||||
if(isMouseInside)
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "search/Save.h"
|
||||
#include "Graphics.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "interface/Colour.h"
|
||||
|
||||
namespace ui
|
||||
{
|
||||
@ -23,11 +24,7 @@ class SaveButton : public Component
|
||||
Save * save;
|
||||
Thumbnail * thumbnail;
|
||||
public:
|
||||
SaveButton(Window* parent_state, Save * save);
|
||||
|
||||
SaveButton(Point position, Point size, Save * save);
|
||||
|
||||
SaveButton(Save * save);
|
||||
virtual ~SaveButton();
|
||||
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
@ -45,6 +42,8 @@ public:
|
||||
void SetActionCallback(SaveButtonAction * action);
|
||||
protected:
|
||||
bool isButtonDown, state, isMouseInside;
|
||||
float voteRatio;
|
||||
Colour voteColour;
|
||||
SaveButtonAction * actionCallback;
|
||||
};
|
||||
}
|
||||
|
@ -44,8 +44,10 @@ void LoginController::Exit()
|
||||
}
|
||||
|
||||
LoginController::~LoginController() {
|
||||
if(loginView)
|
||||
delete loginView;
|
||||
if(ui::Engine::Ref().GetWindow() == loginView)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
}
|
||||
delete loginModel;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,10 @@ void PreviewController::Exit()
|
||||
}
|
||||
|
||||
PreviewController::~PreviewController() {
|
||||
delete previewView;
|
||||
if(ui::Engine::Ref().GetWindow() == previewView)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
}
|
||||
delete previewModel;
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,7 @@ void PreviewModel::Update()
|
||||
{
|
||||
if(updateSavePreviewFinished)
|
||||
{
|
||||
updateSavePreviewWorking = false;
|
||||
pthread_join(updateSavePreviewThread, (void**)(&savePreview));
|
||||
notifyPreviewChanged();
|
||||
}
|
||||
@ -127,6 +128,7 @@ void PreviewModel::Update()
|
||||
{
|
||||
if(updateSaveInfoFinished)
|
||||
{
|
||||
updateSaveInfoWorking = false;
|
||||
pthread_join(updateSaveInfoThread, (void**)(&save));
|
||||
notifySaveChanged();
|
||||
}
|
||||
|
@ -31,11 +31,11 @@ PreviewView::PreviewView():
|
||||
openButton->SetActionCallback(new OpenAction(this));
|
||||
AddComponent(openButton);
|
||||
|
||||
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+5), ui::Point(100, 16), "");
|
||||
saveNameLabel = new ui::Label(ui::Point(5, (YRES/2)+15), ui::Point(100, 16), "");
|
||||
saveNameLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
AddComponent(saveNameLabel);
|
||||
|
||||
authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+5+14), ui::Point(100, 16), "");
|
||||
authorDateLabel = new ui::Label(ui::Point(5, (YRES/2)+15+14), ui::Point(100, 16), "");
|
||||
authorDateLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||
AddComponent(authorDateLabel);
|
||||
}
|
||||
@ -55,6 +55,20 @@ void PreviewView::OnDraw()
|
||||
}
|
||||
g->drawrect(Position.X, Position.Y, XRES/2, YRES/2, 255, 255, 255, 100);
|
||||
g->draw_line(Position.X+XRES/2, Position.Y, Position.X+XRES/2, Position.Y+Size.Y, 255, 255, 255, XRES+BARSIZE);
|
||||
|
||||
|
||||
g->draw_line(Position.X+1, Position.Y+10+YRES/2, Position.X-2+XRES/2, Position.Y+10+YRES/2, 100, 100, 100, XRES+BARSIZE);
|
||||
float factor;
|
||||
if(!votesUp && !votesDown)
|
||||
return;
|
||||
else
|
||||
factor = (float)(((float)(XRES/2))/((float)(votesUp+votesDown)));
|
||||
g->fillrect(Position.X, Position.Y+YRES/2, XRES/2, 10, 200, 50, 50, 255);
|
||||
g->fillrect(Position.X, Position.Y+YRES/2, (int)(((float)votesUp)*factor), 10, 50, 200, 50, 255);
|
||||
g->fillrect(Position.X, Position.Y+(YRES/2), 14, 10, 0, 0, 0, 100);
|
||||
g->fillrect(Position.X+(XRES/2)-14, Position.Y+(YRES/2), 14, 10, 0, 0, 0, 100);
|
||||
g->draw_icon(Position.X+2, Position.Y+(YRES/2)+2, IconVoteUp);
|
||||
g->draw_icon(Position.X+(XRES/2)-12, Position.Y+(YRES/2), IconVoteDown);
|
||||
}
|
||||
|
||||
void PreviewView::OnTick(float dt)
|
||||
@ -73,11 +87,15 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||
Save * save = sender->GetSave();
|
||||
if(save)
|
||||
{
|
||||
votesUp = save->votesUp;
|
||||
votesDown = save->votesDown;
|
||||
saveNameLabel->SetText(save->name);
|
||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
||||
}
|
||||
else
|
||||
{
|
||||
votesUp = 0;
|
||||
votesDown = 0;
|
||||
saveNameLabel->SetText("");
|
||||
authorDateLabel->SetText("");
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ class PreviewView: public ui::Window {
|
||||
ui::Button * openButton;
|
||||
ui::Label * saveNameLabel;
|
||||
ui::Label * authorDateLabel;
|
||||
int votesUp;
|
||||
int votesDown;
|
||||
public:
|
||||
void AttachController(PreviewController * controller) { c = controller;}
|
||||
PreviewView();
|
||||
|
@ -57,7 +57,10 @@ void RenderController::Exit()
|
||||
}
|
||||
|
||||
RenderController::~RenderController() {
|
||||
delete renderView;
|
||||
if(ui::Engine::Ref().GetWindow() == renderView)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
}
|
||||
delete renderModel;
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,13 @@ using namespace std;
|
||||
class Save
|
||||
{
|
||||
private:
|
||||
public:
|
||||
int id;
|
||||
int date;
|
||||
int votesUp, votesDown;
|
||||
unsigned char * data;
|
||||
int dataLength;
|
||||
public:
|
||||
|
||||
Save(Save & save);
|
||||
|
||||
Save(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name);
|
||||
|
@ -68,9 +68,13 @@ void SearchController::Exit()
|
||||
|
||||
SearchController::~SearchController()
|
||||
{
|
||||
if(activePreview)
|
||||
delete activePreview;
|
||||
if(ui::Engine::Ref().GetWindow() == searchView)
|
||||
{
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
}
|
||||
delete searchModel;
|
||||
if(searchView)
|
||||
delete searchView;
|
||||
}
|
||||
|
||||
void SearchController::DoSearch(std::string query)
|
||||
|
Loading…
Reference in New Issue
Block a user