Esempio n. 1
0
bool RegionLoad::OnList(ListPop *list, int index, gedString &text, int listId)
{
	list->getImage()->SetVisible(false);

	if(index == 0)
	{
		PanelQuestion *panel = new PanelQuestion("Remove region?");
		if(panel->Wait() == OK_BUTTON)
		{
			delete this;
		}

		delete panel;
	}
	
	return true;
}
Esempio n. 2
0
bool MainPanel::OnList(ListPop *list, int index, gedString &text, int listId)
{
	if(listEditBox) 
	{
		delete listEditBox;
		listEditBox = NULL;
	}

	switch(listId)
	{
	case LS_FILE:
		{			
			if(text == "New Game")
			{
				/*<Odilon>
				  Verifica se nao foi feito nada, ainda, para
				  pedir confirmacao apenas se necessario.
				*/
				
				if (GameControl::Get()->Modified())
				{
					//<Odilon> Pequena correcao de Ingles...
					PanelQuestion *panel = new PanelQuestion("This will discard the current game.\nProceed anyway?");
					///PanelQuestion *panel = new PanelQuestion("This action will erase the current game.\nTo proceed?");
					
					if(panel->Wait() == OK_BUTTON)
					{
						GameControl::Get()->NewGame();
						UndoControl::Get()->Clear();
						lastScripts.Clear();

						
						ExportGame::ClearExportName();
						
						/*Close actor dialog*/
						ActorProperty::Destroy();
					}
					
					delete panel;
					
				}
				else  //nao eh necessario confirmar; nada foi feito.
				{
					/* Aqui estou repetindo o mesmo codigo acima,...
					   talvez seja melhor encontrar outra maneira de fazer isso,
					   ou talvez nao... */
			
					GameControl::Get()->NewGame();
					UndoControl::Get()->Clear();
					lastScripts.Clear();

					/*Close actor dialog*/
					ActorProperty::Destroy();
				}
				
			}
			else if(text == "Load")
			{
				new LoadSaveGame(LOAD_GAME);

				ExportGame::ClearExportName();
				
			}
			else if(text == "Merge")
			{
				new LoadSaveGame(MERGE_GAME);
			}
#ifdef USE_SYSTEM_FILE_DIALOG
			else if(text == "Save As...")
			{
				new LoadSaveGame(SAVE_GAME);
				ExportGame::ClearExportName();
			}
			else if(text == "Save")
			{
				if(Tutorial::IsOff())
				{
					gedString gamePath(GameControl::Get()->getGamePath());

					if(!gamePath.empty())
					{
						LoadSaveGame::Save(gamePath + DIR_SEP + GameControl::Get()->getGameName());
					}
					else
					{
						new LoadSaveGame(SAVE_GAME);
					}
				}
				else
				{
					new LoadSaveGame(SAVE_GAME);
				}
			}
#else
			else if(text == "Save")
			{
				new LoadSaveGame(SAVE_GAME);
			}
#endif			
			else if(text == "Export")
			{
				#ifdef GAME_EDITOR_PROFESSIONAL

				if(GenericScript::ParserAll())
				{
					new ExportGame();
				}
				else
				{
					new PanelInfo(GenericScript::GetError(), "Error", ALIGN_LEFT);
				}
				
				#else 
				new PanelInfo(GAME_EDITOR_VERSION_ERROR);
				#endif
			}
			else if(text == "Exit")
			{
				//Exit
				SDL_Event event;
				memset(&event, 0, sizeof(SDL_Event));
				event.quit.type = SDL_QUIT;
				SDL_PushEvent(&event);
			}
			else
			{
				//Recent file list
				gedString *sFile = (gedString *)listFile->GetItemData(index);
				if(sFile)
				{
					LoadGame(*sFile, true);
				}
			}		
		}
		break;
	case LS_SETTINGS:
		{
			if(text == "Game Properties")
			{
				new GameSettings();
			}
			else if(text == "Preferences")
			{
				new Preferences();
			}
			else if(text == "Disable Tool Tips")
			{
				Config::Get()->setEnableToolTips(false);
				
				gedString *pEnableDisableToolTips = listConfig->GetTextPtr("Disable Tool Tips");
				if(pEnableDisableToolTips)
				{
					*pEnableDisableToolTips = "Enable Tool Tips";
				}
			}
			else if(text == "Enable Tool Tips")
			{
				Config::Get()->setEnableToolTips(true);
				
				gedString *pEnableDisableToolTips = listConfig->GetTextPtr("Enable Tool Tips");
				if(pEnableDisableToolTips)
				{
					*pEnableDisableToolTips = "Disable Tool Tips";
				}
			}
		}
		break;
	case LS_REGIONS:
		{
			switch(index)
			{
			case 0: //Add Activation Region
#if !defined(GAME_EDITOR_HOME_EDITION)
				new RegionLoad();	
#else
				new PanelInfo(GAME_EDITOR_VERSION_ERROR);
				return true;
#endif
				break;
			case 1: //show/hide
				
				if(RegionLoad::getShowRegions())
				{
					*pShowHideRegions = "Show Regions";
				}
				else
				{
					*pShowHideRegions = "Hide Regions";
				}

				RegionLoad::ToggleVisibility();
				Actor::RegionActorToggleVisibility();
				break;
			}
		}
		break;
	case LS_HELP:
		{
			if(text == "Documentation")
			{
				EditorDirectory editDir;
				
				//Firefox don't open "Docs/index.html" in windows
				//So, use \ on windows and / on linux
			
				openUrl((
#if defined(__MACOSX__)
		gedString("file://")+	GameControl::Get()->getHomePath()+gedString("/")+		 
#endif
						 
						 gedString("Docs") + DIR_SEP + "index.html").c_str());
			}
			else if(text == "About...")
			{
				new AboutDlg();
			}
			else if(text == "User Forums...")
			{
				openUrl("http://game-editor.com/forum");
			}	
#if !defined(__MACOSX__)
			else if(text == "Get Newest Tutorials...")
			{
				TutorialUpdateDlg::Call();
			}
			else if(text == "Check for Updates...")
			{
				UpdateCheck();
			}
#endif // No check for updates outside MACOSX appstore due to apple guidelines
			else if(text == "Game Demos...")
			{
				openUrl("http://game-editor.com/demos.html");				
			}
			else
			{
				//Tutorials
				if(chdir((GameControl::getEditorPath() + DIR_SEP + "Tutorials" + DIR_SEP + text).c_str()) == 0)
				{				
					listTutorialDir->RemoveAll();
					listTutorialDir->getImage()->SetVisible(true);				
					PostMessage(this, 0);
				}
			}
		}
		break;
	case LS_TUTORIALDIR:
		{		
			PanelQuestion *panel = new PanelQuestion("This will discard the current game.\nProceed anyway?", "Tutorial Execution");
			if(panel->Wait() == OK_BUTTON)
			{
				PostMessage(this, 1);					
			}

			delete panel;	
			
		}
		break;

	case LS_EDIT_MENU:
		{
			switch(index)
			{
			case 0:
				editBoxWidget->Cut();
				break;

			case 1:
				editBoxWidget->Copy();
				break;

			case 2:
				editBoxWidget->Paste();
				break;
			}			
		}
		break;

	case LS_SCRIPT:
		{
			if(text == "Global code")
			{
				new ScriptGlobals();
			}
			else
			{
				stAction *action = (stAction *)list->GetItemData(index);
				gedString actorName(text.substr(0, text.find(' ')));

				Actor *actor = GameControl::Get()->GetActor(actorName);								

				if(actor && action)
				{
					AddLastScript(text);
					Action::ShowActionDialog(action, actor);			
				}
			}
		}
		break;
	}

	return true;
}
Esempio n. 3
0
void ExpressionEditor::OnButton(Button *button, int buttonId)
{
	switch(buttonId)
	{
	case BT_CLOSE:
		{
			if(Tutorial::IsCompatible(VERSION_OUT_OF_VISION_OPTIMIZATION))
			{
				if(originalScript != editExp->GetText(ALL_LINES))
				{
					PanelQuestion *panel = new PanelQuestion("Your code has been altered.\nIf you close now all changes will be lost.\nDo you want close anyway?");
					if(panel->Wait() == OK_BUTTON)
					{
						//Restore code
						if(pScript) pScript->Parser(originalScript, false, false, true);
						delete this;
					}
					
					delete panel;			
				}
				else
				{
					delete this;
				}
			}
			else
			{
				delete this;
			}
		}
		break;
	case BT_WEB:
		{
			openUrl("http://game-editor.com/programming.html");
		}
		break;
	case BT_ADD:
		{
			gedString code(editExp->GetText(ALL_LINES));

			if(code.empty())
			{
				new PanelInfo("Can't add an empty script\nPlease, enter your script or close", "Error");
				return;
			}

			if(pScript)
			{
				if(!pScript->Parser(code, false, false, true) || pScript->GetError().length())
				{
					//Error or only warnings?
					
					if(pScript->GetError().find("Error") == gedString::npos)
					{
						//Warnings
						
						PanelQuestion *panel = new PanelQuestion(pScript->GetError() + "\n\nThere is some errors but are not fatal.\nProceed anyway?", "Confirm", "Yes", "No", ALIGN_LEFT);
						
						if(panel->Wait() != OK_BUTTON)
						{
							delete panel;						
							return;
						}
						
						delete panel;
					}
					else
					{
						//Errors
						PanelQuestion *panel = new PanelQuestion(pScript->GetError() + "\n\nThere are script code errors that need to be corrected before your program will execute.\nProceed anyway?", "Error", "Yes", "No", ALIGN_LEFT);
						if(panel->Wait() != OK_BUTTON)
						{
							delete panel;						
							return;
						}
						
						//Add with errors and check again in game mode
						pScript->setAddedWithError(true);
						delete panel;
					}				
				}
				else
				{
					pScript->setAddedWithError(false);
				}
			}
			
			
			if(Tutorial::IsCompatible(VERSION_OUT_OF_VISION_OPTIMIZATION))
			{
				SelectActionType(eventActor, Action::Call(eventActor)->SetExpression(pScript));
			}
			else
			{
				//Old code
				//Don't allow edit action type
				if(!editAction)
				{
					//Add
					SelectActionType(eventActor, Action::Call(eventActor)->SetExpression(pScript));
				}
				else
				{
					delete this;
				}
			}
		}
		break;
	case BT_CREATEVAR:
		{
			new VariableEditor(this);
		}
		break;
	case BT_GLOBALS:

#if !defined(GAME_EDITOR_HOME_EDITION)
		new ScriptGlobals();

		//Check the erros only if add this script
		/*if(pScript->Parser(editExp->GetText(ALL_LINES), false, false, true))
		{
			new ScriptGlobals();
		}
		else
		{
			gedString error(pScript->GetError());
			error += "\n\nFix all errors in this script before enter global codes";

			new PanelInfo(error, "Error", ALIGN_LEFT);
			return;
		}*/
#else
		new PanelInfo(GAME_EDITOR_VERSION_ERROR);
#endif
		break;
	}
}
Esempio n. 4
0
void VariableEditor::OnButton(Button *button, int buttonId)
{
	switch(buttonId)
	{
	case BT_CLOSE:
		delete this;
		break;

	case BT_ADD:
		new CreateVar(this);
		break;

	case BT_EDIT:
		{
			if(listVars->GetSelectedIndex() == -1)
			{
				new PanelInfo("Please, select a variable");
				return;
			}

			gedString variable(listVars->GetText());
			int i = variable.find('[');
			if(i == gedString::npos) i = variable.find(' ');

			variable = variable.substr(0, i);

			new CreateVar(this, variable, (int)listVars->GetItemData(listVars->GetSelectedIndex()));
		}
		break;

	case BT_REMOVE:	
		{
			if(listVars->GetSelectedIndex() == -1)
			{
				new PanelInfo("Please, select a variable");
				return;
			}

			PanelQuestion *panel = new PanelQuestion("Remove variable?");
			if(panel->Wait() == OK_BUTTON)
			{
				gedString variable(listVars->GetText());
				int i = variable.find('[');
				if(i == gedString::npos) i = variable.find(' ');

				variable = variable.substr(0, i);

				int next = listVars->GetSelectedIndex();

				if(!GenericScript::RemoveAndVerifyVariable(variable, (int)listVars->GetItemData(listVars->GetSelectedIndex())))
				{
					delete panel;

					panel = new PanelQuestion(GenericScript::GetError() + "\nProceed anyway?", "Error");
					if(panel->Wait() != OK_BUTTON)
					{
						delete panel;						
						return;
					}
					
					delete panel;
					
					//Force remotion
					GenericScript::RemoveAndVerifyVariable(variable, (int)listVars->GetItemData(listVars->GetSelectedIndex()), NULL, -1, true);
					panel = NULL;
					
				}

				if(next >= listVars->Count() - 1)
				{
					next = 0;
				}

				UpdateVars();
				listVars->SetItem(next);
			}

			if(panel) delete panel;
		}
		break;
	}
}
Esempio n. 5
0
void GameSettings::OnButton(Button *button, int buttonId)
{
	switch(buttonId)
	{
	case BT_CLOSE:
		{
			delete this;
		}
		break;
	case BT_ADD:
		{	
			int w = atol(editX->GetText().c_str());
			int h = atol(editY->GetText().c_str());
			int fps = atol(editFps->GetText().c_str());
			int smax = atol(editMaxSounds->GetText().c_str());
			int viewSafeArea = 0, port = 0;

			if(gamePort) port = atol(gamePort->GetText().c_str());

			if(editViewSafeMargin)
			{
				viewSafeArea = atol(editViewSafeMargin->GetText().c_str());

				if(viewSafeArea < 0) viewSafeArea = 0;
				else if(viewSafeArea > 2048) viewSafeArea = 2048;
			}

			if(w < 2 || w > 2000 || h < 2 || h > 2000)
			{
				new PanelInfo("Game resolution is invalid");
				return;
			}

			if(fps < 1 || fps > 512)
			{
				new PanelInfo("Frame rate is invalid");
				return;
			}

			if(smax < 1 || smax > 512)
			{
				new PanelInfo("Maximum number of simultaneous sounds is invalid");
				return;
			}

			if(gameID && gameID->GetText().length() > MAX_GAME_ID)
			{
				char s[32];
				sprintf(s, "Maximum game id length is %ld", MAX_GAME_ID);
				new PanelInfo(s);
				return;
			}

			if(gamePort && (port < 0 || port > 65535))
			{
				new PanelInfo("Port number must be a value between 1024 and 65535");
				return;
			}

			

			gedString icon(GameControl::Get()->getIconPath());
			if(iconPath->GetSelectedIndex() >= 0)
			{
				icon = iconPath->GetFullPath();
				
				SDL_RWops *src = ged_SDL_RWFromFile(icon.c_str(), "rb");
				if(src)
				{
					SDL_RWclose(src);
					
					gedString iconExt(icon);
					iconExt.lower();
					if(iconExt.substr(iconExt.length() - 4, 4) != ".ico")
					{
						//Validate only non .ico files
						SDL_Surface* surface = ged_IMG_Load(icon.c_str());
						if(!surface)
						{
							new PanelInfo("This format is not supported or file is corrupted\nPlease, select other file");
							return;
						}
					}
				}
				else
				{
					new PanelInfo("Please, select a file");
					return;
				}
			}
			
			if(gameID)
			{
				if(gameID->GetText() != GameControl::Get()->getGameID())
				{
					PanelQuestion *panel = new PanelQuestion("If you change the ID, this game will be recognized as a different game in the network.\nProceed anyway?");
					if(panel->Wait() != OK_BUTTON)
					{
						delete panel;
						return;
					}

					delete panel;
				}				
			}
			
			bool bStereo = false, bFull = false, bShowMouse = false, bSuspendGameIfLostFocus = false, bUseESCKeyToExit = false, bUseMotionCorrection = false, bUseGameEditorServer = false, bAutoStartNetwork = false;
			if(listStereo->GetText() == "Stereo") bStereo = true;			
			if(listFull->GetText() == "Full screen") bFull = true;
			if(listMouse->GetText() == "Show mouse") bShowMouse = true;
			if(listSuspend && listSuspend->GetText() == "Yes") bSuspendGameIfLostFocus = true;
			if(listAutoStartNetwork && listAutoStartNetwork->GetText() == "Yes") bAutoStartNetwork = true;
			if(listGameServer && listGameServer->GetText() == "Yes") bUseGameEditorServer = true;
			if(listESC && listESC->GetText() == "Yes") bUseESCKeyToExit = true;
			if(listMotion && listMotion->GetText() == "Yes") bUseMotionCorrection = true;

			gedString hz = listHz->GetText();

			if(bFull && (w > 1024 || h > 768))
			{
				PanelQuestion *panel = new PanelQuestion("The selected resolution will be able not to work in full screen in some old computers.\nIf your game must work in old machines, make sure select resolutions below 1024x768.\nUse this resolution anyway?");
				if(panel && panel->Wait() != OK_BUTTON)
				{
					delete panel;
					return;
				}			
				
				delete panel;
			}

			GameControl::Get()->SetGameProperties(w, h, fps, bFull, atol(hz.substr(0, hz.find(" ")).c_str()), bStereo, smax, bShowMouse, icon, gameTitle->GetText(), false, backgroundColor->getColor(), bSuspendGameIfLostFocus, viewSafeArea, bUseESCKeyToExit);
			GameControl::Get()->setFlipPocketPCScreen(bFlipPocketPCScreen);
			GameControl::Get()->setUseMotionCorrection(bUseMotionCorrection);
			GameControl::Get()->setUseGameEditorServer(bUseGameEditorServer);
			GameControl::Get()->setAutoStartNetwork(bAutoStartNetwork);

			if(gameID)
			{				
				GameControl::Get()->setGameID(gameID->GetText());
			}

			if(gamePort)
			{				
				GameControl::Get()->setGamePort(port);
			}

			delete this;
		}
		break;
	}
}