Przeglądaj źródła

Fixed Lua debug reporting in player, made IDE throttle down instead of pausing core on lose focus, added open files dropdown and active project name display to the IDE

Ivan Safrin 13 lat temu
rodzic
commit
2522352a17

+ 1 - 0
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -131,6 +131,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 		wrappersHeaderOut += "public:\n"
 		wrappersHeaderOut += "public:\n"
 		wrappersHeaderOut += "	LuaEventHandler() : EventHandler() {}\n"
 		wrappersHeaderOut += "	LuaEventHandler() : EventHandler() {}\n"
 		wrappersHeaderOut += "	void handleEvent(Event *e) {\n"
 		wrappersHeaderOut += "	void handleEvent(Event *e) {\n"
+		wrappersHeaderOut += "		lua_getfield (L, LUA_GLOBALSINDEX, \"__customError\");\n"
 		wrappersHeaderOut += "		int errH = lua_gettop(L);\n"
 		wrappersHeaderOut += "		int errH = lua_gettop(L);\n"
 		wrappersHeaderOut += "		lua_getfield(L, LUA_GLOBALSINDEX, \"__handleEvent\");\n"
 		wrappersHeaderOut += "		lua_getfield(L, LUA_GLOBALSINDEX, \"__handleEvent\");\n"
 		wrappersHeaderOut += "		lua_rawgeti( L, LUA_REGISTRYINDEX, wrapperIndex );\n"
 		wrappersHeaderOut += "		lua_rawgeti( L, LUA_REGISTRYINDEX, wrapperIndex );\n"

+ 5 - 1
Core/Contents/Include/PolyCore.h

