mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 14:28:30 +01:00
Switch from std::string to String/ByteString in most of the code
Also switch SimulationData from weird arrays to std::vector
This commit is contained in:
parent
4912674bfe
commit
ff27d69424
@ -1,6 +1,6 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
@ -9,7 +9,7 @@
|
||||
#include "Format.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
std::string format::URLEncode(std::string source)
|
||||
ByteString format::URLEncode(ByteString source)
|
||||
{
|
||||
char * src = (char *)source.c_str();
|
||||
char * dst = new char[(source.length()*3)+2];
|
||||
@ -33,12 +33,12 @@ std::string format::URLEncode(std::string source)
|
||||
}
|
||||
*d = 0;
|
||||
|
||||
std::string finalString(dst);
|
||||
ByteString finalString(dst);
|
||||
delete[] dst;
|
||||
return finalString;
|
||||
}
|
||||
|
||||
std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
|
||||
ByteString format::UnixtimeToDate(time_t unixtime, ByteString dateFormat)
|
||||
{
|
||||
struct tm * timeData;
|
||||
char buffer[128];
|
||||
@ -46,10 +46,10 @@ std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
|
||||
timeData = localtime(&unixtime);
|
||||
|
||||
strftime(buffer, 128, dateFormat.c_str(), timeData);
|
||||
return std::string(buffer);
|
||||
return ByteString(buffer);
|
||||
}
|
||||
|
||||
std::string format::UnixtimeToDateMini(time_t unixtime)
|
||||
ByteString format::UnixtimeToDateMini(time_t unixtime)
|
||||
{
|
||||
time_t currentTime = time(NULL);
|
||||
struct tm currentTimeData = *localtime(¤tTime);
|
||||
@ -69,7 +69,7 @@ std::string format::UnixtimeToDateMini(time_t unixtime)
|
||||
}
|
||||
}
|
||||
|
||||
std::string format::CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric)
|
||||
String format::CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric)
|
||||
{
|
||||
for (size_t i = 0; i < dirtyString.size(); i++)
|
||||
{
|
||||
@ -226,7 +226,7 @@ struct PNGChunk
|
||||
|
||||
//char[4] CRC();
|
||||
|
||||
PNGChunk(int length, std::string name)
|
||||
PNGChunk(int length, ByteString name)
|
||||
{
|
||||
if (name.length()!=4)
|
||||
throw std::runtime_error("Invalid chunk name");
|
||||
|
32
src/Format.h
32
src/Format.h
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include "common/String.h"
|
||||
#include <vector>
|
||||
|
||||
class VideoBuffer;
|
||||
@ -9,24 +9,38 @@ namespace format
|
||||
{
|
||||
const static char hex[] = "0123456789ABCDEF";
|
||||
|
||||
template <typename T> std::string NumberToString(T number)
|
||||
template <typename T> ByteString NumberToByteString(T number)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ByteString::Stream ss;
|
||||
ss << number;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T> T StringToNumber(const std::string & text)
|
||||
template <typename T> String NumberToString(T number)
|
||||
{
|
||||
std::stringstream ss(text);
|
||||
String::Stream ss;
|
||||
ss << number;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <typename T> T ByteStringToNumber(const ByteString & text)
|
||||
{
|
||||
ByteString::Stream ss(text);
|
||||
T number;
|
||||
return (ss >> number)?number:0;
|
||||
}
|
||||
|
||||
std::string URLEncode(std::string value);
|
||||
std::string UnixtimeToDate(time_t unixtime, std::string dateFomat = "%d %b %Y");
|
||||
std::string UnixtimeToDateMini(time_t unixtime);
|
||||
std::string CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
|
||||
template <typename T> T StringToNumber(const String & text)
|
||||
{
|
||||
String::Stream ss(text);
|
||||
T number;
|
||||
return (ss >> number)?number:0;
|
||||
}
|
||||
|
||||
ByteString URLEncode(ByteString value);
|
||||
ByteString UnixtimeToDate(time_t unixtime, ByteString dateFomat = "%d %b %Y");
|
||||
ByteString UnixtimeToDateMini(time_t unixtime);
|
||||
String CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
|
||||
std::vector<char> VideoBufferToPNG(const VideoBuffer & vidBuf);
|
||||
std::vector<char> VideoBufferToBMP(const VideoBuffer & vidBuf);
|
||||
std::vector<char> VideoBufferToPPM(const VideoBuffer & vidBuf);
|
||||
|
@ -2,8 +2,6 @@
|
||||
#define UTILS_H
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
//Linear interpolation
|
||||
|
@ -20,9 +20,9 @@
|
||||
namespace Platform
|
||||
{
|
||||
|
||||
std::string ExecutableName()
|
||||
ByteString ExecutableName()
|
||||
{
|
||||
std::string ret;
|
||||
ByteString ret;
|
||||
#if defined(WIN)
|
||||
char *name = (char *)malloc(64);
|
||||
DWORD max = 64, res;
|
||||
@ -73,7 +73,7 @@ std::string ExecutableName()
|
||||
|
||||
void DoRestart()
|
||||
{
|
||||
std::string exename = ExecutableName();
|
||||
ByteString exename = ExecutableName();
|
||||
if (exename.length())
|
||||
{
|
||||
#ifdef WIN
|
||||
@ -85,7 +85,7 @@ void DoRestart()
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void OpenURI(std::string uri)
|
||||
void OpenURI(ByteString uri)
|
||||
{
|
||||
#if defined(WIN)
|
||||
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
namespace Platform
|
||||
{
|
||||
std::string ExecutableName();
|
||||
ByteString ExecutableName();
|
||||
void DoRestart();
|
||||
|
||||
void OpenURI(std::string uri);
|
||||
void OpenURI(ByteString uri);
|
||||
|
||||
void Millisleep(long int t);
|
||||
long unsigned int GetTime();
|
||||
|
@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
void EngineProcess();
|
||||
void ClipboardPush(std::string text);
|
||||
std::string ClipboardPull();
|
||||
void ClipboardPush(ByteString text);
|
||||
ByteString ClipboardPull();
|
||||
int GetModifiers();
|
||||
bool LoadWindowPosition(int scale);
|
||||
void SetCursorEnabled(int enabled);
|
||||
|
@ -2,11 +2,10 @@
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
#include "common/String.h"
|
||||
#include "Config.h"
|
||||
#include "Format.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
@ -18,16 +17,16 @@
|
||||
|
||||
|
||||
void EngineProcess() {}
|
||||
void ClipboardPush(std::string) {}
|
||||
std::string ClipboardPull() { return ""; }
|
||||
void ClipboardPush(ByteString) {}
|
||||
ByteString ClipboardPull() { return ""; }
|
||||
int GetModifiers() { return 0; }
|
||||
void SetCursorEnabled(int enabled) {}
|
||||
unsigned int GetTicks() { return 0; }
|
||||
|
||||
void readFile(std::string filename, std::vector<char> & storage)
|
||||
void readFile(ByteString filename, std::vector<char> & storage)
|
||||
{
|
||||
std::ifstream fileStream;
|
||||
fileStream.open(std::string(filename).c_str(), std::ios::binary);
|
||||
fileStream.open(filename.c_str(), std::ios::binary);
|
||||
if(fileStream.is_open())
|
||||
{
|
||||
fileStream.seekg(0, std::ios::end);
|
||||
@ -45,10 +44,10 @@ void readFile(std::string filename, std::vector<char> & storage)
|
||||
}
|
||||
}
|
||||
|
||||
void writeFile(std::string filename, std::vector<char> & fileData)
|
||||
void writeFile(ByteString filename, std::vector<char> & fileData)
|
||||
{
|
||||
std::ofstream fileStream;
|
||||
fileStream.open(std::string(filename).c_str(), std::ios::binary);
|
||||
fileStream.open(filename.c_str(), std::ios::binary);
|
||||
if(fileStream.is_open())
|
||||
{
|
||||
fileStream.write(&fileData[0], fileData.size());
|
||||
@ -59,13 +58,13 @@ void writeFile(std::string filename, std::vector<char> & fileData)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ui::Engine * engine;
|
||||
std::string outputPrefix, inputFilename;
|
||||
ByteString outputPrefix, inputFilename;
|
||||
std::vector<char> inputFile;
|
||||
std::string ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
|
||||
ByteString ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
|
||||
std::vector<char> ppmFile, ptiFile, ptiSmallFile, pngFile, pngSmallFile;
|
||||
|
||||
inputFilename = std::string(argv[1]);
|
||||
outputPrefix = std::string(argv[2]);
|
||||
inputFilename = argv[1];
|
||||
outputPrefix = argv[2];
|
||||
|
||||
ppmFilename = outputPrefix+".ppm";
|
||||
ptiFilename = outputPrefix+".pti";
|
||||
@ -88,7 +87,7 @@ int main(int argc, char *argv[])
|
||||
catch (ParseException e)
|
||||
{
|
||||
//Render the save again later or something? I don't know
|
||||
if (e.what() == "Save from newer version")
|
||||
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifdef USE_SDL
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <ctime>
|
||||
#include <climits>
|
||||
#ifdef WIN
|
||||
@ -18,9 +18,9 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Config.h"
|
||||
#include "common/String.h"
|
||||
#include "graphics/Graphics.h"
|
||||
#if defined(LIN)
|
||||
#include "icon.h"
|
||||
@ -68,7 +68,7 @@ SDL_SysWMinfo sdl_wminfo;
|
||||
Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING;
|
||||
#endif
|
||||
|
||||
std::string clipboardText = "";
|
||||
ByteString clipboardText = "";
|
||||
|
||||
int desktopWidth = 1280, desktopHeight = 1024;
|
||||
|
||||
@ -76,7 +76,7 @@ SDL_Surface * sdl_scrn;
|
||||
int scale = 1;
|
||||
bool fullscreen = false;
|
||||
|
||||
void ClipboardPush(std::string text)
|
||||
void ClipboardPush(ByteString text)
|
||||
{
|
||||
clipboardText = text;
|
||||
#ifdef MACOSX
|
||||
@ -110,11 +110,11 @@ void ClipboardPush(std::string text)
|
||||
|
||||
void EventProcess(SDL_Event event);
|
||||
|
||||
std::string ClipboardPull()
|
||||
ByteString ClipboardPull()
|
||||
{
|
||||
#ifdef MACOSX
|
||||
const char *text = readClipboard();
|
||||
return text ? std::string(text) : "";
|
||||
return text ? ByteString(text).FromUtf8() : "";
|
||||
#elif defined(WIN)
|
||||
if (OpenClipboard(NULL))
|
||||
{
|
||||
@ -125,10 +125,10 @@ std::string ClipboardPull()
|
||||
glbuffer = (char*)GlobalLock(cbuffer);
|
||||
GlobalUnlock(cbuffer);
|
||||
CloseClipboard();
|
||||
return glbuffer ? std::string(glbuffer) : "";
|
||||
return glbuffer ? ByteString(glbuffer) : "";
|
||||
}
|
||||
#elif defined(LIN) && defined(SDL_VIDEO_DRIVER_X11)
|
||||
std::string text = "";
|
||||
ByteString text = "";
|
||||
Window selectionOwner;
|
||||
sdl_wminfo.info.x11.lock_func();
|
||||
selectionOwner = XGetSelectionOwner(sdl_wminfo.info.x11.display, XA_CLIPBOARD);
|
||||
@ -168,7 +168,7 @@ std::string ClipboardPull()
|
||||
result = XGetWindowProperty(sdl_wminfo.info.x11.display, sdl_wminfo.info.x11.window, XA_CLIPBOARD, 0, bytesLeft, 0, AnyPropertyType, &type, &format, &len, &bytesLeft, &data);
|
||||
if (result == Success)
|
||||
{
|
||||
text = data ? (const char*)data : "";
|
||||
text = data ? ByteString((char const *)data) : "";
|
||||
XFree(data);
|
||||
}
|
||||
else
|
||||
@ -526,9 +526,9 @@ unsigned int GetTicks()
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> readArguments(int argc, char * argv[])
|
||||
std::map<ByteString, ByteString> readArguments(int argc, char * argv[])
|
||||
{
|
||||
std::map<std::string, std::string> arguments;
|
||||
std::map<ByteString, ByteString> arguments;
|
||||
|
||||
//Defaults
|
||||
arguments["scale"] = "";
|
||||
@ -545,12 +545,12 @@ std::map<std::string, std::string> readArguments(int argc, char * argv[])
|
||||
{
|
||||
if (!strncmp(argv[i], "scale:", 6) && argv[i]+6)
|
||||
{
|
||||
arguments["scale"] = std::string(argv[i]+6);
|
||||
arguments["scale"] = argv[i]+6;
|
||||
}
|
||||
else if (!strncmp(argv[i], "proxy:", 6))
|
||||
{
|
||||
if(argv[i]+6)
|
||||
arguments["proxy"] = std::string(argv[i]+6);
|
||||
arguments["proxy"] = argv[i]+6;
|
||||
else
|
||||
arguments["proxy"] = "false";
|
||||
}
|
||||
@ -572,17 +572,17 @@ std::map<std::string, std::string> readArguments(int argc, char * argv[])
|
||||
}
|
||||
else if (!strncmp(argv[i], "open", 5) && i+1<argc)
|
||||
{
|
||||
arguments["open"] = std::string(argv[i+1]);;
|
||||
arguments["open"] = argv[i+1];
|
||||
i++;
|
||||
}
|
||||
else if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
|
||||
{
|
||||
arguments["ddir"] = std::string(argv[i+1]);
|
||||
arguments["ddir"] = argv[i+1];
|
||||
i++;
|
||||
}
|
||||
else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
|
||||
{
|
||||
arguments["ptsave"] = std::string(argv[i+1]);
|
||||
arguments["ptsave"] = argv[i+1];
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
@ -753,7 +753,7 @@ void EventProcess(SDL_Event event)
|
||||
|
||||
void DoubleScreenDialog()
|
||||
{
|
||||
std::stringstream message;
|
||||
String::Stream message;
|
||||
message << "Switching to double size mode since your screen was determined to be large enough: ";
|
||||
message << desktopWidth << "x" << desktopHeight << " detected, " << WINDOWW*2 << "x" << WINDOWH*2 << " required";
|
||||
message << "\nTo undo this, hit Cancel. You can toggle double size mode in settings at any time.";
|
||||
@ -916,28 +916,28 @@ bool SaveWindowPosition()
|
||||
|
||||
#endif
|
||||
|
||||
void BlueScreen(const char * detailMessage){
|
||||
void BlueScreen(String detailMessage){
|
||||
ui::Engine * engine = &ui::Engine::Ref();
|
||||
engine->g->fillrect(0, 0, engine->GetWidth(), engine->GetHeight(), 17, 114, 169, 210);
|
||||
|
||||
std::string errorTitle = "ERROR";
|
||||
std::string errorDetails = "Details: " + std::string(detailMessage);
|
||||
std::string errorHelp = "An unrecoverable fault has occurred, please report the error by visiting the website below\n"
|
||||
String errorTitle = "ERROR";
|
||||
String errorDetails = "Details: " + detailMessage;
|
||||
String errorHelp = "An unrecoverable fault has occurred, please report the error by visiting the website below\n"
|
||||
"http://" SERVER;
|
||||
int currentY = 0, width, height;
|
||||
int errorWidth = 0;
|
||||
Graphics::textsize(errorHelp.c_str(), errorWidth, height);
|
||||
Graphics::textsize(errorHelp, errorWidth, height);
|
||||
|
||||
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorTitle.c_str(), 255, 255, 255, 255);
|
||||
Graphics::textsize(errorTitle.c_str(), width, height);
|
||||
Graphics::textsize(errorTitle, width, height);
|
||||
currentY += height + 4;
|
||||
|
||||
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorDetails.c_str(), 255, 255, 255, 255);
|
||||
Graphics::textsize(errorTitle.c_str(), width, height);
|
||||
Graphics::textsize(errorTitle, width, height);
|
||||
currentY += height + 4;
|
||||
|
||||
engine->g->drawtext((engine->GetWidth()/2)-(errorWidth/2), ((engine->GetHeight()/2)-100) + currentY, errorHelp.c_str(), 255, 255, 255, 255);
|
||||
Graphics::textsize(errorTitle.c_str(), width, height);
|
||||
Graphics::textsize(errorTitle, width, height);
|
||||
currentY += height + 4;
|
||||
|
||||
//Death loop
|
||||
@ -985,7 +985,7 @@ int main(int argc, char * argv[])
|
||||
currentHeight = WINDOWH;
|
||||
|
||||
|
||||
std::map<std::string, std::string> arguments = readArguments(argc, argv);
|
||||
std::map<ByteString, ByteString> arguments = readArguments(argc, argv);
|
||||
|
||||
if(arguments["ddir"].length())
|
||||
#ifdef WIN
|
||||
@ -1009,11 +1009,11 @@ int main(int argc, char * argv[])
|
||||
|
||||
if(arguments["scale"].length())
|
||||
{
|
||||
tempScale = format::StringToNumber<int>(arguments["scale"]);
|
||||
tempScale = format::ByteStringToNumber<int>(arguments["scale"]);
|
||||
Client::Ref().SetPref("Scale", tempScale);
|
||||
}
|
||||
|
||||
std::string proxyString = "";
|
||||
ByteString proxyString = "";
|
||||
if(arguments["proxy"].length())
|
||||
{
|
||||
if(arguments["proxy"] == "false")
|
||||
@ -1029,7 +1029,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
else if(Client::Ref().GetPrefString("Proxy", "").length())
|
||||
{
|
||||
proxyString = (Client::Ref().GetPrefString("Proxy", ""));
|
||||
proxyString = (Client::Ref().GetPrefByteString("Proxy", ""));
|
||||
}
|
||||
|
||||
Client::Ref().Initialise(proxyString);
|
||||
@ -1140,7 +1140,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
new ErrorMessage("Error", "Could not open save file:\n"+std::string(e.what())) ;
|
||||
new ErrorMessage("Error", "Could not open save file:\n" + ByteString(e.what()).FromUtf8()) ;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1163,16 +1163,16 @@ int main(int argc, char * argv[])
|
||||
else
|
||||
blit(engine->g->vid);
|
||||
#endif
|
||||
std::string ptsaveArg = arguments["ptsave"];
|
||||
ByteString ptsaveArg = arguments["ptsave"];
|
||||
try
|
||||
{
|
||||
if (ptsaveArg.find("ptsave:"))
|
||||
throw std::runtime_error("Invalid save link");
|
||||
|
||||
std::string saveIdPart = "";
|
||||
ByteString saveIdPart = "";
|
||||
int saveId;
|
||||
size_t hashPos = ptsaveArg.find('#');
|
||||
if (hashPos != std::string::npos)
|
||||
if (hashPos != ByteString::npos)
|
||||
{
|
||||
saveIdPart = ptsaveArg.substr(7, hashPos-7);
|
||||
}
|
||||
@ -1185,7 +1185,7 @@ int main(int argc, char * argv[])
|
||||
#ifdef DEBUG
|
||||
std::cout << "Got Ptsave: id: " << saveIdPart << std::endl;
|
||||
#endif
|
||||
saveId = format::StringToNumber<int>(saveIdPart);
|
||||
saveId = format::ByteStringToNumber<int>(saveIdPart);
|
||||
if (!saveId)
|
||||
throw std::runtime_error("Invalid Save ID");
|
||||
|
||||
@ -1194,7 +1194,7 @@ int main(int argc, char * argv[])
|
||||
throw std::runtime_error("Could not load save info");
|
||||
std::vector<unsigned char> saveData = Client::Ref().GetSaveData(saveId, 0);
|
||||
if (!saveData.size())
|
||||
throw std::runtime_error("Could not load save\n" + Client::Ref().GetLastError());
|
||||
throw std::runtime_error(("Could not load save\n" + Client::Ref().GetLastError()).ToUtf8());
|
||||
GameSave * newGameSave = new GameSave(saveData);
|
||||
newSave->SetGameSave(newGameSave);
|
||||
|
||||
@ -1203,7 +1203,7 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
new ErrorMessage("Error", e.what());
|
||||
new ErrorMessage("Error", ByteString(e.what()).FromUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
// returns 1 on failure, 0 on success
|
||||
int update_start(char *data, unsigned int len)
|
||||
{
|
||||
std::string exeName = Platform::ExecutableName(), updName;
|
||||
ByteString exeName = Platform::ExecutableName(), updName;
|
||||
FILE *f;
|
||||
|
||||
if (!exeName.length())
|
||||
@ -34,7 +34,7 @@ int update_start(char *data, unsigned int len)
|
||||
|
||||
#ifdef WIN
|
||||
updName = exeName;
|
||||
std::string extension = exeName.substr(exeName.length() - 4);
|
||||
ByteString extension = exeName.substr(exeName.length() - 4);
|
||||
if (extension == ".exe")
|
||||
updName = exeName.substr(0, exeName.length() - 4);
|
||||
updName = updName + "_upd.exe";
|
||||
@ -95,7 +95,7 @@ int update_start(char *data, unsigned int len)
|
||||
int update_finish()
|
||||
{
|
||||
#ifdef WIN
|
||||
std::string exeName = Platform::ExecutableName(), updName;
|
||||
ByteString exeName = Platform::ExecutableName(), updName;
|
||||
int timeout = 5, err;
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -103,7 +103,7 @@ int update_finish()
|
||||
#endif
|
||||
|
||||
updName = exeName;
|
||||
std::string extension = exeName.substr(exeName.length() - 4);
|
||||
ByteString extension = exeName.substr(exeName.length() - 4);
|
||||
if (extension == ".exe")
|
||||
updName = exeName.substr(0, exeName.length() - 4);
|
||||
updName = updName + "_upd.exe";
|
||||
@ -122,7 +122,7 @@ int update_finish()
|
||||
#endif
|
||||
// Old versions of powder toy name their update files with _update.exe, delete that upgrade file here
|
||||
updName = exeName;
|
||||
std::string extension = exeName.substr(exeName.length() - 4);
|
||||
ByteString extension = exeName.substr(exeName.length() - 4);
|
||||
if (extension == ".exe")
|
||||
updName = exeName.substr(0, exeName.length() - 4);
|
||||
updName = updName + "_update.exe";
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "common/String.h"
|
||||
#include "Config.h"
|
||||
#include "common/Singleton.h"
|
||||
|
||||
@ -34,24 +35,24 @@ class UpdateInfo
|
||||
{
|
||||
public:
|
||||
enum BuildType { Stable, Beta, Snapshot };
|
||||
std::string File;
|
||||
std::string Changelog;
|
||||
ByteString File;
|
||||
String Changelog;
|
||||
int Major;
|
||||
int Minor;
|
||||
int Build;
|
||||
int Time;
|
||||
BuildType Type;
|
||||
UpdateInfo() : File(""), Changelog(""), Major(0), Minor(0), Build(0), Time(0), Type(Stable) {}
|
||||
UpdateInfo(int major, int minor, int build, std::string file, std::string changelog, BuildType type) : File(file), Changelog(changelog), Major(major), Minor(minor), Build(build), Time(0), Type(type) {}
|
||||
UpdateInfo(int time, std::string file, std::string changelog, BuildType type) : File(file), Changelog(changelog), Major(0), Minor(0), Build(0), Time(time), Type(type) {}
|
||||
UpdateInfo(int major, int minor, int build, ByteString file, String changelog, BuildType type) : File(file), Changelog(changelog), Major(major), Minor(minor), Build(build), Time(0), Type(type) {}
|
||||
UpdateInfo(int time, ByteString file, String changelog, BuildType type) : File(file), Changelog(changelog), Major(0), Minor(0), Build(0), Time(time), Type(type) {}
|
||||
};
|
||||
|
||||
class RequestListener;
|
||||
class ClientListener;
|
||||
class Client: public Singleton<Client> {
|
||||
private:
|
||||
std::string messageOfTheDay;
|
||||
std::vector<std::pair<std::string, std::string> > serverNotifications;
|
||||
String messageOfTheDay;
|
||||
std::vector<std::pair<String, ByteString> > serverNotifications;
|
||||
|
||||
void * versionCheckRequest;
|
||||
void * alternateVersionCheckRequest;
|
||||
@ -59,10 +60,10 @@ private:
|
||||
bool updateAvailable;
|
||||
UpdateInfo updateInfo;
|
||||
|
||||
std::string lastError;
|
||||
String lastError;
|
||||
bool firstRun;
|
||||
|
||||
std::list<std::string> stampIDs;
|
||||
std::list<ByteString> stampIDs;
|
||||
unsigned lastStampTime;
|
||||
int lastStampName;
|
||||
|
||||
@ -75,16 +76,16 @@ private:
|
||||
void * activeThumbRequests[IMGCONNS];
|
||||
int activeThumbRequestTimes[IMGCONNS];
|
||||
int activeThumbRequestCompleteTimes[IMGCONNS];
|
||||
std::string activeThumbRequestIDs[IMGCONNS];
|
||||
ByteString activeThumbRequestIDs[IMGCONNS];
|
||||
void notifyUpdateAvailable();
|
||||
void notifyAuthUserChanged();
|
||||
void notifyMessageOfTheDay();
|
||||
void notifyNewNotification(std::pair<std::string, std::string> notification);
|
||||
void notifyNewNotification(std::pair<String, ByteString> notification);
|
||||
|
||||
// internal preferences handling
|
||||
Json::Value preferences;
|
||||
Json::Value GetPref(Json::Value root, std::string prop, Json::Value defaultValue = Json::nullValue);
|
||||
Json::Value SetPrefHelper(Json::Value root, std::string prop, Json::Value value);
|
||||
Json::Value GetPref(Json::Value root, ByteString prop, Json::Value defaultValue = Json::nullValue);
|
||||
Json::Value SetPrefHelper(Json::Value root, ByteString prop, Json::Value value);
|
||||
|
||||
// Save stealing info
|
||||
Json::Value authors;
|
||||
@ -107,30 +108,30 @@ public:
|
||||
Client();
|
||||
~Client();
|
||||
|
||||
std::vector<std::string> DirectorySearch(std::string directory, std::string search, std::vector<std::string> extensions);
|
||||
std::vector<std::string> DirectorySearch(std::string directory, std::string search, std::string extension);
|
||||
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions);
|
||||
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, ByteString extension);
|
||||
|
||||
std::string FileOpenDialogue();
|
||||
ByteString FileOpenDialogue();
|
||||
//std::string FileSaveDialogue();
|
||||
|
||||
bool DoInstallation();
|
||||
|
||||
std::vector<unsigned char> ReadFile(std::string filename);
|
||||
std::vector<unsigned char> ReadFile(ByteString filename);
|
||||
|
||||
void AddServerNotification(std::pair<std::string, std::string> notification);
|
||||
std::vector<std::pair<std::string, std::string> > GetServerNotifications();
|
||||
void AddServerNotification(std::pair<String, ByteString> notification);
|
||||
std::vector<std::pair<String, ByteString> > GetServerNotifications();
|
||||
|
||||
void SetMessageOfTheDay(std::string message);
|
||||
std::string GetMessageOfTheDay();
|
||||
void SetMessageOfTheDay(String message);
|
||||
String GetMessageOfTheDay();
|
||||
|
||||
void Initialise(std::string proxyString);
|
||||
void SetProxy(std::string proxy);
|
||||
void Initialise(ByteString proxyString);
|
||||
void SetProxy(ByteString proxy);
|
||||
bool IsFirstRun();
|
||||
|
||||
int MakeDirectory(const char * dirname);
|
||||
bool WriteFile(std::vector<unsigned char> fileData, std::string filename);
|
||||
bool WriteFile(std::vector<char> fileData, std::string filename);
|
||||
bool FileExists(std::string filename);
|
||||
bool WriteFile(std::vector<unsigned char> fileData, ByteString filename);
|
||||
bool WriteFile(std::vector<char> fileData, ByteString filename);
|
||||
bool FileExists(ByteString filename);
|
||||
|
||||
void AddListener(ClientListener * listener);
|
||||
void RemoveListener(ClientListener * listener);
|
||||
@ -138,30 +139,30 @@ public:
|
||||
RequestStatus ExecVote(int saveID, int direction);
|
||||
RequestStatus UploadSave(SaveInfo & save);
|
||||
|
||||
SaveFile * GetStamp(std::string stampID);
|
||||
void DeleteStamp(std::string stampID);
|
||||
std::string AddStamp(GameSave * saveData);
|
||||
std::vector<std::string> GetStamps(int start, int count);
|
||||
SaveFile * GetStamp(ByteString stampID);
|
||||
void DeleteStamp(ByteString stampID);
|
||||
ByteString AddStamp(GameSave * saveData);
|
||||
std::vector<ByteString> GetStamps(int start, int count);
|
||||
void RescanStamps();
|
||||
int GetStampsCount();
|
||||
SaveFile * GetFirstStamp();
|
||||
void MoveStampToFront(std::string stampID);
|
||||
void MoveStampToFront(ByteString stampID);
|
||||
void updateStamps();
|
||||
|
||||
RequestStatus AddComment(int saveID, std::string comment);
|
||||
RequestStatus AddComment(int saveID, String comment);
|
||||
|
||||
//Retrieves a "UserInfo" object
|
||||
RequestBroker::Request * GetUserInfoAsync(std::string username);
|
||||
RequestBroker::Request * GetUserInfoAsync(ByteString username);
|
||||
RequestBroker::Request * SaveUserInfoAsync(UserInfo info);
|
||||
|
||||
RequestBroker::Request * GetSaveDataAsync(int saveID, int saveDate);
|
||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
||||
|
||||
LoginStatus Login(std::string username, std::string password, User & user);
|
||||
LoginStatus Login(ByteString username, ByteString password, User & user);
|
||||
void ClearThumbnailRequests();
|
||||
std::vector<SaveInfo*> * SearchSaves(int start, int count, std::string query, std::string sort, std::string category, int & resultCount);
|
||||
std::vector<std::pair<std::string, int> > * GetTags(int start, int count, std::string query, int & resultCount);
|
||||
std::vector<SaveInfo*> * SearchSaves(int start, int count, String query, ByteString sort, ByteString category, int & resultCount);
|
||||
std::vector<std::pair<ByteString, int> > * GetTags(int start, int count, String query, int & resultCount);
|
||||
|
||||
RequestBroker::Request * GetCommentsAsync(int saveID, int start, int count);
|
||||
|
||||
@ -169,15 +170,15 @@ public:
|
||||
RequestBroker::Request * GetSaveAsync(int saveID, int saveDate);
|
||||
|
||||
RequestStatus DeleteSave(int saveID);
|
||||
RequestStatus ReportSave(int saveID, std::string message);
|
||||
RequestStatus ReportSave(int saveID, String message);
|
||||
RequestStatus UnpublishSave(int saveID);
|
||||
RequestStatus PublishSave(int saveID);
|
||||
RequestStatus FavouriteSave(int saveID, bool favourite);
|
||||
void SetAuthUser(User user);
|
||||
User GetAuthUser();
|
||||
std::list<std::string> * RemoveTag(int saveID, std::string tag); //TODO RequestStatus
|
||||
std::list<std::string> * AddTag(int saveID, std::string tag);
|
||||
std::string GetLastError() {
|
||||
std::list<ByteString> * RemoveTag(int saveID, ByteString tag); //TODO RequestStatus
|
||||
std::list<ByteString> * AddTag(int saveID, ByteString tag);
|
||||
String GetLastError() {
|
||||
return lastError;
|
||||
}
|
||||
RequestStatus ParseServerReturn(char *result, int status, bool json);
|
||||
@ -188,19 +189,22 @@ public:
|
||||
// preferences functions
|
||||
void WritePrefs();
|
||||
|
||||
std::string GetPrefString(std::string prop, std::string defaultValue);
|
||||
double GetPrefNumber(std::string prop, double defaultValue);
|
||||
int GetPrefInteger(std::string prop, int defaultValue);
|
||||
unsigned int GetPrefUInteger(std::string prop, unsigned int defaultValue);
|
||||
bool GetPrefBool(std::string prop, bool defaultValue);
|
||||
std::vector<std::string> GetPrefStringArray(std::string prop);
|
||||
std::vector<double> GetPrefNumberArray(std::string prop);
|
||||
std::vector<int> GetPrefIntegerArray(std::string prop);
|
||||
std::vector<unsigned int> GetPrefUIntegerArray(std::string prop);
|
||||
std::vector<bool> GetPrefBoolArray(std::string prop);
|
||||
ByteString GetPrefByteString(ByteString prop, ByteString defaultValue);
|
||||
String GetPrefString(ByteString prop, String defaultValue);
|
||||
double GetPrefNumber(ByteString prop, double defaultValue);
|
||||
int GetPrefInteger(ByteString prop, int defaultValue);
|
||||
unsigned int GetPrefUInteger(ByteString prop, unsigned int defaultValue);
|
||||
bool GetPrefBool(ByteString prop, bool defaultValue);
|
||||
std::vector<ByteString> GetPrefByteStringArray(ByteString prop);
|
||||
std::vector<String> GetPrefStringArray(ByteString prop);
|
||||
std::vector<double> GetPrefNumberArray(ByteString prop);
|
||||
std::vector<int> GetPrefIntegerArray(ByteString prop);
|
||||
std::vector<unsigned int> GetPrefUIntegerArray(ByteString prop);
|
||||
std::vector<bool> GetPrefBoolArray(ByteString prop);
|
||||
|
||||
void SetPref(std::string prop, Json::Value value);
|
||||
void SetPref(std::string property, std::vector<Json::Value> value);
|
||||
void SetPref(ByteString prop, Json::Value value);
|
||||
void SetPref(ByteString property, std::vector<Json::Value> value);
|
||||
void SetPrefUnicode(ByteString prop, String value);
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
||||
|
@ -11,7 +11,7 @@ public:
|
||||
virtual void NotifyUpdateAvailable(Client * sender) {}
|
||||
virtual void NotifyAuthUserChanged(Client * sender) {}
|
||||
virtual void NotifyMessageOfTheDay(Client * sender) {}
|
||||
virtual void NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification) {}
|
||||
virtual void NotifyNewNotification(Client * sender, std::pair<String, ByteString> notification) {}
|
||||
};
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "DownloadManager.h"
|
||||
#include "HTTP.h"
|
||||
|
||||
Download::Download(std::string uri_, bool keepAlive):
|
||||
Download::Download(ByteString uri_, bool keepAlive):
|
||||
http(NULL),
|
||||
keepAlive(keepAlive),
|
||||
downloadData(NULL),
|
||||
@ -17,7 +17,7 @@ Download::Download(std::string uri_, bool keepAlive):
|
||||
downloadCanceled(false),
|
||||
downloadStarted(false)
|
||||
{
|
||||
uri = std::string(uri_);
|
||||
uri = ByteString(uri_);
|
||||
DownloadManager::Ref().AddDownload(this);
|
||||
}
|
||||
|
||||
@ -31,20 +31,20 @@ Download::~Download()
|
||||
}
|
||||
|
||||
// add post data to a request
|
||||
void Download::AddPostData(std::map<std::string, std::string> data)
|
||||
void Download::AddPostData(std::map<ByteString, ByteString> data)
|
||||
{
|
||||
postDataBoundary = FindBoundary(data, "");
|
||||
postData = GetMultipartMessage(data, postDataBoundary);
|
||||
}
|
||||
void Download::AddPostData(std::pair<std::string, std::string> data)
|
||||
void Download::AddPostData(std::pair<ByteString, ByteString> data)
|
||||
{
|
||||
std::map<std::string, std::string> postData;
|
||||
std::map<ByteString, ByteString> postData;
|
||||
postData.insert(data);
|
||||
AddPostData(postData);
|
||||
}
|
||||
|
||||
// add userID and sessionID headers to the download. Must be done after download starts for some reason
|
||||
void Download::AuthHeaders(std::string ID, std::string session)
|
||||
void Download::AuthHeaders(ByteString ID, ByteString session)
|
||||
{
|
||||
if (ID != "0")
|
||||
userID = ID;
|
||||
@ -68,13 +68,13 @@ void Download::Start()
|
||||
}
|
||||
|
||||
// for persistent connections (keepAlive = true), reuse the open connection to make another request
|
||||
bool Download::Reuse(std::string newuri)
|
||||
bool Download::Reuse(ByteString newuri)
|
||||
{
|
||||
if (!keepAlive || !CheckDone() || CheckCanceled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uri = std::string(newuri);
|
||||
uri = newuri;
|
||||
DownloadManager::Ref().Lock();
|
||||
downloadFinished = false;
|
||||
DownloadManager::Ref().Unlock();
|
||||
|
@ -1,12 +1,12 @@
|
||||
#ifndef DOWNLOAD_H
|
||||
#define DOWNLOAD_H
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
class DownloadManager;
|
||||
class Download
|
||||
{
|
||||
std::string uri;
|
||||
ByteString uri;
|
||||
void *http;
|
||||
bool keepAlive;
|
||||
|
||||
@ -14,25 +14,25 @@ class Download
|
||||
int downloadSize;
|
||||
int downloadStatus;
|
||||
|
||||
std::string postData;
|
||||
std::string postDataBoundary;
|
||||
ByteString postData;
|
||||
ByteString postDataBoundary;
|
||||
|
||||
std::string userID;
|
||||
std::string userSession;
|
||||
ByteString userID;
|
||||
ByteString userSession;
|
||||
|
||||
volatile bool downloadFinished;
|
||||
volatile bool downloadCanceled;
|
||||
volatile bool downloadStarted;
|
||||
|
||||
public:
|
||||
Download(std::string uri, bool keepAlive = false);
|
||||
Download(ByteString uri, bool keepAlive = false);
|
||||
~Download();
|
||||
|
||||
void AddPostData(std::map<std::string, std::string> data);
|
||||
void AddPostData(std::pair<std::string, std::string> data);
|
||||
void AuthHeaders(std::string ID, std::string session);
|
||||
void AddPostData(std::map<ByteString, ByteString> data);
|
||||
void AddPostData(std::pair<ByteString, ByteString> data);
|
||||
void AuthHeaders(ByteString ID, ByteString session);
|
||||
void Start();
|
||||
bool Reuse(std::string newuri);
|
||||
bool Reuse(ByteString newuri);
|
||||
char* Finish(int *length, int *status);
|
||||
void Cancel();
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "common/tpt-minmax.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <climits>
|
||||
#include <memory>
|
||||
@ -633,7 +632,7 @@ void GameSave::readOPS(char * data, int dataLength)
|
||||
throw ParseException(ParseException::Corrupt, "Unable to decompress (ret " + format::NumberToString<int>(bz2ret) + ")");
|
||||
}
|
||||
|
||||
set_bson_err_handler([](const char* err) { throw ParseException(ParseException::Corrupt, "BSON error when parsing save: " + std::string(err)); });
|
||||
set_bson_err_handler([](const char* err) { throw ParseException(ParseException::Corrupt, "BSON error when parsing save: " + ByteString(err).FromUtf8()); });
|
||||
bson_init_data_size(&b, (char*)bsonData, bsonDataLen);
|
||||
bson_iterator_init(&iter, &b);
|
||||
|
||||
@ -679,7 +678,7 @@ void GameSave::readOPS(char * data, int dataLength)
|
||||
{
|
||||
if (!strcmp(bson_iterator_key(&signiter), "text") && bson_iterator_type(&signiter) == BSON_STRING)
|
||||
{
|
||||
tempSign.text = format::CleanString(bson_iterator_string(&signiter), true, true, true).substr(0, 45);
|
||||
tempSign.text = format::CleanString(ByteString(bson_iterator_string(&signiter)).FromUtf8(), true, true, true).substr(0, 45);
|
||||
}
|
||||
else if (!strcmp(bson_iterator_key(&signiter), "justification") && bson_iterator_type(&signiter) == BSON_INT)
|
||||
{
|
||||
@ -764,7 +763,7 @@ void GameSave::readOPS(char * data, int dataLength)
|
||||
{
|
||||
if (bson_iterator_type(&subiter) == BSON_INT)
|
||||
{
|
||||
std::string id = std::string(bson_iterator_key(&subiter));
|
||||
ByteString id = bson_iterator_key(&subiter);
|
||||
int num = bson_iterator_int(&subiter);
|
||||
palette.push_back(PaletteItem(id, num));
|
||||
}
|
||||
@ -806,7 +805,7 @@ void GameSave::readOPS(char * data, int dataLength)
|
||||
if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION))
|
||||
#endif
|
||||
{
|
||||
std::stringstream errorMessage;
|
||||
String::Stream errorMessage;
|
||||
#ifdef RENDERER
|
||||
errorMessage << "Save from a newer version: Requires render version " << renderMajor << "." << renderMinor;
|
||||
#else
|
||||
@ -1333,18 +1332,8 @@ void GameSave::readPSv(char * saveDataChar, int dataLength)
|
||||
sign tempSign("", 0, 0, sign::Left);
|
||||
|
||||
//Gol data used to read older saves
|
||||
int goltype[NGOL];
|
||||
int grule[NGOL+1][10];
|
||||
|
||||
int golRulesCount;
|
||||
int * golRulesT = LoadGOLRules(golRulesCount);
|
||||
memcpy(grule, golRulesT, sizeof(int) * (golRulesCount*10));
|
||||
free(golRulesT);
|
||||
|
||||
int golTypesCount;
|
||||
int * golTypesT = LoadGOLTypes(golTypesCount);
|
||||
memcpy(goltype, golTypesT, sizeof(int) * (golTypesCount));
|
||||
free(golTypesT);
|
||||
std::vector<int> goltype = LoadGOLTypes();
|
||||
std::vector<std::array<int, 10> > grule = LoadGOLRules();
|
||||
|
||||
std::vector<Element> elements = GetElements();
|
||||
|
||||
@ -1419,7 +1408,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength)
|
||||
int bzStatus = 0;
|
||||
if ((bzStatus = BZ2_bzBuffToBuffDecompress((char *)data, (unsigned *)&size, (char *)(saveData+12), dataLength-12, 0, 0)))
|
||||
{
|
||||
std::stringstream bzStatusStr;
|
||||
String::Stream bzStatusStr;
|
||||
bzStatusStr << bzStatus;
|
||||
throw ParseException(ParseException::Corrupt, "Cannot decompress: " + bzStatusStr.str());
|
||||
}
|
||||
@ -2399,7 +2388,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength)
|
||||
// Use unique_ptr with a custom deleter to ensure that bson_destroy is called even when an exception is thrown
|
||||
std::unique_ptr<bson, decltype(bson_deleter)> b_ptr(&b, bson_deleter);
|
||||
|
||||
set_bson_err_handler([](const char* err) { throw BuildException("BSON error when parsing save: " + std::string(err)); });
|
||||
set_bson_err_handler([](const char* err) { throw BuildException("BSON error when parsing save: " + ByteString(err).FromUtf8()); });
|
||||
bson_init(&b);
|
||||
bson_append_start_object(&b, "origin");
|
||||
bson_append_int(&b, "majorVersion", SAVE_VERSION);
|
||||
@ -2504,7 +2493,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength)
|
||||
if(signs[i].text.length() && signs[i].x>=0 && signs[i].x<=fullW && signs[i].y>=0 && signs[i].y<=fullH)
|
||||
{
|
||||
bson_append_start_object(&b, "sign");
|
||||
bson_append_string(&b, "text", signs[i].text.c_str());
|
||||
bson_append_string(&b, "text", signs[i].text.ToUtf8().c_str());
|
||||
bson_append_int(&b, "justification", signs[i].ju);
|
||||
bson_append_int(&b, "x", signs[i].x);
|
||||
bson_append_int(&b, "y", signs[i].y);
|
||||
@ -2563,7 +2552,7 @@ void GameSave::ConvertBsonToJson(bson_iterator *iter, Json::Value *j, int depth)
|
||||
bson_iterator_subiterator(iter, &subiter);
|
||||
while (bson_iterator_next(&subiter))
|
||||
{
|
||||
std::string key = bson_iterator_key(&subiter);
|
||||
ByteString key = bson_iterator_key(&subiter);
|
||||
if (bson_iterator_type(&subiter) == BSON_STRING)
|
||||
(*j)[key] = bson_iterator_string(&subiter);
|
||||
else if (bson_iterator_type(&subiter) == BSON_BOOL)
|
||||
@ -2604,7 +2593,7 @@ std::set<int> GetNestedSaveIDs(Json::Value j)
|
||||
std::set<int> saveIDs = std::set<int>();
|
||||
for (Json::Value::Members::iterator iter = members.begin(), end = members.end(); iter != end; ++iter)
|
||||
{
|
||||
std::string member = *iter;
|
||||
ByteString member = *iter;
|
||||
if (member == "id" && j[member].isInt())
|
||||
saveIDs.insert(j[member].asInt());
|
||||
else if (j[member].isArray())
|
||||
@ -2633,7 +2622,7 @@ void GameSave::ConvertJsonToBson(bson *b, Json::Value j, int depth)
|
||||
Json::Value::Members members = j.getMemberNames();
|
||||
for (Json::Value::Members::iterator iter = members.begin(), end = members.end(); iter != end; ++iter)
|
||||
{
|
||||
std::string member = *iter;
|
||||
ByteString member = *iter;
|
||||
if (j[member].isString())
|
||||
bson_append_string(b, member.c_str(), j[member].asCString());
|
||||
else if (j[member].isBool())
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define The_Powder_Toy_GameSave_h
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Config.h"
|
||||
#include "Misc.h"
|
||||
|
||||
@ -15,24 +15,24 @@
|
||||
|
||||
struct ParseException: public std::exception {
|
||||
enum ParseResult { OK = 0, Corrupt, WrongVersion, InvalidDimensions, InternalError, MissingElement };
|
||||
std::string message;
|
||||
String message;
|
||||
ParseResult result;
|
||||
public:
|
||||
ParseException(ParseResult result, std::string message_): message(message_), result(result) {}
|
||||
ParseException(ParseResult result, String message_): message(message_), result(result) {}
|
||||
const char * what() const throw()
|
||||
{
|
||||
return message.c_str();
|
||||
return message.ToUtf8().c_str();
|
||||
}
|
||||
~ParseException() throw() {}
|
||||
};
|
||||
|
||||
struct BuildException: public std::exception {
|
||||
std::string message;
|
||||
String message;
|
||||
public:
|
||||
BuildException(std::string message_): message(message_) {}
|
||||
BuildException(String message_): message(message_) {}
|
||||
const char * what() const throw()
|
||||
{
|
||||
return message.c_str();
|
||||
return message.ToUtf8().c_str();
|
||||
}
|
||||
~BuildException() throw() {}
|
||||
};
|
||||
@ -104,7 +104,7 @@ public:
|
||||
StkmData stkm;
|
||||
|
||||
//Element palette
|
||||
typedef std::pair<std::string, int> PaletteItem;
|
||||
typedef std::pair<ByteString, int> PaletteItem;
|
||||
std::vector<PaletteItem> palette;
|
||||
|
||||
// author information
|
||||
|
@ -20,8 +20,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "common/String.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@ -193,11 +192,11 @@ void http_init(char *proxy)
|
||||
free(host);
|
||||
free(port);
|
||||
}
|
||||
std::stringstream userAgentBuilder;
|
||||
ByteString::Stream userAgentBuilder;
|
||||
userAgentBuilder << "PowderToy/" << SAVE_VERSION << "." << MINOR_VERSION << " ";
|
||||
userAgentBuilder << "(" << IDENT_PLATFORM << "; " << IDENT_BUILD << "; M" << MOD_ID << ") ";
|
||||
userAgentBuilder << "TPTPP/" << SAVE_VERSION << "." << MINOR_VERSION << "." << BUILD_NUM << IDENT_RELTYPE << "." << SNAPSHOT_ID;
|
||||
std::string newUserAgent = userAgentBuilder.str();
|
||||
ByteString newUserAgent = userAgentBuilder.str();
|
||||
userAgent = new char[newUserAgent.length()+1];
|
||||
std::copy(newUserAgent.begin(), newUserAgent.end(), userAgent);
|
||||
userAgent[newUserAgent.length()] = 0;
|
||||
@ -938,13 +937,13 @@ const char *http_ret_text(int ret)
|
||||
// Find the boundary used in the multipart POST request
|
||||
// the boundary is a string that never appears in any of the parts, ex. 'A92'
|
||||
// keeps looking recursively until it finds one
|
||||
std::string FindBoundary(std::map<std::string, std::string> parts, std::string boundary)
|
||||
ByteString FindBoundary(std::map<ByteString, ByteString> parts, ByteString boundary)
|
||||
{
|
||||
// we only look for a-zA-Z0-9 chars
|
||||
unsigned int map[62];
|
||||
size_t blen = boundary.length();
|
||||
std::fill(&map[0], &map[62], 0);
|
||||
for (std::map<std::string, std::string>::iterator iter = parts.begin(); iter != parts.end(); iter++)
|
||||
for (std::map<ByteString, ByteString>::iterator iter = parts.begin(); iter != parts.end(); iter++)
|
||||
{
|
||||
// loop through every character in each part and search for the substring, adding 1 to map for every character found (character after the substring)
|
||||
for (ssize_t j = 0; j < (ssize_t)((*iter).second.length()-blen); j++)
|
||||
@ -986,15 +985,15 @@ std::string FindBoundary(std::map<std::string, std::string> parts, std::string b
|
||||
// Generates a MIME multipart message to be used in POST requests
|
||||
// see https://en.wikipedia.org/wiki/MIME#Multipart_messages
|
||||
// this function used in Download class, and eventually all http requests
|
||||
std::string GetMultipartMessage(std::map<std::string, std::string> parts, std::string boundary)
|
||||
ByteString GetMultipartMessage(std::map<ByteString, ByteString> parts, ByteString boundary)
|
||||
{
|
||||
std::stringstream data;
|
||||
ByteString::Stream data;
|
||||
|
||||
// loop through each part, adding it
|
||||
for (std::map<std::string, std::string>::iterator iter = parts.begin(); iter != parts.end(); iter++)
|
||||
for (std::map<ByteString, ByteString>::iterator iter = parts.begin(); iter != parts.end(); iter++)
|
||||
{
|
||||
std::string name = (*iter).first;
|
||||
std::string value = (*iter).second;
|
||||
ByteString name = (*iter).first;
|
||||
ByteString value = (*iter).second;
|
||||
|
||||
data << "--" << boundary << "\r\n";
|
||||
data << "Content-transfer-encoding: binary" << "\r\n";
|
||||
@ -1020,9 +1019,9 @@ std::string GetMultipartMessage(std::map<std::string, std::string> parts, std::s
|
||||
}
|
||||
|
||||
// add the header needed to make POSTS work
|
||||
void http_add_multipart_header(void *ctx, std::string boundary)
|
||||
void http_add_multipart_header(void *ctx, ByteString boundary)
|
||||
{
|
||||
std::string header = "multipart/form-data; boundary=" + boundary;
|
||||
ByteString header = "multipart/form-data; boundary=" + boundary;
|
||||
http_async_add_header(ctx, "Content-type", header.c_str());
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
#define HTTP_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
static const char hexChars[] = "0123456789abcdef";
|
||||
static const long http_timeout = 15;
|
||||
@ -43,9 +43,9 @@ char *http_async_req_stop(void *ctx, int *ret, int *len);
|
||||
void http_async_req_close(void *ctx);
|
||||
void http_force_close(void *ctx);
|
||||
|
||||
std::string FindBoundary(std::map<std::string, std::string>, std::string boundary);
|
||||
std::string GetMultipartMessage(std::map<std::string, std::string>, std::string boundary);
|
||||
void http_add_multipart_header(void *ctx, std::string boundary);
|
||||
ByteString FindBoundary(std::map<ByteString, ByteString>, ByteString boundary);
|
||||
ByteString GetMultipartMessage(std::map<ByteString, ByteString>, ByteString boundary);
|
||||
void http_add_multipart_header(void *ctx, ByteString boundary);
|
||||
char *http_multipart_post(const char *uri, const char *const *names, const char *const *parts, size_t *plens, const char *user, const char *pass, const char * session_id, int *ret, int *len);
|
||||
void *http_multipart_post_async(const char *uri, const char *const *names, const char *const *parts, int *plens, const char *user, const char *pass, const char *session_id);
|
||||
|
||||
|
@ -26,11 +26,11 @@ void SaveFile::SetThumbnail(Thumbnail * thumb)
|
||||
thumbnail = thumb;
|
||||
}
|
||||
|
||||
SaveFile::SaveFile(std::string filename):
|
||||
SaveFile::SaveFile(ByteString filename):
|
||||
thumbnail(NULL),
|
||||
gameSave(NULL),
|
||||
filename(filename),
|
||||
displayName(filename),
|
||||
displayName(filename.FromUtf8()),
|
||||
loadingError("")
|
||||
{
|
||||
|
||||
@ -46,32 +46,32 @@ void SaveFile::SetGameSave(GameSave * save)
|
||||
gameSave = save;
|
||||
}
|
||||
|
||||
std::string SaveFile::GetName()
|
||||
ByteString SaveFile::GetName()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
void SaveFile::SetFileName(std::string fileName)
|
||||
void SaveFile::SetFileName(ByteString fileName)
|
||||
{
|
||||
this->filename = fileName;
|
||||
}
|
||||
|
||||
std::string SaveFile::GetDisplayName()
|
||||
String SaveFile::GetDisplayName()
|
||||
{
|
||||
return displayName;
|
||||
}
|
||||
|
||||
void SaveFile::SetDisplayName(std::string displayName)
|
||||
void SaveFile::SetDisplayName(String displayName)
|
||||
{
|
||||
this->displayName = displayName;
|
||||
}
|
||||
|
||||
std::string SaveFile::GetError()
|
||||
String SaveFile::GetError()
|
||||
{
|
||||
return loadingError;
|
||||
}
|
||||
|
||||
void SaveFile::SetLoadingError(std::string error)
|
||||
void SaveFile::SetLoadingError(String error)
|
||||
{
|
||||
loadingError = error;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef SAVEFILE_H_
|
||||
#define SAVEFILE_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
class GameSave;
|
||||
class Thumbnail;
|
||||
@ -9,26 +9,26 @@ class Thumbnail;
|
||||
class SaveFile {
|
||||
public:
|
||||
SaveFile(SaveFile & save);
|
||||
SaveFile(std::string filename);
|
||||
SaveFile(ByteString filename);
|
||||
|
||||
Thumbnail * GetThumbnail();
|
||||
GameSave * GetGameSave();
|
||||
void SetThumbnail(Thumbnail * thumb);
|
||||
void SetGameSave(GameSave * save);
|
||||
std::string GetDisplayName();
|
||||
void SetDisplayName(std::string displayName);
|
||||
std::string GetName();
|
||||
void SetFileName(std::string fileName);
|
||||
std::string GetError();
|
||||
void SetLoadingError(std::string error);
|
||||
String GetDisplayName();
|
||||
void SetDisplayName(String displayName);
|
||||
ByteString GetName();
|
||||
void SetFileName(ByteString fileName);
|
||||
String GetError();
|
||||
void SetLoadingError(String error);
|
||||
|
||||
virtual ~SaveFile();
|
||||
private:
|
||||
Thumbnail * thumbnail;
|
||||
GameSave * gameSave;
|
||||
std::string filename;
|
||||
std::string displayName;
|
||||
std::string loadingError;
|
||||
ByteString filename;
|
||||
String displayName;
|
||||
String loadingError;
|
||||
};
|
||||
|
||||
#endif /* SAVEFILE_H_ */
|
||||
|
@ -19,14 +19,14 @@ SaveInfo::SaveInfo(SaveInfo & save):
|
||||
Published(save.Published),
|
||||
gameSave(NULL)
|
||||
{
|
||||
std::list<std::string> tagsSorted = save.tags;
|
||||
std::list<ByteString> tagsSorted = save.tags;
|
||||
tagsSorted.sort();
|
||||
tags = tagsSorted;
|
||||
if (save.gameSave)
|
||||
gameSave = new GameSave(*save.gameSave);
|
||||
}
|
||||
|
||||
SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, std::string _userName, std::string _name):
|
||||
SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, ByteString _userName, String _name):
|
||||
id(_id),
|
||||
createdDate(_createdDate),
|
||||
updatedDate(_updatedDate),
|
||||
@ -47,7 +47,7 @@ SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, in
|
||||
|
||||
}
|
||||
|
||||
SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags_):
|
||||
SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, int _vote, ByteString _userName, String _name, String description_, bool published_, std::list<ByteString> tags_):
|
||||
id(_id),
|
||||
createdDate(_createdDate),
|
||||
updatedDate(_updatedDate),
|
||||
@ -65,7 +65,7 @@ SaveInfo::SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, in
|
||||
tags(),
|
||||
gameSave(NULL)
|
||||
{
|
||||
std::list<std::string> tagsSorted = tags_;
|
||||
std::list<ByteString> tagsSorted = tags_;
|
||||
tagsSorted.sort();
|
||||
tags=tagsSorted;
|
||||
}
|
||||
@ -78,20 +78,20 @@ SaveInfo::~SaveInfo()
|
||||
}
|
||||
}
|
||||
|
||||
void SaveInfo::SetName(std::string name)
|
||||
void SaveInfo::SetName(String name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
std::string SaveInfo::GetName()
|
||||
String SaveInfo::GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void SaveInfo::SetDescription(std::string description)
|
||||
void SaveInfo::SetDescription(String description)
|
||||
{
|
||||
Description = description;
|
||||
}
|
||||
std::string SaveInfo::GetDescription()
|
||||
String SaveInfo::GetDescription()
|
||||
{
|
||||
return Description;
|
||||
}
|
||||
@ -114,12 +114,12 @@ int SaveInfo::GetVote()
|
||||
return vote;
|
||||
}
|
||||
|
||||
void SaveInfo::SetUserName(std::string userName)
|
||||
void SaveInfo::SetUserName(ByteString userName)
|
||||
{
|
||||
this->userName = userName;
|
||||
}
|
||||
|
||||
std::string SaveInfo::GetUserName()
|
||||
ByteString SaveInfo::GetUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
@ -160,14 +160,14 @@ int SaveInfo::GetVersion()
|
||||
return Version;
|
||||
}
|
||||
|
||||
void SaveInfo::SetTags(std::list<std::string> tags)
|
||||
void SaveInfo::SetTags(std::list<ByteString> tags)
|
||||
{
|
||||
std::list<std::string> tagsSorted = tags;
|
||||
std::list<ByteString> tagsSorted = tags;
|
||||
tagsSorted.sort();
|
||||
this->tags=tagsSorted;
|
||||
}
|
||||
|
||||
std::list<std::string> SaveInfo::GetTags()
|
||||
std::list<ByteString> SaveInfo::GetTags()
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
@ -23,34 +23,34 @@ public:
|
||||
int Views;
|
||||
int Version;
|
||||
|
||||
std::string userName;
|
||||
ByteString userName;
|
||||
|
||||
std::string name;
|
||||
std::string Description;
|
||||
String name;
|
||||
String Description;
|
||||
bool Published;
|
||||
|
||||
std::list<std::string> tags;
|
||||
std::list<ByteString> tags;
|
||||
GameSave * gameSave;
|
||||
|
||||
SaveInfo(SaveInfo & save);
|
||||
|
||||
SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, std::string _userName, std::string _name);
|
||||
SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, ByteString _userName, String _name);
|
||||
|
||||
SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, int _vote, std::string _userName, std::string _name, std::string description_, bool published_, std::list<std::string> tags);
|
||||
SaveInfo(int _id, int _createdDate, int _updatedDate, int _votesUp, int _votesDown, int _vote, ByteString _userName, String _name, String description_, bool published_, std::list<ByteString> tags);
|
||||
|
||||
~SaveInfo();
|
||||
|
||||
void SetName(std::string name);
|
||||
std::string GetName();
|
||||
void SetName(String name);
|
||||
String GetName();
|
||||
|
||||
void SetDescription(std::string description);
|
||||
std::string GetDescription();
|
||||
void SetDescription(String description);
|
||||
String GetDescription();
|
||||
|
||||
void SetPublished(bool published);
|
||||
bool GetPublished();
|
||||
|
||||
void SetUserName(std::string userName);
|
||||
std::string GetUserName();
|
||||
void SetUserName(ByteString userName);
|
||||
ByteString GetUserName();
|
||||
|
||||
void SetID(int id);
|
||||
int GetID();
|
||||
@ -67,8 +67,8 @@ public:
|
||||
void SetVersion(int version);
|
||||
int GetVersion();
|
||||
|
||||
void SetTags(std::list<std::string> tags);
|
||||
std::list<std::string> GetTags();
|
||||
void SetTags(std::list<ByteString> tags);
|
||||
std::list<ByteString> GetTags();
|
||||
|
||||
GameSave * GetGameSave();
|
||||
void SetGameSave(GameSave * gameSave);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef USER_H_
|
||||
#define USER_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
|
||||
class User
|
||||
@ -12,11 +12,11 @@ public:
|
||||
ElevationAdmin, ElevationModerator, ElevationNone
|
||||
};
|
||||
int UserID;
|
||||
std::string Username;
|
||||
std::string SessionID;
|
||||
std::string SessionKey;
|
||||
ByteString Username;
|
||||
ByteString SessionID;
|
||||
ByteString SessionKey;
|
||||
Elevation UserElevation;
|
||||
User(int id, std::string username):
|
||||
User(int id, ByteString username):
|
||||
UserID(id),
|
||||
Username(username),
|
||||
SessionID(""),
|
||||
|
@ -1,17 +1,17 @@
|
||||
#ifndef USERINFO_H_
|
||||
#define USERINFO_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
class UserInfo
|
||||
{
|
||||
public:
|
||||
int UserID;
|
||||
int age;
|
||||
std::string username;
|
||||
std::string biography;
|
||||
std::string location;
|
||||
std::string website;
|
||||
ByteString username;
|
||||
String biography;
|
||||
String location;
|
||||
ByteString website;
|
||||
|
||||
int saveCount;
|
||||
float averageScore;
|
||||
@ -21,7 +21,7 @@ public:
|
||||
int topicReplies;
|
||||
int reputation;
|
||||
|
||||
UserInfo(int id, int age, std::string username, std::string biography, std::string location, std::string website, int saveCount, float averageScore, int highestScore, int topicCount, int topicReplies, int reputation):
|
||||
UserInfo(int id, int age, ByteString username, String biography, String location, ByteString website, int saveCount, float averageScore, int highestScore, int topicCount, int topicReplies, int reputation):
|
||||
UserID(id),
|
||||
age(age),
|
||||
username(username),
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "client/HTTP.h"
|
||||
#include "APIResultParser.h"
|
||||
|
||||
APIRequest::APIRequest(std::string url, APIResultParser * parser, ListenerHandle listener, int identifier):
|
||||
APIRequest::APIRequest(ByteString url, APIResultParser * parser, ListenerHandle listener, int identifier):
|
||||
RequestBroker::Request(API, listener, identifier)
|
||||
{
|
||||
Post = false;
|
||||
@ -18,7 +18,7 @@ APIRequest::APIRequest(std::string url, APIResultParser * parser, ListenerHandle
|
||||
URL = url;
|
||||
}
|
||||
|
||||
APIRequest::APIRequest(std::string url, std::map<std::string, std::string> postData, APIResultParser * parser, ListenerHandle listener, int identifier):
|
||||
APIRequest::APIRequest(ByteString url, std::map<ByteString, ByteString> postData, APIResultParser * parser, ListenerHandle listener, int identifier):
|
||||
RequestBroker::Request(API, listener, identifier)
|
||||
{
|
||||
Post = true;
|
||||
@ -81,11 +81,11 @@ RequestBroker::ProcessResponse APIRequest::Process(RequestBroker & rb)
|
||||
int * postLength = new int[PostData.size()];
|
||||
|
||||
int i = 0;
|
||||
std::map<std::string, std::string>::iterator iter = PostData.begin();
|
||||
std::map<ByteString, ByteString>::iterator iter = PostData.begin();
|
||||
while(iter != PostData.end())
|
||||
{
|
||||
std::string name = iter->first;
|
||||
std::string data = iter->second;
|
||||
ByteString name = iter->first;
|
||||
ByteString data = iter->second;
|
||||
char * cName = new char[name.length() + 1];
|
||||
char * cData = new char[data.length() + 1];
|
||||
std::strcpy(cName, name.c_str());
|
||||
@ -103,7 +103,7 @@ RequestBroker::ProcessResponse APIRequest::Process(RequestBroker & rb)
|
||||
User user = Client::Ref().GetAuthUser();
|
||||
char userName[12];
|
||||
char *userSession = new char[user.SessionID.length() + 1];
|
||||
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
|
||||
std::strcpy(userName, format::NumberToByteString<int>(user.UserID).c_str());
|
||||
std::strcpy(userSession, user.SessionID.c_str());
|
||||
HTTPContext = http_multipart_post_async((char*)URL.c_str(), postNames, postData, postLength, userName, NULL, userSession);
|
||||
delete[] userSession;
|
||||
@ -122,7 +122,7 @@ RequestBroker::ProcessResponse APIRequest::Process(RequestBroker & rb)
|
||||
User user = Client::Ref().GetAuthUser();
|
||||
char userName[12];
|
||||
char *userSession = new char[user.SessionID.length() + 1];
|
||||
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
|
||||
std::strcpy(userName, format::NumberToByteString<int>(user.UserID).c_str());
|
||||
std::strcpy(userSession, user.SessionID.c_str());
|
||||
http_auth_headers(HTTPContext, userName, NULL, userSession);
|
||||
delete[] userSession;
|
||||
|
@ -7,11 +7,11 @@ class APIRequest: public RequestBroker::Request
|
||||
public:
|
||||
bool Post;
|
||||
APIResultParser * Parser;
|
||||
std::string URL;
|
||||
std::map<std::string, std::string> PostData;
|
||||
ByteString URL;
|
||||
std::map<ByteString, ByteString> PostData;
|
||||
void * HTTPContext;
|
||||
APIRequest(std::string url, APIResultParser * parser, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
APIRequest(std::string url, std::map<std::string, std::string>, APIResultParser * parser, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
APIRequest(ByteString url, APIResultParser * parser, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
APIRequest(ByteString url, std::map<ByteString, ByteString>, APIResultParser * parser, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
virtual RequestBroker::ProcessResponse Process(RequestBroker & rb);
|
||||
virtual ~APIRequest();
|
||||
virtual void Cleanup();
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "graphics/Graphics.h"
|
||||
#include "client/HTTP.h"
|
||||
|
||||
ImageRequest::ImageRequest(std::string url, int width, int height, ListenerHandle listener, int identifier):
|
||||
ImageRequest::ImageRequest(ByteString url, int width, int height, ListenerHandle listener, int identifier):
|
||||
Request(Image, listener, identifier)
|
||||
{
|
||||
URL = url;
|
||||
@ -24,7 +24,7 @@ RequestBroker::ProcessResponse ImageRequest::Process(RequestBroker & rb)
|
||||
VideoBuffer * image = NULL;
|
||||
|
||||
//Have a look at the thumbnail cache
|
||||
for(std::deque<std::pair<std::string, VideoBuffer*> >::iterator iter = rb.imageCache.begin(), end = rb.imageCache.end(); iter != end; ++iter)
|
||||
for(std::deque<std::pair<ByteString, VideoBuffer*> >::iterator iter = rb.imageCache.begin(), end = rb.imageCache.end(); iter != end; ++iter)
|
||||
{
|
||||
if((*iter).first == URL)
|
||||
{
|
||||
@ -71,7 +71,7 @@ RequestBroker::ProcessResponse ImageRequest::Process(RequestBroker & rb)
|
||||
delete rb.imageCache.front().second;
|
||||
rb.imageCache.pop_front();
|
||||
}
|
||||
rb.imageCache.push_back(std::pair<std::string, VideoBuffer*>(URL, image));
|
||||
rb.imageCache.push_back(std::pair<ByteString, VideoBuffer*>(URL, image));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4,11 +4,11 @@ class ImageRequest: public RequestBroker::Request
|
||||
{
|
||||
public:
|
||||
int Width, Height;
|
||||
std::string URL;
|
||||
ByteString URL;
|
||||
int RequestTime;
|
||||
void * HTTPContext;
|
||||
bool started = false;
|
||||
ImageRequest(std::string url, int width, int height, ListenerHandle listener, int identifier = 0);
|
||||
ImageRequest(ByteString url, int width, int height, ListenerHandle listener, int identifier = 0);
|
||||
virtual RequestBroker::ProcessResponse Process(RequestBroker & rb);
|
||||
virtual ~ImageRequest();
|
||||
virtual void Cleanup();
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include "RequestBroker.h"
|
||||
#include "RequestListener.h"
|
||||
@ -35,7 +34,7 @@ RequestBroker::RequestBroker()
|
||||
|
||||
RequestBroker::~RequestBroker()
|
||||
{
|
||||
for(std::deque<std::pair<std::string, VideoBuffer*> >::iterator iter = imageCache.begin(), end = imageCache.end(); iter != end; ++iter)
|
||||
for(std::deque<std::pair<ByteString, VideoBuffer*> >::iterator iter = imageCache.begin(), end = imageCache.end(); iter != end; ++iter)
|
||||
{
|
||||
delete (*iter).second;
|
||||
}
|
||||
@ -98,7 +97,7 @@ void RequestBroker::RenderThumbnail(GameSave * gameSave, bool decorations, bool
|
||||
|
||||
void RequestBroker::RetrieveThumbnail(int saveID, int saveDate, int width, int height, RequestListener * tListener)
|
||||
{
|
||||
std::stringstream urlStream;
|
||||
ByteString::Stream urlStream;
|
||||
urlStream << "http://" << STATICSERVER << "/" << saveID;
|
||||
if(saveDate)
|
||||
{
|
||||
@ -109,9 +108,9 @@ void RequestBroker::RetrieveThumbnail(int saveID, int saveDate, int width, int h
|
||||
RetrieveImage(urlStream.str(), width, height, tListener);
|
||||
}
|
||||
|
||||
void RequestBroker::RetrieveAvatar(std::string username, int width, int height, RequestListener * tListener)
|
||||
void RequestBroker::RetrieveAvatar(ByteString username, int width, int height, RequestListener * tListener)
|
||||
{
|
||||
std::stringstream urlStream;
|
||||
ByteString::Stream urlStream;
|
||||
urlStream << "http://" << STATICSERVER << "/avatars/" << username << ".pti";
|
||||
|
||||
RetrieveImage(urlStream.str(), width, height, tListener);
|
||||
@ -130,7 +129,7 @@ void RequestBroker::Start(Request * request, RequestListener * tListener, int id
|
||||
assureRunning();
|
||||
}
|
||||
|
||||
void RequestBroker::RetrieveImage(std::string imageUrl, int width, int height, RequestListener * tListener)
|
||||
void RequestBroker::RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener)
|
||||
{
|
||||
ListenerHandle handle = AttachRequestListener(tListener);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <list>
|
||||
#include <utility>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "common/tpt-thread.h"
|
||||
|
||||
#include "Config.h"
|
||||
@ -33,7 +33,7 @@ private:
|
||||
|
||||
std::vector<ListenerHandle> validListeners;
|
||||
|
||||
std::deque<std::pair<std::string, VideoBuffer*> > imageCache;
|
||||
std::deque<std::pair<ByteString, VideoBuffer*> > imageCache;
|
||||
|
||||
std::queue<Request*> completeQueue;
|
||||
std::vector<Request*> requestQueue;
|
||||
@ -51,12 +51,12 @@ public:
|
||||
void Shutdown();
|
||||
|
||||
void FlushThumbQueue();
|
||||
void RetrieveImage(std::string imageUrl, int width, int height, RequestListener * tListener);
|
||||
void RetrieveImage(ByteString imageUrl, int width, int height, RequestListener * tListener);
|
||||
void RenderThumbnail(GameSave * gameSave, bool decorations, bool fire, int width, int height, RequestListener * tListener);
|
||||
void RenderThumbnail(GameSave * gameSave, int width, int height, RequestListener * tListener);
|
||||
void RetrieveThumbnail(int saveID, int saveDate, int width, int height, RequestListener * tListener);
|
||||
void RetrieveThumbnail(int saveID, int width, int height, RequestListener * tListener);
|
||||
void RetrieveAvatar(std::string username, int width, int height, RequestListener * tListener);
|
||||
void RetrieveAvatar(ByteString username, int width, int height, RequestListener * tListener);
|
||||
void Start(Request * request, RequestListener * tLIstener, int identifier = 0);
|
||||
|
||||
bool CheckRequestListener(ListenerHandle handle);
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "client/HTTP.h"
|
||||
#include "APIResultParser.h"
|
||||
|
||||
WebRequest::WebRequest(std::string url, ListenerHandle listener, int identifier):
|
||||
WebRequest::WebRequest(ByteString url, ListenerHandle listener, int identifier):
|
||||
RequestBroker::Request(API, listener, identifier)
|
||||
{
|
||||
Post = false;
|
||||
@ -18,7 +18,7 @@ WebRequest::WebRequest(std::string url, ListenerHandle listener, int identifier)
|
||||
URL = url;
|
||||
}
|
||||
|
||||
WebRequest::WebRequest(std::string url, std::map<std::string, std::string> postData, ListenerHandle listener, int identifier):
|
||||
WebRequest::WebRequest(ByteString url, std::map<ByteString, ByteString> postData, ListenerHandle listener, int identifier):
|
||||
RequestBroker::Request(API, listener, identifier)
|
||||
{
|
||||
Post = true;
|
||||
@ -81,11 +81,11 @@ RequestBroker::ProcessResponse WebRequest::Process(RequestBroker & rb)
|
||||
int * postLength = new int[PostData.size()];
|
||||
|
||||
int i = 0;
|
||||
std::map<std::string, std::string>::iterator iter = PostData.begin();
|
||||
std::map<ByteString, ByteString>::iterator iter = PostData.begin();
|
||||
while(iter != PostData.end())
|
||||
{
|
||||
std::string name = iter->first;
|
||||
std::string data = iter->second;
|
||||
ByteString name = iter->first;
|
||||
ByteString data = iter->second;
|
||||
char * cName = new char[name.length() + 1];
|
||||
char * cData = new char[data.length() + 1];
|
||||
std::strcpy(cName, name.c_str());
|
||||
@ -106,7 +106,7 @@ RequestBroker::ProcessResponse WebRequest::Process(RequestBroker & rb)
|
||||
User user = Client::Ref().GetAuthUser();
|
||||
char userName[12];
|
||||
char *userSession = new char[user.SessionID.length() + 1];
|
||||
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
|
||||
std::strcpy(userName, format::NumberToByteString<int>(user.UserID).c_str());
|
||||
std::strcpy(userSession, user.SessionID.c_str());
|
||||
HTTPContext = http_multipart_post_async((char*)URL.c_str(), postNames, postData, postLength, userName, NULL, userSession);
|
||||
delete[] userSession;
|
||||
@ -125,7 +125,7 @@ RequestBroker::ProcessResponse WebRequest::Process(RequestBroker & rb)
|
||||
User user = Client::Ref().GetAuthUser();
|
||||
char userName[12];
|
||||
char *userSession = new char[user.SessionID.length() + 1];
|
||||
std::strcpy(userName, format::NumberToString<int>(user.UserID).c_str());
|
||||
std::strcpy(userName, format::NumberToByteString<int>(user.UserID).c_str());
|
||||
std::strcpy(userSession, user.SessionID.c_str());
|
||||
http_auth_headers(HTTPContext, userName, NULL, userSession);
|
||||
delete[] userSession;
|
||||
|
@ -5,11 +5,11 @@ class WebRequest: public RequestBroker::Request
|
||||
{
|
||||
public:
|
||||
bool Post;
|
||||
std::string URL;
|
||||
std::map<std::string, std::string> PostData;
|
||||
ByteString URL;
|
||||
std::map<ByteString, ByteString> PostData;
|
||||
void * HTTPContext;
|
||||
WebRequest(std::string url, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
WebRequest(std::string url, std::map<std::string, std::string>, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
WebRequest(ByteString url, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
WebRequest(ByteString url, std::map<ByteString, ByteString>, ListenerHandle listener = ListenerHandle(0, (RequestListener*)0), int identifier = 0);
|
||||
virtual RequestBroker::ProcessResponse Process(RequestBroker & rb);
|
||||
virtual ~WebRequest();
|
||||
virtual void Cleanup();
|
||||
|
@ -87,3 +87,135 @@ ByteString String::ToUtf8() const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<> std::ctype<char32_t>::~ctype()
|
||||
{
|
||||
}
|
||||
template<> std::numpunct<char32_t>::numpunct(size_t ref): std::locale::facet(ref)
|
||||
{
|
||||
}
|
||||
template<> std::numpunct<char32_t>::~numpunct()
|
||||
{
|
||||
}
|
||||
|
||||
static struct Locale32Impl
|
||||
{
|
||||
std::ctype<wchar_t> const &ctype16;
|
||||
std::numpunct<wchar_t> const &numpunct16;
|
||||
Locale32Impl():
|
||||
ctype16(std::use_facet<std::ctype<wchar_t> >(std::locale())),
|
||||
numpunct16(std::use_facet<std::numpunct<wchar_t> >(std::locale()))
|
||||
{
|
||||
std::locale::global(std::locale(std::locale(), new std::ctype<char32_t>()));
|
||||
std::locale::global(std::locale(std::locale(), new std::numpunct<char32_t>()));
|
||||
std::locale::global(std::locale(std::locale(), new std::num_put<char32_t>()));
|
||||
}
|
||||
}
|
||||
Locale32Impl;
|
||||
|
||||
template<> bool std::ctype<char32_t>::do_is(mask m, char32_t ch) const
|
||||
{
|
||||
return ch <= 0xFFFF ? Locale32Impl.ctype16.is(m, ch) : (m & print);
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_is(char32_t const *low, char32_t const *high, mask *vec) const
|
||||
{
|
||||
while(low < high)
|
||||
{
|
||||
if(*low <= 0xFFFF)
|
||||
{
|
||||
wchar_t l = *low;
|
||||
Locale32Impl.ctype16.is(&l, &l + 1, vec);
|
||||
}
|
||||
else
|
||||
*vec = print;
|
||||
low++;
|
||||
}
|
||||
return high;
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_scan_is(mask m, char32_t const *beg, char32_t const *end) const
|
||||
{
|
||||
while(beg < end)
|
||||
if(do_is(m, *beg))
|
||||
return beg;
|
||||
else
|
||||
beg++;
|
||||
return end;
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_scan_not(mask m, char32_t const *beg, char32_t const *end) const
|
||||
{
|
||||
while(beg < end)
|
||||
if(!do_is(m, *beg))
|
||||
return beg;
|
||||
else
|
||||
beg++;
|
||||
return end;
|
||||
}
|
||||
template<> char32_t std::ctype<char32_t>::do_toupper(char32_t ch) const
|
||||
{
|
||||
return ch <= 0xFFFF ? Locale32Impl.ctype16.toupper(ch) : ch;
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_toupper(char32_t *beg, char32_t const *end) const
|
||||
{
|
||||
while(beg < end)
|
||||
{
|
||||
*beg = do_toupper(*beg);
|
||||
beg++;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
template<> char32_t std::ctype<char32_t>::do_tolower(char32_t ch) const
|
||||
{
|
||||
return ch <= 0xFFFF ? Locale32Impl.ctype16.tolower(ch) : ch;
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_tolower(char32_t *beg, char32_t const *end) const
|
||||
{
|
||||
while(beg < end)
|
||||
{
|
||||
*beg = do_tolower(*beg);
|
||||
beg++;
|
||||
}
|
||||
return end;
|
||||
}
|
||||
template<> char32_t std::ctype<char32_t>::do_widen(char ch) const
|
||||
{
|
||||
return Locale32Impl.ctype16.widen(ch);
|
||||
}
|
||||
template<> char const *std::ctype<char32_t>::do_widen(char const *beg, char const *end, char32_t *dst) const
|
||||
{
|
||||
while(beg < end)
|
||||
*(dst++) = do_widen(*(beg++));
|
||||
return end;
|
||||
}
|
||||
template<> char std::ctype<char32_t>::do_narrow(char32_t ch, char dflt) const
|
||||
{
|
||||
return ch <= 0xFFFF ? Locale32Impl.ctype16.narrow(ch, dflt) : dflt;
|
||||
}
|
||||
template<> char32_t const *std::ctype<char32_t>::do_narrow(char32_t const *beg, char32_t const *end, char dflt, char *dst) const
|
||||
{
|
||||
while(beg < end)
|
||||
*(dst++) = do_narrow(*(beg++), dflt);
|
||||
return end;
|
||||
}
|
||||
|
||||
template<> char32_t std::numpunct<char32_t>::do_decimal_point() const
|
||||
{
|
||||
return Locale32Impl.numpunct16.decimal_point();
|
||||
}
|
||||
template<> char32_t std::numpunct<char32_t>::do_thousands_sep() const
|
||||
{
|
||||
return Locale32Impl.numpunct16.thousands_sep();
|
||||
}
|
||||
template<> std::string std::numpunct<char32_t>::do_grouping() const
|
||||
{
|
||||
return Locale32Impl.numpunct16.grouping();
|
||||
}
|
||||
template<> std::basic_string<char32_t> std::numpunct<char32_t>::do_truename() const
|
||||
{
|
||||
std::basic_string<wchar_t> name = Locale32Impl.numpunct16.truename();
|
||||
return std::basic_string<char32_t>(name.begin(), name.end());
|
||||
}
|
||||
template<> std::basic_string<char32_t> std::numpunct<char32_t>::do_falsename() const
|
||||
{
|
||||
std::basic_string<wchar_t> name = Locale32Impl.numpunct16.falsename();
|
||||
return std::basic_string<char32_t>(name.begin(), name.end());
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef TPT_STRING
|
||||
#define TPT_STRING
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
class String;
|
||||
@ -13,11 +15,18 @@ public:
|
||||
inline ByteString(value_type const *ch, size_type count): std::basic_string<char>(ch, count) {}
|
||||
inline ByteString(value_type const *ch): std::basic_string<char>(ch) {}
|
||||
template<class It> inline ByteString(It first, It last): std::basic_string<char>(first, last) {}
|
||||
inline ByteString(std::basic_string<char> const &other): std::basic_string<char>(other) {}
|
||||
inline ByteString(std::basic_string<char> &&other): std::basic_string<char>(std::move(other)) {}
|
||||
inline ByteString(ByteString const &other): std::basic_string<char>(other) {}
|
||||
inline ByteString(ByteString &&other): std::basic_string<char>(std::move(other)) {}
|
||||
|
||||
ByteString &operator=(ByteString const &other) { std::basic_string<char>::operator=(other); return *this; }
|
||||
ByteString &operator=(ByteString &&other) { std::basic_string<char>::operator=(std::move(other)); return *this; }
|
||||
inline ByteString &operator=(ByteString const &other) { std::basic_string<char>::operator=(other); return *this; }
|
||||
inline ByteString &operator=(ByteString &&other) { std::basic_string<char>::operator=(std::move(other)); return *this; }
|
||||
|
||||
template<typename T> ByteString &operator+=(T &&other) { std::basic_string<char>::operator+=(std::forward<T>(other)); return *this; }
|
||||
template<typename T> inline ByteString operator+(T &&other) const { ByteString tmp = *this; tmp += std::forward<T>(other); return tmp; }
|
||||
template<typename... Ts> ByteString substr(Ts&&... args) const { return std::basic_string<char>::substr(std::forward<Ts>(args)...); }
|
||||
template<typename... Ts> ByteString &insert(Ts&&... args) { std::basic_string<char>::insert(std::forward<Ts>(args)...); return *this; }
|
||||
|
||||
class ConversionError : public std::runtime_error
|
||||
{
|
||||
@ -29,8 +38,14 @@ public:
|
||||
|
||||
String FromUtf8(bool ignoreError = true) const;
|
||||
inline String FromAscii() const;
|
||||
|
||||
using Stream = std::basic_stringstream<value_type>;
|
||||
};
|
||||
|
||||
inline ByteString operator+(ByteString::value_type const *ch, ByteString const &str) { return ByteString(ch) + str; }
|
||||
inline ByteString operator+(std::basic_string<char> const &other, ByteString const &str) { return ByteString(other) + str; }
|
||||
inline ByteString operator+(std::basic_string<char> &&other, ByteString const &str) { return ByteString(std::move(other)) + str; }
|
||||
|
||||
class String : public std::basic_string<char32_t>
|
||||
{
|
||||
public:
|
||||
@ -39,22 +54,52 @@ public:
|
||||
inline String(value_type const *ch, size_type count): std::basic_string<char32_t>(ch, count) {}
|
||||
inline String(value_type const *ch): std::basic_string<char32_t>(ch) {}
|
||||
template<class It> inline String(It first, It last): std::basic_string<char32_t>(first, last) {}
|
||||
inline String(std::basic_string<char32_t> const &other): std::basic_string<char32_t>(other) {}
|
||||
inline String(std::basic_string<char32_t> &&other): std::basic_string<char32_t>(std::move(other)) {}
|
||||
inline String(String const &other): std::basic_string<char32_t>(other) {}
|
||||
inline String(String &&other): std::basic_string<char32_t>(std::move(other)) {}
|
||||
template<unsigned N> inline String(ByteString::value_type const (&ch)[N]): std::basic_string<char32_t>(ByteString(ch, N - 1).FromAscii()) {}
|
||||
|
||||
String &operator=(String const &other) { std::basic_string<char32_t>::operator=(other); return *this; }
|
||||
String &operator=(String &&other) { std::basic_string<char32_t>::operator=(std::move(other)); return *this; }
|
||||
inline String &operator=(String const &other) { std::basic_string<char32_t>::operator=(other); return *this; }
|
||||
inline String &operator=(String &&other) { std::basic_string<char32_t>::operator=(other); return *this; }
|
||||
|
||||
template<typename T> inline String &operator+=(T &&other) { std::basic_string<char32_t>::operator+=(std::forward<T>(other)); return *this; }
|
||||
template<unsigned N> inline String &operator+=(ByteString::value_type const (&ch)[N]) { std::basic_string<char32_t>::operator+=(ByteString(ch, N - 1).FromAscii()); return *this; }
|
||||
template<typename T> inline String operator+(T &&other) const { String tmp = *this; tmp += std::forward<T>(other); return tmp; }
|
||||
template<typename... Ts> inline String substr(Ts&&... args) const { return std::basic_string<char32_t>::substr(std::forward<Ts>(args)...); }
|
||||
inline String &insert(size_t pos, String &str) { std::basic_string<char32_t>::insert(pos, str); return *this; }
|
||||
inline String &insert(size_t pos, size_t n, value_type ch) { std::basic_string<char32_t>::insert(pos, n, ch); return *this; }
|
||||
template<unsigned N> inline String &insert(size_t pos, ByteString::value_type const (&ch)[N]) { std::basic_string<char32_t>::insert(pos, ByteString(ch, N - 1).FromAscii()); return *this; }
|
||||
inline size_t find(String const &str, size_t pos = 0) { return std::basic_string<char32_t>::find(str, pos); }
|
||||
inline size_t find(value_type ch, size_t pos = 0) { return std::basic_string<char32_t>::find(ch, pos); }
|
||||
|
||||
template<unsigned N> inline String(ByteString::value_type const (&ch)[N]): std::basic_string<char32_t>(ByteString(ch, N).FromAscii()) {}
|
||||
inline bool operator==(String const &other) { return std::basic_string<char32_t>(*this) == other; }
|
||||
|
||||
ByteString ToUtf8() const;
|
||||
ByteString ToAscii() const;
|
||||
|
||||
using Stream = std::basic_stringstream<value_type>;
|
||||
};
|
||||
|
||||
inline String operator+(String::value_type const *ch, String const &str) { return String(ch) + str; }
|
||||
inline String operator+(std::basic_string<char32_t> const &other, String const &str) { return String(other) + str; }
|
||||
inline String operator+(std::basic_string<char32_t> &&other, String const &str) { return String(std::move(other)) + str; }
|
||||
template<unsigned N> inline String operator+(ByteString::value_type const (&ch)[N], String const &str) { return String(ch) + str; }
|
||||
|
||||
|
||||
inline String ByteString::FromAscii() const
|
||||
{
|
||||
String destination = String(size(), String::value_type());
|
||||
for(size_t i = 0; i < size(); i++)
|
||||
destination[i] = typename String::value_type(operator[](i));
|
||||
destination[i] = String::value_type(std::make_unsigned<ByteString::value_type>::type(operator[](i)));
|
||||
return destination;
|
||||
}
|
||||
|
||||
inline ByteString String::ToAscii() const
|
||||
{
|
||||
ByteString destination = ByteString(size(), ByteString::value_type());
|
||||
for(size_t i = 0; i < size(); i++)
|
||||
destination[i] = ByteString::value_type(operator[](i));
|
||||
return destination;
|
||||
}
|
||||
#endif
|
||||
|
@ -27,21 +27,21 @@ void DebugLines::Draw()
|
||||
g->draw_line(0, drawPoint2.Y, XRES, drawPoint2.Y, 255, 255, 255, 120);
|
||||
g->draw_line(drawPoint2.X, 0, drawPoint2.X, YRES, 255, 255, 255, 120);
|
||||
|
||||
std::stringstream info;
|
||||
String::Stream info;
|
||||
info << drawPoint2.X << " x " << drawPoint2.Y;
|
||||
g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info.str().c_str())-3), drawPoint2.Y+(drawPoint2.Y<drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
|
||||
g->drawtext_outline(drawPoint2.X+(drawPoint2.X>drawPoint1.X?3:-g->textwidth(info.str())-3), drawPoint2.Y+(drawPoint2.Y<drawPoint1.Y?-10:3), info.str(), 255, 255, 255, 200);
|
||||
|
||||
info.str("");
|
||||
info.str(String());
|
||||
info << drawPoint1.X << " x " << drawPoint1.Y;
|
||||
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str().c_str())-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
|
||||
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str())-2), drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str(), 255, 255, 255, 200);
|
||||
|
||||
info.str("");
|
||||
info.str(String());
|
||||
info << std::abs(drawPoint2.X-drawPoint1.X);
|
||||
g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info.str().c_str())/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str().c_str(), 255, 255, 255, 200);
|
||||
g->drawtext_outline((drawPoint1.X+drawPoint2.X)/2-g->textwidth(info.str())/2, drawPoint1.Y+(drawPoint2.Y>drawPoint1.Y?-10:3), info.str(), 255, 255, 255, 200);
|
||||
|
||||
info.str("");
|
||||
info.str(String());
|
||||
info << std::abs(drawPoint2.Y-drawPoint1.Y);
|
||||
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str().c_str())-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info.str().c_str(), 255, 255, 255, 200);
|
||||
g->drawtext_outline(drawPoint1.X+(drawPoint2.X<drawPoint1.X?3:-g->textwidth(info.str())-2), (drawPoint1.Y+drawPoint2.Y)/2-3, info.str(), 255, 255, 255, 200);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "DebugParts.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
#include "simulation/Simulation.h"
|
||||
@ -16,7 +15,7 @@ void DebugParts::Draw()
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
|
||||
int x = 0, y = 0, lpx = 0, lpy = 0;
|
||||
std::stringstream info;
|
||||
String::Stream info;
|
||||
info << sim->parts_lastActiveIndex << "/" << NPART << " (" << std::fixed << std::setprecision(2) << (float)sim->parts_lastActiveIndex/(NPART)*100.0f << "%)";
|
||||
for (int i = 0; i < NPART; i++)
|
||||
{
|
||||
@ -46,8 +45,8 @@ void DebugParts::Draw()
|
||||
g->addpixel(lpx, lpy+1, 255, 50, 50, 120);
|
||||
g->addpixel(lpx, lpy-1, 255, 50, 50, 120);
|
||||
|
||||
g->fillrect(7, YRES-26, g->textwidth(info.str().c_str())+5, 14, 0, 0, 0, 180);
|
||||
g->drawtext(10, YRES-22, info.str().c_str(), 255, 255, 255, 255);
|
||||
g->fillrect(7, YRES-26, g->textwidth(info.str())+5, 14, 0, 0, 0, 180);
|
||||
g->drawtext(10, YRES-22, info.str(), 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
DebugParts::~DebugParts()
|
||||
|
@ -18,8 +18,8 @@ void ElementPopulationDebug::Draw()
|
||||
int yBottom = YRES-10;
|
||||
int xStart = 10;
|
||||
|
||||
std::string maxValString;
|
||||
std::string halfValString;
|
||||
String maxValString;
|
||||
String halfValString;
|
||||
|
||||
|
||||
float maxVal = 255;
|
||||
@ -41,7 +41,7 @@ void ElementPopulationDebug::Draw()
|
||||
halfValString = format::NumberToString<int>(maxAverage/2);
|
||||
|
||||
|
||||
g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString.c_str())+10, 255 + 13, 0, 0, 0, 180);
|
||||
g->fillrect(xStart-5, yBottom - 263, bars+10+Graphics::textwidth(maxValString)+10, 255 + 13, 0, 0, 0, 180);
|
||||
|
||||
bars = 0;
|
||||
for(int i = 0; i < PT_NUM; i++)
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <sstream>
|
||||
#include "ParticleDebug.h"
|
||||
#include "gui/interface/Engine.h"
|
||||
#include "gui/game/GameView.h"
|
||||
@ -16,7 +15,7 @@ void ParticleDebug::Debug(int mode, int x, int y)
|
||||
{
|
||||
int debug_currentParticle = sim->debug_currentParticle;
|
||||
int i = 0;
|
||||
std::stringstream logmessage;
|
||||
String::Stream logmessage;
|
||||
|
||||
if (mode == 0)
|
||||
{
|
||||
@ -90,7 +89,7 @@ bool ParticleDebug::KeyPress(int key, Uint16 character, bool shift, bool ctrl, b
|
||||
{
|
||||
sim->UpdateParticles(sim->debug_currentParticle, NPART);
|
||||
sim->AfterSim();
|
||||
std::stringstream logmessage;
|
||||
String::Stream logmessage;
|
||||
logmessage << "Updated particles from #" << sim->debug_currentParticle << " to end, updated sim";
|
||||
model->Log(logmessage.str(), false);
|
||||
sim->debug_currentParticle = 0;
|
||||
|
@ -1,7 +1,6 @@
|
||||
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, String s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
|
||||
void xor_pixel(int x, int y);
|
||||
void xor_line(int x, int y, int x2, int y2);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <bzlib.h>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Config.h"
|
||||
#include "Misc.h"
|
||||
#include "Graphics.h"
|
||||
@ -566,9 +566,10 @@ pixel *Graphics::rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f
|
||||
return q;
|
||||
}
|
||||
|
||||
int Graphics::textwidth(const char *s)
|
||||
int Graphics::textwidth(String str)
|
||||
{
|
||||
int x = 0;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if(((char)*s)=='\b')
|
||||
@ -581,19 +582,20 @@ int Graphics::textwidth(const char *s)
|
||||
s+=3;
|
||||
continue;
|
||||
}
|
||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
x += font_data[font_ptrs[*s]];
|
||||
}
|
||||
return x-1;
|
||||
}
|
||||
|
||||
int Graphics::CharWidth(unsigned char c)
|
||||
int Graphics::CharWidth(String::value_type c)
|
||||
{
|
||||
return font_data[font_ptrs[(int)c]];
|
||||
}
|
||||
|
||||
int Graphics::textnwidth(char *s, int n)
|
||||
int Graphics::textnwidth(String str, int n)
|
||||
{
|
||||
int x = 0;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (!n)
|
||||
@ -608,20 +610,23 @@ int Graphics::textnwidth(char *s, int n)
|
||||
s+=3;
|
||||
continue;
|
||||
}
|
||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
x += font_data[font_ptrs[*s]];
|
||||
n--;
|
||||
}
|
||||
return x-1;
|
||||
}
|
||||
|
||||
void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||
void Graphics::textnpos(String str, int n, int w, int *cx, int *cy)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int wordlen, charspace;
|
||||
String::value_type const *s = str.c_str();
|
||||
while (*s&&n)
|
||||
{
|
||||
wordlen = strcspn(s," .,!?\n");
|
||||
wordlen = 0;
|
||||
while(*s && String(" .,!?\n").find(*s) != String::npos)
|
||||
s++;
|
||||
charspace = textwidthx(s, w-x);
|
||||
if (charspace<wordlen && wordlen && w-x<w/3)
|
||||
{
|
||||
@ -633,7 +638,7 @@ void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||
if (!n) {
|
||||
break;
|
||||
}
|
||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
x += font_data[font_ptrs[*s]];
|
||||
if (x>=w)
|
||||
{
|
||||
x = 0;
|
||||
@ -646,9 +651,10 @@ void Graphics::textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||
*cy = y;
|
||||
}
|
||||
|
||||
int Graphics::textwidthx(char *s, int w)
|
||||
int Graphics::textwidthx(String str, int w)
|
||||
{
|
||||
int x=0,n=0,cw;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if((char)*s == '\b')
|
||||
@ -662,7 +668,7 @@ int Graphics::textwidthx(char *s, int w)
|
||||
s+=3;
|
||||
continue;
|
||||
}
|
||||
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
cw = font_data[font_ptrs[*s]];
|
||||
if (x+(cw/2) >= w)
|
||||
break;
|
||||
x += cw;
|
||||
@ -671,9 +677,10 @@ int Graphics::textwidthx(char *s, int w)
|
||||
return n;
|
||||
}
|
||||
|
||||
int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY)
|
||||
int Graphics::PositionAtCharIndex(String str, int charIndex, int & positionX, int & positionY)
|
||||
{
|
||||
int x = 0, y = 0, lines = 1;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (!charIndex)
|
||||
@ -695,7 +702,7 @@ int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int &
|
||||
charIndex-=4;
|
||||
continue;
|
||||
}
|
||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
x += font_data[font_ptrs[*s]];
|
||||
charIndex--;
|
||||
}
|
||||
positionX = x;
|
||||
@ -703,9 +710,10 @@ int Graphics::PositionAtCharIndex(char *s, int charIndex, int & positionX, int &
|
||||
return lines;
|
||||
}
|
||||
|
||||
int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY)
|
||||
int Graphics::CharIndexAtPosition(String str, int positionX, int positionY)
|
||||
{
|
||||
int x=0, y=-2,charIndex=0,cw;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if(*s == '\n') {
|
||||
@ -724,7 +732,7 @@ int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY)
|
||||
charIndex+=4;
|
||||
continue;
|
||||
}
|
||||
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
cw = font_data[font_ptrs[*s]];
|
||||
if ((x+(cw/2) >= positionX && y+FONT_H >= positionY) || y > positionY)
|
||||
break;
|
||||
x += cw;
|
||||
@ -734,14 +742,17 @@ int Graphics::CharIndexAtPosition(char *s, int positionX, int positionY)
|
||||
}
|
||||
|
||||
|
||||
int Graphics::textwrapheight(char *s, int width)
|
||||
int Graphics::textwrapheight(String str, int width)
|
||||
{
|
||||
int x=0, height=FONT_H, cw;
|
||||
int wordlen;
|
||||
int charspace;
|
||||
String::value_type const *s = str.c_str();
|
||||
while (*s)
|
||||
{
|
||||
wordlen = strcspn(s," .,!?\n");
|
||||
wordlen = 0;
|
||||
while(*s && String(" .,!?\n").find(*s) != String::npos)
|
||||
s++;
|
||||
charspace = textwidthx(s, width-x);
|
||||
if (charspace<wordlen && wordlen && width-x<width/3)
|
||||
{
|
||||
@ -767,7 +778,7 @@ int Graphics::textwrapheight(char *s, int width)
|
||||
}
|
||||
else
|
||||
{
|
||||
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
cw = font_data[font_ptrs[*s]];
|
||||
if (x+cw>=width)
|
||||
{
|
||||
x = 0;
|
||||
@ -780,9 +791,9 @@ int Graphics::textwrapheight(char *s, int width)
|
||||
return height;
|
||||
}
|
||||
|
||||
void Graphics::textsize(const char * s, int & width, int & height)
|
||||
void Graphics::textsize(String str, int & width, int & height)
|
||||
{
|
||||
if(!strlen(s))
|
||||
if(!str.size())
|
||||
{
|
||||
width = 0;
|
||||
height = FONT_H-2;
|
||||
@ -790,6 +801,7 @@ void Graphics::textsize(const char * s, int & width, int & height)
|
||||
}
|
||||
|
||||
int cHeight = FONT_H-2, cWidth = 0, lWidth = 0;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (*s == '\n')
|
||||
@ -809,7 +821,7 @@ void Graphics::textsize(const char * s, int & width, int & height)
|
||||
}
|
||||
else
|
||||
{
|
||||
cWidth += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
cWidth += font_data[font_ptrs[*s]];
|
||||
if(cWidth>lWidth)
|
||||
lWidth = cWidth;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef GRAPHICS_H
|
||||
#define GRAPHICS_H
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
@ -116,15 +116,15 @@ public:
|
||||
static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
|
||||
|
||||
//Font/text metrics
|
||||
static int CharIndexAtPosition(char *s, int positionX, int positionY);
|
||||
static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY);
|
||||
static int CharWidth(unsigned char c);
|
||||
static int textnwidth(char *s, int n);
|
||||
static void textnpos(char *s, int n, int w, int *cx, int *cy);
|
||||
static int textwidthx(char *s, int w);
|
||||
static int textwrapheight(char *s, int width);
|
||||
static int textwidth(const char *s);
|
||||
static void textsize(const char * s, int & width, int & height);
|
||||
static int CharIndexAtPosition(String s, int positionX, int positionY);
|
||||
static int PositionAtCharIndex(String s, int charIndex, int & positionX, int & positionY);
|
||||
static int CharWidth(String::value_type c);
|
||||
static int textnwidth(String s, int n);
|
||||
static void textnpos(String s, int n, int w, int *cx, int *cy);
|
||||
static int textwidthx(String s, int w);
|
||||
static int textwrapheight(String s, int width);
|
||||
static int textwidth(String s);
|
||||
static void textsize(String s, int & width, int & height);
|
||||
|
||||
VideoBuffer DumpFrame();
|
||||
|
||||
@ -139,11 +139,10 @@ public:
|
||||
void Clear();
|
||||
void Finalise();
|
||||
//
|
||||
int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int drawtext_outline(int x, int y, String s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, String s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
|
||||
void xor_pixel(int x, int y);
|
||||
void xor_line(int x, int y, int x2, int y2);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "../data/font.h"
|
||||
#include <cmath>
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, String s, int r, int g, int b, int a)
|
||||
{
|
||||
drawtext(x-1, y-1, s, 0, 0, 0, 120);
|
||||
drawtext(x+1, y+1, s, 0, 0, 0, 120);
|
||||
@ -12,7 +12,7 @@ int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int
|
||||
return drawtext(x, y, s, r, g, b, a);
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, String str, int r, int g, int b, int a)
|
||||
{
|
||||
bool invert = false;
|
||||
if(!strlen(s))
|
||||
@ -23,6 +23,7 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
VideoBuffer texture(width, height);
|
||||
int characterX = 0, characterY = 0;
|
||||
int startX = characterX;
|
||||
String::value_type *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (*s == '\n')
|
||||
@ -98,7 +99,7 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
}
|
||||
else
|
||||
{
|
||||
characterX = texture.SetCharacter(characterX, characterY, *(unsigned char *)s, r, g, b, a);
|
||||
characterX = texture.SetCharacter(characterX, characterY, *s, r, g, b, a);
|
||||
}
|
||||
}
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
@ -128,12 +129,7 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
return x;
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int b, int a)
|
||||
{
|
||||
return drawtext(x, y, s.c_str(), r, g, b, a);
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawchar(int x, int y, String::value_type c, int r, int g, int b, int a)
|
||||
{
|
||||
unsigned char *rp = font_data + font_ptrs[c];
|
||||
int w = *(rp++);
|
||||
@ -162,7 +158,7 @@ int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a
|
||||
return x + w;
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::addchar(int x, int y, String::value_type c, int r, int g, int b, int a)
|
||||
{
|
||||
unsigned char *rp = font_data + font_ptrs[c];
|
||||
int w = *(rp++);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "font.h"
|
||||
#include <cmath>
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, String s, int r, int g, int b, int a)
|
||||
{
|
||||
drawtext(x-1, y-1, s, 0, 0, 0, 120);
|
||||
drawtext(x+1, y+1, s, 0, 0, 0, 120);
|
||||
@ -12,15 +12,16 @@ int PIXELMETHODS_CLASS::drawtext_outline(int x, int y, const char *s, int r, int
|
||||
return drawtext(x, y, s, r, g, b, a);
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, String str, int r, int g, int b, int a)
|
||||
{
|
||||
if(!strlen(s))
|
||||
if(!str.size())
|
||||
return 0;
|
||||
|
||||
int invert = 0;
|
||||
int oR = r, oG = g, oB = b;
|
||||
int characterX = x, characterY = y;
|
||||
int startX = characterX;
|
||||
String::value_type const *s = str.c_str();
|
||||
for (; *s; s++)
|
||||
{
|
||||
if (*s == '\n')
|
||||
@ -96,18 +97,13 @@ int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int
|
||||
}
|
||||
else
|
||||
{
|
||||
characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a);
|
||||
characterX = drawchar(characterX, characterY, *s, r, g, b, a);
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int b, int a)
|
||||
{
|
||||
return drawtext(x, y, s.c_str(), r, g, b, a);
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::drawchar(int x, int y, String::value_type c, int r, int g, int b, int a)
|
||||
{
|
||||
int i, j, w, bn = 0, ba = 0;
|
||||
unsigned char *rp = font_data + font_ptrs[c];
|
||||
@ -127,7 +123,7 @@ int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a
|
||||
return x + w;
|
||||
}
|
||||
|
||||
int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a)
|
||||
int PIXELMETHODS_CLASS::addchar(int x, int y, String::value_type c, int r, int g, int b, int a)
|
||||
{
|
||||
int i, j, w, bn = 0, ba = 0;
|
||||
unsigned char *rp = font_data + font_ptrs[c];
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -519,17 +520,16 @@ void Renderer::RenderZoom()
|
||||
#endif
|
||||
}
|
||||
|
||||
int Renderer_wtypesCount;
|
||||
wall_type * Renderer_wtypes = LoadWalls(Renderer_wtypesCount);
|
||||
std::vector<wall_type> Renderer_wtypes = LoadWalls();
|
||||
|
||||
|
||||
VideoBuffer * Renderer::WallIcon(int wallID, int width, int height)
|
||||
{
|
||||
int i, j;
|
||||
int wt = wallID;
|
||||
if (wt<0 || wt>=Renderer_wtypesCount)
|
||||
if (wt<0 || wt>=(int)Renderer_wtypes.size())
|
||||
return 0;
|
||||
wall_type *wtypes = Renderer_wtypes;
|
||||
wall_type *wtypes = Renderer_wtypes.data();
|
||||
pixel pc = wtypes[wt].colour;
|
||||
pixel gc = wtypes[wt].eglow;
|
||||
VideoBuffer * newTexture = new VideoBuffer(width, height);
|
||||
@ -985,8 +985,8 @@ void Renderer::DrawSigns()
|
||||
for (size_t i = 0; i < signs.size(); i++)
|
||||
if (signs[i].text.length())
|
||||
{
|
||||
char type = 0;
|
||||
std::string text = signs[i].getText(sim);
|
||||
String::value_type type = 0;
|
||||
String text = signs[i].getText(sim);
|
||||
sign::splitsign(signs[i].text, &type);
|
||||
signs[i].pos(text, x, y, w, h);
|
||||
clearrect(x, y, w+1, h);
|
||||
@ -1496,9 +1496,9 @@ void Renderer::render_parts()
|
||||
|
||||
if (mousePos.X>(nx-3) && mousePos.X<(nx+3) && mousePos.Y<(ny+3) && mousePos.Y>(ny-3)) //If mouse is in the head
|
||||
{
|
||||
char buff[12]; //Buffer for HP
|
||||
sprintf(buff, "%3d", sim->parts[i].life); //Show HP
|
||||
drawtext(mousePos.X-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousePos.Y-12, buff, 255, 255, 255, 255);
|
||||
String::Stream hp;
|
||||
hp << std::setw(3) << sim->parts[i].life;
|
||||
drawtext(mousePos.X-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousePos.Y-12, hp.str(), 255, 255, 255, 255);
|
||||
}
|
||||
|
||||
if (findingElement == t)
|
||||
|
@ -113,11 +113,10 @@ public:
|
||||
|
||||
void draw_icon(int x, int y, Icon icon);
|
||||
|
||||
int drawtext_outline(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, const char *s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, std::string s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, int c, int r, int g, int b, int a);
|
||||
int drawtext_outline(int x, int y, String s, int r, int g, int b, int a);
|
||||
int drawtext(int x, int y, String s, int r, int g, int b, int a);
|
||||
int drawchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
int addchar(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
|
||||
void xor_pixel(int x, int y);
|
||||
void xor_line(int x, int y, int x2, int y2);
|
||||
|
@ -108,8 +108,8 @@ void ColourPickerActivity::UpdateTextboxes(int r, int g, int b, int a)
|
||||
gValue->SetText(format::NumberToString<int>(g));
|
||||
bValue->SetText(format::NumberToString<int>(b));
|
||||
aValue->SetText(format::NumberToString<int>(a));
|
||||
std::stringstream hex;
|
||||
hex << std::hex << "0x" << std::setfill('0') << std::setw(2) << std::uppercase << a << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b;
|
||||
String::Stream hex;
|
||||
hex << std::hex << "0x" << std::setfill(String::value_type('0')) << std::setw(2) << std::uppercase << a << std::setw(2) << r << std::setw(2) << g << std::setw(2) << b;
|
||||
hexValue->SetText(hex.str());
|
||||
}
|
||||
void ColourPickerActivity::OnTryExit(ExitMethod method)
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Activity.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
|
@ -4,18 +4,18 @@
|
||||
class ConsoleCommand
|
||||
{
|
||||
public:
|
||||
ConsoleCommand(std::string command, int returnStatus, std::string returnValue):
|
||||
ConsoleCommand(String command, int returnStatus, String returnValue):
|
||||
Command(command), ReturnStatus(returnStatus), ReturnValue(returnValue)
|
||||
{
|
||||
|
||||
}
|
||||
std::string Command;
|
||||
String Command;
|
||||
int ReturnStatus;
|
||||
std::string ReturnValue;
|
||||
String ReturnValue;
|
||||
|
||||
operator std::string() const
|
||||
operator ByteString() const
|
||||
{
|
||||
return Command;
|
||||
return Command.ToUtf8();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,7 @@ ConsoleController::ConsoleController(ControllerCallback * callback, CommandInter
|
||||
this->commandInterface = commandInterface;
|
||||
}
|
||||
|
||||
void ConsoleController::EvaluateCommand(std::string command)
|
||||
void ConsoleController::EvaluateCommand(String command)
|
||||
{
|
||||
if(command.length())
|
||||
{
|
||||
@ -31,7 +31,7 @@ void ConsoleController::CloseConsole()
|
||||
consoleView->CloseActiveWindow();
|
||||
}
|
||||
|
||||
std::string ConsoleController::FormatCommand(std::string command)
|
||||
String ConsoleController::FormatCommand(String command)
|
||||
{
|
||||
return commandInterface->FormatCommand(command);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CONSOLECONTROLLER_H_
|
||||
#define CONSOLECONTROLLER_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Controller.h"
|
||||
#include "ConsoleView.h"
|
||||
#include "ConsoleModel.h"
|
||||
@ -18,8 +18,8 @@ class ConsoleController {
|
||||
public:
|
||||
bool HasDone;
|
||||
ConsoleController(ControllerCallback * callback, CommandInterface * commandInterface);
|
||||
std::string FormatCommand(std::string command);
|
||||
void EvaluateCommand(std::string command);
|
||||
String FormatCommand(String command);
|
||||
void EvaluateCommand(String command);
|
||||
void NextCommand();
|
||||
void PreviousCommand();
|
||||
void Exit();
|
||||
|
@ -2,8 +2,8 @@
|
||||
#include "ConsoleModel.h"
|
||||
|
||||
ConsoleModel::ConsoleModel() {
|
||||
std::vector<std::string> previousHistory = Client::Ref().GetPrefStringArray("Console.History");
|
||||
for(std::vector<std::string>::reverse_iterator iter = previousHistory.rbegin(), end = previousHistory.rend(); iter != end; ++iter)
|
||||
std::vector<String> previousHistory = Client::Ref().GetPrefStringArray("Console.History");
|
||||
for(std::vector<String>::reverse_iterator iter = previousHistory.rbegin(), end = previousHistory.rend(); iter != end; ++iter)
|
||||
{
|
||||
if(previousCommands.size()<25)
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "gui/interface/ScrollPanel.h"
|
||||
#include "PowderToy.h"
|
||||
|
||||
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
|
||||
ConfirmPrompt::ConfirmPrompt(String title, String message, ConfirmDialogueCallback * callback_):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(250, 35)),
|
||||
callback(callback_)
|
||||
{
|
||||
@ -68,7 +68,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDial
|
||||
MakeActiveWindow();
|
||||
}
|
||||
|
||||
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, std::string buttonText, ConfirmDialogueCallback * callback_):
|
||||
ConfirmPrompt::ConfirmPrompt(String title, String message, String buttonText, ConfirmDialogueCallback * callback_):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(250, 50)),
|
||||
callback(callback_)
|
||||
{
|
||||
@ -130,7 +130,7 @@ ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, std::string
|
||||
MakeActiveWindow();
|
||||
}
|
||||
|
||||
bool ConfirmPrompt::Blocking(std::string title, std::string message, std::string buttonText)
|
||||
bool ConfirmPrompt::Blocking(String title, String message, String buttonText)
|
||||
{
|
||||
class BlockingPromptCallback: public ConfirmDialogueCallback {
|
||||
public:
|
||||
|
@ -1,16 +1,16 @@
|
||||
#ifndef CONFIRMPROMPT_H_
|
||||
#define CONFIRMPROMPT_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "gui/interface/Window.h"
|
||||
|
||||
class ConfirmDialogueCallback;
|
||||
class ConfirmPrompt: public ui::Window {
|
||||
public:
|
||||
enum DialogueResult { ResultCancel, ResultOkay };
|
||||
ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_ = NULL);
|
||||
ConfirmPrompt(std::string title, std::string message, std::string buttonText, ConfirmDialogueCallback * callback_ = NULL);
|
||||
static bool Blocking(std::string title, std::string message, std::string buttonText = "Confirm");
|
||||
ConfirmPrompt(String title, String message, ConfirmDialogueCallback * callback_ = NULL);
|
||||
ConfirmPrompt(String title, String message, String buttonText, ConfirmDialogueCallback * callback_ = NULL);
|
||||
static bool Blocking(String title, String message, String buttonText = "Confirm");
|
||||
virtual void OnDraw();
|
||||
virtual ~ConfirmPrompt();
|
||||
ConfirmDialogueCallback * callback;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "gui/interface/Label.h"
|
||||
#include "PowderToy.h"
|
||||
|
||||
ErrorMessage::ErrorMessage(std::string title, std::string message, ErrorMessageCallback * callback_):
|
||||
ErrorMessage::ErrorMessage(String title, String message, ErrorMessageCallback * callback_):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 35)),
|
||||
callback(callback_)
|
||||
{
|
||||
@ -50,7 +50,7 @@ ErrorMessage::ErrorMessage(std::string title, std::string message, ErrorMessage
|
||||
MakeActiveWindow();
|
||||
}
|
||||
|
||||
void ErrorMessage::Blocking(std::string title, std::string message)
|
||||
void ErrorMessage::Blocking(String title, String message)
|
||||
{
|
||||
class BlockingDismissCallback: public ErrorMessageCallback {
|
||||
public:
|
||||
|
@ -7,8 +7,8 @@ class ErrorMessageCallback;
|
||||
class ErrorMessage: public ui::Window {
|
||||
ErrorMessageCallback * callback;
|
||||
public:
|
||||
ErrorMessage(std::string title, std::string message, ErrorMessageCallback * callback_ = NULL);
|
||||
static void Blocking(std::string title, std::string message);
|
||||
ErrorMessage(String title, String message, ErrorMessageCallback * callback_ = NULL);
|
||||
static void Blocking(String title, String message);
|
||||
virtual void OnDraw();
|
||||
virtual ~ErrorMessage();
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "gui/interface/Label.h"
|
||||
#include "gui/interface/ScrollPanel.h"
|
||||
|
||||
InformationMessage::InformationMessage(std::string title, std::string message, bool large):
|
||||
InformationMessage::InformationMessage(String title, String message, bool large):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 35))
|
||||
{
|
||||
if (large) //Maybe also use this large mode for changelogs eventually, or have it as a customizable size?
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
class InformationMessage: public ui::Window {
|
||||
public:
|
||||
InformationMessage(std::string title, std::string message, bool large);
|
||||
InformationMessage(String title, String message, bool large);
|
||||
virtual void OnDraw();
|
||||
virtual ~InformationMessage();
|
||||
};
|
||||
|
@ -2,10 +2,10 @@
|
||||
|
||||
//Legacy blocking prompts
|
||||
//This are not implemented here, but rather in the engine bootstrapper
|
||||
bool ConfirmUI(std::string title, std::string message, std::string confirmText) {}
|
||||
bool ConfirmUI(String title, String message, String confirmText) {}
|
||||
|
||||
void ErrorUI(std::string title, std::string message) {}
|
||||
void ErrorUI(String title, String message) {}
|
||||
|
||||
void InformationUI(std::string title, std::string message) {}
|
||||
void InformationUI(String title, String message) {}
|
||||
|
||||
std::string MessagePromptUI(std::string title, std::string message, std::string text, std::string placeholder) {}
|
||||
String MessagePromptUI(String title, String message, String text, String placeholder) {}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
TextPrompt::TextPrompt(std::string title, std::string message, std::string text, std::string placeholder, bool multiline, TextDialogueCallback * callback_):
|
||||
TextPrompt::TextPrompt(String title, String message, String text, String placeholder, bool multiline, TextDialogueCallback * callback_):
|
||||
ui::Window(ui::Point(-1, -1), ui::Point(200, 65)),
|
||||
callback(callback_)
|
||||
{
|
||||
@ -77,15 +77,15 @@ TextPrompt::TextPrompt(std::string title, std::string message, std::string text,
|
||||
MakeActiveWindow();
|
||||
}
|
||||
|
||||
std::string TextPrompt::Blocking(std::string title, std::string message, std::string text, std::string placeholder, bool multiline)
|
||||
String TextPrompt::Blocking(String title, String message, String text, String placeholder, bool multiline)
|
||||
{
|
||||
std::string returnString = "";
|
||||
String returnString = "";
|
||||
|
||||
class BlockingTextCallback: public TextDialogueCallback {
|
||||
std::string & outputString;
|
||||
String & outputString;
|
||||
public:
|
||||
BlockingTextCallback(std::string & output) : outputString(output) {}
|
||||
virtual void TextCallback(TextPrompt::DialogueResult result, std::string resultText) {
|
||||
BlockingTextCallback(String & output) : outputString(output) {}
|
||||
virtual void TextCallback(TextPrompt::DialogueResult result, String resultText) {
|
||||
if(result == ResultOkay)
|
||||
outputString = resultText;
|
||||
else
|
||||
|
@ -11,8 +11,8 @@ protected:
|
||||
public:
|
||||
friend class CloseAction;
|
||||
enum DialogueResult { ResultCancel, ResultOkay };
|
||||
TextPrompt(std::string title, std::string message, std::string text, std::string placeholder, bool multiline, TextDialogueCallback * callback_);
|
||||
static std::string Blocking(std::string title, std::string message, std::string text, std::string placeholder, bool multiline);
|
||||
TextPrompt(String title, String message, String text, String placeholder, bool multiline, TextDialogueCallback * callback_);
|
||||
static String Blocking(String title, String message, String text, String placeholder, bool multiline);
|
||||
virtual void OnDraw();
|
||||
virtual ~TextPrompt();
|
||||
TextDialogueCallback * callback;
|
||||
@ -21,7 +21,7 @@ public:
|
||||
class TextDialogueCallback
|
||||
{
|
||||
public:
|
||||
virtual void TextCallback(TextPrompt::DialogueResult result, std::string resultText) {}
|
||||
virtual void TextCallback(TextPrompt::DialogueResult result, String resultText) {}
|
||||
virtual ~TextDialogueCallback() {}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include "common/String.h"
|
||||
#include "ElementSearchActivity.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "gui/interface/Label.h"
|
||||
@ -91,7 +92,7 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st
|
||||
searchTools("");
|
||||
}
|
||||
|
||||
void ElementSearchActivity::searchTools(std::string query)
|
||||
void ElementSearchActivity::searchTools(String query)
|
||||
{
|
||||
firstResult = NULL;
|
||||
for(std::vector<ToolButton*>::iterator iter = toolButtons.begin(), end = toolButtons.end(); iter != end; ++iter) {
|
||||
@ -103,7 +104,7 @@ void ElementSearchActivity::searchTools(std::string query)
|
||||
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
|
||||
ui::Point current = ui::Point(0, 0);
|
||||
|
||||
std::string queryLower = std::string(query);
|
||||
ByteString queryLower = query.ToAscii();
|
||||
std::transform(queryLower.begin(), queryLower.end(), queryLower.begin(), ::tolower);
|
||||
|
||||
std::vector<Tool *> matches;
|
||||
@ -112,13 +113,13 @@ void ElementSearchActivity::searchTools(std::string query)
|
||||
|
||||
for(std::vector<Tool*>::const_iterator iter = tools.begin(), end = tools.end(); iter != end; ++iter)
|
||||
{
|
||||
std::string nameLower = std::string((*iter)->GetName());
|
||||
ByteString nameLower = (*iter)->GetName();
|
||||
std::transform(nameLower.begin(), nameLower.end(), nameLower.begin(), ::tolower);
|
||||
if(!strcmp(nameLower.c_str(), queryLower.c_str()))
|
||||
if(nameLower == queryLower)
|
||||
exactmatches.push_back(*iter);
|
||||
else if(!strncmp(nameLower.c_str(), queryLower.c_str(), queryLower.length()))
|
||||
else if(!nameLower.compare(0, queryLower.length(), queryLower))
|
||||
frontmatches.push_back(*iter);
|
||||
else if(strstr(nameLower.c_str(), queryLower.c_str()))
|
||||
else if(nameLower.find(queryLower) != String::npos)
|
||||
matches.push_back(*iter);
|
||||
}
|
||||
|
||||
@ -198,7 +199,7 @@ void ElementSearchActivity::OnDraw()
|
||||
g->drawrect(Position.X+searchField->Position.X, Position.Y+searchField->Position.Y+searchField->Size.Y+8, searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23, 255, 255, 255, 180);
|
||||
if (toolTipPresence && toolTip.length())
|
||||
{
|
||||
g->drawtext(10, Size.Y+70, (char*)toolTip.c_str(), 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
g->drawtext(10, Size.Y+70, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ void ElementSearchActivity::OnKeyRelease(int key, Uint16 character, bool shift,
|
||||
}
|
||||
}
|
||||
|
||||
void ElementSearchActivity::ToolTip(ui::Point senderPosition, std::string toolTip)
|
||||
void ElementSearchActivity::ToolTip(ui::Point senderPosition, String toolTip)
|
||||
{
|
||||
this->toolTip = toolTip;
|
||||
this->isToolTipFadingIn = true;
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define ELEMENTSEARCHACTIVITY_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Activity.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
@ -18,13 +17,13 @@ class ElementSearchActivity: public WindowActivity
|
||||
std::vector<Tool*> tools;
|
||||
ui::Textbox * searchField;
|
||||
std::vector<ToolButton*> toolButtons;
|
||||
std::string toolTip;
|
||||
String toolTip;
|
||||
int toolTipPresence;
|
||||
bool shiftPressed;
|
||||
bool ctrlPressed;
|
||||
bool altPressed;
|
||||
bool isToolTipFadingIn;
|
||||
void searchTools(std::string query);
|
||||
void searchTools(String query);
|
||||
|
||||
public:
|
||||
class ToolAction;
|
||||
@ -37,7 +36,7 @@ public:
|
||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||
virtual void OnDraw();
|
||||
virtual void ToolTip(ui::Point senderPosition, std::string ToolTip);
|
||||
virtual void ToolTip(ui::Point senderPosition, String ToolTip);
|
||||
};
|
||||
|
||||
#endif /* ELEMENTSEARCHACTIVITY_H_ */
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include "FileBrowserActivity.h"
|
||||
@ -42,8 +41,8 @@ public:
|
||||
//Currently, reading is done on another thread, we can't render outside the main thread due to some bullshit with OpenGL
|
||||
class LoadFilesTask: public Task
|
||||
{
|
||||
std::string directory;
|
||||
std::string search;
|
||||
ByteString directory;
|
||||
ByteString search;
|
||||
std::vector<SaveFile*> saveFiles;
|
||||
|
||||
virtual void before()
|
||||
@ -58,15 +57,15 @@ class LoadFilesTask: public Task
|
||||
|
||||
virtual bool doWork()
|
||||
{
|
||||
std::vector<std::string> files = Client::Ref().DirectorySearch(directory, search, ".cps");
|
||||
std::sort(files.rbegin(), files.rend(), [](std::string a, std::string b) {
|
||||
std::vector<ByteString> files = Client::Ref().DirectorySearch(directory, search, ".cps");
|
||||
std::sort(files.rbegin(), files.rend(), [](ByteString a, ByteString b) {
|
||||
std::transform(a.begin(), a.end(), a.begin(), ::tolower);
|
||||
std::transform(b.begin(), b.end(), b.begin(), ::tolower);
|
||||
return a < b;
|
||||
});
|
||||
|
||||
notifyProgress(-1);
|
||||
for(std::vector<std::string>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
|
||||
for(std::vector<ByteString>::iterator iter = files.begin(), end = files.end(); iter != end; ++iter)
|
||||
{
|
||||
SaveFile * saveFile = new SaveFile(*iter);
|
||||
try
|
||||
@ -76,18 +75,18 @@ class LoadFilesTask: public Task
|
||||
saveFile->SetGameSave(tempSave);
|
||||
saveFiles.push_back(saveFile);
|
||||
|
||||
std::string filename = *iter;
|
||||
ByteString filename = *iter;
|
||||
size_t folderPos = filename.rfind(PATH_SEP);
|
||||
if(folderPos!=std::string::npos && folderPos+1 < filename.size())
|
||||
if(folderPos!=ByteString::npos && folderPos+1 < filename.size())
|
||||
{
|
||||
filename = filename.substr(folderPos+1);
|
||||
}
|
||||
size_t extPos = filename.rfind(".");
|
||||
if(extPos!=std::string::npos)
|
||||
if(extPos!=ByteString::npos)
|
||||
{
|
||||
filename = filename.substr(0, extPos);
|
||||
}
|
||||
saveFile->SetDisplayName(filename);
|
||||
saveFile->SetDisplayName(filename.FromUtf8());
|
||||
}
|
||||
catch(std::exception & e)
|
||||
{
|
||||
@ -103,7 +102,7 @@ public:
|
||||
return saveFiles;
|
||||
}
|
||||
|
||||
LoadFilesTask(std::string directory, std::string search):
|
||||
LoadFilesTask(ByteString directory, ByteString search):
|
||||
directory(directory),
|
||||
search(search)
|
||||
{
|
||||
@ -117,11 +116,11 @@ public:
|
||||
FileBrowserActivity * a;
|
||||
SearchAction(FileBrowserActivity * a) : a(a) {}
|
||||
virtual void TextChangedCallback(ui::Textbox * sender) {
|
||||
a->DoSearch(sender->GetText());
|
||||
a->DoSearch(sender->GetText().ToUtf8());
|
||||
}
|
||||
};
|
||||
|
||||
FileBrowserActivity::FileBrowserActivity(std::string directory, FileSelectedCallback * callback):
|
||||
FileBrowserActivity::FileBrowserActivity(ByteString directory, FileSelectedCallback * callback):
|
||||
WindowActivity(ui::Point(-1, -1), ui::Point(450, 300)),
|
||||
callback(callback),
|
||||
directory(directory),
|
||||
@ -167,7 +166,7 @@ FileBrowserActivity::FileBrowserActivity(std::string directory, FileSelectedCall
|
||||
loadDirectory(directory, "");
|
||||
}
|
||||
|
||||
void FileBrowserActivity::DoSearch(std::string search)
|
||||
void FileBrowserActivity::DoSearch(ByteString search)
|
||||
{
|
||||
if(!loadFiles)
|
||||
{
|
||||
@ -184,7 +183,7 @@ void FileBrowserActivity::SelectSave(SaveFile * file)
|
||||
|
||||
void FileBrowserActivity::DeleteSave(SaveFile * file)
|
||||
{
|
||||
std::string deleteMessage = "Are you sure you want to delete " + file->GetDisplayName() + ".cps?";
|
||||
String deleteMessage = "Are you sure you want to delete " + file->GetDisplayName() + ".cps?";
|
||||
if (ConfirmPrompt::Blocking("Delete Save", deleteMessage))
|
||||
{
|
||||
remove(file->GetName().c_str());
|
||||
@ -194,7 +193,7 @@ void FileBrowserActivity::DeleteSave(SaveFile * file)
|
||||
|
||||
void FileBrowserActivity::RenameSave(SaveFile * file)
|
||||
{
|
||||
std::string newName = TextPrompt::Blocking("Rename", "Change save name", file->GetDisplayName(), "", 0);
|
||||
ByteString newName = TextPrompt::Blocking("Rename", "Change save name", file->GetDisplayName(), "", 0).ToUtf8();
|
||||
if (newName.length())
|
||||
{
|
||||
newName = directory + PATH_SEP + newName + ".cps";
|
||||
@ -208,7 +207,7 @@ void FileBrowserActivity::RenameSave(SaveFile * file)
|
||||
ErrorMessage::Blocking("Error", "No save name given");
|
||||
}
|
||||
|
||||
void FileBrowserActivity::loadDirectory(std::string directory, std::string search)
|
||||
void FileBrowserActivity::loadDirectory(ByteString directory, ByteString search)
|
||||
{
|
||||
for (size_t i = 0; i < components.size(); i++)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Activity.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "tasks/TaskListener.h"
|
||||
@ -33,7 +33,7 @@ class FileBrowserActivity: public TaskListener, public WindowActivity
|
||||
std::vector<SaveFile*> files;
|
||||
std::vector<ui::Component*> components;
|
||||
std::vector<ui::Component*> componentsQueue;
|
||||
std::string directory;
|
||||
ByteString directory;
|
||||
|
||||
ui::ProgressBar * progressBar;
|
||||
|
||||
@ -46,16 +46,16 @@ class FileBrowserActivity: public TaskListener, public WindowActivity
|
||||
class SearchAction;
|
||||
void populateList();
|
||||
public:
|
||||
FileBrowserActivity(std::string directory, FileSelectedCallback * callback);
|
||||
FileBrowserActivity(ByteString directory, FileSelectedCallback * callback);
|
||||
virtual void OnDraw();
|
||||
virtual void OnTick(float dt);
|
||||
virtual void OnTryExit(ExitMethod method);
|
||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||
void loadDirectory(std::string directory, std::string search);
|
||||
void loadDirectory(ByteString directory, ByteString search);
|
||||
void SelectSave(SaveFile * file);
|
||||
void DeleteSave(SaveFile * file);
|
||||
void RenameSave(SaveFile * file);
|
||||
void DoSearch(std::string search);
|
||||
void DoSearch(ByteString search);
|
||||
virtual ~FileBrowserActivity();
|
||||
|
||||
virtual void NotifyDone(Task * task);
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
@ -19,7 +18,7 @@
|
||||
unsigned char *font_data;
|
||||
short *font_ptrs;
|
||||
|
||||
void FontEditor::ReadHeader(std::string header)
|
||||
void FontEditor::ReadHeader(ByteString header)
|
||||
{
|
||||
std::fstream file;
|
||||
file.open(header, std::ios_base::in);
|
||||
@ -27,7 +26,7 @@ void FontEditor::ReadHeader(std::string header)
|
||||
throw std::runtime_error("Could not open " + header);
|
||||
file >> std::skipws;
|
||||
|
||||
std::string word;
|
||||
ByteString word;
|
||||
|
||||
while(word != "font_data[]")
|
||||
file >> word;
|
||||
@ -82,24 +81,24 @@ void FontEditor::ReadHeader(std::string header)
|
||||
size_t eof = file.tellg();
|
||||
|
||||
file.seekg(0);
|
||||
beforeFontData = std::string(startFontData, 0);
|
||||
beforeFontData = ByteString(startFontData, 0);
|
||||
file.read(&beforeFontData[0], startFontData);
|
||||
|
||||
file.seekg(endFontData);
|
||||
afterFontData = std::string(startFontPtrs - endFontData, 0);
|
||||
afterFontData = ByteString(startFontPtrs - endFontData, 0);
|
||||
file.read(&afterFontData[0], startFontPtrs - endFontData);
|
||||
|
||||
file.seekg(endFontData);
|
||||
afterFontData = std::string(startFontPtrs - endFontData, 0);
|
||||
afterFontData = ByteString(startFontPtrs - endFontData, 0);
|
||||
file.read(&afterFontData[0], startFontPtrs - endFontData);
|
||||
|
||||
file.seekg(endFontPtrs);
|
||||
afterFontPtrs = std::string(eof - endFontPtrs, 0);
|
||||
afterFontPtrs = ByteString(eof - endFontPtrs, 0);
|
||||
file.read(&afterFontPtrs[0], eof - endFontPtrs);
|
||||
file.close();
|
||||
}
|
||||
|
||||
void FontEditor::WriteHeader(std::string header, std::vector<unsigned char> const &fontData, std::vector<short> const &fontPtrs)
|
||||
void FontEditor::WriteHeader(ByteString header, std::vector<unsigned char> const &fontData, std::vector<short> const &fontPtrs)
|
||||
{
|
||||
std::fstream file;
|
||||
file.open(header, std::ios_base::out | std::ios_base::trunc);
|
||||
@ -189,7 +188,7 @@ void FontEditor::PackData(
|
||||
}
|
||||
|
||||
#define FONT_SCALE 16
|
||||
FontEditor::FontEditor(std::string _header):
|
||||
FontEditor::FontEditor(ByteString _header):
|
||||
ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)),
|
||||
header(_header),
|
||||
currentChar(0x80),
|
||||
@ -228,7 +227,7 @@ FontEditor::FontEditor(std::string _header):
|
||||
void TextChangedCallback(ui::Textbox *)
|
||||
{
|
||||
unsigned int number;
|
||||
std::stringstream ss(v->currentCharTextbox->GetText());
|
||||
String::Stream ss(v->currentCharTextbox->GetText());
|
||||
ss >> std::hex >> number;
|
||||
if(number < 256)
|
||||
v->currentChar = number;
|
||||
@ -320,14 +319,14 @@ FontEditor::FontEditor(std::string _header):
|
||||
ColorComponentAction(int &_color): color(_color) {}
|
||||
void TextChangedCallback(ui::Textbox *box)
|
||||
{
|
||||
std::stringstream ss(box->GetText());
|
||||
String::Stream ss(box->GetText());
|
||||
ss >> color;
|
||||
}
|
||||
};
|
||||
int *refs[6] = {&fgR, &fgG, &fgB, &bgR, &bgG, &bgB};
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
std::stringstream ss;
|
||||
String::Stream ss;
|
||||
ss << *refs[i];
|
||||
ui::Textbox *colorComponent = new ui::Textbox(ui::Point(currentX, baseline), ui::Point(27, 17), ss.str());
|
||||
currentX += 28;
|
||||
@ -385,8 +384,8 @@ FontEditor::FontEditor(std::string _header):
|
||||
PreviewAction(FontEditor *_v): v(_v) {}
|
||||
void TextChangedCallback(ui::Textbox *box)
|
||||
{
|
||||
std::stringstream ss(box->GetText());
|
||||
std::string text;
|
||||
String::Stream ss(box->GetText());
|
||||
String text;
|
||||
while(!ss.eof())
|
||||
{
|
||||
if(ss.peek() == '\n')
|
||||
@ -399,12 +398,12 @@ FontEditor::FontEditor(std::string _header):
|
||||
if(ss.fail())
|
||||
{
|
||||
ss.clear();
|
||||
char ch = ss.get();
|
||||
String::value_type ch = ss.get();
|
||||
if(!ss.eof())
|
||||
text.push_back(ch);
|
||||
continue;
|
||||
}
|
||||
text.push_back((char)ch);
|
||||
text.push_back(ch);
|
||||
}
|
||||
v->outputPreview->SetText(text);
|
||||
}
|
||||
@ -416,7 +415,7 @@ FontEditor::FontEditor(std::string _header):
|
||||
inputPreview->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||
inputPreview->SetActionCallback(new PreviewAction(this));
|
||||
|
||||
std::stringstream input;
|
||||
String::Stream input;
|
||||
for(unsigned int ch = 0x20; ch <= 0xFF; ch++)
|
||||
{
|
||||
if(!(ch & 0x3F))
|
||||
@ -493,7 +492,7 @@ void FontEditor::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bo
|
||||
|
||||
void FontEditor::UpdateCharNumber()
|
||||
{
|
||||
std::stringstream ss;
|
||||
String::Stream ss;
|
||||
ss << std::hex << currentChar;
|
||||
currentCharTextbox->SetText(ss.str());
|
||||
}
|
||||
|
@ -13,19 +13,19 @@
|
||||
class FontEditor: public ui::Window
|
||||
{
|
||||
private:
|
||||
std::string header;
|
||||
ByteString header;
|
||||
std::array<char, 256> fontWidths;
|
||||
std::array<std::array<std::array<char, MAX_WIDTH>, FONT_H>, 256> fontPixels;
|
||||
|
||||
std::vector<unsigned char> fontData;
|
||||
std::vector<short> fontPtrs;
|
||||
|
||||
std::string beforeFontData;
|
||||
std::string afterFontData;
|
||||
std::string afterFontPtrs;
|
||||
ByteString beforeFontData;
|
||||
ByteString afterFontData;
|
||||
ByteString afterFontPtrs;
|
||||
|
||||
void ReadHeader(std::string header);
|
||||
void WriteHeader(std::string header, std::vector<unsigned char> const &fontData, std::vector<short> const &fontPtrs);
|
||||
void ReadHeader(ByteString header);
|
||||
void WriteHeader(ByteString header, std::vector<unsigned char> const &fontData, std::vector<short> const &fontPtrs);
|
||||
static void PackData(
|
||||
std::array<char, 256> const &fontWidths,
|
||||
std::array<std::array<std::array<char, MAX_WIDTH>, FONT_H>, 256> const &fontPixels,
|
||||
@ -57,7 +57,7 @@ private:
|
||||
void Save();
|
||||
|
||||
public:
|
||||
FontEditor(std::string header);
|
||||
FontEditor(ByteString header);
|
||||
|
||||
void OnDraw();
|
||||
void OnMouseDown(int x, int y, unsigned button);
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
return newTexture;
|
||||
}
|
||||
|
||||
DecorationTool(Renderer *ren_, int decoMode, string name, string description, int r, int g, int b, std::string identifier):
|
||||
DecorationTool(Renderer *ren_, int decoMode, ByteString name, String description, int r, int g, int b, ByteString identifier):
|
||||
Tool(decoMode, name, description, r, g, b, identifier),
|
||||
Red(0),
|
||||
Green(0),
|
||||
|
@ -4,16 +4,16 @@
|
||||
#include <algorithm>
|
||||
|
||||
Favorite::Favorite():
|
||||
favoritesList(std::vector<std::string>())
|
||||
favoritesList(std::vector<ByteString>())
|
||||
{}
|
||||
|
||||
|
||||
std::vector<std::string> Favorite::GetFavoritesList()
|
||||
std::vector<ByteString> Favorite::GetFavoritesList()
|
||||
{
|
||||
return favoritesList;
|
||||
}
|
||||
|
||||
bool Favorite::IsFavorite(std::string identifier)
|
||||
bool Favorite::IsFavorite(ByteString identifier)
|
||||
{
|
||||
return std::find(favoritesList.begin(), favoritesList.end(), identifier) != favoritesList.end();
|
||||
}
|
||||
@ -23,7 +23,7 @@ bool Favorite::AnyFavorites()
|
||||
return favoritesList.size() == 0;
|
||||
}
|
||||
|
||||
void Favorite::AddFavorite(std::string identifier)
|
||||
void Favorite::AddFavorite(ByteString identifier)
|
||||
{
|
||||
if (!IsFavorite(identifier))
|
||||
{
|
||||
@ -31,7 +31,7 @@ void Favorite::AddFavorite(std::string identifier)
|
||||
}
|
||||
}
|
||||
|
||||
void Favorite::RemoveFavorite(std::string identifier)
|
||||
void Favorite::RemoveFavorite(ByteString identifier)
|
||||
{
|
||||
favoritesList.erase(std::remove(favoritesList.begin(), favoritesList.end(), identifier), favoritesList.end());
|
||||
}
|
||||
@ -43,5 +43,5 @@ void Favorite::SaveFavoritesToPrefs()
|
||||
|
||||
void Favorite::LoadFavoritesFromPrefs()
|
||||
{
|
||||
favoritesList = Client::Ref().GetPrefStringArray("Favorites");
|
||||
favoritesList = Client::Ref().GetPrefByteStringArray("Favorites");
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
#ifndef FAVORITE_H
|
||||
#define FAVORITE_H
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <vector>
|
||||
|
||||
#include "common/Singleton.h"
|
||||
|
||||
class Favorite : public Singleton<Favorite>
|
||||
{
|
||||
std::vector<std::string> favoritesList;
|
||||
std::vector<ByteString> favoritesList;
|
||||
public:
|
||||
Favorite();
|
||||
|
||||
std::vector<std::string> GetFavoritesList();
|
||||
bool IsFavorite(std::string identifier);
|
||||
std::vector<ByteString> GetFavoritesList();
|
||||
bool IsFavorite(ByteString identifier);
|
||||
bool AnyFavorites();
|
||||
|
||||
void AddFavorite(std::string identifier);
|
||||
void RemoveFavorite(std::string identifier);
|
||||
void AddFavorite(ByteString identifier);
|
||||
void RemoveFavorite(ByteString identifier);
|
||||
|
||||
void SaveFavoritesToPrefs();
|
||||
void LoadFavoritesFromPrefs();
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
}
|
||||
catch(GameModelException & ex)
|
||||
{
|
||||
new ErrorMessage("Cannot open save", ex.what());
|
||||
new ErrorMessage("Cannot open save", ByteString(ex.what()).FromUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +79,7 @@ public:
|
||||
}
|
||||
catch(GameModelException & ex)
|
||||
{
|
||||
new ErrorMessage("Cannot open save", ex.what());
|
||||
new ErrorMessage("Cannot open save", ByteString(ex.what()).FromUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ int GameController::GetSignAt(int x, int y)
|
||||
}
|
||||
|
||||
// assumed to already be a valid sign
|
||||
std::string GameController::GetSignText(int signID)
|
||||
String GameController::GetSignText(int signID)
|
||||
{
|
||||
return gameModel->GetSimulation()->signs[signID].text;
|
||||
}
|
||||
@ -573,7 +573,7 @@ void GameController::ToolClick(int toolSelection, ui::Point point)
|
||||
activeTool->Click(sim, cBrush, point);
|
||||
}
|
||||
|
||||
std::string GameController::StampRegion(ui::Point point1, ui::Point point2, bool includePressure)
|
||||
ByteString GameController::StampRegion(ui::Point point1, ui::Point point2, bool includePressure)
|
||||
{
|
||||
bool incPressure = Client::Ref().GetPrefBool("Simulation.IncludePressure", true);
|
||||
if (!incPressure)
|
||||
@ -583,7 +583,7 @@ std::string GameController::StampRegion(ui::Point point1, ui::Point point2, bool
|
||||
if(newSave)
|
||||
{
|
||||
newSave->paused = gameModel->GetPaused();
|
||||
std::string stampName = Client::Ref().AddStamp(newSave);
|
||||
ByteString stampName = Client::Ref().AddStamp(newSave);
|
||||
delete newSave;
|
||||
if (stampName.length() == 0)
|
||||
new ErrorMessage("Could not create stamp", "Error serializing save file");
|
||||
@ -666,15 +666,15 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
|
||||
if (foundSignID != -1)
|
||||
{
|
||||
sign foundSign = gameModel->GetSimulation()->signs[foundSignID];
|
||||
std::string str = foundSign.text;
|
||||
char type;
|
||||
String str = foundSign.text;
|
||||
String::value_type type;
|
||||
int pos = sign::splitsign(str, &type);
|
||||
if (pos)
|
||||
{
|
||||
ret = false;
|
||||
if (type == 'c' || type == 't' || type == 's')
|
||||
{
|
||||
std::string link = str.substr(3, pos-3);
|
||||
String link = str.substr(3, pos-3);
|
||||
switch (type)
|
||||
{
|
||||
case 'c':
|
||||
@ -687,8 +687,8 @@ bool GameController::MouseUp(int x, int y, unsigned button, char type)
|
||||
case 't':
|
||||
{
|
||||
// buff is already confirmed to be a number by sign::splitsign
|
||||
std::stringstream uri;
|
||||
uri << "http://powdertoy.co.uk/Discussions/Thread/View.html?Thread=" << link;
|
||||
ByteString::Stream uri;
|
||||
uri << "http://powdertoy.co.uk/Discussions/Thread/View.html?Thread=" << link.ToUtf8();
|
||||
Platform::OpenURI(uri.str());
|
||||
break;
|
||||
}
|
||||
@ -1175,7 +1175,7 @@ void GameController::SetActiveTool(int toolSelection, Tool * tool)
|
||||
((PropertyTool *)tool)->OpenWindow(gameModel->GetSimulation());
|
||||
}
|
||||
|
||||
void GameController::SetActiveTool(int toolSelection, std::string identifier)
|
||||
void GameController::SetActiveTool(int toolSelection, ByteString identifier)
|
||||
{
|
||||
Tool *tool = gameModel->GetToolFromIdentifier(identifier);
|
||||
if (!tool)
|
||||
@ -1198,7 +1198,7 @@ void GameController::SetReplaceModeFlags(int flags)
|
||||
gameModel->GetSimulation()->replaceModeFlags = flags;
|
||||
}
|
||||
|
||||
void GameController::OpenSearch(std::string searchText)
|
||||
void GameController::OpenSearch(String searchText)
|
||||
{
|
||||
if(!search)
|
||||
search = new SearchController(new SearchCallback(this));
|
||||
@ -1524,7 +1524,7 @@ void GameController::Vote(int direction)
|
||||
}
|
||||
catch(GameModelException & ex)
|
||||
{
|
||||
new ErrorMessage("Error while voting", ex.what());
|
||||
new ErrorMessage("Error while voting", ByteString(ex.what()).FromUtf8());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1555,14 +1555,14 @@ void GameController::ReloadSim()
|
||||
}
|
||||
}
|
||||
|
||||
std::string GameController::ElementResolve(int type, int ctype)
|
||||
ByteString GameController::ElementResolve(int type, int ctype)
|
||||
{
|
||||
if(gameModel && gameModel->GetSimulation())
|
||||
{
|
||||
if (type == PT_LIFE && ctype >= 0 && ctype < NGOL)
|
||||
return gameModel->GetSimulation()->gmenu[ctype].name;
|
||||
else if (type >= 0 && type < PT_NUM)
|
||||
return std::string(gameModel->GetSimulation()->elements[type].Name);
|
||||
return gameModel->GetSimulation()->elements[type].Name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -1577,10 +1577,10 @@ bool GameController::IsValidElement(int type)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string GameController::WallName(int type)
|
||||
String GameController::WallName(int type)
|
||||
{
|
||||
if(gameModel && gameModel->GetSimulation() && type >= 0 && type < UI_WALLCOUNT)
|
||||
return std::string(gameModel->GetSimulation()->wtypes[type].name);
|
||||
return gameModel->GetSimulation()->wtypes[type].name;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
@ -1596,13 +1596,13 @@ void GameController::NotifyAuthUserChanged(Client * sender)
|
||||
gameModel->SetUser(newUser);
|
||||
}
|
||||
|
||||
void GameController::NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification)
|
||||
void GameController::NotifyNewNotification(Client * sender, std::pair<String, ByteString> notification)
|
||||
{
|
||||
class LinkNotification : public Notification
|
||||
{
|
||||
std::string link;
|
||||
ByteString link;
|
||||
public:
|
||||
LinkNotification(std::string link_, std::string message) : Notification(message), link(link_) {}
|
||||
LinkNotification(ByteString link_, String message) : Notification(message), link(link_) {}
|
||||
virtual ~LinkNotification() {}
|
||||
|
||||
virtual void Action()
|
||||
@ -1632,13 +1632,13 @@ void GameController::NotifyUpdateAvailable(Client * sender)
|
||||
{
|
||||
GameController * c;
|
||||
public:
|
||||
UpdateNotification(GameController * c, std::string message) : Notification(message), c(c) {}
|
||||
UpdateNotification(GameController * c, String message) : Notification(message), c(c) {}
|
||||
virtual ~UpdateNotification() {}
|
||||
|
||||
virtual void Action()
|
||||
{
|
||||
UpdateInfo info = Client::Ref().GetUpdateInfo();
|
||||
std::stringstream updateMessage;
|
||||
String::Stream updateMessage;
|
||||
updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n ";
|
||||
|
||||
#ifdef SNAPSHOT
|
||||
@ -1674,16 +1674,16 @@ void GameController::NotifyUpdateAvailable(Client * sender)
|
||||
{
|
||||
case UpdateInfo::Snapshot:
|
||||
#if MOD_ID > 0
|
||||
gameModel->AddNotification(new UpdateNotification(this, std::string("A new mod update is available - click here to update")));
|
||||
gameModel->AddNotification(new UpdateNotification(this, "A new mod update is available - click here to update"));
|
||||
#else
|
||||
gameModel->AddNotification(new UpdateNotification(this, std::string("A new snapshot is available - click here to update")));
|
||||
gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update"));
|
||||
#endif
|
||||
break;
|
||||
case UpdateInfo::Stable:
|
||||
gameModel->AddNotification(new UpdateNotification(this, std::string("A new version is available - click here to update")));
|
||||
gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update"));
|
||||
break;
|
||||
case UpdateInfo::Beta:
|
||||
gameModel->AddNotification(new UpdateNotification(this, std::string("A new beta is available - click here to update")));
|
||||
gameModel->AddNotification(new UpdateNotification(this, "A new beta is available - click here to update"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
~GameController();
|
||||
GameView * GetView();
|
||||
int GetSignAt(int x, int y);
|
||||
std::string GetSignText(int signID);
|
||||
String GetSignText(int signID);
|
||||
|
||||
bool MouseMove(int x, int y, int dx, int dy);
|
||||
bool MouseDown(int x, int y, unsigned button);
|
||||
@ -89,7 +89,7 @@ public:
|
||||
void DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
|
||||
void DrawLine(int toolSelection, ui::Point point1, ui::Point point2);
|
||||
void DrawFill(int toolSelection, ui::Point point);
|
||||
std::string StampRegion(ui::Point point1, ui::Point point2, bool includePressure);
|
||||
ByteString StampRegion(ui::Point point1, ui::Point point2, bool includePressure);
|
||||
void CopyRegion(ui::Point point1, ui::Point point2, bool includePressure);
|
||||
void CutRegion(ui::Point point1, ui::Point point2, bool includePressure);
|
||||
void Update();
|
||||
@ -109,7 +109,7 @@ public:
|
||||
void RebuildFavoritesMenu();
|
||||
Tool * GetActiveTool(int selection);
|
||||
void SetActiveTool(int toolSelection, Tool * tool);
|
||||
void SetActiveTool(int toolSelection, std::string identifier);
|
||||
void SetActiveTool(int toolSelection, ByteString identifier);
|
||||
void SetLastTool(Tool * tool);
|
||||
int GetReplaceModeFlags();
|
||||
void SetReplaceModeFlags(int flags);
|
||||
@ -119,7 +119,7 @@ public:
|
||||
void SetToolStrength(float value);
|
||||
void LoadSaveFile(SaveFile * file);
|
||||
void LoadSave(SaveInfo * save);
|
||||
void OpenSearch(std::string searchText);
|
||||
void OpenSearch(String searchText);
|
||||
void OpenLogin();
|
||||
void OpenProfile();
|
||||
void OpenTags();
|
||||
@ -147,9 +147,9 @@ public:
|
||||
bool MouseInZoom(ui::Point position);
|
||||
ui::Point PointTranslate(ui::Point point);
|
||||
ui::Point NormaliseBlockCoord(ui::Point point);
|
||||
std::string ElementResolve(int type, int ctype);
|
||||
ByteString ElementResolve(int type, int ctype);
|
||||
bool IsValidElement(int type);
|
||||
std::string WallName(int type);
|
||||
String WallName(int type);
|
||||
int Record(bool record);
|
||||
|
||||
void ResetAir();
|
||||
@ -167,7 +167,7 @@ public:
|
||||
|
||||
virtual void NotifyUpdateAvailable(Client * sender);
|
||||
virtual void NotifyAuthUserChanged(Client * sender);
|
||||
virtual void NotifyNewNotification(Client * sender, std::pair<std::string, std::string> notification);
|
||||
virtual void NotifyNewNotification(Client * sender, std::pair<String, ByteString> notification);
|
||||
void RunUpdater();
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,7 @@ GameModel::GameModel():
|
||||
brushList.push_back(new TriangleBrush(ui::Point(4, 4)));
|
||||
|
||||
//Load more from brushes folder
|
||||
std::vector<string> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb");
|
||||
std::vector<ByteString> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb");
|
||||
for (size_t i = 0; i < brushFiles.size(); i++)
|
||||
{
|
||||
std::vector<unsigned char> brushData = Client::Ref().ReadFile(brushFiles[i]);
|
||||
@ -234,7 +234,7 @@ void GameModel::BuildMenus()
|
||||
if(activeMenu != -1)
|
||||
lastMenu = activeMenu;
|
||||
|
||||
std::string activeToolIdentifiers[4];
|
||||
ByteString activeToolIdentifiers[4];
|
||||
if(regularToolset[0])
|
||||
activeToolIdentifiers[0] = regularToolset[0]->GetIdentifier();
|
||||
if(regularToolset[1])
|
||||
@ -264,7 +264,7 @@ void GameModel::BuildMenus()
|
||||
//Create menus
|
||||
for (int i = 0; i < SC_TOTAL; i++)
|
||||
{
|
||||
menuList.push_back(new Menu((const char)sim->msections[i].icon[0], sim->msections[i].name, sim->msections[i].doshow));
|
||||
menuList.push_back(new Menu(sim->msections[i].icon[0], sim->msections[i].name, sim->msections[i].doshow));
|
||||
}
|
||||
|
||||
//Build menus from Simulation elements
|
||||
@ -305,14 +305,14 @@ void GameModel::BuildMenus()
|
||||
//Build menu for GOL types
|
||||
for(int i = 0; i < NGOL; i++)
|
||||
{
|
||||
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), sim->gmenu[i].name, std::string(sim->gmenu[i].description), PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+std::string(sim->gmenu[i].name));
|
||||
Tool * tempTool = new ElementTool(PT_LIFE|PMAPID(i), sim->gmenu[i].name, sim->gmenu[i].description, PIXR(sim->gmenu[i].colour), PIXG(sim->gmenu[i].colour), PIXB(sim->gmenu[i].colour), "DEFAULT_PT_LIFE_"+sim->gmenu[i].name);
|
||||
menuList[SC_LIFE]->AddTool(tempTool);
|
||||
}
|
||||
|
||||
//Build other menus from wall data
|
||||
for(int i = 0; i < UI_WALLCOUNT; i++)
|
||||
{
|
||||
Tool * tempTool = new WallTool(i, "", std::string(sim->wtypes[i].descs), PIXR(sim->wtypes[i].colour), PIXG(sim->wtypes[i].colour), PIXB(sim->wtypes[i].colour), sim->wtypes[i].identifier, sim->wtypes[i].textureGen);
|
||||
Tool * tempTool = new WallTool(i, "", sim->wtypes[i].descs, PIXR(sim->wtypes[i].colour), PIXG(sim->wtypes[i].colour), PIXB(sim->wtypes[i].colour), sim->wtypes[i].identifier, sim->wtypes[i].textureGen);
|
||||
menuList[SC_WALL]->AddTool(tempTool);
|
||||
//sim->wtypes[i]
|
||||
}
|
||||
@ -386,7 +386,7 @@ void GameModel::BuildFavoritesMenu()
|
||||
{
|
||||
menuList[SC_FAVORITES]->ClearTools();
|
||||
|
||||
std::vector<std::string> favList = Favorite::Ref().GetFavoritesList();
|
||||
std::vector<ByteString> favList = Favorite::Ref().GetFavoritesList();
|
||||
for (size_t i = 0; i < favList.size(); i++)
|
||||
{
|
||||
Tool *tool = GetToolFromIdentifier(favList[i]);
|
||||
@ -403,7 +403,7 @@ void GameModel::BuildFavoritesMenu()
|
||||
notifyLastToolChanged();
|
||||
}
|
||||
|
||||
Tool * GameModel::GetToolFromIdentifier(std::string identifier)
|
||||
Tool * GameModel::GetToolFromIdentifier(ByteString identifier)
|
||||
{
|
||||
for (std::vector<Menu*>::iterator iter = menuList.begin(), end = menuList.end(); iter != end; ++iter)
|
||||
{
|
||||
@ -657,8 +657,8 @@ void GameModel::SetSave(SaveInfo * newSave)
|
||||
saveData->authors["type"] = "save";
|
||||
saveData->authors["id"] = newSave->id;
|
||||
saveData->authors["username"] = newSave->userName;
|
||||
saveData->authors["title"] = newSave->name;
|
||||
saveData->authors["description"] = newSave->Description;
|
||||
saveData->authors["title"] = newSave->name.ToUtf8();
|
||||
saveData->authors["description"] = newSave->Description.ToUtf8();
|
||||
saveData->authors["published"] = (int)newSave->Published;
|
||||
saveData->authors["date"] = newSave->updatedDate;
|
||||
}
|
||||
@ -912,7 +912,7 @@ void GameModel::SetPaused(bool pauseState)
|
||||
{
|
||||
if (!pauseState && sim->debug_currentParticle > 0)
|
||||
{
|
||||
std::stringstream logmessage;
|
||||
String::Stream logmessage;
|
||||
logmessage << "Updated particles from #" << sim->debug_currentParticle << " to end due to unpause";
|
||||
sim->UpdateParticles(sim->debug_currentParticle, NPART);
|
||||
sim->AfterSim();
|
||||
@ -1048,17 +1048,17 @@ GameSave * GameModel::GetPlaceSave()
|
||||
return placeSave;
|
||||
}
|
||||
|
||||
void GameModel::Log(string message, bool printToFile)
|
||||
void GameModel::Log(String message, bool printToFile)
|
||||
{
|
||||
consoleLog.push_front(message);
|
||||
if(consoleLog.size()>100)
|
||||
consoleLog.pop_back();
|
||||
notifyLogChanged(message);
|
||||
if (printToFile)
|
||||
std::cout << message << std::endl;
|
||||
std::cout << message.ToUtf8() << std::endl;
|
||||
}
|
||||
|
||||
deque<string> GameModel::GetLog()
|
||||
deque<String> GameModel::GetLog()
|
||||
{
|
||||
return consoleLog;
|
||||
}
|
||||
@ -1088,24 +1088,24 @@ void GameModel::RemoveNotification(Notification * notification)
|
||||
notifyNotificationsChanged();
|
||||
}
|
||||
|
||||
void GameModel::SetToolTip(std::string text)
|
||||
void GameModel::SetToolTip(String text)
|
||||
{
|
||||
toolTip = text;
|
||||
notifyToolTipChanged();
|
||||
}
|
||||
|
||||
void GameModel::SetInfoTip(std::string text)
|
||||
void GameModel::SetInfoTip(String text)
|
||||
{
|
||||
infoTip = text;
|
||||
notifyInfoTipChanged();
|
||||
}
|
||||
|
||||
std::string GameModel::GetToolTip()
|
||||
String GameModel::GetToolTip()
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
std::string GameModel::GetInfoTip()
|
||||
String GameModel::GetInfoTip()
|
||||
{
|
||||
return infoTip;
|
||||
}
|
||||
@ -1246,7 +1246,7 @@ void GameModel::notifyPlaceSaveChanged()
|
||||
}
|
||||
}
|
||||
|
||||
void GameModel::notifyLogChanged(string entry)
|
||||
void GameModel::notifyLogChanged(String entry)
|
||||
{
|
||||
for (size_t i = 0; i < observers.size(); i++)
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ private:
|
||||
//unsigned char * clipboardData;
|
||||
GameSave * clipboard;
|
||||
GameSave * placeSave;
|
||||
deque<string> consoleLog;
|
||||
deque<String> consoleLog;
|
||||
vector<GameView*> observers;
|
||||
vector<Tool*> toolList;
|
||||
|
||||
@ -77,8 +77,8 @@ private:
|
||||
|
||||
int edgeMode;
|
||||
|
||||
std::string infoTip;
|
||||
std::string toolTip;
|
||||
String infoTip;
|
||||
String toolTip;
|
||||
//bool zoomEnabled;
|
||||
void notifyRendererChanged();
|
||||
void notifySimulationChanged();
|
||||
@ -98,7 +98,7 @@ private:
|
||||
void notifyColourPresetsChanged();
|
||||
void notifyColourActivePresetChanged();
|
||||
void notifyNotificationsChanged();
|
||||
void notifyLogChanged(string entry);
|
||||
void notifyLogChanged(String entry);
|
||||
void notifyInfoTipChanged();
|
||||
void notifyToolTipChanged();
|
||||
void notifyQuickOptionsChanged();
|
||||
@ -123,10 +123,10 @@ public:
|
||||
void SetColourSelectorColour(ui::Colour colour);
|
||||
ui::Colour GetColourSelectorColour();
|
||||
|
||||
void SetToolTip(std::string text);
|
||||
void SetInfoTip(std::string text);
|
||||
std::string GetToolTip();
|
||||
std::string GetInfoTip();
|
||||
void SetToolTip(String text);
|
||||
void SetInfoTip(String text);
|
||||
String GetToolTip();
|
||||
String GetInfoTip();
|
||||
|
||||
void BuildMenus();
|
||||
void BuildFavoritesMenu();
|
||||
@ -149,7 +149,7 @@ public:
|
||||
float GetToolStrength();
|
||||
Tool * GetLastTool();
|
||||
void SetLastTool(Tool * newTool);
|
||||
Tool * GetToolFromIdentifier(std::string identifier);
|
||||
Tool * GetToolFromIdentifier(ByteString identifier);
|
||||
Tool * GetElementTool(int elementID);
|
||||
vector<Tool*> GetToolList();
|
||||
vector<Tool*> GetUnlistedTools();
|
||||
@ -200,8 +200,8 @@ public:
|
||||
ui::Point GetZoomWindowPosition();
|
||||
void SetClipboard(GameSave * save);
|
||||
void SetPlaceSave(GameSave * save);
|
||||
void Log(string message, bool printToFile);
|
||||
deque<string> GetLog();
|
||||
void Log(String message, bool printToFile);
|
||||
deque<String> GetLog();
|
||||
GameSave * GetClipboard();
|
||||
GameSave * GetPlaceSave();
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
#ifndef GAMEMODELEXCEPTION_H_
|
||||
#define GAMEMODELEXCEPTION_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <exception>
|
||||
using namespace std;
|
||||
|
||||
struct GameModelException: public exception {
|
||||
string message;
|
||||
String message;
|
||||
public:
|
||||
GameModelException(string message_): message(message_) {}
|
||||
GameModelException(String message_): message(message_) {}
|
||||
const char * what() const throw()
|
||||
{
|
||||
return message.c_str();
|
||||
return message.ToUtf8().c_str();
|
||||
}
|
||||
~GameModelException() throw() {};
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
#include "GameView.h"
|
||||
@ -40,10 +39,10 @@ private:
|
||||
bool leftDown;
|
||||
bool showSplit;
|
||||
int splitPosition;
|
||||
std::string toolTip2;
|
||||
String toolTip2;
|
||||
SplitButtonAction * splitActionCallback;
|
||||
public:
|
||||
SplitButton(ui::Point position, ui::Point size, std::string buttonText, std::string toolTip, std::string toolTip2, int split) :
|
||||
SplitButton(ui::Point position, ui::Point size, String buttonText, String toolTip, String toolTip2, int split) :
|
||||
Button(position, size, buttonText, toolTip),
|
||||
showSplit(true),
|
||||
splitPosition(split),
|
||||
@ -52,7 +51,7 @@ public:
|
||||
{
|
||||
|
||||
}
|
||||
void SetRightToolTip(std::string tooltip) { toolTip2 = tooltip; }
|
||||
void SetRightToolTip(String tooltip) { toolTip2 = tooltip; }
|
||||
bool GetShowSplit() { return showSplit; }
|
||||
void SetShowSplit(bool split) { showSplit = split; }
|
||||
SplitButtonAction * GetSplitActionCallback() { return splitActionCallback; }
|
||||
@ -101,12 +100,12 @@ public:
|
||||
return;
|
||||
SetToolTip(x, y);
|
||||
}
|
||||
virtual void TextPosition(std::string ButtonText)
|
||||
virtual void TextPosition(String ButtonText)
|
||||
{
|
||||
ui::Button::TextPosition(ButtonText);
|
||||
textPosition.X += 3;
|
||||
}
|
||||
void SetToolTips(std::string newToolTip1, std::string newToolTip2)
|
||||
void SetToolTips(String newToolTip1, String newToolTip2)
|
||||
{
|
||||
toolTip = newToolTip1;
|
||||
toolTip2 = newToolTip2;
|
||||
@ -183,7 +182,7 @@ GameView::GameView():
|
||||
buttonTip(""),
|
||||
isButtonTipFadingIn(false),
|
||||
introText(2048),
|
||||
introTextMessage(introTextData),
|
||||
introTextMessage(ByteString(introTextData).FromAscii()),
|
||||
|
||||
doScreenshot(false),
|
||||
screenshotIndex(0),
|
||||
@ -610,9 +609,9 @@ void GameView::NotifyMenuListChanged(GameModel * sender)
|
||||
{
|
||||
if (menuList[i]->GetVisible())
|
||||
{
|
||||
std::string tempString = "";
|
||||
String tempString = "";
|
||||
tempString += menuList[i]->GetIcon();
|
||||
std::string description = menuList[i]->GetDescription();
|
||||
String description = menuList[i]->GetDescription();
|
||||
if (i == SC_FAVORITES && Favorite::Ref().AnyFavorites())
|
||||
description += " (Use ctrl+shift+click to favorite an element)";
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(WINDOWW-16, currentY), ui::Point(15, 15), tempString, description);
|
||||
@ -912,7 +911,7 @@ void GameView::NotifyUserChanged(GameModel * sender)
|
||||
}
|
||||
else
|
||||
{
|
||||
loginButton->SetText(sender->GetUser().Username);
|
||||
loginButton->SetText(sender->GetUser().Username.FromUtf8());
|
||||
((SplitButton*)loginButton)->SetShowSplit(true);
|
||||
((SplitButton*)loginButton)->SetRightToolTip("Edit profile");
|
||||
}
|
||||
@ -978,15 +977,15 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
tagSimulationButton->Enabled = sender->GetSave()->GetID();
|
||||
if (sender->GetSave()->GetID())
|
||||
{
|
||||
std::stringstream tagsStream;
|
||||
std::list<string> tags = sender->GetSave()->GetTags();
|
||||
String::Stream tagsStream;
|
||||
std::list<ByteString> tags = sender->GetSave()->GetTags();
|
||||
if (tags.size())
|
||||
{
|
||||
for (std::list<std::string>::const_iterator iter = tags.begin(), begin = tags.begin(), end = tags.end(); iter != end; iter++)
|
||||
for (std::list<ByteString>::const_iterator iter = tags.begin(), begin = tags.begin(), end = tags.end(); iter != end; iter++)
|
||||
{
|
||||
if (iter != begin)
|
||||
tagsStream << " ";
|
||||
tagsStream << *iter;
|
||||
tagsStream << iter->FromUtf8();
|
||||
}
|
||||
tagSimulationButton->SetText(tagsStream.str());
|
||||
}
|
||||
@ -1067,7 +1066,7 @@ int GameView::Record(bool record)
|
||||
{
|
||||
time_t startTime = time(NULL);
|
||||
recordingFolder = startTime;
|
||||
std::stringstream recordingDir;
|
||||
ByteString::Stream recordingDir;
|
||||
recordingDir << "recordings" << PATH_SEP << recordingFolder;
|
||||
Client::Ref().MakeDirectory("recordings");
|
||||
Client::Ref().MakeDirectory(recordingDir.str().c_str());
|
||||
@ -1327,7 +1326,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
|
||||
UpdateDrawMode();
|
||||
}
|
||||
|
||||
void GameView::ToolTip(ui::Point senderPosition, std::string toolTip)
|
||||
void GameView::ToolTip(ui::Point senderPosition, String toolTip)
|
||||
{
|
||||
// buttom button tooltips
|
||||
if (senderPosition.Y > Size.Y-17)
|
||||
@ -1342,16 +1341,16 @@ void GameView::ToolTip(ui::Point senderPosition, std::string toolTip)
|
||||
else if(senderPosition.X > Size.X-BARSIZE)// < Size.Y-(quickOptionButtons.size()+1)*16)
|
||||
{
|
||||
this->toolTip = toolTip;
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), senderPosition.Y+3);
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), senderPosition.Y+3);
|
||||
if(toolTipPosition.Y+10 > Size.Y-MENUSIZE)
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), Size.Y-MENUSIZE-10);
|
||||
isToolTipFadingIn = true;
|
||||
}
|
||||
// element tooltips
|
||||
else
|
||||
{
|
||||
this->toolTip = toolTip;
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth((char*)toolTip.c_str()), Size.Y-MENUSIZE-10);
|
||||
toolTipPosition = ui::Point(Size.X-27-Graphics::textwidth(toolTip), Size.Y-MENUSIZE-10);
|
||||
isToolTipFadingIn = true;
|
||||
}
|
||||
}
|
||||
@ -1490,8 +1489,8 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
if ((Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator
|
||||
|| Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin) && ctrl)
|
||||
{
|
||||
std::string authorString = Client::Ref().GetAuthorInfo().toStyledString();
|
||||
new InformationMessage("Save authorship info", authorString, true);
|
||||
ByteString authorString = Client::Ref().GetAuthorInfo().toStyledString();
|
||||
new InformationMessage("Save authorship info", authorString.FromUtf8(), true);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
@ -1609,7 +1608,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
||||
break;
|
||||
case 'l':
|
||||
{
|
||||
std::vector<std::string> stampList = Client::Ref().GetStamps(0, 1);
|
||||
std::vector<ByteString> stampList = Client::Ref().GetStamps(0, 1);
|
||||
if (stampList.size())
|
||||
{
|
||||
SaveFile *saveFile = Client::Ref().GetStamp(stampList[0]);
|
||||
@ -1735,13 +1734,13 @@ void GameView::OnTick(float dt)
|
||||
int foundSignID = c->GetSignAt(mousePosition.X, mousePosition.Y);
|
||||
if (foundSignID != -1)
|
||||
{
|
||||
std::string str = c->GetSignText(foundSignID);
|
||||
char type = '\0';
|
||||
String str = c->GetSignText(foundSignID);
|
||||
String::value_type type = '\0';
|
||||
int pos = sign::splitsign(str, &type);
|
||||
if (type == 'c' || type == 't' || type == 's')
|
||||
{
|
||||
std::string linkSign = str.substr(3, pos-3);
|
||||
std::stringstream tooltip;
|
||||
String linkSign = str.substr(3, pos-3);
|
||||
String::Stream tooltip;
|
||||
switch (type)
|
||||
{
|
||||
case 'c':
|
||||
@ -1903,7 +1902,7 @@ void GameView::NotifyNotificationsChanged(GameModel * sender)
|
||||
int currentY = YRES-23;
|
||||
for(std::vector<Notification*>::iterator iter = notifications.begin(), end = notifications.end(); iter != end; ++iter)
|
||||
{
|
||||
int width = (Graphics::textwidth((*iter)->Message.c_str()))+8;
|
||||
int width = (Graphics::textwidth((*iter)->Message))+8;
|
||||
ui::Button * tempButton = new ui::Button(ui::Point(XRES-width-22, currentY), ui::Point(width, 15), (*iter)->Message);
|
||||
tempButton->SetActionCallback(new NotificationButtonAction(*iter));
|
||||
tempButton->Appearance.BorderInactive = style::Colour::WarningTitle;
|
||||
@ -1934,9 +1933,9 @@ void GameView::NotifyZoomChanged(GameModel * sender)
|
||||
zoomEnabled = sender->GetZoomEnabled();
|
||||
}
|
||||
|
||||
void GameView::NotifyLogChanged(GameModel * sender, string entry)
|
||||
void GameView::NotifyLogChanged(GameModel * sender, String entry)
|
||||
{
|
||||
logEntries.push_front(std::pair<std::string, int>(entry, 600));
|
||||
logEntries.push_front(std::pair<String, int>(entry, 600));
|
||||
if (logEntries.size() > 20)
|
||||
logEntries.pop_back();
|
||||
}
|
||||
@ -2218,7 +2217,7 @@ void GameView::OnDraw()
|
||||
VideoBuffer screenshot(ren->DumpFrame());
|
||||
std::vector<char> data = format::VideoBufferToPNG(screenshot);
|
||||
|
||||
std::stringstream filename;
|
||||
ByteString::Stream filename;
|
||||
filename << "screenshot_";
|
||||
filename << std::setfill('0') << std::setw(6) << (screenshotIndex++);
|
||||
filename << ".png";
|
||||
@ -2232,7 +2231,7 @@ void GameView::OnDraw()
|
||||
VideoBuffer screenshot(ren->DumpFrame());
|
||||
std::vector<char> data = format::VideoBufferToPPM(screenshot);
|
||||
|
||||
std::stringstream filename;
|
||||
ByteString::Stream filename;
|
||||
filename << "recordings" << PATH_SEP << recordingFolder << PATH_SEP;
|
||||
filename << "frame_";
|
||||
filename << std::setfill('0') << std::setw(6) << (recordingIndex++);
|
||||
@ -2245,10 +2244,10 @@ void GameView::OnDraw()
|
||||
{
|
||||
int startX = 20;
|
||||
int startY = YRES-20;
|
||||
deque<std::pair<std::string, int> >::iterator iter;
|
||||
deque<std::pair<String, int> >::iterator iter;
|
||||
for(iter = logEntries.begin(); iter != logEntries.end(); iter++)
|
||||
{
|
||||
string message = (*iter).first;
|
||||
String message = (*iter).first;
|
||||
int alpha = std::min((*iter).second, 255);
|
||||
if (alpha <= 0) //erase this and everything older
|
||||
{
|
||||
@ -2256,8 +2255,8 @@ void GameView::OnDraw()
|
||||
break;
|
||||
}
|
||||
startY -= 14;
|
||||
g->fillrect(startX-3, startY-3, Graphics::textwidth((char*)message.c_str())+6, 14, 0, 0, 0, 100);
|
||||
g->drawtext(startX, startY, message.c_str(), 255, 255, 255, alpha);
|
||||
g->fillrect(startX-3, startY-3, Graphics::textwidth(message)+6, 14, 0, 0, 0, 100);
|
||||
g->drawtext(startX, startY, message, 255, 255, 255, alpha);
|
||||
(*iter).second -= 3;
|
||||
}
|
||||
}
|
||||
@ -2265,13 +2264,13 @@ void GameView::OnDraw()
|
||||
|
||||
if(recording)
|
||||
{
|
||||
std::stringstream sampleInfo;
|
||||
String::Stream sampleInfo;
|
||||
sampleInfo << recordingIndex;
|
||||
sampleInfo << ". \x8E REC";
|
||||
|
||||
int textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str());
|
||||
int textWidth = Graphics::textwidth(sampleInfo.str());
|
||||
g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5);
|
||||
g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 50, 20, 255);
|
||||
g->drawtext(XRES-16-textWidth, 16, sampleInfo.str(), 255, 50, 20, 255);
|
||||
}
|
||||
else if(showHud)
|
||||
{
|
||||
@ -2281,7 +2280,7 @@ void GameView::OnDraw()
|
||||
alpha = 255-toolTipPresence*3;
|
||||
if (alpha < 50)
|
||||
alpha = 50;
|
||||
std::stringstream sampleInfo;
|
||||
String::Stream sampleInfo;
|
||||
sampleInfo.precision(2);
|
||||
|
||||
int type = sample.particle.type;
|
||||
@ -2295,15 +2294,15 @@ void GameView::OnDraw()
|
||||
if (showDebug)
|
||||
{
|
||||
if (type == PT_LAVA && c->IsValidElement(ctype))
|
||||
sampleInfo << "Molten " << c->ElementResolve(ctype, -1);
|
||||
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
|
||||
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
|
||||
sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]);
|
||||
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
|
||||
else if (type == PT_LIFE)
|
||||
sampleInfo << c->ElementResolve(type, ctype);
|
||||
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
|
||||
else if (type == PT_FILT)
|
||||
{
|
||||
sampleInfo << c->ElementResolve(type, ctype);
|
||||
const char* filtModes[] = {"set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"};
|
||||
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
|
||||
String filtModes[] = {"set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"};
|
||||
if (sample.particle.tmp>=0 && sample.particle.tmp<=11)
|
||||
sampleInfo << " (" << filtModes[sample.particle.tmp] << ")";
|
||||
else
|
||||
@ -2311,14 +2310,14 @@ void GameView::OnDraw()
|
||||
}
|
||||
else
|
||||
{
|
||||
sampleInfo << c->ElementResolve(type, ctype);
|
||||
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
|
||||
if (wavelengthGfx)
|
||||
sampleInfo << " (" << ctype << ")";
|
||||
// Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2
|
||||
else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV)
|
||||
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)) << ")";
|
||||
sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)).FromAscii() << ")";
|
||||
else if (c->IsValidElement(ctype))
|
||||
sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")";
|
||||
sampleInfo << " (" << c->ElementResolve(ctype, -1).FromAscii() << ")";
|
||||
else
|
||||
sampleInfo << " ()";
|
||||
}
|
||||
@ -2336,13 +2335,13 @@ void GameView::OnDraw()
|
||||
else
|
||||
{
|
||||
if (type == PT_LAVA && c->IsValidElement(ctype))
|
||||
sampleInfo << "Molten " << c->ElementResolve(ctype, -1);
|
||||
sampleInfo << "Molten " << c->ElementResolve(ctype, -1).FromAscii();
|
||||
else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype))
|
||||
sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]);
|
||||
sampleInfo << c->ElementResolve(type, -1).FromAscii() << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]).FromAscii();
|
||||
else if (type == PT_LIFE)
|
||||
sampleInfo << c->ElementResolve(type, ctype);
|
||||
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
|
||||
else
|
||||
sampleInfo << c->ElementResolve(type, ctype);
|
||||
sampleInfo << c->ElementResolve(type, ctype).FromAscii();
|
||||
sampleInfo << ", Temp: " << std::fixed << sample.particle.temp - 273.15f << " C";
|
||||
sampleInfo << ", Pressure: " << std::fixed << sample.AirPressure;
|
||||
}
|
||||
@ -2361,9 +2360,9 @@ void GameView::OnDraw()
|
||||
sampleInfo << "Empty";
|
||||
}
|
||||
|
||||
int textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str());
|
||||
int textWidth = Graphics::textwidth(sampleInfo.str());
|
||||
g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5f);
|
||||
g->drawtext(XRES-16-textWidth, 16, (const char*)sampleInfo.str().c_str(), 255, 255, 255, alpha*0.75f);
|
||||
g->drawtext(XRES-16-textWidth, 16, sampleInfo.str(), 255, 255, 255, alpha*0.75f);
|
||||
|
||||
#ifndef OGLI
|
||||
if (wavelengthGfx)
|
||||
@ -2404,7 +2403,7 @@ void GameView::OnDraw()
|
||||
|
||||
if (showDebug)
|
||||
{
|
||||
sampleInfo.str(std::string());
|
||||
sampleInfo.str(String());
|
||||
|
||||
if (type)
|
||||
sampleInfo << "#" << sample.ParticleID << ", ";
|
||||
@ -2417,16 +2416,16 @@ void GameView::OnDraw()
|
||||
if (c->GetAHeatEnable())
|
||||
sampleInfo << ", AHeat: " << std::fixed << sample.AirTemperature -273.15f << " C";
|
||||
|
||||
textWidth = Graphics::textwidth((char*)sampleInfo.str().c_str());
|
||||
textWidth = Graphics::textwidth(sampleInfo.str());
|
||||
g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, alpha*0.5f);
|
||||
g->drawtext(XRES-16-textWidth, 30, (const char*)sampleInfo.str().c_str(), 255, 255, 255, alpha*0.75f);
|
||||
g->drawtext(XRES-16-textWidth, 30, sampleInfo.str(), 255, 255, 255, alpha*0.75f);
|
||||
}
|
||||
}
|
||||
|
||||
if(showHud && introText < 51)
|
||||
{
|
||||
//FPS and some version info
|
||||
std::stringstream fpsInfo;
|
||||
String::Stream fpsInfo;
|
||||
fpsInfo.precision(2);
|
||||
fpsInfo << "FPS: " << std::fixed << ui::Engine::Ref().GetFps();
|
||||
#ifdef DEBUG
|
||||
@ -2449,37 +2448,37 @@ void GameView::OnDraw()
|
||||
if (ren && ren->findingElement)
|
||||
fpsInfo << " [FIND]";
|
||||
|
||||
int textWidth = Graphics::textwidth((char*)fpsInfo.str().c_str());
|
||||
int textWidth = Graphics::textwidth(fpsInfo.str());
|
||||
int alpha = 255-introText*5;
|
||||
g->fillrect(12, 12, textWidth+8, 15, 0, 0, 0, alpha*0.5);
|
||||
g->drawtext(16, 16, (const char*)fpsInfo.str().c_str(), 32, 216, 255, alpha*0.75);
|
||||
g->drawtext(16, 16, fpsInfo.str(), 32, 216, 255, alpha*0.75);
|
||||
}
|
||||
|
||||
//Tooltips
|
||||
if(infoTipPresence)
|
||||
{
|
||||
int infoTipAlpha = (infoTipPresence>50?50:infoTipPresence)*5;
|
||||
g->drawtext_outline((XRES-Graphics::textwidth((char*)infoTip.c_str()))/2, (YRES/2)-2, (char*)infoTip.c_str(), 255, 255, 255, infoTipAlpha);
|
||||
g->drawtext_outline((XRES-Graphics::textwidth(infoTip))/2, (YRES/2)-2, infoTip, 255, 255, 255, infoTipAlpha);
|
||||
}
|
||||
|
||||
if(toolTipPresence && toolTipPosition.X!=-1 && toolTipPosition.Y!=-1 && toolTip.length())
|
||||
{
|
||||
if (toolTipPosition.Y == Size.Y-MENUSIZE-10)
|
||||
g->drawtext_outline(toolTipPosition.X, toolTipPosition.Y, (char*)toolTip.c_str(), 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
g->drawtext_outline(toolTipPosition.X, toolTipPosition.Y, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
else
|
||||
g->drawtext(toolTipPosition.X, toolTipPosition.Y, (char*)toolTip.c_str(), 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
g->drawtext(toolTipPosition.X, toolTipPosition.Y, toolTip, 255, 255, 255, toolTipPresence>51?255:toolTipPresence*5);
|
||||
}
|
||||
|
||||
if(buttonTipShow > 0)
|
||||
{
|
||||
g->drawtext(16, Size.Y-MENUSIZE-24, (char*)buttonTip.c_str(), 255, 255, 255, buttonTipShow>51?255:buttonTipShow*5);
|
||||
g->drawtext(16, Size.Y-MENUSIZE-24, buttonTip, 255, 255, 255, buttonTipShow>51?255:buttonTipShow*5);
|
||||
}
|
||||
|
||||
//Introduction text
|
||||
if(introText)
|
||||
{
|
||||
g->fillrect(0, 0, WINDOWW, WINDOWH, 0, 0, 0, introText>51?102:introText*2);
|
||||
g->drawtext(16, 20, (char*)introTextMessage.c_str(), 255, 255, 255, introText>51?255:introText*5);
|
||||
g->drawtext(16, 20, introTextMessage, 255, 255, 255, introText>51?255:introText*5);
|
||||
}
|
||||
|
||||
// Clear menu areas, to ensure particle graphics don't overlap
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "GameController.h"
|
||||
#include "GameModel.h"
|
||||
#include "gui/interface/Window.h"
|
||||
@ -54,16 +54,16 @@ private:
|
||||
int lastMenu;
|
||||
|
||||
int toolTipPresence;
|
||||
std::string toolTip;
|
||||
String toolTip;
|
||||
bool isToolTipFadingIn;
|
||||
ui::Point toolTipPosition;
|
||||
int infoTipPresence;
|
||||
std::string infoTip;
|
||||
String infoTip;
|
||||
int buttonTipShow;
|
||||
std::string buttonTip;
|
||||
String buttonTip;
|
||||
bool isButtonTipFadingIn;
|
||||
int introText;
|
||||
std::string introTextMessage;
|
||||
String introTextMessage;
|
||||
|
||||
bool doScreenshot;
|
||||
int screenshotIndex;
|
||||
@ -80,7 +80,7 @@ private:
|
||||
vector<ui::Button*> menuButtons;
|
||||
vector<ToolButton*> toolButtons;
|
||||
vector<ui::Component*> notificationComponents;
|
||||
deque<std::pair<std::string, int> > logEntries;
|
||||
deque<std::pair<String, int> > logEntries;
|
||||
ui::Button * scrollBar;
|
||||
ui::Button * searchButton;
|
||||
ui::Button * reloadButton;
|
||||
@ -178,14 +178,14 @@ public:
|
||||
void NotifyColourActivePresetChanged(GameModel * sender);
|
||||
void NotifyPlaceSaveChanged(GameModel * sender);
|
||||
void NotifyNotificationsChanged(GameModel * sender);
|
||||
void NotifyLogChanged(GameModel * sender, string entry);
|
||||
void NotifyLogChanged(GameModel * sender, String entry);
|
||||
void NotifyToolTipChanged(GameModel * sender);
|
||||
void NotifyInfoTipChanged(GameModel * sender);
|
||||
void NotifyQuickOptionsChanged(GameModel * sender);
|
||||
void NotifyLastToolChanged(GameModel * sender);
|
||||
|
||||
|
||||
virtual void ToolTip(ui::Point senderPosition, std::string toolTip);
|
||||
virtual void ToolTip(ui::Point senderPosition, String toolTip);
|
||||
|
||||
virtual void OnMouseMove(int x, int y, int dx, int dy);
|
||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||
|
@ -1,19 +1,20 @@
|
||||
#ifndef MENU_H_
|
||||
#define MENU_H_
|
||||
|
||||
#include "common/String.h"
|
||||
#include "Tool.h"
|
||||
|
||||
class Menu
|
||||
{
|
||||
char icon;
|
||||
string description;
|
||||
vector<Tool*> tools;
|
||||
String::value_type icon;
|
||||
String description;
|
||||
std::vector<Tool*> tools;
|
||||
bool visible;
|
||||
public:
|
||||
Menu(char icon_, string description_, int visible_):
|
||||
Menu(String::value_type icon_, String description_, int visible_):
|
||||
icon(icon_),
|
||||
description(description_),
|
||||
tools(vector<Tool*>()),
|
||||
tools(std::vector<Tool*>()),
|
||||
visible(visible_ ? true : false)
|
||||
{
|
||||
|
||||
@ -28,17 +29,17 @@ public:
|
||||
tools.clear();
|
||||
}
|
||||
|
||||
vector<Tool*> GetToolList()
|
||||
std::vector<Tool*> GetToolList()
|
||||
{
|
||||
return tools;
|
||||
}
|
||||
|
||||
char GetIcon()
|
||||
String::value_type GetIcon()
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
|
||||
string GetDescription()
|
||||
String GetDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef NOTIFICATION_H_
|
||||
#define NOTIFICATION_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
class Notification
|
||||
{
|
||||
public:
|
||||
Notification(std::string message) : Message(message) {}
|
||||
Notification(String message) : Message(message) {}
|
||||
virtual ~Notification() {};
|
||||
std::string Message;
|
||||
String Message;
|
||||
|
||||
virtual void Action() { }
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "Tool.h"
|
||||
#include "client/Client.h"
|
||||
#include "gui/Style.h"
|
||||
@ -69,7 +68,7 @@ sim(sim_)
|
||||
PropertyWindow * w;
|
||||
public:
|
||||
PropertyChanged(PropertyWindow * w): w(w) { }
|
||||
virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option)
|
||||
virtual void OptionChanged(ui::DropDown * sender, std::pair<String, int> option)
|
||||
{
|
||||
w->FocusComponent(w->textField);
|
||||
}
|
||||
@ -79,7 +78,7 @@ sim(sim_)
|
||||
AddComponent(property);
|
||||
for (size_t i = 0; i < properties.size(); i++)
|
||||
{
|
||||
property->AddOption(std::pair<std::string, int>(properties[i].Name, i));
|
||||
property->AddOption(std::pair<String, int>(properties[i].Name.FromAscii(), i));
|
||||
}
|
||||
property->SetOption(Client::Ref().GetPrefInteger("Prop.Type", 0));
|
||||
|
||||
@ -97,7 +96,7 @@ void PropertyWindow::SetProperty()
|
||||
{
|
||||
if(property->GetOption().second!=-1 && textField->GetText().length() > 0)
|
||||
{
|
||||
std::string value = textField->GetText();
|
||||
String value = textField->GetText();
|
||||
try {
|
||||
switch(properties[property->GetOption().second].Type)
|
||||
{
|
||||
@ -108,23 +107,23 @@ void PropertyWindow::SetProperty()
|
||||
if(value.length() > 2 && value.substr(0, 2) == "0x")
|
||||
{
|
||||
//0xC0FFEE
|
||||
std::stringstream buffer;
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer;
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer << std::hex << value.substr(2);
|
||||
buffer >> v;
|
||||
}
|
||||
else if(value.length() > 1 && value[0] == '#')
|
||||
{
|
||||
//#C0FFEE
|
||||
std::stringstream buffer;
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer;
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer << std::hex << value.substr(1);
|
||||
buffer >> v;
|
||||
}
|
||||
else
|
||||
{
|
||||
int type;
|
||||
if (properties[property->GetOption().second].Type == StructProperty::ParticleType && (type = sim->GetParticleType(value)) != -1)
|
||||
if (properties[property->GetOption().second].Type == StructProperty::ParticleType && (type = sim->GetParticleType(value.ToUtf8())) != -1)
|
||||
{
|
||||
v = type;
|
||||
|
||||
@ -134,8 +133,8 @@ void PropertyWindow::SetProperty()
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream buffer(value);
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer(value);
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer >> v;
|
||||
}
|
||||
}
|
||||
@ -159,23 +158,23 @@ void PropertyWindow::SetProperty()
|
||||
if(value.length() > 2 && value.substr(0, 2) == "0x")
|
||||
{
|
||||
//0xC0FFEE
|
||||
std::stringstream buffer;
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer;
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer << std::hex << value.substr(2);
|
||||
buffer >> v;
|
||||
}
|
||||
else if(value.length() > 1 && value[0] == '#')
|
||||
{
|
||||
//#C0FFEE
|
||||
std::stringstream buffer;
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer;
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer << std::hex << value.substr(1);
|
||||
buffer >> v;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream buffer(value);
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer(value);
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer >> v;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
@ -186,8 +185,8 @@ void PropertyWindow::SetProperty()
|
||||
}
|
||||
case StructProperty::Float:
|
||||
{
|
||||
std::stringstream buffer(value);
|
||||
buffer.exceptions(std::stringstream::failbit | std::stringstream::badbit);
|
||||
String::Stream buffer(value);
|
||||
buffer.exceptions(String::Stream::failbit | String::Stream::badbit);
|
||||
buffer >> tool->propValue.Float;
|
||||
if (properties[property->GetOption().second].Name == "temp" && value.length())
|
||||
{
|
||||
@ -212,7 +211,7 @@ void PropertyWindow::SetProperty()
|
||||
return;
|
||||
}
|
||||
Client::Ref().SetPref("Prop.Type", property->GetOption().second);
|
||||
Client::Ref().SetPref("Prop.Value", textField->GetText());
|
||||
Client::Ref().SetPrefUnicode("Prop.Value", textField->GetText());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include <vector>
|
||||
|
||||
class GameModel;
|
||||
@ -23,9 +23,9 @@ protected:
|
||||
std::vector<QuickOptionListener*> listeners;
|
||||
GameModel * m;
|
||||
Type type;
|
||||
std::string icon;
|
||||
std::string description;
|
||||
QuickOption(std::string icon, std::string description, GameModel * m, Type type) :
|
||||
String icon;
|
||||
String description;
|
||||
QuickOption(String icon, String description, GameModel * m, Type type) :
|
||||
m(m),
|
||||
type(type),
|
||||
icon(icon),
|
||||
@ -57,10 +57,10 @@ public:
|
||||
virtual int GetMutli() { return 0;}
|
||||
virtual int GetMultiCount() { return 0;}
|
||||
|
||||
std::string GetIcon() { return icon; }
|
||||
void SetIcon(std::string icon) { this->icon = icon; }
|
||||
std::string GetDescription() { return description; }
|
||||
void SetDescription(std::string description) { this->description = description; }
|
||||
String GetIcon() { return icon; }
|
||||
void SetIcon(String icon) { this->icon = icon; }
|
||||
String GetDescription() { return description; }
|
||||
void SetDescription(String description) { this->description = description; }
|
||||
void Perform()
|
||||
{
|
||||
perform();
|
||||
|
@ -3,13 +3,13 @@
|
||||
class RenderPreset
|
||||
{
|
||||
public:
|
||||
std::string Name;
|
||||
String Name;
|
||||
std::vector<unsigned int> RenderModes;
|
||||
std::vector<unsigned int> DisplayModes;
|
||||
unsigned int ColourMode;
|
||||
|
||||
RenderPreset(): Name(""), ColourMode(0) {}
|
||||
RenderPreset(std::string name, std::vector<unsigned int> renderModes, std::vector<unsigned int> displayModes, unsigned int colourMode):
|
||||
RenderPreset(String name, std::vector<unsigned int> renderModes, std::vector<unsigned int> displayModes, unsigned int colourMode):
|
||||
Name(name),
|
||||
RenderModes(renderModes),
|
||||
DisplayModes(displayModes),
|
||||
|
@ -128,10 +128,10 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
||||
|
||||
justification = new ui::DropDown(ui::Point(52, 48), ui::Point(50, 16));
|
||||
AddComponent(justification);
|
||||
justification->AddOption(std::pair<std::string, int>("\xA0 Left", (int)sign::Left));
|
||||
justification->AddOption(std::pair<std::string, int>("\x9E Middle", (int)sign::Middle));
|
||||
justification->AddOption(std::pair<std::string, int>("\x9F Right", (int)sign::Right));
|
||||
justification->AddOption(std::pair<std::string, int>("\x9D None", (int)sign::None));
|
||||
justification->AddOption(std::pair<String, int>("\xA0 Left", (int)sign::Left));
|
||||
justification->AddOption(std::pair<String, int>("\x9E Middle", (int)sign::Middle));
|
||||
justification->AddOption(std::pair<String, int>("\x9F Right", (int)sign::Right));
|
||||
justification->AddOption(std::pair<String, int>("\x9D None", (int)sign::None));
|
||||
justification->SetOption(1);
|
||||
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
|
||||
@ -181,9 +181,9 @@ void SignWindow::DoDraw()
|
||||
{
|
||||
sign & currentSign = *iter;
|
||||
int x, y, w, h, dx, dy;
|
||||
char type = 0;
|
||||
String::value_type type = 0;
|
||||
Graphics * g = GetGraphics();
|
||||
std::string text = currentSign.getText(sim);
|
||||
String text = currentSign.getText(sim);
|
||||
sign::splitsign(currentSign.text, &type);
|
||||
currentSign.pos(text, x, y, w, h);
|
||||
g->clearrect(x, y, w+1, h);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Tool.h"
|
||||
#include "gui/game/Brush.h"
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
Tool::Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
Tool::Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
textureGen(textureGen),
|
||||
toolID(id),
|
||||
toolName(name),
|
||||
@ -32,9 +32,9 @@ void Tool::SetTextureGen(VideoBuffer * (*textureGen)(int, int, int))
|
||||
{
|
||||
this->textureGen = textureGen;
|
||||
}
|
||||
std::string Tool::GetIdentifier() { return identifier; }
|
||||
string Tool::GetName() { return toolName; }
|
||||
string Tool::GetDescription() { return toolDescription; }
|
||||
ByteString Tool::GetIdentifier() { return identifier; }
|
||||
ByteString Tool::GetName() { return toolName; }
|
||||
String Tool::GetDescription() { return toolDescription; }
|
||||
Tool::~Tool() {}
|
||||
|
||||
void Tool::Click(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
@ -50,7 +50,7 @@ void Tool::DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Po
|
||||
void Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {}
|
||||
|
||||
|
||||
ElementTool::ElementTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
ElementTool::ElementTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
Tool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{
|
||||
}
|
||||
@ -69,7 +69,7 @@ void ElementTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position)
|
||||
}
|
||||
|
||||
|
||||
WallTool::WallTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
WallTool::WallTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
Tool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{
|
||||
blocky = true;
|
||||
@ -110,7 +110,7 @@ void WallTool::DrawFill(Simulation * sim, Brush * brush, ui::Point position) {
|
||||
sim->FloodWalls(position.X, position.Y, toolID, -1);
|
||||
}
|
||||
|
||||
WindTool::WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
WindTool::WindTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int)):
|
||||
Tool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{
|
||||
}
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "common/String.h"
|
||||
#include "gui/interface/Point.h"
|
||||
#include "simulation/StructProperty.h"
|
||||
|
||||
@ -17,19 +16,19 @@ class Tool
|
||||
protected:
|
||||
VideoBuffer * (*textureGen)(int, int, int);
|
||||
int toolID;
|
||||
string toolName;
|
||||
string toolDescription;
|
||||
ByteString toolName;
|
||||
String toolDescription;
|
||||
float strength;
|
||||
bool blocky;
|
||||
std::string identifier;
|
||||
ByteString identifier;
|
||||
public:
|
||||
int colRed, colGreen, colBlue;
|
||||
|
||||
Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
int GetToolID() { return toolID; }
|
||||
string GetName();
|
||||
string GetDescription();
|
||||
std::string GetIdentifier();
|
||||
ByteString GetName();
|
||||
String GetDescription();
|
||||
ByteString GetIdentifier();
|
||||
int GetBlocky() { return blocky; }
|
||||
void SetStrength(float value) { strength = value; }
|
||||
float GetStrength() { return strength; }
|
||||
@ -106,7 +105,7 @@ public:
|
||||
class ElementTool: public Tool
|
||||
{
|
||||
public:
|
||||
ElementTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
ElementTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
virtual ~ElementTool();
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
|
||||
@ -117,7 +116,7 @@ public:
|
||||
class Element_LIGH_Tool: public ElementTool
|
||||
{
|
||||
public:
|
||||
Element_LIGH_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
Element_LIGH_Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
ElementTool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{ }
|
||||
virtual ~Element_LIGH_Tool() { }
|
||||
@ -130,7 +129,7 @@ public:
|
||||
class Element_TESC_Tool: public ElementTool
|
||||
{
|
||||
public:
|
||||
Element_TESC_Tool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
Element_TESC_Tool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
ElementTool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{ }
|
||||
virtual ~Element_TESC_Tool() {}
|
||||
@ -141,7 +140,7 @@ public:
|
||||
class PlopTool: public ElementTool
|
||||
{
|
||||
public:
|
||||
PlopTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
PlopTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL):
|
||||
ElementTool(id, name, description, r, g, b, identifier, textureGen)
|
||||
{ }
|
||||
virtual ~PlopTool() { }
|
||||
@ -155,7 +154,7 @@ public:
|
||||
class WallTool: public Tool
|
||||
{
|
||||
public:
|
||||
WallTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
WallTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
virtual ~WallTool();
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position);
|
||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
|
||||
@ -166,7 +165,7 @@ public:
|
||||
class WindTool: public Tool
|
||||
{
|
||||
public:
|
||||
WindTool(int id, string name, string description, int r, int g, int b, std::string identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
WindTool(int id, ByteString name, String description, int r, int g, int b, ByteString identifier, VideoBuffer * (*textureGen)(int, int, int) = NULL);
|
||||
virtual ~WindTool() { }
|
||||
virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) { }
|
||||
virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2, bool dragging = false);
|
||||
|
@ -4,8 +4,8 @@
|
||||
#include "gui/interface/Mouse.h"
|
||||
#include "Favorite.h"
|
||||
|
||||
ToolButton::ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolIdentifier, std::string toolTip):
|
||||
ui::Button(position, size, text_, toolTip),
|
||||
ToolButton::ToolButton(ui::Point position, ui::Point size, ByteString text_, ByteString toolIdentifier, String toolTip):
|
||||
ui::Button(position, size, text_.FromAscii(), toolTip),
|
||||
toolIdentifier(toolIdentifier)
|
||||
{
|
||||
SetSelectionState(-1);
|
||||
|
@ -6,9 +6,9 @@
|
||||
class ToolButton: public ui::Button
|
||||
{
|
||||
int currentSelection;
|
||||
std::string toolIdentifier;
|
||||
ByteString toolIdentifier;
|
||||
public:
|
||||
ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolIdentifier, std::string toolTip = "");
|
||||
ToolButton(ui::Point position, ui::Point size, ByteString text_, ByteString toolIdentifier, String toolTip = "");
|
||||
virtual void OnMouseUnclick(int x, int y, unsigned int button);
|
||||
virtual void OnMouseUp(int x, int y, unsigned int button);
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
AvatarButton::AvatarButton(Point position, Point size, std::string username):
|
||||
AvatarButton::AvatarButton(Point position, Point size, ByteString username):
|
||||
Component(position, size),
|
||||
avatar(NULL),
|
||||
name(username),
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef AVATARBUTTON_H_
|
||||
#define AVATARBUTTON_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
|
||||
#include "Component.h"
|
||||
#include "graphics/Graphics.h"
|
||||
@ -21,10 +21,10 @@ public:
|
||||
class AvatarButton : public Component, public RequestListener
|
||||
{
|
||||
VideoBuffer * avatar;
|
||||
std::string name;
|
||||
ByteString name;
|
||||
bool tried;
|
||||
public:
|
||||
AvatarButton(Point position, Point size, std::string username);
|
||||
AvatarButton(Point position, Point size, ByteString username);
|
||||
virtual ~AvatarButton();
|
||||
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
@ -42,8 +42,8 @@ public:
|
||||
|
||||
virtual void DoAction();
|
||||
|
||||
void SetUsername(std::string username) { name = username; }
|
||||
std::string GetUsername() { return name; }
|
||||
void SetUsername(ByteString username) { name = username; }
|
||||
ByteString GetUsername() { return name; }
|
||||
void SetActionCallback(AvatarButtonAction * action);
|
||||
protected:
|
||||
bool isMouseInside, isButtonDown;
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
Button::Button(Point position, Point size, std::string buttonText, std::string toolTip):
|
||||
Button::Button(Point position, Point size, String buttonText, String toolTip):
|
||||
Component(position, size),
|
||||
ButtonText(buttonText),
|
||||
toolTip(toolTip),
|
||||
@ -19,14 +19,14 @@ Button::Button(Point position, Point size, std::string buttonText, std::string t
|
||||
TextPosition(ButtonText);
|
||||
}
|
||||
|
||||
void Button::TextPosition(std::string ButtonText)
|
||||
void Button::TextPosition(String ButtonText)
|
||||
{
|
||||
buttonDisplayText = ButtonText;
|
||||
if(buttonDisplayText.length())
|
||||
{
|
||||
if(Graphics::textwidth((char *)buttonDisplayText.c_str()) > Size.X - (Appearance.icon? 22 : 0))
|
||||
if(Graphics::textwidth(buttonDisplayText) > Size.X - (Appearance.icon? 22 : 0))
|
||||
{
|
||||
int position = Graphics::textwidthx((char *)buttonDisplayText.c_str(), Size.X - (Appearance.icon? 38 : 22));
|
||||
int position = Graphics::textwidthx(buttonDisplayText, Size.X - (Appearance.icon? 38 : 22));
|
||||
buttonDisplayText = buttonDisplayText.erase(position, buttonDisplayText.length()-position);
|
||||
buttonDisplayText += "...";
|
||||
}
|
||||
@ -41,7 +41,7 @@ void Button::SetIcon(Icon icon)
|
||||
TextPosition(ButtonText);
|
||||
}
|
||||
|
||||
void Button::SetText(std::string buttonText)
|
||||
void Button::SetText(String buttonText)
|
||||
{
|
||||
ButtonText = buttonText;
|
||||
TextPosition(ButtonText);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef BUTTON_H_
|
||||
#define BUTTON_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Misc.h"
|
||||
#include "Component.h"
|
||||
#include "Colour.h"
|
||||
@ -21,7 +21,7 @@ public:
|
||||
class Button : public Component
|
||||
{
|
||||
public:
|
||||
Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "", std::string toolTip = "");
|
||||
Button(Point position = Point(0, 0), Point size = Point(0, 0), String buttonText = "", String toolTip = "");
|
||||
virtual ~Button();
|
||||
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
@ -34,7 +34,7 @@ public:
|
||||
|
||||
virtual void Draw(const Point& screenPos);
|
||||
|
||||
virtual void TextPosition(std::string);
|
||||
virtual void TextPosition(String);
|
||||
inline bool GetState() { return state; }
|
||||
virtual void DoAction(); //action of button what ever it may be
|
||||
virtual void DoAltAction(); //action of button what ever it may be
|
||||
@ -44,15 +44,15 @@ public:
|
||||
void SetToggleState(bool state);
|
||||
void SetActionCallback(ButtonAction * action);
|
||||
ButtonAction * GetActionCallback() { return actionCallback; }
|
||||
void SetText(std::string buttonText);
|
||||
void SetText(String buttonText);
|
||||
void SetIcon(Icon icon);
|
||||
inline std::string GetText() { return ButtonText; }
|
||||
void SetToolTip(std::string newToolTip) { toolTip = newToolTip; }
|
||||
inline String GetText() { return ButtonText; }
|
||||
void SetToolTip(String newToolTip) { toolTip = newToolTip; }
|
||||
protected:
|
||||
|
||||
std::string ButtonText;
|
||||
std::string toolTip;
|
||||
std::string buttonDisplayText;
|
||||
String ButtonText;
|
||||
String toolTip;
|
||||
String buttonDisplayText;
|
||||
|
||||
bool isButtonDown, isAltButtonDown, state, isMouseInside, isTogglable, toggle;
|
||||
ButtonAction * actionCallback;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
using namespace ui;
|
||||
|
||||
Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text, std::string toolTip):
|
||||
Checkbox::Checkbox(ui::Point position, ui::Point size, String text, String toolTip):
|
||||
Component(position, size),
|
||||
text(text),
|
||||
toolTip(toolTip),
|
||||
@ -15,12 +15,12 @@ Checkbox::Checkbox(ui::Point position, ui::Point size, std::string text, std::st
|
||||
|
||||
}
|
||||
|
||||
void Checkbox::SetText(std::string text)
|
||||
void Checkbox::SetText(String text)
|
||||
{
|
||||
this->text = text;
|
||||
}
|
||||
|
||||
std::string Checkbox::GetText()
|
||||
String Checkbox::GetText()
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef CHECKBOX_H_
|
||||
#define CHECKBOX_H_
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "Component.h"
|
||||
namespace ui
|
||||
{
|
||||
@ -13,15 +13,15 @@ public:
|
||||
virtual ~CheckboxAction() {}
|
||||
};
|
||||
class Checkbox: public ui::Component {
|
||||
std::string text;
|
||||
std::string toolTip;
|
||||
String text;
|
||||
String toolTip;
|
||||
bool checked;
|
||||
bool isMouseOver;
|
||||
CheckboxAction * actionCallback;
|
||||
public:
|
||||
Checkbox(ui::Point position, ui::Point size, std::string text, std::string toolTip);
|
||||
void SetText(std::string text);
|
||||
std::string GetText();
|
||||
Checkbox(ui::Point position, ui::Point size, String text, String toolTip);
|
||||
void SetText(String text);
|
||||
String GetText();
|
||||
void SetIcon(Icon icon);
|
||||
void Draw(const Point& screenPos);
|
||||
virtual void OnMouseEnter(int x, int y);
|
||||
|
@ -62,13 +62,13 @@ void Component::Refresh()
|
||||
drawn = false;
|
||||
}
|
||||
|
||||
void Component::TextPosition(std::string displayText)
|
||||
void Component::TextPosition(String displayText)
|
||||
{
|
||||
|
||||
textPosition = ui::Point(0, 0);
|
||||
|
||||
int textWidth, textHeight = 10;
|
||||
Graphics::textsize((char*)displayText.c_str(), textWidth, textHeight);
|
||||
Graphics::textsize(displayText, textWidth, textHeight);
|
||||
textSize.X = textWidth; textSize.Y = textHeight;
|
||||
textHeight-=3;
|
||||
textWidth-=1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "common/String.h"
|
||||
#include "common/tpt-compat.h"
|
||||
#include "Appearance.h"
|
||||
#include "Point.h"
|
||||
@ -49,7 +49,7 @@ namespace ui
|
||||
ui::Appearance Appearance;
|
||||
//virtual void SetAppearance(ui::Appearance);
|
||||
//ui::Appearance GetAppearance();
|
||||
virtual void TextPosition(std::string);
|
||||
virtual void TextPosition(String);
|
||||
|
||||
void Refresh();
|
||||
|
||||
|
@ -70,7 +70,7 @@ void ContextMenu::OnMouseDown(int x, int y, unsigned button)
|
||||
CloseActiveWindow();
|
||||
}
|
||||
|
||||
void ContextMenu::SetItem(int id, std::string text)
|
||||
void ContextMenu::SetItem(int id, String text)
|
||||
{
|
||||
for (size_t i = 0; i < items.size(); i++)
|
||||
{
|
||||
|
@ -12,9 +12,9 @@ class ContextMenuItem
|
||||
{
|
||||
public:
|
||||
int ID;
|
||||
std::string Text;
|
||||
String Text;
|
||||
bool Enabled;
|
||||
ContextMenuItem(std::string text, int id, bool enabled) : ID(id), Text(text), Enabled(enabled) {}
|
||||
ContextMenuItem(String text, int id, bool enabled) : ID(id), Text(text), Enabled(enabled) {}
|
||||
};
|
||||
|
||||
class ContextMenu: public ui::Window, public ButtonAction {
|
||||
@ -28,7 +28,7 @@ public:
|
||||
virtual void ActionCallbackItem(ui::Button *sender, int item);
|
||||
virtual void AddItem(ContextMenuItem item);
|
||||
virtual void RemoveItem(int id);
|
||||
virtual void SetItem(int id, std::string text);
|
||||
virtual void SetItem(int id, String text);
|
||||
virtual void Show(ui::Point position);
|
||||
virtual void OnDraw();
|
||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace ui
|
||||
{
|
||||
CopyTextButton::CopyTextButton(Point position, Point size, std::string buttonText, Label *copyTextLabel_):
|
||||
CopyTextButton::CopyTextButton(Point position, Point size, String buttonText, Label *copyTextLabel_):
|
||||
Button(position, size, buttonText)
|
||||
{
|
||||
copyTextLabel = copyTextLabel_;
|
||||
@ -20,7 +20,7 @@ namespace ui
|
||||
void CopyTextButton::OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
ui::Button::OnMouseClick(x, y, button);
|
||||
ClipboardPush(ButtonText);
|
||||
ClipboardPush(ButtonText.ToUtf8());
|
||||
|
||||
copyTextLabel->SetText("Copied!");
|
||||
|
||||
|
@ -10,7 +10,7 @@ class CopyTextButton : public Button
|
||||
{
|
||||
ui::Label *copyTextLabel;
|
||||
public:
|
||||
CopyTextButton(Point position, Point size, std::string buttonText, Label *copyTextLabel_);
|
||||
CopyTextButton(Point position, Point size, String buttonText, Label *copyTextLabel_);
|
||||
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
|
||||
|
@ -18,9 +18,9 @@ public:
|
||||
class ItemSelectedAction: public ButtonAction
|
||||
{
|
||||
DropDownWindow * window;
|
||||
std::string option;
|
||||
String option;
|
||||
public:
|
||||
ItemSelectedAction(DropDownWindow * window, std::string option): window(window), option(option) { }
|
||||
ItemSelectedAction(DropDownWindow * window, String option): window(window), option(option) { }
|
||||
virtual void ActionCallback(ui::Button *sender)
|
||||
{
|
||||
window->CloseActiveWindow();
|
||||
@ -50,7 +50,7 @@ public:
|
||||
Graphics * g = GetGraphics();
|
||||
g->clearrect(Position.X, Position.Y, Size.X, Size.Y);
|
||||
}
|
||||
void setOption(std::string option)
|
||||
void setOption(String option)
|
||||
{
|
||||
dropDown->SetOption(option);
|
||||
if (dropDown->callback)
|
||||
@ -129,16 +129,16 @@ void DropDown::OnMouseLeave(int x, int y)
|
||||
{
|
||||
isMouseInside = false;
|
||||
}
|
||||
std::pair<std::string, int> DropDown::GetOption()
|
||||
std::pair<String, int> DropDown::GetOption()
|
||||
{
|
||||
if(optionIndex!=-1)
|
||||
{
|
||||
return options[optionIndex];
|
||||
}
|
||||
return std::pair<std::string, int>("", -1);
|
||||
return std::pair<String, int>("", -1);
|
||||
}
|
||||
|
||||
void DropDown::SetOption(std::string option)
|
||||
void DropDown::SetOption(String option)
|
||||
{
|
||||
for (size_t i = 0; i < options.size(); i++)
|
||||
{
|
||||
@ -162,7 +162,7 @@ void DropDown::OnMouseLeave(int x, int y)
|
||||
}
|
||||
}
|
||||
}
|
||||
void DropDown::AddOption(std::pair<std::string, int> option)
|
||||
void DropDown::AddOption(std::pair<String, int> option)
|
||||
{
|
||||
for (size_t i = 0; i < options.size(); i++)
|
||||
{
|
||||
@ -171,7 +171,7 @@ void DropDown::OnMouseLeave(int x, int y)
|
||||
}
|
||||
options.push_back(option);
|
||||
}
|
||||
void DropDown::RemoveOption(std::string option)
|
||||
void DropDown::RemoveOption(String option)
|
||||
{
|
||||
start:
|
||||
for (size_t i = 0; i < options.size(); i++)
|
||||
@ -185,7 +185,7 @@ void DropDown::OnMouseLeave(int x, int y)
|
||||
}
|
||||
}
|
||||
}
|
||||
void DropDown::SetOptions(std::vector<std::pair<std::string, int> > options)
|
||||
void DropDown::SetOptions(std::vector<std::pair<String, int> > options)
|
||||
{
|
||||
this->options = options;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class DropDownWindow;
|
||||
class DropDownAction
|
||||
{
|
||||
public:
|
||||
virtual void OptionChanged(DropDown * sender, std::pair<std::string, int> newOption) {}
|
||||
virtual void OptionChanged(DropDown * sender, std::pair<String, int> newOption) {}
|
||||
virtual ~DropDownAction() {}
|
||||
};
|
||||
class DropDown: public ui::Component {
|
||||
@ -20,15 +20,15 @@ class DropDown: public ui::Component {
|
||||
bool isMouseInside;
|
||||
int optionIndex;
|
||||
DropDownAction * callback;
|
||||
std::vector<std::pair<std::string, int> > options;
|
||||
std::vector<std::pair<String, int> > options;
|
||||
public:
|
||||
DropDown(Point position, Point size);
|
||||
std::pair<std::string, int> GetOption();
|
||||
std::pair<String, int> GetOption();
|
||||
void SetOption(int option);
|
||||
void SetOption(std::string option);
|
||||
void AddOption(std::pair<std::string, int> option);
|
||||
void RemoveOption(std::string option);
|
||||
void SetOptions(std::vector<std::pair<std::string, int> > options);
|
||||
void SetOption(String option);
|
||||
void AddOption(std::pair<String, int> option);
|
||||
void RemoveOption(String option);
|
||||
void SetOptions(std::vector<std::pair<String, int> > options);
|
||||
void SetActionCallback(DropDownAction * action) { callback = action;}
|
||||
virtual void Draw(const Point& screenPos);
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user