forked from jaildesigner-jailgames/jaildoctors_dilemma
Arreglada la clase Screen. Había un lio de conceptos con varias variables
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include "common/jscore.h"
|
||||
#include "common/utils.h"
|
||||
#include "director.h"
|
||||
#include <errno.h>
|
||||
@@ -52,11 +53,14 @@ Director::Director(int argc, char *argv[])
|
||||
resource = new Resource(renderer, asset, options);
|
||||
input = new Input(asset->get("gamecontrollerdb.txt"));
|
||||
initInput();
|
||||
screen = new Screen(window, renderer, options, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||
screen = new Screen(window, renderer, asset, options);
|
||||
screen->setBorderColor(borderColor);
|
||||
screen->setVideoMode(options->fullScreenMode);
|
||||
// screen->setVideoMode(options->videoMode);
|
||||
debug = new Debug(renderer, screen, asset);
|
||||
music = JA_LoadMusic(asset->get("title.ogg").c_str());
|
||||
|
||||
// Inicializa los servicios online
|
||||
// initOnline();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
@@ -78,6 +82,56 @@ Director::~Director()
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
// Inicializa los servicios online
|
||||
void Director::initOnline()
|
||||
{
|
||||
if (!options->online.enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Obten el Jailer ID
|
||||
if (options->online.jailerID == "")
|
||||
{ // Jailer ID no definido
|
||||
screen->showText("No ha especificado ningun Jailer ID");
|
||||
std::cout << "No ha especificado ningun Jailer ID" << std::endl;
|
||||
}
|
||||
else
|
||||
{ // Jailer ID iniciado
|
||||
|
||||
// Establece el servidor y el puerto
|
||||
jscore::init(options->online.server, options->online.port);
|
||||
|
||||
// Obtiene la información online
|
||||
if (jscore::initOnlineScore(options->online.gameID))
|
||||
{
|
||||
screen->showText(options->online.jailerID + " ha iniciado sesion");
|
||||
std::cout << options->online.jailerID << " ha iniciado sesion" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
screen->showText("Fallo al conectar a " + options->online.server);
|
||||
std::cout << "Fallo al conectar a " << options->online.server << std::endl;
|
||||
|
||||
options->online.enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Obten las estadisticas online
|
||||
const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID);
|
||||
if (points == 0)
|
||||
{ // Fallo de conexión o no hay registros
|
||||
screen->showText("No se ha podido obtener la puntuacion online");
|
||||
std::cout << "No se ha podido obtener la puntuacion online" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->online.score = points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void Director::iniOptions()
|
||||
{
|
||||
@@ -85,7 +139,9 @@ void Director::iniOptions()
|
||||
options = new options_t;
|
||||
|
||||
// Inicializa valores
|
||||
options->fullScreenMode = 0;
|
||||
options->gameWidth = GAMECANVAS_WIDTH;
|
||||
options->gameHeight = GAMECANVAS_HEIGHT;
|
||||
options->videoMode = 0;
|
||||
options->windowSize = 3;
|
||||
options->filter = FILTER_NEAREST;
|
||||
options->vSync = true;
|
||||
@@ -103,6 +159,13 @@ void Director::iniOptions()
|
||||
options->cheat.altSkin = false;
|
||||
options->rooms = 0;
|
||||
options->items = 0;
|
||||
|
||||
// Online
|
||||
options->online.enabled = false;
|
||||
options->online.server = "";
|
||||
options->online.port = 0;
|
||||
options->online.gameID = "jaildoctors_dilemma_test";
|
||||
options->online.jailerID = "";
|
||||
}
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
@@ -193,19 +256,33 @@ bool Director::loadConfig()
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
// Normaliza los valores
|
||||
const bool a = options->videoMode == 0;
|
||||
const bool b = options->videoMode == SDL_WINDOW_FULLSCREEN;
|
||||
const bool c = options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
if (!(a || b || c))
|
||||
{
|
||||
options->videoMode = 0;
|
||||
}
|
||||
|
||||
if (options->windowSize < 1 || options->windowSize > 4)
|
||||
{
|
||||
options->windowSize = 3;
|
||||
}
|
||||
|
||||
// Aplica opciones
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
|
||||
const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
|
||||
options->screenWidth = (GAMECANVAS_WIDTH + incWidth) * options->windowSize;
|
||||
options->screenHeight = (GAMECANVAS_HEIGHT + incHeight) * options->windowSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->screenWidth = GAMECANVAS_WIDTH * options->windowSize;
|
||||
options->screenHeight = GAMECANVAS_HEIGHT * options->windowSize;
|
||||
}
|
||||
// if (options->borderEnabled)
|
||||
//{
|
||||
// const int incWidth = GAMECANVAS_WIDTH * options->borderSize;
|
||||
// const int incHeight = GAMECANVAS_HEIGHT * options->borderSize;
|
||||
// options->gameWidth = GAMECANVAS_WIDTH + incWidth;
|
||||
// options->gameHeight = GAMECANVAS_HEIGHT + incHeight;
|
||||
//}
|
||||
// else
|
||||
//{
|
||||
// options->gameWidth = GAMECANVAS_WIDTH;
|
||||
// options->gameHeight = GAMECANVAS_HEIGHT;
|
||||
//}
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -234,19 +311,20 @@ bool Director::saveConfig()
|
||||
}
|
||||
|
||||
// Escribe en el fichero
|
||||
if (options->fullScreenMode == 0)
|
||||
file << "## VISUAL OPTIONS\n";
|
||||
if (options->videoMode == 0)
|
||||
{
|
||||
file << "fullScreenMode=0\n";
|
||||
file << "videoMode=0\n";
|
||||
}
|
||||
|
||||
else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN)
|
||||
else if (options->videoMode == SDL_WINDOW_FULLSCREEN)
|
||||
{
|
||||
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN\n";
|
||||
file << "videoMode=SDL_WINDOW_FULLSCREEN\n";
|
||||
}
|
||||
|
||||
else if (options->fullScreenMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
else if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
{
|
||||
file << "fullScreenMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
||||
file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
||||
}
|
||||
|
||||
file << "windowSize=" + std::to_string(options->windowSize) + "\n";
|
||||
@@ -267,6 +345,12 @@ bool Director::saveConfig()
|
||||
file << "borderSize=" + std::to_string(options->borderSize) + "\n";
|
||||
file << "palette=" + std::to_string(options->palette) + "\n";
|
||||
|
||||
file << "\n## ONLINE OPTIONS\n";
|
||||
file << "enabled=" + boolToString(options->online.enabled) + "\n";
|
||||
file << "server=" + options->online.server + "\n";
|
||||
file << "port=" + std::to_string(options->online.port) + "\n";
|
||||
file << "jailerID=" + options->online.jailerID + "\n";
|
||||
|
||||
// Cierra el fichero
|
||||
file.close();
|
||||
|
||||
@@ -277,15 +361,15 @@ bool Director::saveConfig()
|
||||
void Director::createSystemFolder()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
systemFolder = std::string(getenv("APPDATA")) + "/jailgames/jaildoctors_dilemma";
|
||||
systemFolder = std::string(getenv("APPDATA")) + "/jaildoctors_dilemma";
|
||||
#elif __APPLE__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/Library/Application Support/jailgames/jaildoctors_dilemma";
|
||||
systemFolder = std::string(homedir) + "/Library/Application Support/jaildoctors_dilemma";
|
||||
#elif __linux__
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
const char *homedir = pw->pw_dir;
|
||||
systemFolder = std::string(homedir) + "/.jailgames/jaildoctors_dilemma";
|
||||
systemFolder = std::string(homedir) + "/.jaildoctors_dilemma";
|
||||
#endif
|
||||
|
||||
struct stat st = {0};
|
||||
@@ -883,19 +967,19 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
if (var == "fullScreenMode")
|
||||
if (var == "videoMode")
|
||||
{
|
||||
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
||||
{
|
||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
options->videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
else if (value == "SDL_WINDOW_FULLSCREEN")
|
||||
{
|
||||
options->fullScreenMode = SDL_WINDOW_FULLSCREEN;
|
||||
options->videoMode = SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
options->fullScreenMode = 0;
|
||||
options->videoMode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -964,7 +1048,31 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
|
||||
}
|
||||
}
|
||||
|
||||
else if (var == "")
|
||||
else if (var == "enabled")
|
||||
{
|
||||
options->online.enabled = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "server")
|
||||
{
|
||||
options->online.server = value;
|
||||
}
|
||||
|
||||
else if (var == "port")
|
||||
{
|
||||
if (value == "")
|
||||
{
|
||||
value = "0";
|
||||
}
|
||||
options->online.port = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "jailerID")
|
||||
{
|
||||
options->online.jailerID = value;
|
||||
}
|
||||
|
||||
else if (var == "" || var.substr(0, 1) == "#")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1044,7 +1152,15 @@ bool Director::initSDL()
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, options->screenWidth, options->screenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
int incW = 0;
|
||||
int incH = 0;
|
||||
if (options->borderEnabled)
|
||||
{
|
||||
incW = options->gameWidth * options->borderSize;
|
||||
incH = options->gameHeight * options->borderSize;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (window == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
@@ -1079,7 +1195,7 @@ bool Director::initSDL()
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(renderer, options->screenWidth, options->screenHeight);
|
||||
SDL_RenderSetLogicalSize(renderer, options->gameWidth, options->gameHeight);
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
Reference in New Issue
Block a user