@@ -241,7 +241,11 @@ namespace Polycode {
 		/**
 		/**
 		* Opens a system folder picker and suspends operation.
 		* Opens a system folder picker and suspends operation.
 		* @return The selected path returned from the picker.
 		* @return The selected path returned from the picker.
-		*/																					
+		*/		
+		
+
+		void setFramerate(int frameRate);
+
 		virtual String openFolderPicker() = 0;
 		virtual String openFolderPicker() = 0;
 		
 		
 		/**
 		/**

+ 4 - 0
Core/Contents/Source/PolyCore.cpp

@@ -80,6 +80,10 @@ namespace Polycode {
 		threadedEventMutex = NULL;
 		threadedEventMutex = NULL;
 	}
 	}
 	
 	
+	void Core::setFramerate(int frameRate) {
+		refreshInterval = 1000 / frameRate;
+	}
+	
 	void Core::enableMouse(bool newval) {
 	void Core::enableMouse(bool newval) {
 		mouseEnabled = newval;
 		mouseEnabled = newval;
 	}
 	}

+ 4 - 4
IDE/Contents/Include/PolycodeEditorManager.h

@@ -27,7 +27,7 @@
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
-class PolycodeEditorManager { 
+class PolycodeEditorManager : public EventDispatcher { 
 	public:
 	public:
 		PolycodeEditorManager();
 		PolycodeEditorManager();
 		~PolycodeEditorManager();
 		~PolycodeEditorManager();
@@ -36,15 +36,15 @@ class PolycodeEditorManager {
 		PolycodeEditor *createEditorForExtension(String extension);
 		PolycodeEditor *createEditorForExtension(String extension);
 		void registerEditorFactory(PolycodeEditorFactory *editorFactory);
 		void registerEditorFactory(PolycodeEditorFactory *editorFactory);
 	
 	
-		void setCurrentEditor(PolycodeEditor *editor) { currentEditor = editor; }
+		void setCurrentEditor(PolycodeEditor *editor, bool sendChangeEvent = true);
 		PolycodeEditor *getCurrentEditor() { return currentEditor; }
 		PolycodeEditor *getCurrentEditor() { return currentEditor; }
 		
 		
 	//	int close
 	//	int close
-	
+	std::vector<PolycodeEditor*> openEditors;
+		
 protected:
 protected:
 	
 	
 	PolycodeEditor *currentEditor;
 	PolycodeEditor *currentEditor;
 	
 	
-	std::vector<PolycodeEditor*> openEditors;
 	std::vector<PolycodeEditorFactory*> editorFactories;	
 	std::vector<PolycodeEditorFactory*> editorFactories;	
 };
 };

+ 5 - 0
IDE/Contents/Include/PolycodeFrame.h

@@ -32,6 +32,7 @@
 #include "NewFileWindow.h"
 #include "NewFileWindow.h"
 #include "ToolWindows.h"
 #include "ToolWindows.h"
 #include "PolycodeProjectManager.h"
 #include "PolycodeProjectManager.h"
+#include "PolycodeEditorManager.h"
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
@@ -187,6 +188,7 @@ public:
 	
 	
 	ScreenEntity *welcomeEntity;	
 	ScreenEntity *welcomeEntity;	
 	PolycodeProjectBrowser *projectBrowser;
 	PolycodeProjectBrowser *projectBrowser;
+	PolycodeEditorManager *editorManager;
 		
 		
 	UIImageButton *playButton;
 	UIImageButton *playButton;
 	UIImageButton *stopButton;
 	UIImageButton *stopButton;
@@ -223,6 +225,9 @@ private:
 	ScreenLabel *dragLabel;
 	ScreenLabel *dragLabel;
 	bool isDragging;
 	bool isDragging;
 	
 	
+	ScreenLabel *currentProjectTitle;
+	UIComboBox *currentFileSelector;
+	
 	ScreenImage *welcomeImage;	
 	ScreenImage *welcomeImage;	
 	
 	
 	
 	

+ 1 - 1
IDE/Contents/Include/PolycodeProjectManager.h

@@ -29,7 +29,7 @@
 
 
 using namespace Polycode;
 using namespace Polycode;
 
 
-class PolycodeProjectManager {
+class PolycodeProjectManager : public EventDispatcher {
 	public:
 	public:
 		PolycodeProjectManager();
 		PolycodeProjectManager();
 		~PolycodeProjectManager();
 		~PolycodeProjectManager();

+ 9 - 1
IDE/Contents/Source/PolycodeEditorManager.cpp

@@ -23,7 +23,7 @@
 #include "PolycodeEditorManager.h"
 #include "PolycodeEditorManager.h"
 
 
 
 
-PolycodeEditorManager::PolycodeEditorManager() {
+PolycodeEditorManager::PolycodeEditorManager()  : EventDispatcher() {
 	currentEditor = NULL;
 	currentEditor = NULL;
 }
 }
 
 
@@ -43,6 +43,14 @@ PolycodeEditor *PolycodeEditorManager::createEditorForExtension(String extension
 	return NULL;
 	return NULL;
 }
 }
 
 
+void PolycodeEditorManager::setCurrentEditor(PolycodeEditor *editor, bool sendChangeEvent) {
+	currentEditor = editor;
+	if(sendChangeEvent){
+		dispatchEvent(new Event(), Event::CHANGE_EVENT);
+	}
+}
+
+
 PolycodeEditor *PolycodeEditorManager::getEditorForPath(String path) {
 PolycodeEditor *PolycodeEditorManager::getEditorForPath(String path) {
 	for(int i=0; i < openEditors.size();i++) {
 	for(int i=0; i < openEditors.size();i++) {
 		PolycodeEditor *editor = openEditors[i];
 		PolycodeEditor *editor = openEditors[i];

+ 35 - 0
IDE/Contents/Source/PolycodeFrame.cpp

@@ -555,6 +555,16 @@ PolycodeFrame::PolycodeFrame() : ScreenEntity() {
 	addChild(stopButton);
 	addChild(stopButton);
 	stopButton->setPosition(10,4);
 	stopButton->setPosition(10,4);
 
 
+	currentProjectTitle = new ScreenLabel("", 32, "section");
+	addChild(currentProjectTitle);
+	currentProjectTitle->color.a = 0.4;
+	currentProjectTitle->setPosition(70, 0);
+
+	currentFileSelector = new UIComboBox(globalMenu, 300);
+	currentFileSelector->addEventListener(this, UIEvent::CHANGE_EVENT);
+	
+	addChild(currentFileSelector);
+
 	
 	
 	resizer = new ScreenImage("Images/corner_resize.png");	
 	resizer = new ScreenImage("Images/corner_resize.png");	
 	addChild(resizer);
 	addChild(resizer);
@@ -728,6 +738,29 @@ void PolycodeFrame::showAssetBrowser(std::vector<String> extensions) {
 
 
 void PolycodeFrame::handleEvent(Event *event) {
 void PolycodeFrame::handleEvent(Event *event) {
 	
 	
+	if(event->getDispatcher() == currentFileSelector && event->getEventType() == "UIEvent") {
+		PolycodeEditor *editor = editorManager->openEditors[currentFileSelector->getSelectedIndex()];
+		editorManager->setCurrentEditor(editor, false);
+		showEditor(editor);
+	}
+	
+	if(event->getDispatcher() == editorManager) {	
+		currentFileSelector->clearItems();
+		
+		for(int i=0; i < editorManager->openEditors.size(); i++) {
+			OSFileEntry entry(editorManager->openEditors[i]->getFilePath(), OSFileEntry::TYPE_FILE);
+			currentFileSelector->addComboItem(entry.name);
+			if(editorManager->getCurrentEditor() == editorManager->openEditors[i]) {
+				currentFileSelector->setSelectedIndex(i);
+			}
+			
+		}
+	}
+	
+	if(event->getDispatcher() == projectManager) {
+		currentProjectTitle->setText(projectManager->getActiveProject()->getProjectName());
+	}
+	
 	if(event->getDispatcher() == aboutOKButton && event->getEventType() == "UIEvent") {
 	if(event->getDispatcher() == aboutOKButton && event->getEventType() == "UIEvent") {
 		hideModal();
 		hideModal();
 	}
 	}
@@ -814,6 +847,8 @@ void PolycodeFrame::Resize(int x, int y) {
 	modalBlocker->setShapeSize(x, y);
 	modalBlocker->setShapeSize(x, y);
 	fileDialogBlocker->setShapeSize(x, y);
 	fileDialogBlocker->setShapeSize(x, y);
 		
 		
+	currentFileSelector->setPosition(x-350, 11);
+	
 	
 	
 	if(this->modalChild) {
 	if(this->modalChild) {
 		modalChild->setPosition((x-modalChild->getWidth())/2.0f, (y-modalChild->getHeight())/2.0f);
 		modalChild->setPosition((x-modalChild->getWidth())/2.0f, (y-modalChild->getHeight())/2.0f);

+ 18 - 14
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -32,10 +32,12 @@ PolycodeClipboard *globalClipboard;
 
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
 	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
-	core->pauseOnLoseFocus = true;
+//	core->pauseOnLoseFocus = true;
 	
 	
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
-	
+	core->addEventListener(this, Core::EVENT_LOST_FOCUS);
+	core->addEventListener(this, Core::EVENT_GAINED_FOCUS);
+			
 	globalClipboard = new PolycodeClipboard();
 	globalClipboard = new PolycodeClipboard();
 	
 	
 	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
 	CoreServices::getInstance()->getRenderer()->setTextureFilteringMode(Renderer::TEX_FILTERING_NEAREST);
@@ -65,6 +67,7 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	
 	
 	willRunProject = false;
 	willRunProject = false;
 
 
+	globalMenu	= new UIGlobalMenu();
 		
 		
 	printf("creating font editor\n"); 
 	printf("creating font editor\n"); 
 	
 	
@@ -76,6 +79,9 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	frame = new PolycodeFrame();
 	frame = new PolycodeFrame();
 	frame->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 	frame->setPositionMode(ScreenEntity::POSITION_TOPLEFT);
 
 
+	frame->editorManager = editorManager;
+	editorManager->addEventListener(frame, Event::CHANGE_EVENT);
+
 	frame->console->backtraceWindow->addEventListener(this, BackTraceEvent::EVENT_BACKTRACE_SELECTED);
 	frame->console->backtraceWindow->addEventListener(this, BackTraceEvent::EVENT_BACKTRACE_SELECTED);
 
 
 	frame->textInputPopup->addEventListener(this, UIEvent::OK_EVENT);	
 	frame->textInputPopup->addEventListener(this, UIEvent::OK_EVENT);	
@@ -96,6 +102,8 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	projectManager->setProjectBrowser(frame->getProjectBrowser());
 	projectManager->setProjectBrowser(frame->getProjectBrowser());
 	
 	
 	frame->projectManager = projectManager;
 	frame->projectManager = projectManager;
+
+	projectManager->addEventListener(frame, Event::CHANGE_EVENT);
 	
 	
 	frame->getProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
 	frame->getProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
 	frame->getProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);
 	frame->getProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);
@@ -115,7 +123,6 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	editorManager->registerEditorFactory(new PolycodeSpriteEditorFactory());
 	editorManager->registerEditorFactory(new PolycodeSpriteEditorFactory());
 
 
 		
 		
-	globalMenu	= new UIGlobalMenu();
 	screen->addChild(globalMenu);	
 	screen->addChild(globalMenu);	
 				
 				
 	loadConfigFile();
 	loadConfigFile();
@@ -451,6 +458,12 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 
 
 	if(event->getDispatcher() == core) {
 	if(event->getDispatcher() == core) {
 		switch(event->getEventCode()) {
 		switch(event->getEventCode()) {
+			case Core::EVENT_LOST_FOCUS:
+				core->setFramerate(1);
+			break;		
+			case Core::EVENT_GAINED_FOCUS:
+				core->setFramerate(30);			
+			break;					
 			case Core::EVENT_CORE_RESIZE:
 			case Core::EVENT_CORE_RESIZE:
 				if(menuBar) {
 				if(menuBar) {
 					frame->Resize(core->getXRes(), core->getYRes()-25);
 					frame->Resize(core->getXRes(), core->getYRes()-25);
@@ -715,16 +728,7 @@ bool PolycodeIDEApp::Update() {
 		frame->mainSizer->enabled = false;		
 		frame->mainSizer->enabled = false;		
 	}
 	}
 
 
-	// ugly hack to update the screen when debugger connects
-	bool oldPaused = core->paused;
-	if(needsRedraw) {
-		core->paused = false;
-	}
-	bool retStat = core->Update();
-	if(oldPaused == true && needsRedraw) {
-		core->paused = true;
-		needsRedraw = false;
-	}
-	return retStat;
+
+	return core->Update();
 }
 }
 
 

+ 2 - 1
IDE/Contents/Source/PolycodeProjectManager.cpp

@@ -23,7 +23,7 @@
 #include "PolycodeProjectManager.h"
 #include "PolycodeProjectManager.h"
 #include "PolycodeToolLauncher.h"
 #include "PolycodeToolLauncher.h"
 
 
-PolycodeProjectManager::PolycodeProjectManager() {
+PolycodeProjectManager::PolycodeProjectManager() : EventDispatcher() {
 	activeProject = NULL;
 	activeProject = NULL;
 	activeFolder = "";
 	activeFolder = "";
 	selectedFile = "";
 	selectedFile = "";
@@ -106,6 +106,7 @@ void PolycodeProjectManager::setActiveProject(PolycodeProject* project) {
 		if(project){			
 		if(project){			
 			CoreServices::getInstance()->getResourceManager()->addArchive(project->getRootFolder());
 			CoreServices::getInstance()->getResourceManager()->addArchive(project->getRootFolder());
 		}
 		}
+		dispatchEvent(new Event(), Event::CHANGE_EVENT);
 	}
 	}
 }
 }
 
 

+ 1 - 1
Modules/Contents/UI/Source/PolyUIComboBox.cpp

@@ -133,7 +133,7 @@ UIComboBoxItem *UIComboBox::getSelectedItem() {
 
 
 void UIComboBox::toggleDropDown() {
 void UIComboBox::toggleDropDown() {
 	Vector2 screenPos = this->getScreenPosition();
 	Vector2 screenPos = this->getScreenPosition();
-	dropDownMenu = globalMenu->showMenu(screenPos.x, screenPos.y - height, width);
+	dropDownMenu = globalMenu->showMenu(screenPos.x, screenPos.y, width);
 	
 	
 	for(int i=0; i < items.size(); i++) {
 	for(int i=0; i < items.size(); i++) {
 		dropDownMenu->addOption(items[i]->label, String::IntToString(i));
 		dropDownMenu->addOption(items[i]->label, String::IntToString(i));

+ 23 - 5
Player/Contents/Source/PolycodePlayer.cpp

@@ -814,50 +814,65 @@ void PolycodePlayer::handleEvent(Event *event) {
 			case InputEvent::EVENT_KEYDOWN:
 			case InputEvent::EVENT_KEYDOWN:
 			{
 			{
 				if(L && !crashed) {
 				if(L && !crashed) {
+					lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+					errH = lua_gettop(L);					
 					lua_getfield(L, LUA_GLOBALSINDEX, "onKeyDown");
 					lua_getfield(L, LUA_GLOBALSINDEX, "onKeyDown");
 					lua_pushinteger(L, inputEvent->keyCode());
 					lua_pushinteger(L, inputEvent->keyCode());
-					lua_pcall(L, 1,0,errH);					
+					lua_pcall(L, 1,0,errH);
+					lua_settop(L, 0);
 				}
 				}
 			}
 			}
 			break;
 			break;
 			case InputEvent::EVENT_KEYUP:
 			case InputEvent::EVENT_KEYUP:
 			{
 			{
 				if(L && !crashed) {
 				if(L && !crashed) {
+					lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+					errH = lua_gettop(L);									
 					lua_getfield(L, LUA_GLOBALSINDEX, "onKeyUp");
 					lua_getfield(L, LUA_GLOBALSINDEX, "onKeyUp");
 					lua_pushinteger(L, inputEvent->keyCode());
 					lua_pushinteger(L, inputEvent->keyCode());
-					lua_pcall(L, 1,0,errH);					
+					lua_pcall(L, 1,0,errH);
+					lua_settop(L, 0);								
 				}
 				}
 			}
 			}
 			break;
 			break;
 			case InputEvent::EVENT_MOUSEDOWN:
 			case InputEvent::EVENT_MOUSEDOWN:
 			{
 			{
 				if(L && !crashed) {
 				if(L && !crashed) {
+					lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+					errH = lua_gettop(L);									
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseDown");
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseDown");
 					lua_pushinteger(L, inputEvent->mouseButton);
 					lua_pushinteger(L, inputEvent->mouseButton);
 					lua_pushnumber(L, inputEvent->mousePosition.x);
 					lua_pushnumber(L, inputEvent->mousePosition.x);
-					lua_pushnumber(L, inputEvent->mousePosition.y);					
+					lua_pushnumber(L, inputEvent->mousePosition.y);	
 					lua_pcall(L, 3,0,errH);					
 					lua_pcall(L, 3,0,errH);					
+					lua_settop(L, 0);					
 				}
 				}
 			}
 			}
 			break;	
 			break;	
 			case InputEvent::EVENT_MOUSEUP:
 			case InputEvent::EVENT_MOUSEUP:
 			{
 			{
 				if(L && !crashed) {
 				if(L && !crashed) {
+					lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+					errH = lua_gettop(L);									
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseUp");
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseUp");
 					lua_pushinteger(L, inputEvent->mouseButton);
 					lua_pushinteger(L, inputEvent->mouseButton);
 					lua_pushnumber(L, inputEvent->mousePosition.x);
 					lua_pushnumber(L, inputEvent->mousePosition.x);
-					lua_pushnumber(L, inputEvent->mousePosition.y);					
+					lua_pushnumber(L, inputEvent->mousePosition.y);		
 					lua_pcall(L, 3,0,errH);					
 					lua_pcall(L, 3,0,errH);					
+					lua_settop(L, 0);					
 				}
 				}
 			}
 			}
 			break;	
 			break;	
 			case InputEvent::EVENT_MOUSEMOVE:
 			case InputEvent::EVENT_MOUSEMOVE:
 			{
 			{
 				if(L && !crashed) {
 				if(L && !crashed) {
+					lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+					errH = lua_gettop(L);									
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseMove");
 					lua_getfield(L, LUA_GLOBALSINDEX, "onMouseMove");
 					lua_pushnumber(L, inputEvent->mousePosition.x);
 					lua_pushnumber(L, inputEvent->mousePosition.x);
-					lua_pushnumber(L, inputEvent->mousePosition.y);					
+					lua_pushnumber(L, inputEvent->mousePosition.y);	
 					lua_pcall(L, 2,0,errH);					
 					lua_pcall(L, 2,0,errH);					
+					lua_settop(L, 0);					
 				}
 				}
 			}
 			}
 			break;																			
 			break;																			
@@ -868,6 +883,8 @@ void PolycodePlayer::handleEvent(Event *event) {
 
 
 bool PolycodePlayer::Update() {
 bool PolycodePlayer::Update() {
 	if(L) {
 	if(L) {
+		lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
+		errH = lua_gettop(L);	
 		if(doCodeInject) {
 		if(doCodeInject) {
 			printf("INJECTING CODE:[%s]\n", injectCodeString.c_str());
 			printf("INJECTING CODE:[%s]\n", injectCodeString.c_str());
 			doCodeInject = false;			
 			doCodeInject = false;			
@@ -880,6 +897,7 @@ bool PolycodePlayer::Update() {
 			lua_pushnumber(L, core->getElapsed());
 			lua_pushnumber(L, core->getElapsed());
 			lua_pcall(L, 1,0,errH);
 			lua_pcall(L, 1,0,errH);
 		}
 		}
+		lua_settop(L, 0);
 	}
 	}
 	return core->Update();
 	return core->Update();
 }
 }