Ejemplo n.º 1
0
void ListPop::SetListText(gedString text)
{
	int width = Width() - 20, n;
	KrRect rect;
	gedString s(text);

	rect.Set(0, 0, 0, 0);
	
	if(s.length() > 5)
	{
		for(n = 1; n <= text.length() && rect.Width() < width; n++)
		{
			s = text.substr(0, n);
			rect = Text::GetDimensions(s);		
		}
		
		if(s.length() != text.length() && n > 3)
		{
			s = s.substr(0, s.length() - 3) + "...";
			SetToolTip(text);
		}
	}
	
	SetText(s);
	selectedText = text;
}
Ejemplo n.º 2
0
void VariableEditor::UpdateVars(const gedString item)
{
	listVars->RemoveAll();

	Script::PopulateLocalUserVars(listVars);
	GameControl::Get()->PopulateGlobalUserVars(listVars);
	
	listVars->Sort();

	if(item.length())
	{
		for(int index = 0; index < listVars->Count(); index++)
		{
			gedString variable(listVars->GetText(index));
			int i = variable.find('[');
			if(i == gedString::npos) i = variable.find(' ');
			
			variable = variable.substr(0, i);
			
			if(variable == item)
			{
				listVars->SetItem(index);
				break;
			}
		}
	}
}
Ejemplo n.º 3
0
ListPop::ListPop(int x, int y,
			   int width, int height,
			   int listpopId,
			   Actor *parent,
			   gedString buttonText)
