Commits

Ricky Curtice  committed d1e9585

Got UI Core compiling.

However, the logic, design, and even some of the code may not yet be correct.
It's just compiling.

  • Participants
  • Parent commits 7f889de

Comments (0)

Files changed (7)

File src/ui_core/HUD.cpp

 namespace UICore {
 	
 	void HUD::Render(LPDIRECT3DDEVICE9 device) {
-		if (!showmenu) {
-			for (int i=0;i<parts.size();++i) parts[i].Render(device);
-		} else if (menu!=NULL) {
-			menu->Render(device);
+		if (!this->showmenu) {
+			for (int i = 0; i < this->parts.size(); ++i) {
+				this->parts[i]->Render(device);
+			}
+		}
+		else if (this->menu != NULL) {
+			this->menu->Render(device);
 		}
 	}
 	
 	void HUD::click(int a,int b) {
-		if (showmenu && menu!=NULL) menu->click(a,b);
+		if (this->showmenu && this->menu != NULL) {
+			this->menu->click(a, b);
+		}
 		else {
-			for (int i=0;i<parts.size();++i) {
-				if (parts[i].contains(a,b)) parts[i].click(a-parts[i].x,b-parts[i].y);
+			for (int i = 0; i < parts.size(); ++i) {
+				if (this->parts[i]->contains(a, b)) {
+					this->parts[i]->click(a - this->parts[i]->x, b - this->parts[i]->y);
+				}
 			}
 		}
 	}
 	
 	void HUD::Update(double dt) {
-		if (showmenu && menu!=NULL) menu->Update(dt);
+		if (this->showmenu && this->menu != NULL) {
+			this->menu->Update(dt);
+		}
 		else {
-			for (int i=0;i<parts.size();++i) {
-				parts[i].Update(dt);
+			for (int i = 0; i < this->parts.size(); ++i) {
+				this->parts[i]->Update(dt);
 			}
 		}
 	}
 
-}
+}

File src/ui_core/HUD.h

 	class HUDPart;
 	class Menu;
 
-class HUD : RenderableComponent {
-public:
-	std::vector<HUDPart> parts;
-	bool showmenu;
-	Menu* menu;
-	
-	HUD(RenderEngine* engine) : RenderableComponent(NULL, engine) {
-		this->SetCoordSpace(GraphicsCore::CS_SCREEN);
-	}
+	class HUD : public GraphicsCore::RenderableComponent {
+	public:
+		HUD(Entity* owner, CoreInterface* core) : GraphicsCore::RenderableComponent(owner, core) {
+			this->SetCoordSpace(GraphicsCore::CS_SCREEN);
+		}
 
-	~HUD() {
+		~HUD() {
+			
+		}
 
-	}
+		void Render(LPDIRECT3DDEVICE9 device);
+		void click(int a,int b);
+		void Update(double dt);
 
-	void Render(LPDIRECT3DDEVICE9 device);
-	void click(int a,int b);
-	void Update(double dt);
-};
+		//*TODO: maybe should be private?
+		std::vector<HUDPart*> parts;
+		bool showmenu;
+		Menu* menu;
+	private:
+		
+	};
 
-}
+}

File src/ui_core/Input.cpp

 #include <windows.h>
+#include "../CoreInterface.h"
 #include "../ComponentInterface.h"
-#include "Menu.h"
+#include "../Envelope.h"
+#include "Input.h"
 
 namespace UICore {
 
 		return KeyArray[KeyBuffer];
 	}
 
