예제 #1
0
void ConsoleBuffer::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns) {
    if (table == "console" && row_index < messages.size()) {
        for (size_t i = 0; i < columns.size(); i++) {
            if (columns[i] == "message") {
                eventMessage* em = &(messages[row_index]);
                Rocket::Core::String msg(em->message.c_str());
                row.push_back(msg);
            } else if (columns[i] == "color") {
                eventMessage* em = &(messages[row_index]);
                switch (em->type) {
                case SYSTEM_MSG:
                    row.push_back(systemMsgColorString);
                    break;
                case MOVE_MSG:
                    row.push_back(moveMsgColorString);
                    break;
                case ATTACK_MSG:
                    row.push_back(attackMsgColorString);
                    break;
                default:
                    assert(0);
                }
            }
        }
    }
}
예제 #2
0
void HighScores::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns)
{
	if (table == "scores")
	{
		for (size_t i = 0; i < columns.size(); i++)
		{
			if (columns[i] == "name")
			{
				row.push_back(scores[row_index].name);
			}
			else if (columns[i] == "name_required")
			{
				row.push_back(Rocket::Core::String(4, "%d", scores[row_index].name_required));
			}
			else if (columns[i] == "score")
			{
				row.push_back(Rocket::Core::String(32, "%d", scores[row_index].score));
			}
			else if (columns[i] == "colour")
			{
				Rocket::Core::String colour_string;
				Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(scores[row_index].colour, colour_string);
				row.push_back(colour_string);
			}
			else if (columns[i] == "wave")
			{
				row.push_back(Rocket::Core::String(8, "%d", scores[row_index].wave));
			}
		}
	}
}
예제 #3
0
void Phobos::Game::Gui::LevelFileDataSource::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns)
{
	if(table == "files")
	{
		row.push_back(vecFiles[row_index].c_str());
	}
}
예제 #4
0
/// Fetches the contents of one row of a table within the data source.
/// @param[out] row The list of values in the table.
/// @param[in] table The name of the table to query.
/// @param[in] row_index The index of the desired row.
/// @param[in] columns The list of desired columns within the row.
void LuaDataSource::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns)
{
    if(getRowRef == LUA_NOREF || getRowRef == LUA_REFNIL) return;

    //setup the call
    Interpreter::BeginCall(getRowRef);
    lua_State* L = Interpreter::GetLuaState();
    lua_pushstring(L,table.CString());
    lua_pushinteger(L,row_index);
    lua_newtable(L);
    int index = 0;
    for(Rocket::Core::StringList::const_iterator itr = columns.begin(); itr != columns.end(); ++itr)
    {
        lua_pushstring(L,itr->CString());
        lua_rawseti(L,-2,index++);
    }
    Interpreter::ExecuteCall(3,1); //3 parameters, 1 return. After here, the top of the stack contains the return value

    int res = lua_gettop(L);
    if(lua_type(L,res) == LUA_TTABLE)
    {
        lua_pushnil(L);
        while(lua_next(L,res) != 0)
        {
            //key at -2, value at -1
            row.push_back(luaL_checkstring(L,-1));
            lua_pop(L,1); //pops value, leaves key for next iteration
        }
        lua_pop(L,1); //pop key
    }
    else
        Log::Message(Log::LT_WARNING, "Lua: DataSource.GetRow must return a table, the function it called returned a %s", lua_typename(L,res));

    Interpreter::EndCall(1);
}
예제 #5
0
void GameTypesDataSource::GetRow( Rocket::Core::StringList &row, const Rocket::Core::String&, int row_index, const Rocket::Core::StringList& cols ) {
	if( row_index < 0 || (size_t)row_index >= gameTypes.size() ) {
		return;
	}

	for( Rocket::Core::StringList::const_iterator it = cols.begin();
		 it != cols.end();
		 ++it ) {
		if( *it == "name" ) {
			row.push_back( gameTypes[row_index].name.c_str() );
		} else if( *it == "title" ) {
			row.push_back( gameTypes[row_index].title.c_str() );
		} else if( *it == "description" ) {
			row.push_back( gameTypes[row_index].description.c_str() );
		} else {
			row.push_back( "" );
		}
	}
}
예제 #6
0
void ItemViewModel::GetRow(Rocket::Core::StringList& row,
      const Rocket::Core::String& table, int row_index,
      const Rocket::Core::StringList& columns)
{
   if (table == "items")
   {
      const ItemList& itemList = m_playerData.getInventory()->getItemList();
      for (int i = 0; i < columns.size(); ++i)
      {
         const UsableId usableId = itemList[row_index].first;
         const int itemQuantity = itemList[row_index].second;
         const Item* rowItem = m_metadata.getItem(usableId);
         if (columns[i] == "name")
         {
            if(rowItem == nullptr)
            {
               row.emplace_back(13, "Unknown %d", usableId);
            }
            else
            {
               row.emplace_back(rowItem->getName().c_str());
            }
         }
         else if (columns[i] == "quantity")
         {
            row.emplace_back(5, "%d", itemQuantity);
         }
         else if (columns[i] == "icon")
         {
            if(rowItem == nullptr)
            {
               row.push_back(ItemViewModel::UnknownItemIconPath);
            }
            else
            {
               row.emplace_back(rowItem->getIconPath().c_str());
            }
         }
      }
   }
}
// Builds the option list from the data source.
void ElementFormControlDataSelect::BuildOptions()
{
	widget->ClearOptions();

	if (data_source == NULL)
		return;

	// Store the old selection value and index. These will be used to restore the selection to the
	// most appropriate option after the options have been rebuilt.
	Rocket::Core::String old_value = GetValue();
	int old_selection = GetSelection();

	Rocket::Core::String fields_attribute = GetAttribute<Rocket::Core::String>("fields", "");
	Rocket::Core::String valuefield_attribute = GetAttribute<Rocket::Core::String>("valuefield", "");
	Rocket::Core::String data_formatter_attribute = GetAttribute<Rocket::Core::String>("formatter", "");
	DataFormatter* data_formatter = NULL;

	// Process the attributes.
	if (fields_attribute.Empty())
	{
		Core::Log::Message(Rocket::Core::Log::LT_ERROR, "DataQuery failed, no fields specified for %s.", GetTagName().CString());
		return;
	}

	if (valuefield_attribute.Empty())
	{
		valuefield_attribute = fields_attribute.Substring(0, fields_attribute.Find(","));
	}

	if (!data_formatter_attribute.Empty())
	{
		data_formatter = DataFormatter::GetDataFormatter(data_formatter_attribute);
		if (!data_formatter)
			Core::Log::Message(Rocket::Core::Log::LT_WARNING, "Unable to find data formatter named '%s', formatting skipped.", data_formatter_attribute.CString());
	}

	// Build a list of attributes
	Rocket::Core::String fields(valuefield_attribute);
	fields += ",";
	fields += fields_attribute;

	DataQuery query(data_source, data_table, fields);
	while (query.NextRow())
	{
		Rocket::Core::StringList fields;
		Rocket::Core::String value = query.Get<Rocket::Core::String>(0, "");

		for (size_t i = 1; i < query.GetNumFields(); ++i)
			fields.push_back(query.Get< Rocket::Core::String>(i, ""));

		Rocket::Core::String formatted("");
		if (fields.size() > 0)
			formatted = fields[0];

		if (data_formatter)
			data_formatter->FormatData(formatted, fields);

		// Add the data as an option.
		widget->AddOption(formatted, value, -1, false);
	}

	// If an option was selected before, attempt to restore the selection to it.
	if (old_selection > -1)
	{
		// Try to find a selection with the same value as the previous one.
		for (int i = 0; i < GetNumOptions(); ++i)
		{
			SelectOption* option = GetOption(i);
			if (option->GetValue() == old_value)
			{
				widget->SetSelection(i, true);
				return;
			}
		}

		// Failed to find an option with the same value. Attempt to at least set the same index.
		int new_selection = Rocket::Core::Math::Clamp(old_selection, 0, GetNumOptions() - 1);
		if (GetNumOptions() == 0)
			new_selection = -1;

		widget->SetSelection(new_selection, true);
	}
}