mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 14:28:30 +01:00
Add date to Preview View, fixes issue #64
This commit is contained in:
parent
ab8466e990
commit
268795eec1
35
src/Format.cpp
Normal file
35
src/Format.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
#include "Format.h"
|
||||
|
||||
std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
|
||||
{
|
||||
struct tm * timeData;
|
||||
char buffer[128];
|
||||
|
||||
timeData = localtime(&unixtime);
|
||||
|
||||
strftime(buffer, 128, dateFormat.c_str(), timeData);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
std::string format::UnixtimeToDateMini(time_t unixtime)
|
||||
{
|
||||
time_t currentTime = time(NULL);
|
||||
struct tm currentTimeData = *localtime(¤tTime);
|
||||
struct tm timeData = *localtime(&unixtime);
|
||||
|
||||
if(currentTimeData.tm_year != timeData.tm_year)
|
||||
{
|
||||
return UnixtimeToDate(unixtime, "%b %Y");
|
||||
}
|
||||
else if(currentTimeData.tm_mon != timeData.tm_mon || currentTimeData.tm_mday != timeData.tm_mday)
|
||||
{
|
||||
return UnixtimeToDate(unixtime, "%d %B");
|
||||
}
|
||||
else
|
||||
{
|
||||
return UnixtimeToDate(unixtime, "%H:%M:%S");
|
||||
}
|
||||
}
|
23
src/Format.h
Normal file
23
src/Format.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace format
|
||||
{
|
||||
template <typename T> std::string NumberToString(T number)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << number;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T> T StringToNumber(const std::string & text)
|
||||
{
|
||||
std::stringstream ss(text);
|
||||
T number;
|
||||
return (ss >> number)?number:0;
|
||||
}
|
||||
|
||||
std::string UnixtimeToDate(time_t unixtime, std::string dateFomat = "%d %b %Y");
|
||||
std::string UnixtimeToDateMini(time_t unixtime);
|
||||
}
|
14
src/Misc.h
14
src/Misc.h
@ -83,20 +83,6 @@ void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
|
||||
|
||||
void OpenURI(std::string uri);
|
||||
|
||||
template <typename T> std::string NumberToString(T number)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << number;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T> T StringToNumber(const std::string & text)
|
||||
{
|
||||
std::stringstream ss(text);
|
||||
T number;
|
||||
return (ss >> number)?number:0;
|
||||
}
|
||||
|
||||
void membwand(void * dest, void * src, size_t destsize, size_t srcsize);
|
||||
// a b
|
||||
// c d
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "interface/Slider.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "simulation/SaveRenderer.h"
|
||||
#include "Format.h"
|
||||
#include "QuickOption.h"
|
||||
|
||||
GameView::GameView():
|
||||
@ -603,10 +604,10 @@ void GameView::NotifyColourSelectorColourChanged(GameModel * sender)
|
||||
{
|
||||
std::string intR, intG, intB, intA;
|
||||
|
||||
intR = NumberToString<int>(sender->GetColourSelectorColour().Red);
|
||||
intG = NumberToString<int>(sender->GetColourSelectorColour().Green);
|
||||
intB = NumberToString<int>(sender->GetColourSelectorColour().Blue);
|
||||
intA = NumberToString<int>(sender->GetColourSelectorColour().Alpha);
|
||||
intR = format::NumberToString<int>(sender->GetColourSelectorColour().Red);
|
||||
intG = format::NumberToString<int>(sender->GetColourSelectorColour().Green);
|
||||
intB = format::NumberToString<int>(sender->GetColourSelectorColour().Blue);
|
||||
intA = format::NumberToString<int>(sender->GetColourSelectorColour().Alpha);
|
||||
|
||||
colourRSlider->SetValue(sender->GetColourSelectorColour().Red);
|
||||
colourRSlider->SetColour(ui::Colour(0, 0, 0), ui::Colour(255, 0, 0));
|
||||
@ -1318,10 +1319,10 @@ void GameView::changeColourSlider()
|
||||
void GameView::changeColourText()
|
||||
{
|
||||
c->SetColour(ui::Colour(
|
||||
std::min(255U, StringToNumber<unsigned int>(colourRValue->GetText())),
|
||||
std::min(255U, StringToNumber<unsigned int>(colourGValue->GetText())),
|
||||
std::min(255U, StringToNumber<unsigned int>(colourBValue->GetText())),
|
||||
std::min(255U, StringToNumber<unsigned int>(colourAValue->GetText())))
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourRValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourGValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourBValue->GetText())),
|
||||
std::min(255U, format::StringToNumber<unsigned int>(colourAValue->GetText())))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Textbox.h"
|
||||
#include "Style.h"
|
||||
#include "Format.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "client/Client.h"
|
||||
#include "interface/ScrollPanel.h"
|
||||
@ -316,7 +317,7 @@ void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||
votesUp = save->votesUp;
|
||||
votesDown = save->votesDown;
|
||||
saveNameLabel->SetText(save->name);
|
||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw ");
|
||||
authorDateLabel->SetText("\bgAuthor:\bw " + save->userName + " \bgDate:\bw " + format::UnixtimeToDateMini(save->date));
|
||||
saveDescriptionLabel->SetText(save->Description);
|
||||
if(save->Favourite)
|
||||
favButton->Enabled = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user