-	void keyPress(int key) {
-		Envelope<int> e;
+	void Input::keyPress(int key) {
+		EnvelopeAny e;
 		e.AddData(key);
-		core->msghndlr->SendMessage(701,e);
+		//core->msghndlr->SendMessage(701,e);
 	}
 
-	void mousePress() {
-		Envelope<int> e;
+	void Input::mouseClick() {
+		EnvelopeAny e;
 		e.AddData(mouseloc.x);
 		e.AddData(mouseloc.y);
-		core->msghndlr->SendMessage(702,e);
+		//core->msghndlr->SendMessage(702,e);
 	}
 
-	void mouseDrag() {
-		Envelope<int> e;
+	void Input::mouseDrag() {
+		EnvelopeAny e;
 		e.AddData(mouseloc.x);
 		e.AddData(mouseloc.y);
-		core->msghndlr->SendMessage(703,e);
+		//core->msghndlr->SendMessage(703,e);
 	}
 
-	LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-	{
-		switch (message) 
-		{
-		case WM_DESTROY:
-				PostQuitMessage(0);
-				break;
-	
-		case WM_KEYDOWN:
-				KeyBuffer = (int)wParam;    // virtual-key code 
-				keyData = lParam;          // key data 
-				KeyArray[KeyBuffer]=true;
-				keyPress();
-				break;
-		 
-		case WM_KEYUP:
-				KeyBuffer = (int)wParam;    // virtual-key code 
-				keyData = lParam;          // key data 
-				KeyArray[KeyBuffer]=false;
-				break;
+	LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
+		switch (message) {
+		//case WM_KEYDOWN:
+		//		KeyBuffer = (int)wParam;    // virtual-key code 
+		//		keyData = lParam;          // key data 
+		//		KeyArray[KeyBuffer]=true;
+		//		keyPress();
+		//		break;
+		// 
+		//case WM_KEYUP:
+		//		KeyBuffer = (int)wParam;    // virtual-key code 
+		//		keyData = lParam;          // key data 
+		//		KeyArray[KeyBuffer]=false;
+		//		break;
 
-		case WM_LBUTTONDOWN:
-				mouseClick();
-		      	 	LeftDown = true;
-		       		break;
+////		case WM_LBUTTONDOWN:
+		//		mouseClick();
+		//      	 	LeftDown = true;
+		//       		break;
 
-		case WM_MOUSEMOVE:
-				GetCursorPos(&mouseloc);
-				if ( LeftDown || RightDown ) mouseDrag(); 
-		      		break;
+////		case WM_MOUSEMOVE:
+		//		GetCursorPos(&mouseloc);
+		//		if ( LeftDown || RightDown ) mouseDrag(); 
+		//      		break;
 
-		case WM_LBUTTONUP:
-		       		LeftDown = false;
-		       		break;
+////		case WM_LBUTTONUP:
+		//       		LeftDown = false;
+		//       		break;
 
-		case WM_RBUTTONDOWN:
-		      		mouseClick();
-				RightDown = true;
-		     		break;
+////		case WM_RBUTTONDOWN:
+		//      		mouseClick();
+		//		RightDown = true;
+		//     		break;
 
 		case WM_RBUTTONUP:
-				RightDown = false;
-		     		break;
+		//		RightDown = false;
+			break;
 
 		default:
-				break;
+			break;
 		}
 	
 		return DefWindowProc(hWnd, message, wParam, lParam);
 	}
-	return 0;
-	}
-}
+}

File src/ui_core/Input.h

 namespace UICore {
 
 	class Input : public ComponentInterface {
-		int KeyBuffer = NULL;
-		POINT mouseloc;
-		LPARAM keyData = NULL;
-		bool KeyArray[300] = {0};
-		bool LeftDown = false;
-		bool RightDown = false;
-
+	public:
 		Input(Entity* owner,CoreInterface* core) : ComponentInterface(owner,core) {
-
+			KeyBuffer = NULL;
+			keyData = NULL;
+			for (unsigned int index = 0; index < 300; ++index) {
+				KeyArray[index] = false;
+			}
+			LeftDown = false;
+			RightDown = false;
 		}
 
 		~Input() { }
 		void keyPress(int key);
 		void mouseClick();
 		void mouseDrag();
+		
+		
+		int KeyBuffer;
+		POINT mouseloc;
+		LPARAM keyData;
+		bool KeyArray[300];
+		bool LeftDown;
+		bool RightDown;
+
 	};
-}
+}

File src/ui_core/Menu.h

