Пример #1
0
long MechListBox::AddItem(aListItem* itemString)
{
	itemString->setID( ID );
	MechListBoxItem* pItem = dynamic_cast<MechListBoxItem*>(itemString);
	EString addedName;
	char tmp[256];
	cLoadString( pItem->getMech()->getChassisName(), tmp, 255 );
	addedName = tmp;
	
	if ( pItem )
	{
		pItem->bOrange = bOrange;
		pItem->bIncludeForceGroup = bIncludeForceGroup;

		if ( !bDeleteIfNoInventory )
		{
			pItem->countText.setColor( 0 );
			pItem->countText.showGUIWindow( 0 );
		}
	
		EString chassisName;
		for ( int i = 0; i < itemCount; i++ )
		{

			long ID = ((MechListBoxItem*)items[i])->pMech->getChassisName();
			char tmpChassisName[256];
			cLoadString( ID, tmpChassisName, 255 );
			chassisName = tmpChassisName;
			if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() < pItem->pMech->getMaxWeight() )
			{
				return InsertItem( itemString, i );
				break;
			}
			else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight()
				&& chassisName.Compare( addedName ) > 0 )
			{
				return InsertItem( itemString, i );
			}
			else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight()
				&& chassisName.Compare( addedName ) == 0 
				&& ((MechListBoxItem*)itemString)->pMech->getName().Find("Prime") != -1 )
			{
				return InsertItem( itemString, i );
			}
			else if ( ((MechListBoxItem*)items[i])->pMech->getMaxWeight() == pItem->pMech->getMaxWeight()
				&& chassisName.Compare( addedName ) == 0 
				&& ( ((MechListBoxItem*)items[i])->pMech->getName().Find("Prime" ) == -1 ) 
				&& ((MechListBoxItem*)items[i])->pMech->getName().Compare( pItem->pMech->getName() ) > 0 )
			{
				return InsertItem( itemString, i );
			}
		}

	}

	
	return aListBox::AddItem( itemString );
}
void MissionSelectionScreen::begin()
{
	status = RUNNING;
	playedLogisticsTune = false;

	if ( fadeInTime )
		operationScreen.beginFadeIn( fadeInTime );

	// initialize the operation
	const char* str = LogisticsData::instance->getCurrentOperationFileName();

	FullPathFileName fileName;
	fileName.init( artPath, str, ".fit" );

	FitIniFile file;
	if ( NO_ERR != file.open( fileName ) )
	{
		char errorStr[256];
		sprintf( errorStr, "couldn't open file %s", fileName );
		Assert( 0, 0, errorStr );
	}
	
	operationScreen.moveTo( 0, 0 );
	operationScreen.init( file, "Static", "Text", "Rect", "Button" );
	
	operationScreen.moveTo( rects[MAP_RECT].left(), 
							rects[MAP_RECT].top() );


	
	str = LogisticsData::instance->getCurrentVideoFileName();
	if ( str && strlen( str ) )
	{
		FullPathFileName videoName;
		videoName.init( moviePath, str, ".bik" );

		if (fileExists(videoName) || fileExistsOnCD(videoName))
		{
			RECT movieRect;
			movieRect.left = rects[VIDEO_RECT].left()+1;
			movieRect.top = rects[VIDEO_RECT].top()+1;
			movieRect.right = movieRect.left + rects[VIDEO_RECT].width()-2;
			movieRect.bottom = movieRect.top + rects[VIDEO_RECT].height()-2;
		
			//If there is one already here, cause we loaded a savegame or something,
			// Toss it to prevent leaking from the system Heap!
			if (bMovie)
			{
				bMovie->stop();
				delete bMovie;
				bMovie = NULL;
			}

			bMovie = new MC2Movie;
			bMovie->init(videoName,movieRect,true);

			if (Environment.Renderer == 3)
			{
				//DO NOT show the movies by default in software.
				// It will still work, if they hit play.
				bMovie->stop();
			}

			if ( LogisticsData::instance->getVideoShown() )
				bMovie->stop();

			LogisticsData::instance->setVideoShown( );
		}
	}

	missionCount = MAX_MISSIONS_IN_GROUP;
	int result = LogisticsData::instance->getCurrentMissions( missionNames, missionCount );

	EString selMissionName = LogisticsData::instance->getCurrentMission();
	gosASSERT( result == NO_ERR );

	bool bPressed = 0;
	for ( int i = 0; i < missionCount; i++ )
	{
		if ( i > operationScreen.buttonCount )
		{
			Assert( 0, 0, "not enough buttons on the operation screen" );
		}
		else 
		{
			operationScreen.buttons[i].setID( MSG_FIRST_MISSION + i );
			operationScreen.buttons[i].setPressFX( LOG_SELECT );
			if ( !LogisticsData::instance->getMissionAvailable( missionNames[i] ) )
				operationScreen.buttons[i].disable( true );


			else
			{
				operationScreen.buttons[i].disable( false );
				if ( selMissionName.Compare( missionNames[i], 0 ) == 0 )
				{
					operationScreen.buttons[i].press( true );
					handleMessage( 0, MSG_FIRST_MISSION + i );
					bPressed = 1;
					pressedButton = i;

				}
				if ( !bPressed && !selMissionName.Length()  )
				{
					bPressed = 1;
					pressedButton = i;
					operationScreen.buttons[i].press( true );
					handleMessage( 0, MSG_FIRST_MISSION + i );
				}
			}
		}

	}

	for ( ; i < operationScreen.buttonCount; i++ )
	{
		operationScreen.buttons[i].showGUIWindow( 0 );
	}

	bStop = 0;
}
Пример #3
0
void LogisticsSaveDialog::update()
{
	if ( !bPromptOverwrite && !bDeletePrompt )
		LogisticsDialog::update();

	if ( exitAnim.isDone() )
		bDone = true;

	buttons[2].disable( 0 );
	buttons[0].disable( 0 );

	EString fileName;
	edits[0].getEntry( fileName );

	if (bCampaign)
	{
		fileName.Empty();
		EString displayName;
		edits[0].getEntry( displayName );
		{
			/*if there is a selected item and it matches the text in the editbox, then use that selected item*/
			aLocalizedListItem* pSelectedItem = 0;
			int selectedIndex = gameListBox.GetSelectedItem();
			if ((0 <= selectedIndex) && (gameListBox.GetItemCount() > selectedIndex))
			{
				pSelectedItem = dynamic_cast<aLocalizedListItem*>(gameListBox.GetItem(selectedIndex));
			}
			if (pSelectedItem)
			{
				if (0 == displayName.Compare(pSelectedItem->getText(), false/*not case sensitive*/))
				{
					fileName = pSelectedItem->getHiddenText();
				}
			}
		}

		if (fileName.IsEmpty())
		{
			/* No item is selected or the selected item doesn't match the editbox. */
			// loop through the entries in the game list box, and fine the same one, and find its hidden text
			for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
			{
				aLocalizedListItem* pItem = dynamic_cast<aLocalizedListItem*>(gameListBox.GetItem( i ));
				if ( displayName.Compare( pItem->getText(), false/*not case sensitive*/ ) == 0  )
				{
					fileName = pItem->getHiddenText( );
					break;
				}
			}
		}
	}

	if ( (bLoad || bCampaign) && fileName.Length() )
	{

		FullPathFileName path;
		path.init( bCampaign ? campaignPath : savePath, fileName, ".fit" );

		if ( fileExists( path ) )
			getButton( YES )->disable( false );
		else
			getButton( YES )->disable( true );
	}
	else if (!fileName.Length() )
	{	
		getButton( YES )->disable( true );	
	}
	else
		getButton( YES )->disable( false );


	if ( bPromptOverwrite )
	{
		LogisticsOKDialog::instance()->update();
		if ( LogisticsOKDialog::instance()->isDone() )
		{
			if ( YES == LogisticsOKDialog::instance()->getStatus() )
			{
				status = YES;
				bPromptOverwrite = 0;
				end();
			}
			else if ( NO == LogisticsOKDialog::instance()->getStatus() )
			{
				bPromptOverwrite = 0;
			}
		}
	}
	else if ( bDeletePrompt )
	{
		LogisticsOKDialog::instance()->update();
		if ( YES == LogisticsOKDialog::instance()->getStatus() )
		{
			FullPathFileName name;
			if ( bCampaign )
			{
				name.init( campaignPath, selectedName, ".fit" );
			}
			else
			{
				name.init( savePath, selectedName, ".fit" );
			}
				// delete the file
				DeleteFile( name );

				initDialog(bCampaign ? campaignPath : savePath, bCampaign ? 1 : 0 );
				bDeletePrompt = 0;

				edits[0].getEntry( selectedName );
				edits[0].setEntry( "" );
				selectedName = "";

				aListItem* pItem = gameListBox.GetItem( 0 );
				if ( pItem )
				{
					pItem->select();
					edits[0].setEntry( ((aTextListItem*)pItem)->getText() );
					selectedName = ( ((aLocalizedListItem*)pItem)->getHiddenText() );
				}

		}
		else if ( NO == LogisticsOKDialog::instance()->getStatus() )
		{
			bDeletePrompt = 0;
		}
	
	}
	
	gameListBox.update();

	if ( userInput->isLeftClick()  )
	{
		if ( gameListBox.pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			// get selected item
			int item = gameListBox.GetSelectedItem();
			if ( item != -1 )
			{
				for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
				{
					gameListBox.GetItem( i )->setColor( edits[0].getColor() );
				}
				gameListBox.GetItem( item )->setColor( edits[0].getHighlightColor() );
				const char* text = ((aTextListItem*)gameListBox.GetItem( item ))->getText();
				edits[0].setEntry( text );
				selectedName = ((aLocalizedListItem*)gameListBox.GetItem( item ))->getHiddenText();

				// update mission info
				updateMissionInfo();
			}
		}
		else if ( edits[0].pointInside( userInput->getMouseX(), userInput->getMouseY() ) )
		{
			gameListBox.SelectItem( -1 );
			for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
			{
				gameListBox.GetItem( i )->setColor( edits[0].getColor() );
			}
		}
	}

}
Пример #4
0
int	LogisticsSaveDialog::handleMessage( unsigned long what, unsigned long who )
{
	
	if ( YES == who )
	{
		EString str;
		edits[0].getEntry(str);
		bool bFound = 0;

		// look and see if you are overwriting anything here...
		for ( int i= 0; i < gameListBox.GetItemCount(); i++ )
		{
		 if ( str.Compare( ((aLocalizedListItem*)gameListBox.GetItem( i ))->getText(), 0 ) == 0 )
		 {
			 // do prompt here
			selectedName = ((aLocalizedListItem*)gameListBox.GetItem( i ))->getHiddenText();
			char str[256];
			cLoadString( IDS_DIALOG_OVERWRITE_PROMPT, str, 255 );
			char promptString[256];
			sprintf( promptString, str, (const char*)selectedName );
			LogisticsOKDialog::instance()->setText( IDS_DIALOG_QUIT_PROMPT,
				IDS_DIALOG_NO, IDS_DIALOG_YES );
			LogisticsOKDialog::instance()->setText( promptString );
			LogisticsOKDialog::instance()->begin();
			bPromptOverwrite = true;
			bFound = 1;
			break;
		 }
		}

		 if ( (!bFound || bLoad)  )
		 {
			status = YES;
			bPromptOverwrite = 0;
			if ( bLoad )
				beginFadeOut( 1.0 );

			//Selected Name is coming back in SAVE with the default savegame.
			// NOT with what I typed in the box.  Maybe this will fix?  -fs
			if ( !bCampaign )
				selectedName = str;
			end();
		 }
	}
	if ( NO == who )
	{
		selectedName = "";
		status = NO;
		end();
	}
	if ( DELETE_BUTTON == who )
	{
		if (gameListBox.GetItemCount())
		{
			EString tmpName;
			edits[0].getEntry(tmpName);
			for ( int i = 0; i < gameListBox.GetItemCount(); i++ )
			{
				const char* pFileName = ((aLocalizedListItem*)gameListBox.GetItem(i))->getHiddenText();
				if ( tmpName.Compare( pFileName, 0  ) == 0 )
				{
					selectedName = pFileName;
					break;
				}
			}
			char str[256];
			cLoadString( IDS_DIALOG_DELETE_PROMPT, str, 255 );
			char promptString[256];
			sprintf( promptString, str, (const char*)tmpName );
	
			LogisticsOKDialog::instance()->setText( IDS_DIALOG_QUIT_PROMPT,
						IDS_DIALOG_NO, IDS_DIALOG_YES );	
			LogisticsOKDialog::instance()->setText( promptString );
			LogisticsOKDialog::instance()->begin();
	
			bDeletePrompt = true;
		}
	}

	return 0;
}
Пример #5
0
int main(int argc, char **argv)
{
	bool printUsageAndExit = true;
	bool showDebug = false;
	bool showInfo = false;

	EPath prog(argv[0]);
	EStringArray files;
	const char *lang = "C";
	const char *style = "DocBook";
	const char *options = NULL;
	files.AddItem(NULL);

	const char *tmp_env = getenv("LC_ALL");
	if(tmp_env == NULL) tmp_env = getenv("LANG");
	if(tmp_env != NULL) lang = tmp_env;

	do {
		if(argc < 2) break;

		for(int n = 1; n < argc; n++)
		{
			if(strcmp(argv[n], "-s") == 0)
			{
				if(argc - n < 2) break;
				n++;
				style = argv[n];
			}
			else if(strcmp(argv[n], "-t") == 0)
			{
				if(argc - n < 2) break;
				n++;
				options = argv[n];
			}
			else if(strcmp(argv[n], "-o") == 0)
			{
				if(argc - n < 2) break;
				n++;
				if(files.ReplaceItem(0, argv[n]) == false) break;
			}
			else if(strcmp(argv[n], "-l") == 0)
			{
				if(argc - n < 2) break;
				n++;
				lang = argv[n];
			}
			else if(strcmp(argv[n], "--debug") == 0)
			{
				showDebug = true;
			}
			else if(strcmp(argv[n], "--showinfo") == 0)
			{
				showInfo = true;
			}
			else
			{
				files.AddItem(argv[n]);
			}
		}

		if(files.CountItems() < 2) break;

		printUsageAndExit = false;
	} while(false);

	if(printUsageAndExit)
	{
		print_usage(prog.Leaf());
		exit(1);
	}

	EString xml_buffer;
	EString strDocStart = "<document ";
	EString strDocEnd = "</document>";

	for(eint32 i = 1; i < files.CountItems(); i++)
	{
		if(files.ItemAt(i) == NULL) continue;
		EPath readInPath(files.ItemAt(i)->String(), NULL, true);
		EFile readIn(readInPath.Path(), E_READ_ONLY);
		if(readIn.InitCheck() != E_OK)
		{
			ETK_DEBUG("[%s] --- Unable to read \"%s\".", prog.Leaf(), files.ItemAt(i)->String());
			continue;
		}

		eint32 old_length = xml_buffer.Length();

		char buffer[BUFFER_SIZE];
		bool foundDocEnd = true;
		size_t nLeave = 0;
		xml_buffer.AppendFormat("<!-- convert from \"%s\" -->\n", readInPath.Leaf());
		while(true)
		{
			ssize_t len = readIn.Read(buffer + nLeave, BUFFER_SIZE - nLeave);
			if(len <= 0) break;
			EString str;
			str.SetTo(buffer, len + nLeave);
			str.RemoveAll("\r");
			eint32 offset = 0;
			while(offset >= 0 && offset < str.Length())
			{
				nLeave = 0;
				if(foundDocEnd)
				{
					offset = str.FindFirst("/*", offset);
					if(offset < 0)
					{
						if(str.Length() < 2) break;
						if(str[str.Length() - 1] == '/' && str[str.Length() - 2] != '*') nLeave = 1; break;
					}

					nLeave = str.Length() - offset;
					offset = str.FindFirst("\n", offset);
					if(offset < 0)
					{
						if(nLeave > 80) nLeave = 0;
						break;
					}
					nLeave = 0;

					offset++;
					if(offset >= str.Length()) break;

					if(strDocStart.Compare(str.String() + offset, strDocStart.Length()) != 0)
					{
						eint32 tmp = str.FindLast("<");
						if(tmp >= 0 && str.Length() - tmp < strDocStart.Length())
						{
							nLeave = str.Length() - tmp;
						}
						else
						{
							nLeave = 0;
						}
						continue;
					}

					foundDocEnd = false;
				}

				eint32 endOffset = str.FindFirst(strDocEnd, offset);
				if(endOffset >= 0)
				{
					endOffset += strDocEnd.Length();
					foundDocEnd = true;
					nLeave = 0;
				}
				else
				{
					eint32 tmp = str.FindLast("<");
					if(tmp >= 0 && str.Length() - tmp < strDocEnd.Length())
					{
						nLeave = str.Length() - tmp;
					}
					else
					{
						nLeave = 0;
					}
				}

				xml_buffer.Append(str.String() + offset, (endOffset >= 0 ? endOffset : str.Length()) - offset - nLeave);
				if(foundDocEnd) xml_buffer.Append("\n");
				offset = endOffset;
			}
			if(nLeave > 0) str.CopyInto(buffer, BUFFER_SIZE, str.Length() - nLeave, nLeave);
		}

		if(foundDocEnd == false)
		{
			xml_buffer.Remove(old_length, -1);
			ETK_DEBUG("[%s] --- Invalid document \"%s\".", prog.Leaf(), readInPath.Path());
		}
	}

	EString output_buffer;

	if(strcmp(style, "None") == 0)
	{
		output_buffer.Adopt(xml_buffer);
	}
	else if(strcmp(style, "DocBook") == 0)
	{
		xml_buffer.ReplaceAll("&", "&amp;");
		xml_buffer.ReplaceAll("&amp;lt;", "&lt;");
		xml_buffer.ReplaceAll("&amp;gt;", "&gt;");
		xml_buffer.ReplaceAll("&amp;nbsp;", "&nbsp;");
		xml_buffer.ReplaceAll("©", "&copy;");
		xml_buffer.ReplaceAll("®", "&reg;");
		xml_buffer.ReplaceAll("\n", "&br;");

		eint32 offset = 0;
		while(offset >= 0 && offset < xml_buffer.Length())
		{
			if((offset = xml_buffer.FindFirst(">", offset)) < 0) break;
			eint32 tmp = xml_buffer.FindFirst("<", offset);
			if(tmp < 0 || tmp - offset <= 1) {offset = tmp; continue;}
			EString str;
			xml_buffer.MoveInto(str, offset + 1, tmp - offset);
			str.ReplaceAll(" ", "&nbsp;");
			xml_buffer.Insert(str, offset + 1);
			offset += str.Length() + 1;
		}

		ESimpleXmlNode node(NULL, NULL);
		if(etk_parse_simple_xml(xml_buffer.String(), &node) != E_OK)
		{
			ETK_OUTPUT("[%s] --- Unable to parse.\n", prog.Leaf());
			exit(1);
		}

		ESimpleXmlNode *aNode = NULL;
		offset = 0;
		while(offset >= 0 && offset < node.CountNodes())
		{
			if((offset = node.FindNode("document", offset)) < 0) break;
			if((aNode = node.NodeAt(offset)) == NULL) break;

			eint32 index = aNode->FindAttribute("lang");
			const char *tmp = NULL;
			if(index < 0 || aNode->AttributeAt(index, &tmp) == NULL || tmp == NULL || strcmp(tmp, lang) != 0)
			{
				aNode->RemoveSelf();
				delete aNode;
				continue;
			}

			offset++;
		}

		aNode = find_xml_node_deep(&node, "documentinfo");
		if(aNode != NULL)
		{
			if(!showInfo)
			{
				ESimpleXmlNode *cNode = aNode->NodeAt(aNode->FindNode("title"));
				if(cNode) cNode->RemoveSelf();
				ESimpleXmlNode *nNode;
				while((nNode = aNode->NodeAt(0)) != NULL) {nNode->RemoveSelf(); delete nNode;}
				if(cNode) aNode->AddNode(cNode);
			}
			aNode->RemoveSelf();
			if(node.AddNode(aNode) == false) delete aNode;
		}

		foreach_xml_node(&node, NULL, docbook_foreach, NULL);

		if(showDebug) node.PrintToStream();

		if(convert_to_docbook(&node, &output_buffer, options, lang) != E_OK)
		{
			ETK_OUTPUT("[%s] --- Unable to convert to \"DocBook\" style.\n", prog.Leaf());
			exit(1);
		}
	}
	else
	{
		ETK_OUTPUT("[%s] --- style \"%s\" unsupport yet.\n", prog.Leaf(), style);
		exit(1);
	}

	if(files.ItemAt(0) == NULL || files.ItemAt(0)->String() == NULL)
	{
		for(eint32 offset = 0; offset < output_buffer.Length(); offset += BUFFER_SIZE)
		{
			EString str(output_buffer.String() + offset, BUFFER_SIZE);
			fprintf(stdout, "%s", str.String());
		}
	}
	else
	{
		EFile writeOut(files.ItemAt(0)->String(), E_WRITE_ONLY | E_CREATE_FILE | E_ERASE_FILE);
		if(writeOut.InitCheck() != E_OK)
		{
			ETK_OUTPUT("[%s] --- Unable to write \"%s\".\n", prog.Leaf(), files.ItemAt(0)->String());
			exit(1);
		}
		else
		{
			for(eint32 offset = 0; offset < output_buffer.Length(); offset += BUFFER_SIZE)
				writeOut.Write(output_buffer.String() + offset, min_c(BUFFER_SIZE, output_buffer.Length() - offset));
		}
	}

	return 0;
}