: Button(buttonText, x, y, width, height, -1, parent,
			0, 0, 0, (width < 200)?"makslistPop.bmp":"makslistPopBig.bmp", "maksfont.bmp", true)
{
	textBox->SetPos(px, py);
	this->listpopId = listpopId;
	heightItem = Text::GetDimensions("CALIBRATION").Height() + 2;

	bListDirectory = false;
	
	RemoveAll();

	if(buttonText.size()) bButtonText = true;
	else bButtonText = false;	

	bHideOnClickOutList = true;
	//listName = "ListPopSelect";

	bCenterListOnMouse = true;

	Reset();
	pCurrentList = &allItens;
	pCurrentStack = &stackItens;
}
Ejemplo n.º 4
0
//#ifndef STAND_ALONE_GAME
void Text::GetDimensions(const gedString& text, int &width, int &height, const gedString& fontName)
{
	//Calculate dimensions
	KrFontResource *fontResource = GameControl::Get()->GetFont(fontName);
	if(fontResource)
	{
		if(text.find('\n') == gedString::npos)
		{			
			width = fontResource->FontWidth(text.getCharBuf());
			height = fontResource->FontHeight();
		}
		else
		{
			gedString aux(text);
			int w = 0;
			//KrScheme scheme(fontResource);	
			width = 0;
			
			const int lineSpacing = 0;
			int nLines = 1, ini = 0;
			char *buf = (char *)malloc(aux.size()+1);
			strcpy(buf, (char *)aux.c_str());
			
			for(int i = 0; i < aux.size(); i++)
			{
				if(buf[i] == '\n')
				{
					buf[i] = 0;
					w = fontResource->FontWidth((const char *)&buf[ini]);
					width = max(width, w);
					ini = i+1;
					nLines++;
				}
			}
			
			w = fontResource->FontWidth((const char *)&buf[ini]);
			width = max(width, w);
			height = nLines*(fontResource->FontHeight() + lineSpacing);
			free(buf);
		}
	}
	else
	{
		width = height = 0;
	}
}
Ejemplo n.º 5
0
void Text::SetText(gedString text)
{
	if(!textBox) return;
	
	if(text.length())
	{
		if(text.find('\n') != gedString::npos)
		{
			gedString tmp(text);
			U16 *buf = (U16 *)tmp.c_str16();
			
			int line = 0, ini = 0;
			for(int i = 0; i < text.size(); i++)
			{
				if(buf[i] == '\n')
				{
					buf[i] = 0;
					textBox->SetText(&buf[ini], line);	
					ini = i+1;
					line++;
				}
			}
			
			if(buf[ini])
				textBox->SetText(&buf[ini], line);
		}
		else
		{
			textBox->SetText(text, 0);
		}
	}
	else
	{
		for(int i = 0; i < textBox->NumLines(); i++)
		{
			textBox->SetText("", i);
		}
	}
}
Ejemplo n.º 6
0
bool GameSettings::OnList(ListPop *list, int index, gedString &text, int listId)
{
	switch(listId)
	{
	case LS_RES:
		{
			int w, h;
			gedString sFlip(text.substr(text.length() - 4, 4));

			w = atol(text.substr(0, text.find(" ")).c_str());
			h = atol(text.substr(text.find("x ")+2, gedString::npos).c_str());
			editX->SetText(w);
			editY->SetText(h);

			if(sFlip == "down" || sFlip == "ight")
			{
				bFlipPocketPCScreen = true;
			}
			else
			{
				bFlipPocketPCScreen = false;
			}
			if(w == 320 || h == 480)
			{
				if(sFlip == "down") list->SetText("320 x 480 Up. down");
				else if(sFlip == "left") list->SetText("480 x 320 Rot. left");
				else if(sFlip == "ight") list->SetText("480 x 320 Rot.right");
			}
			else 
			if(w == 240 || h == 240)
			{
				if(sFlip == "down") list->SetText("240 x 320 Up. down");
				else if(sFlip == "left") list->SetText("320 x 240 Rot. left");
				else if(sFlip == "ight") list->SetText("320 x 240 Rot.right");
			}
			else if(w == 800 && h == 480)
			{				
				if(sFlip == "left") list->SetText("800 x 480 Rot. left");
				else if(sFlip == "ight") list->SetText("800 x 480 Rot.right");
			}
			else if(w == 480 || h == 480)
			{
				if(sFlip == "down") list->SetText("480 x 640 Up. down");
				else if(sFlip == "left") list->SetText("640 x 480 Rot. left");
				else if(sFlip == "ight") list->SetText("640 x 480 Rot.right");
			}
		}
		break;
	case LS_POCKET_KEYS:
		{
			new DlgPocketPCKey(*((SDLKey *)list->GetItemData(index)));
		}
		break;
	}

	return true;
}
Ejemplo n.º 7
0
Text::Text(const gedString& text, int x, int y, int align,
		   Actor *parent, 
		   int red, int green, int blue,
		   const gedString &fontName,
		   int iniASCIIChar, int nChars,
		   bool _bEditable, bool _hasBorder, bool _hasBackGround, bool _getFocus,
		   KrRGBA _borderColor, KrRGBA _cursorColor, KrRGBA _backGroundColor)
{	
	this->fontName = fontName;
	this->iniASCIIChar = iniASCIIChar;
	this->nChars = nChars;
	this->text = text;

	bEditable = _bEditable;
	bDrawBorder = _hasBorder;
	bDrawBackground = _hasBackGround;
	bGetFocus = _getFocus;
	borderColor = _borderColor;
	cursorColor = _cursorColor;
	backGroundColor = _backGroundColor;

	textBox = NULL;

	
	fontResource = GameControl::Get()->GetFont(fontName, iniASCIIChar, nChars);
	
	if(fontResource)
	{
		const int lineSpacing = 0;
		int nLines = 1;
		gedString maxTextWidth;	
		bool bOnlyBlank = true;

		

		if(bEditable)
		{
			for(int i = 0; i < text.size(); i++)
			{
				if(text[i] != '\n')
				{
					maxTextWidth += 'O';
				}
				else
				{
					maxTextWidth += '\n';
					nLines++;
				}

				if( text[i] != ' ' && 
					text[i] != '\t' &&
					text[i] != '\r' &&
					text[i] != '\n')
				{
					bOnlyBlank = false;					
				}
			}
		}
		else
		{
			maxTextWidth = text;
			
			for(int i = 0; i < text.size(); i++)
			{
				if(text[i] == '\n')
				{
					nLines++;
				}
			}
		}

		
		int textWidth;

		if(nLines == 1)
		{
			textWidth  = fontResource->FontWidth(maxTextWidth.c_str());
		}
		else
		{
			int height;
			GetDimensions(maxTextWidth, textWidth, height, fontName);
		}

				
		switch(align)
		{
		case ALIGN_CENTER:
			align = KrTextBox::CENTER;
			break;
		case ALIGN_RIGHT:
			align = KrTextBox::RIGHT;
			break;
		case ALIGN_AUTOMATIC: //Only left (solve the text jump in textJump.ged)
			//if(nLines == 1) align = KrTextBox::CENTER;
			/*else*/ align = KrTextBox::LEFT;
			break;
		default:
			align = KrTextBox::LEFT;
			break;
		}			
		

		if(bEditable && !bDrawBackground)
		{
			//Draw a invisible background if editable text has no background
			backGroundColor.all = 0;
			backGroundColor.c.alpha = 1;
		}

		
		textBox = new KrTextWidget( fontResource, 
							 textWidth,
							 nLines*(fontResource->FontHeight() + lineSpacing), 
							 lineSpacing,
							 (KrTextBox::Alignment)align,
							 parent,
							 nLines > 1,
							 bEditable, bDrawBorder, bDrawBackground, bGetFocus,
							 borderColor, cursorColor, backGroundColor);

				
		KrColorTransform color;
		// sky change color of text
		ColorScheme *cs = get_color_scheme();
		color.Set(cs->editor_text_r, 0, cs->editor_text_g, 0, cs->editor_text_b, 0, 255);
		textBox->SetColor(color);

		if(x == CENTER_TEXT)
			x = (parent->Width() - textWidth) / 2;

		if(y == CENTER_TEXT)
			y = (parent->Height() - fontResource->FontHeight()) / 2;

				
		textBox->SetNodeId((int)textBox);
		engine->Tree()->AddNode( parent?parent->getImage():NULL, textBox );
		textBox->SetPos(x, y);

		
		if(!bEditable || !bOnlyBlank || (!InGameMode() && !InStandAloneMode()))
		{
			SetText(text); //After add tree
		}

		fontResource->refCount++;

		
		//Call walk here to update the compositeBounds
		//So, the text will be load by the RegionLoad::DefineActors()
		//Solve the reload - text bug.ged
		//Only in game mode (solve the Issue 80)

		if(parent && GameControl::Get()->getGameMode())
		{
			engine->Tree()->CalculateCompositBounds(parent->getImage());
		}
	}
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
bool ListPop::OnList(ListPop *list, int index, gedString &text, int listId)
{
	if(text == LIST_SEPARATOR) return true;

	int realFps = GameControl::Get()->getRealFrameRate();
	if(realFps <= 0) realFps = 1;

	int interval = (int)(1000.0/realFps);
	selectedText.clear();

	if(text[0] == '+')
	{
		//Expand clone names
		PopulateCloneList(&text.c_str()[2]);
		OnMouseButtonDown(GameControl::Get()->getMouseX(), GameControl::Get()->getMouseY(), 255);
	}
	else if(text == MORE_ITENS)
	{
		pCurrentStack->PushFront(firstListItem);
		ResetWork();
		AddTextWork(LESS_ITENS);
		PopulateWorkList(true);
		
		
		OnMouseButtonDown(xMouse, yMouse, 255);
	}
	else if(text == LESS_ITENS)
	{
		firstListItem = pCurrentStack->Front();
		pCurrentStack->PopFront();			
		
		ResetWork();
		if(pCurrentStack->size()) AddTextWork(LESS_ITENS);
		
		PopulateWorkList(false);
		
		
		OnMouseButtonDown(xMouse, yMouse, 255);
	}
	else
	{
		if(!bButtonText) SetListText(text);
		selectedText = text;

		if(listId < 0) listId = listpopId;
		if(index < 0) 
		{
			//Get index from text
			UseMainList();
			
			for(int i = 0; i < pCurrentList->Count(); i++)
			{
				if(text == (*pCurrentList)[i].text)
				{
					index = i;
					break;
				}
			}
			
			if(index >= 0) this->index = index;
		}
		else
		{
			if(firstListItem > 0) index = firstListItem + index - 1; //Work index to all index
			UseMainList();

			//Put after UseMainList() to get the
			//correct clone in the panel of getclone function
			this->index = index;
		}

		
		firstListItem = -1;
		getParent()->OnList(this, index, text, listId);
	}	

	return true;
}