-#include <vector.h>
+#include <vector>
 #include <d3d9.h>
 #include <d3dx9tex.h>
 #include "HUDPart.h"
 
 	class Menu : public HUDPart {
 	public:
-		std::vector<Menu> submenu;
+		std::vector<Menu*> submenu;
 		Menu* up;
 		HUD* hud;
 	
 		//Add a menu to this menu's list of submenus
 		void addSubmenu(Menu* m);
 	};
-}
+}

File src/ui_core/UIEngine.cpp

+#include <boost/foreach.hpp>
+
+#include "../Envelope.h"
 #include "UIEngine.h"
 
 namespace UICore {
+	UIEngine::UIEngine(GlobalProperties* gprops, MessageDispatcher* msghndlr) : CoreInterface(gprops,msghndlr) {
+		this->hud = new HUD(NULL, this); //*HACK: NULL here will cause a runtime crash in RenderEngine.
+		this->input = new Input(NULL, this);
+	}
 
-	void UIEngine::Startup() {
-		hud=new HUD(renderEngine);
-		input=new Input(NULL,this);
+	UIEngine::~UIEngine() {
+		delete this->hud;
+		delete this->input;
+	}
+
+
+	bool UIEngine::Startup() {
+		bool status = false;
+		
+		//*TODO: Does something need to be done here?
+		
+		return status;
 	}
 
 	void UIEngine::Update(double dt) {
-		hud->Update(dt);
+		this->hud->Update(dt);
 	}
 
-	void UIEngine::Shutdown() {delete hud;delete input;}
+	void UIEngine::Shutdown() {
+	}
 
-	void UIEngine::Message(int msg,EnvelopeAny* e) {
-		if (msg==701) {
-			int x = e->GetData(0);
-			int y = e->GetData(1);
-			hud->click(x,y);
+	void UIEngine::Message(int msg, EnvelopeAny* e) {
+		if (msg == 710) {
+			int x = boost::any_cast<int>(e->GetData(0)); //*TODO: try-catch the boost::bad_any_cast error case and log it.
+			int y = boost::any_cast<int>(e->GetData(1));
+			this->hud->click(x, y);
 		}
 	}
 
-	void UIEngine::addPart(HUDPart* a) {
-		hud->parts.push_back(a);
+	void UIEngine::CreateComponent(std::string type, std::map< std::string, boost::any > &attributes, Entity* e) {
+		//*TODO: Create the requested components
 	}
 
-	void UIEngine::addPart(HUDPart* a,char* b) {
-		hud->parts.push_back(a);
-		labels[b] = a;
+	void UIEngine::addPart(HUDPart* a) {
+		this->hud->parts.push_back(a);
+	}
+
+	void UIEngine::addPart(HUDPart* a, std::string name) {
+		this->hud->parts.push_back(a);
+		this->labels[name] = a;
 	}
 
 	void UIEngine::removePart(HUDPart* a) {
-		for (int i=0;i<hud->parts.size();++i) if (hud->parts[i]==a) hud->parts.erase(i);
-		for (iterator i = labels.begin();i!=labels.end();++i) if ((*i).second==a) labels.erase(*i);
+		for (std::vector<HUDPart*>::iterator it = this->hud->parts.begin(); it != this->hud->parts.end(); ++it) {
+			HUDPart* hudPart = *it;
+			if (hudPart == a) { //*TODO: Can't compare pointers!!!
+				this->hud->parts.erase(it);
+			}
+		}
+		
+		for (std::map<std::string, HUDPart*>::iterator i = this->labels.begin(); i != this->labels.end(); ++i) {
+			if ((*i).second == a) {
+				this->labels.erase(i);
+			}
+		}
 	}
 
-	void UIEngine::removePart(char* b) {
-		for (int i=0;i<hud->parts.size();++i) if (hud->parts[i]==labels[b]) hud->parts.erase(i);
-		for (iterator i = labels.begin();i!=labels.end();++i) if ((*i).first==b) labels.erase(*i);
+	void UIEngine::removePart(std::string name) {
+		for (std::vector<HUDPart*>::iterator it = this->hud->parts.begin(); it != this->hud->parts.end(); ++it) {
+			HUDPart* hudPart = *it;
+			if (hudPart == this->labels[name]) { //*TODO: Can't compare pointers!!!
+				this->hud->parts.erase(it);
+			}
+		}
+		
+		for (std::map<std::string, HUDPart*>::iterator i = this->labels.begin(); i != this->labels.end(); ++i) {
+			if (name.compare((*i).first) == 0) {
+				this->labels.erase(i);
+			}
+		}
 	}
 
 	void UIEngine::showAll() {
-		for (int i=0;i<hud->parts.size();++i) hud->parts[i].show();
+		for (unsigned int i=0; i < this->hud->parts.size(); ++i) {
+			this->hud->parts[i]->show();
+		}
 	}
 
 	void UIEngine::hideAll() {
-		for (int i=0;i<hud->parts.size();++i) hud->parts[i].hide();
+		for (unsigned int i = 0; i < this->hud->parts.size(); ++i) {
+			this->hud->parts[i]->hide();
+		}
 	}
 
-	HUDPart* UIEngine::get(char* b) {
-		return labels[b];
+	HUDPart* UIEngine::get(std::string name) {
+		return this->labels[name];
 	}
-}
+}

File src/ui_core/UIEngine.h

 #include <map>
 #include <string>
+#include <boost/any.hpp>
+
+#include "../CoreInterface.h"
 #include "HUD.h"
 #include "HUDPart.h"
-#include "../CoreInterface.h"
-#include "../lib/boost/any.hpp"
+#include "Input.h"
 
 namespace UICore {
+	class UIEngine : public CoreInterface {
+	public:
+		UIEngine(GlobalProperties* gprops, MessageDispatcher* msghndlr);
+		~UIEngine();
 
-	class UIEngine : CoreInterface {
-	public:
-		HUD hud;
-		Input input;
-		RenderEngine* renderEngine;
 
-		UIEngine(GlobalProperties* gprops, MessageDispatcher* msghndlr, RenderEngine* engine) : CoreInterface(gprops,msghndlr) {renderEngine=engine;}
-		~UIEngine() { }
-
-
+		// Inherited from CoreInterface
 		void Update(double dt);
-		void Pause();
-		void Resume();
-		void Startup();
+		void Pause() { }; // Unused
+		void Resume() { }; // Unused
+		bool Startup();
 		void Shutdown();
 		void Message(int msg, EnvelopeAny* e);
-		void CreateComponent(std::string type, std::map< std::string, std::string > &attributes, Entity* e) { }; // Called to create a component of type (type), with the set of attributes (attributes), and with parent entity (e)
-		void CreateComponent(std::string type, std::map< std::string, boost::any > &attributes, Entity* e) { }; // Called to create a component of type (type), with the set of attributes (attributes), and with parent entity (e)
-		void RegisterComponent(ComponentInterface* comp) { }; // Used to register a component created in another core for use in this core
+		void CreateComponent(std::string type, std::map< std::string, boost::any > &attributes, Entity* e); // Called to create a component of type (type), with the set of attributes (attributes), and with parent entity (e)
+		void RegisterComponent(ComponentInterface* comp) { }; // Unused
 
 
+		//*TODO: shouldn't these be private?
 		void addPart(HUDPart* part);
-		void addPart(HUDPart* part,char* label);
+		void addPart(HUDPart* part, std::string label);
 		void removePart(HUDPart* part);
-		void removePart(char* label);
-		HUDPart* get(char* label);
+		void removePart(std::string label);
+		HUDPart* get(std::string label);
 		void showAll();
 		void hideAll();
 
+		//*TODO: shouldn't these be private?
+		HUD* hud;
+		Input* input;
+
 	private:
-		std::map<char*,HUDPart*> labels;
+		std::map<std::string, HUDPart*> labels;
 	};
-}
+}