Commit 2061ee57 authored by Leeor Dicker's avatar Leeor Dicker

Pulled config options. Completes issue #2.

parent 9f637192
#ifndef __CONFIG_STRINGS__
#define __CONFIG_STRINGS__
#include <string>
const std::string CONFIG_UI_BUTTON_CREATE_NEW_MAP = "ui-button-create-new-map";
const std::string CONFIG_UI_BUTTON_LOAD_EXISTING_MAP = "ui-button-load-existing-map";
const std::string CONFIG_UI_BUTTON_REFRESH_LISTS = "ui-button-refresh-lists";
const std::string CONFIG_UI_TEXTFIELD_DEFAULT_WIDTH = "ui-textfield-default-map-width";
const std::string CONFIG_UI_TEXTFIELD_DEFAULT_HEIGHT = "ui-textfield-default-map-height";
const std::string CONFIG_UI_MOUSE_POINTER_IMAGE = "ui-mouse-pointer-image";
const std::string CONFIG_UI_TILEPALETTE_SHOW_IMAGE = "ui-tilepalette-show-image";
const std::string CONFIG_UI_TILEPALETTE_DOWN_IMAGE = "ui-tilepalette-down-image";
const std::string CONFIG_UI_TILEPALETTE_PREV_IMAGE = "ui-tilepalette-prev-image";
const std::string CONFIG_UI_TILEPALETTE_NEXT_IMAGE = "ui-tilepalette-next-image";
const std::string CONFIG_UI_TILEPALETTE_BUCKET_IMAGE = "ui-tilepalette-bucket-image";
const std::string CONFIG_EDITOR_MAPS_PATH = "editor-maps-path";
const std::string CONFIG_EDITOR_TILESETS_PATH = "editor-tilesets-path";
const std::string CONFIG_EDITOR_NEW_MAP_NAME = "editor-new-map-name";
#endif
\ No newline at end of file
......@@ -2,25 +2,9 @@
#include <string>
// This file defines a number of default strings and other values
// that are stored in the Configuration file.
const std::string UI_BUTTON_CREATE_NEW_MAP = "Create New";
const std::string UI_BUTTON_LOAD_EXISTING_MAP = "Load Map";
const std::string UI_BUTTON_REFRESH_LISTS = "Refresh Lists";
const std::string UI_TEXTFIELD_DEFAULT_WIDTH = "50";
const std::string UI_TEXTFIELD_DEFAULT_HEIGHT = "50";
const std::string UI_MOUSE_POINTER_IMAGE = "sys/normal.png";
const std::string UI_TILEPALETTE_SHOW_IMAGE = "sys/up.png";
const std::string UI_TILEPALETTE_DOWN_IMAGE = "sys/down.png";
const std::string UI_TILEPALETTE_PREV_IMAGE = "sys/prev.png";
const std::string UI_TILEPALETTE_NEXT_IMAGE = "sys/next.png";
const std::string UI_TILEPALETTE_BUCKET_IMAGE = "sys/paintcan.png";
const std::string EDITOR_MAPS_PATH = "maps/";
const std::string EDITOR_TILESETS_PATH = "tsets/";
const std::string EDITOR_TSET_PATH = "tsets/";
const std::string EDITOR_NEW_MAP_NAME = "New Map";
#include "StartState.h"
#include "ConfigStrings.h"
#include "Defaults.h"
#include "Common.h"
......@@ -22,7 +22,7 @@ void setMessage(const std::string& msg)
* C'tpr
*/
StartState::StartState(): mFont("fonts/ui-normal.png", 7, 9, 0),
mMousePointer(Utility<Configuration>::get().option(CONFIG_UI_MOUSE_POINTER_IMAGE)),
mMousePointer("sys/normal.png"),
mLayoutRect(15, 15, Utility<Renderer>::get().width() - 30, Utility<Renderer>::get().height() - 40),
mReturnState(nullptr)
{
......@@ -55,32 +55,32 @@ void StartState::initialize()
mBtnCreateNew.font(mFont);
mBtnCreateNew.size(85, 25);
mBtnCreateNew.text(c.option(CONFIG_UI_BUTTON_CREATE_NEW_MAP));
mBtnCreateNew.text("Create New");
mBtnCreateNew.position(mLayoutRect.x() + mLayoutRect.w() - 95, mLayoutRect.y() + mLayoutRect.h() - 35);
mBtnCreateNew.click().Connect(this, &StartState::button_CreateNew_click);
mBtnLoadExisting.font(mFont);
mBtnLoadExisting.size(85, 25);
mBtnLoadExisting.text(c.option(CONFIG_UI_BUTTON_LOAD_EXISTING_MAP));
mBtnLoadExisting.text("Load Map");
mBtnLoadExisting.position(mLayoutRect.x() + 10, mLayoutRect.y() + mLayoutRect.h() - 35);
mBtnLoadExisting.click().Connect(this, &StartState::button_LoadExisting_click);
mBtnRefreshLists.font(mFont);
mBtnRefreshLists.size(100, 25);
mBtnRefreshLists.text(c.option(CONFIG_UI_BUTTON_REFRESH_LISTS));
mBtnRefreshLists.text("Refresh List");
mBtnRefreshLists.position(mLayoutRect.x() + (mLayoutRect.w() / 2) - mBtnRefreshLists.rect().w() - 10, mLayoutRect.y() + mLayoutRect.h() - 35);
mBtnRefreshLists.click().Connect(this, &StartState::button_RefreshLists_click);
mTxtWidth.font(mFont);
mTxtWidth.width(100);
mTxtWidth.text(c.option(CONFIG_UI_TEXTFIELD_DEFAULT_WIDTH));
mTxtWidth.text(UI_TEXTFIELD_DEFAULT_WIDTH);
mTxtWidth.position(mLayoutRect.x() + mLayoutRect.w() / 2 + 10 + mFont.width("Width:") + 5, mLayoutRect.y() + 10);
mTxtWidth.border(TextField::ALWAYS);
mTxtHeight.font(mFont);
mTxtHeight.width(100);
mTxtHeight.text(c.option(CONFIG_UI_TEXTFIELD_DEFAULT_HEIGHT));
mTxtHeight.text(c.option(UI_TEXTFIELD_DEFAULT_HEIGHT));
mTxtHeight.position(mLayoutRect.x() + mLayoutRect.w() / 2 + 210 + mFont.width("Height:") + 5, mLayoutRect.y() + 10);
mTxtHeight.border(TextField::ALWAYS);
......@@ -91,12 +91,12 @@ void StartState::initialize()
mMapFilesMenu.font(mFont);
mMapFilesMenu.position(mLayoutRect.x() + 10, mLayoutRect.y() + 10);
scanDirectory(c.option(CONFIG_EDITOR_MAPS_PATH), mMapFilesMenu);
scanDirectory(EDITOR_MAPS_PATH, mMapFilesMenu);
mMapFilesMenu.width(mLayoutRect.w() / 2 - 20);
mTsetFilesMenu.font(mFont);
mTsetFilesMenu.position(mLayoutRect.x() + mLayoutRect.w() / 2 + 10, mLayoutRect.y() + 50);
scanDirectory(c.option(CONFIG_EDITOR_TILESETS_PATH), mTsetFilesMenu);
scanDirectory(EDITOR_TSET_PATH, mTsetFilesMenu);
mTsetFilesMenu.width(mLayoutRect.w() / 2 - 20);
......@@ -175,7 +175,7 @@ void StartState::button_CreateNew_click()
}
Configuration& c = Utility<Configuration>::get();
mReturnState = new EditorState(c.option(CONFIG_EDITOR_NEW_MAP_NAME), c.option(CONFIG_EDITOR_MAPS_PATH) + txtMapPath.text(), c.option(CONFIG_EDITOR_TILESETS_PATH) + mTsetFilesMenu.selectionText(), mapWidth, mapHeight);
mReturnState = new EditorState(EDITOR_NEW_MAP_NAME, EDITOR_MAPS_PATH + txtMapPath.text(), EDITOR_TSET_PATH + mTsetFilesMenu.selectionText(), mapWidth, mapHeight);
}
......@@ -184,7 +184,7 @@ void StartState::button_CreateNew_click()
*/
void StartState::button_LoadExisting_click()
{
string mapPath = Utility<Configuration>::get().option(CONFIG_EDITOR_MAPS_PATH) + mMapFilesMenu.selectionText();
string mapPath = EDITOR_MAPS_PATH + mMapFilesMenu.selectionText();
// In the event someone does something completely idiotic like deleting map files after the
// editor has scanned the maps directory (or some other error occurs where the map file is
......@@ -206,8 +206,8 @@ void StartState::button_RefreshLists_click()
Configuration& c = Utility<Configuration>::get();
scanDirectory(c.option(CONFIG_EDITOR_MAPS_PATH), mMapFilesMenu);
scanDirectory(c.option(CONFIG_EDITOR_TILESETS_PATH), mTsetFilesMenu);
scanDirectory(EDITOR_MAPS_PATH, mMapFilesMenu);
scanDirectory(EDITOR_TSET_PATH, mTsetFilesMenu);
}
......
......@@ -45,12 +45,12 @@ void TilePalette::init()
mBtnPrev.size(30, 20);
mBtnPrev.position(mRect.x() + 3, yPosition);
mBtnPrev.image(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_PREV_IMAGE));
mBtnPrev.image("sys/prev.png");
mBtnPrev.click().Connect(this, &TilePalette::button_Prev_click);
mBtnNext.size(30, 20);
mBtnNext.position(mRect.x() + mRect.w() - (mBtnNext.width() + 2), yPosition);
mBtnNext.image(Utility<Configuration>::get().option(CONFIG_UI_TILEPALETTE_NEXT_IMAGE));
mBtnNext.image("sys/next.png");
mBtnNext.click().Connect(this, &TilePalette::button_Next_click);
// Hook events
......
......@@ -3,15 +3,15 @@
#include "EditorState.h"
#include "StartState.h"
#include "ConfigStrings.h"
#include "Defaults.h"
using namespace std;
#ifdef WINDOWS
#include <Windows.h>
#endif
void validateOptions();
using namespace std;
int main(int argc, char *argv[])
......@@ -20,8 +20,10 @@ int main(int argc, char *argv[])
try
{
Game game("Landlord", argv[0], "editor.xml");
validateOptions();
game.mount("editor.zip");
throw;
game.go(new StartState());
}
catch(Exception e)
......@@ -29,65 +31,17 @@ int main(int argc, char *argv[])
stringstream errorMessage;
errorMessage << "Error (" << e.getCode() << "):" << endl << endl << e.getDescription();
#if defined(WIN32)
#if defined(WINDOWS)
MessageBoxA(NULL, errorMessage.str().c_str(), e.getBriefDescription().c_str(), MB_OK | MB_ICONERROR | MB_TASKMODAL);
#endif
}
catch(...)
{
#if defined(WINDOWS)
MessageBoxA(NULL, "An unexpected error occured. Please yell at Lee about\nthis so he can fix it.", "Unhandled Exception", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#endif
}
return 0;
}
void validateOptions()
{
Configuration& c = Utility<Configuration>::get();
if(c.option(CONFIG_UI_BUTTON_CREATE_NEW_MAP).empty())
c.option(CONFIG_UI_BUTTON_CREATE_NEW_MAP, UI_BUTTON_CREATE_NEW_MAP);
if(c.option(CONFIG_UI_BUTTON_LOAD_EXISTING_MAP).empty())
c.option(CONFIG_UI_BUTTON_LOAD_EXISTING_MAP, UI_BUTTON_LOAD_EXISTING_MAP);
if(c.option(CONFIG_UI_BUTTON_REFRESH_LISTS).empty())
c.option(CONFIG_UI_BUTTON_REFRESH_LISTS, UI_BUTTON_REFRESH_LISTS);
if(c.option(CONFIG_UI_TEXTFIELD_DEFAULT_WIDTH).empty())
c.option(CONFIG_UI_TEXTFIELD_DEFAULT_WIDTH, UI_TEXTFIELD_DEFAULT_WIDTH);
if(c.option(CONFIG_UI_TEXTFIELD_DEFAULT_HEIGHT).empty())
c.option(CONFIG_UI_TEXTFIELD_DEFAULT_HEIGHT, UI_TEXTFIELD_DEFAULT_HEIGHT);
if(c.option(CONFIG_UI_MOUSE_POINTER_IMAGE).empty())
c.option(CONFIG_UI_MOUSE_POINTER_IMAGE, UI_MOUSE_POINTER_IMAGE);
if(c.option(CONFIG_UI_TILEPALETTE_SHOW_IMAGE).empty())
c.option(CONFIG_UI_TILEPALETTE_SHOW_IMAGE, UI_TILEPALETTE_SHOW_IMAGE);
if(c.option(CONFIG_UI_TILEPALETTE_DOWN_IMAGE).empty())
c.option(CONFIG_UI_TILEPALETTE_DOWN_IMAGE, UI_TILEPALETTE_DOWN_IMAGE);
if(c.option(CONFIG_UI_TILEPALETTE_NEXT_IMAGE).empty())
c.option(CONFIG_UI_TILEPALETTE_NEXT_IMAGE, UI_TILEPALETTE_NEXT_IMAGE);
if(c.option(CONFIG_UI_TILEPALETTE_PREV_IMAGE).empty())
c.option(CONFIG_UI_TILEPALETTE_PREV_IMAGE, UI_TILEPALETTE_PREV_IMAGE);
if(c.option(CONFIG_UI_TILEPALETTE_BUCKET_IMAGE).empty())
c.option(CONFIG_UI_TILEPALETTE_BUCKET_IMAGE, UI_TILEPALETTE_BUCKET_IMAGE);
if(c.option(CONFIG_EDITOR_MAPS_PATH).empty())
c.option(CONFIG_EDITOR_MAPS_PATH, EDITOR_MAPS_PATH);
if(c.option(CONFIG_EDITOR_TILESETS_PATH).empty())
c.option(CONFIG_EDITOR_TILESETS_PATH, EDITOR_TILESETS_PATH);
if(c.option(CONFIG_EDITOR_NEW_MAP_NAME).empty())
c.option(CONFIG_EDITOR_NEW_MAP_NAME, EDITOR_NEW_MAP_NAME);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment