//----------------------------------------------------------------------------
//
// Name       : LoadText
//
// Description: Load an interpreted text in a user interface item.
//
// Parameters : textbox					: user interface item
//              filename				: name of the text to interpret
//              so						: ?
//
// Globals    : m_great_library_info	: great library database
//
// Returns    : sint32 (bool)			: function result
//
// Remark(s)  : The function result is 1 (true?) when the requested name of
//              the text exist in the database, 0 when it does not exist.
//
//              However, the result is also 1 (illogical) when the passed
//              user interface item is NULL. In that case, this function does
//              nothing.
//
//----------------------------------------------------------------------------
sint32 GreatLibraryWindow::LoadText(ctp2_HyperTextBox *textbox, char *filename, SlicObject &so)
{
    if (textbox)
    {
        char const *    text    =
            GreatLibrary::s_great_library_info->Look_Up_Data(filename);

        if (text == NULL)
        {
		    textbox->SetHyperText(" ");
            return 0;
        }

	    MBCHAR interpreted[k_MAX_GL_ENTRY];
	    stringutils_Interpret(text, so, interpreted, k_MAX_GL_ENTRY);
        textbox->SetHyperText(interpreted);
    }

    return 1;
}
예제 #2
0
void TradeManager::UpdateAdviceText()
{
	ctp2_HyperTextBox *advice = (ctp2_HyperTextBox *)aui_Ldl::GetObject(s_tradeAdviceBlock, "Advice");
	Assert(advice);
	if(advice) {
		Assert(m_createList);
		
		SlicContext sc;
		
		Player *p = g_player[g_selected_item->GetVisiblePlayer()];

		if(m_createList) {
			ctp2_ListItem *selItem = (ctp2_ListItem *)m_createList->GetSelectedItem();
			if(selItem && !m_createList->IsHidden()) {
				CreateListData *data = (CreateListData *)selItem->GetUserData();
				sc.AddCity(data->m_source);
				sc.AddCity(data->m_destination);
				sc.AddGood(data->m_resource);
				sc.AddGold(data->m_price);
				sc.AddInt(data->m_caravans);
				
				MBCHAR interp[k_MAX_NAME_LEN];
				interp[0] = 0;
				
				stringutils_Interpret(g_theStringDB->GetNameStr("SELECTED_TRADE_ADVICE"),
									  sc, interp);

				if(p) {
					if(data->m_caravans > (p->m_tradeTransportPoints - p->m_usedTradeTransportPoints)) {
						SlicContext sc2;
						sc2.AddInt(data->m_caravans - (p->m_tradeTransportPoints - p->m_usedTradeTransportPoints));

						strcat(interp + strlen(interp), "  ");

						stringutils_Interpret(g_theStringDB->GetNameStr("NEED_MORE_CARAVANS"),
											  sc2, interp + strlen(interp));
					}
				}

				advice->SetHyperText(interp);
			} else {
				
				if(p) {
					PointerList<CreateListData>::Walker walk(&m_createData);
					CreateListData *maxData = NULL;
					while(walk.IsValid()) {
						CreateListData *data = walk.GetObj();
						if(data->m_curDestination.m_id != 0) {
							
							walk.Next();
							continue;
						}
						if(data->m_caravans <= (p->m_tradeTransportPoints - p->m_usedTradeTransportPoints)) {
							if(!maxData || data->m_price > maxData->m_price) {
								maxData = data;
							}
						}
						walk.Next();
					}

					MBCHAR interp[k_MAX_NAME_LEN];
					interp[0] = 0;
						
					if(maxData) {
						SlicContext sc;
						sc.AddCity(maxData->m_source);
						sc.AddCity(maxData->m_destination);
						sc.AddGood(maxData->m_resource);
						
						stringutils_Interpret(g_theStringDB->GetNameStr("CREATE_ROUTE_ADVICE"),
											  sc, interp);
					} else if(m_createData.GetCount() > 0) {
						strcpy(interp, g_theStringDB->GetNameStr("BUILD_MORE_CARAVANS"));
					} else {
						strcpy(interp, g_theStringDB->GetNameStr("MAXIMUM_TRADE_EFFICIENCY"));
					}
					
					advice->SetHyperText(interp);
				}
			}
		}
	}
}