Permalink
Browse files

Programmed GameConsole better and made Editor a console

  • Loading branch information...
1 parent 2501e95 commit 03135d8a404571be0ed631dcb1381358518fa823 @deek0146 committed Jun 22, 2012
View
@@ -23,9 +23,12 @@
namespace Editor
{
Editor::Editor()
+ :TypedGameComponent("gameMode", Filesystem::global()),
+ ConsoleInterface(false)
{
CEGUI::Window* root = CEGUI::System::getSingleton().getGUISheet();
activeMode = nullptr;
+ static_cast<Log*>(Filesystem::global()->getNode("dev/log"))->newConsole(this, "editor");
// activeMode = new EntityListEditor(this, new EntityListData("penis"), root);
}
@@ -48,19 +51,19 @@ namespace Editor
void Editor::init()
{
std::string command("new Folder named factories in .");
- executeCommand(&command);
+ executeCommand(command);
command = "new Folder named entities in .";
- executeCommand(&command);
+ executeCommand(command);
command = "new StaticSkinFactory named staticSkin in factories";
- executeCommand(&command);
+ executeCommand(command);
//command = "new GameObject named Crate in factories";
- //executeCommand(&command);
+ //executeCommand(command);
command = "new GameObject named crate in entities";
- executeCommand(&command);
+ executeCommand(command);
command = "new StaticPosition named position in entities/crate";
- executeCommand(&command);
+ executeCommand(command);
command = "new staticSkin named skin in entities/crate";
- executeCommand(&command);
+ executeCommand(command);
CEGUI::Window* root = CEGUI::System::getSingleton().getGUISheet();
activeMode = new FilesystemEditor(this);
@@ -73,28 +76,30 @@ namespace Editor
}
};
- void Editor::registerActions()
+ void Editor::registerActions(GameComponentType* _type)
{
DefaultFactories::global()->addFactory<Editor, StaticData>();
+ _type->exposeInterface<Editor, ConsoleInterface>();
+ _type->exposeInterface<Editor, UpdateFunctionInterface>();
}
- bool Editor::v_Update()
+ void Editor::virtualOutputText(const std::string& _message)
+ {
+ }
+
+ void Editor::update()
{
bool running = true;
/// FIXME needs a timer
//activeMode->update();
running = g_InputManager.processInput();
- g_GraphicsManager.beginScene();
- // g_InputManager.render();
- //activeMode->render();
- //SDL_Delay(5);
- g_GraphicsManager.endScene();
- return running;
+ if (!running)
+ getParent()->detachChild(this);
}
- void Editor::executeCommand(std::string* _command)
+ void Editor::executeCommand(const std::string& _command)
{
- parser->executeCommand(_command);
+ parser->executeCommand(&_command);
}
void Editor::rebuild(InstanceParameters* _parameters)
View
@@ -1,6 +1,8 @@
#pragma once
-#include <GameModes/GameMode.h>
+#include <Objects/GameComponent.h>
+#include <Objects/GameInterfaces/ConsoleInterface.h>
+#include <Objects/GameInterfaces/UpdateFunctionInterface.h>
class PropertyBagInterface;
class InstanceParameters;
@@ -10,20 +12,25 @@ namespace Editor
class CommandParser;
class DataManager;
class StaticData;
- class Editor: public GameMode
+ class Editor: public TypedGameComponent<Editor>, public ConsoleInterface, public UpdateFunctionInterface
{
public:
Editor();
~Editor();
void init();
- void executeCommand(std::string* _command);
DataManager* getData(){return data;}
void rebuild(InstanceParameters* _params);
- static void registerActions();
+ static void registerActions(GameComponentType* _type);
+ static std::string name()
+ {
+ return "Editor";
+ }
static void typeInit(StaticData* _data, PropertyBagInterface* _params);
void instanceInit(StaticData* _data, PropertyBagInterface* _params);
+ void executeCommand(const std::string& _command);
protected:
- bool v_Update();
+ void virtualOutputText(const std::string& _message);
+ void update();
EditorMode* activeMode;
CommandParser* parser;
DataManager* data;
@@ -26,7 +26,7 @@ namespace Editor
{
}
- void CommandParser::executeCommand(std::string* _command)
+ void CommandParser::executeCommand(const std::string* _command)
{
try
{
@@ -65,7 +65,7 @@ namespace Editor
}
}
- void CommandParser::parse(std::string* _command, bool _undo)
+ void CommandParser::parse(const std::string* _command, bool _undo)
{
g_CommandParser = this;
input = *_command + '\n';
@@ -24,7 +24,7 @@ namespace Editor
public:
CommandParser(Editor* _editor, DataManager* _data);
~CommandParser();
- void executeCommand(std::string* _command);
+ void executeCommand(const std::string* _command);
void undo();
void redo();
@@ -41,7 +41,7 @@ namespace Editor
int getInput();
private:
//AbstractFactories* getFactories();
- void parse(std::string* _command, bool _undo);
+ void parse(const std::string* _command, bool _undo);
UndoControl<std::string>* undoControl;
Editor* editor;
@@ -15,14 +15,21 @@ Filesystem::Filesystem()
assert(getChildren() == dev);
assert(getNode("dev") == dev);
assert(getIndividualNode("dev") == dev);
- orphanList = new OrphanList(this);
+ orphanList = new OrphanList;
+ attachChild(orphanList);
}
Filesystem::~Filesystem()
{
//dtor
}
+OrphanList* Filesystem::getOrphanList()
+{
+ static OrphanList* orphanList = new OrphanList;
+ getNode("dev")->attachChild(orphanList);
+ return orphanList;
+}
Filesystem* Filesystem::global()
{
return singleton();
View
@@ -11,8 +11,7 @@ class Filesystem: public Singleton<Filesystem>
{
public:
void shutdown();
- OrphanList* getOrphanList() /// "/dev/orphans"
- {return orphanList;}
+ OrphanList* getOrphanList(); /// "/dev/orphans"
static Filesystem* global(); /// "/"
static void singletonRegisterActions(GameComponentType* _type);
View
@@ -1,22 +1,23 @@
#include "OrphanList.h"
-OrphanList::OrphanList(GameComponent* _parent)
- :TypedGameComponent<OrphanList>("orphans", _parent, false)
+OrphanList::OrphanList()
+ :Singleton("orphans", false)
{
- //ctor
+ //ctor
+ //Filesystem::global()->getNode("dev")->attachChild(this);
}
OrphanList::~OrphanList()
{
- //dtor
+ //dtor
}
void OrphanList::attachOrphan(GameComponent* _node)
{
attachChild(_node);
}
-void OrphanList::registerActions(GameComponentType* _type)
+void OrphanList::singletonRegisterActions(GameComponentType* _type)
{
}
View
@@ -1,24 +1,24 @@
#ifndef ORPHANLIST_H
#define ORPHANLIST_H
-#include <GameObject.h>
+#include <Objects/Singleton.h>
-class OrphanList : public TypedGameComponent<OrphanList>
+class OrphanList : public Singleton<OrphanList>
{
- public:
- OrphanList(GameComponent* _parent);
- virtual ~OrphanList();
- void attachOrphan(GameComponent* _node);
- static void registerActions(GameComponentType* _type);
- static std::string name()
- {
- return "OrphanList";
- }
- EventHandle* getEventHandle(const std::string& _name){throw -1;}
- void print(std::string* _output);
- protected:
- private:
- std::string virtualPrint();
+public:
+ OrphanList();
+ virtual ~OrphanList();
+ void attachOrphan(GameComponent* _node);
+ static void singletonRegisterActions(GameComponentType* _type);
+ static std::string name()
+ {
+ return "OrphanList";
+ }
+ EventHandle* getEventHandle(const std::string& _name){throw -1;}
+ void print(std::string* _output);
+protected:
+private:
+ std::string virtualPrint();
};
#endif // ORPHANLIST_H
View
@@ -40,7 +40,6 @@ void Game::init()
//EditorMode* typedMode = new EditorMode(new ShooterGame());
Editor::Editor* typedMode = new Editor::Editor();
typedMode->instanceInit(nullptr, nullptr);
- gameMode = typedMode;
CEGUI::EventArgs args;
// typedMode->activate(args);
@@ -56,12 +55,15 @@ Game::~Game()
#include <GL/gl.h>
void Game::run()
{
- while (static_cast<GameMode*>(Filesystem::global()->getNode("gameMode"))->update())
+ GameComponent* gameMode = Filesystem::global()->getNode("gameMode");
+ while (gameMode)
{
g_GraphicsManager.beginScene();
+ gameMode->getInterface<UpdateFunctionInterface>()->update();
//Filesystem::global()->getNode("game/entities/crate/skin")->getInterface<RenderInterface>()->render();
Filesystem::global()->getNode("game/entities/crate/skin")->getInterface<RenderInterface>()->render();
g_GraphicsManager.endScene();
+ gameMode = Filesystem::global()->getNode("gameMode");
}
//delete gameMode;
}
View
5 Game.h
@@ -1,10 +1,6 @@
#ifndef GAME_H
#define GAME_H
-class InputContext;
-class Level;
-class GameMode;
-
extern class Game
{
public:
@@ -14,7 +10,6 @@ extern class Game
void run();
protected:
private:
- GameMode* gameMode;
}g_Game;
#endif // GAME_H
View
@@ -0,0 +1,42 @@
+#include <Log/ConsoleBox.h>
+#include <Objects/GameInterfaces/ConsoleInterface.h>
+#include <CEGUI/CEGUI.h>
+#include <Log/Log.h>
+
+ConsoleBox::ConsoleBox(ConsoleInterface* _console, CEGUI::Window* _window, const std::string& _name)
+ :TypedGameComponent(_name)
+{
+ console = _console;
+ window = _window;
+ window->setUserData(this);
+ console->getTextPrintedHandle()->registerListener(this, print);
+}
+
+ConsoleBox::~ConsoleBox()
+{
+}
+
+ActionHandle* ConsoleBox::print = nullptr;
+void ConsoleBox::registerActions(GameComponentType* _type)
+{
+ print = _type->createActionHandle<ConsoleBox, std::string>("print", &ConsoleBox::printAction);
+}
+
+void ConsoleBox::printAction(std::string* _message)
+{
+ std::string message = *_message;
+ outputText(*_message);
+}
+
+void ConsoleBox::outputText(std::string _msg, unsigned int _timeStamp, unsigned int _colour)
+{
+ CEGUI::Listbox *outputWindow = dynamic_cast<CEGUI::Listbox*>(window);
+ //static_cast<CEGUI::Listbox*>(window->getChildRecursive("ChatBox"));
+ assert(outputWindow);
+
+ CEGUI::ListboxTextItem *newItem=0;
+ newItem = new CEGUI::ListboxTextItem(Log::getTimeString(_timeStamp) + ' ' + _msg,CEGUI::HTF_WORDWRAP_LEFT_ALIGNED);
+ newItem->setTextColours(_colour);
+ outputWindow->addItem(newItem);
+}
+
View
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <Objects/GameComponent.h>
+class ConsoleInterface;
+namespace CEGUI
+{
+ class Window;
+}
+
+class ConsoleBox: public TypedGameComponent<ConsoleBox>
+{
+public:
+ ConsoleBox(ConsoleInterface* _console, CEGUI::Window* _window, const std::string& _name);
+ ~ConsoleBox();
+ static void registerActions(GameComponentType* _type);
+ static std::string name()
+ {
+ return "ConsoleBox";
+ }
+ ConsoleInterface* getConsoleInterface(){return console;}
+private:
+ static ActionHandle* print;
+ ConsoleInterface* console;
+ CEGUI::Window* window;
+ void outputText(std::string _msg, unsigned int timeStamp = 0, unsigned int _colour = -1);
+ void printAction(std::string* _print);
+};
Oops, something went wrong.

0 comments on commit 03135d8

Please sign in to comment.