Exemple #1
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);
}
bool EventListener::Compile()
{
	Rocket::Core::String function_name(64, "Event_%x", this);
	Rocket::Core::String function_code(64, "def %s():", function_name.CString());

	Rocket::Core::StringList lines;
	Rocket::Core::StringUtilities::ExpandString(lines, source_code, ';');
	for (size_t i = 0; i < lines.size(); i++)
	{
		// Python doesn't handle \r's, strip em and indent the code correctly
		function_code += Rocket::Core::String(1024, "\n\t%s", lines[i].CString()).Replace("\r", "");
	}

	ROCKET_ASSERT(element != NULL);

	PyObject* py_namespace = GetGlobalNamespace();

	// Add our function to the namespace
	PyObject* result = PyRun_String(function_code.CString(), Py_file_input, py_namespace, py_namespace);
	if (!result)
	{
		Rocket::Core::Python::Utilities::PrintError();		
		return false;
	}
	Py_DECREF(result);

	// Get a handle to our function
	callable = PyDict_GetItemString(py_namespace, function_name.CString());
	Py_INCREF(callable);

	return true;
}
Exemple #3
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);
                }
            }
        }
    }
}
Exemple #4
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] == "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));
			}
		}
	}
}
Exemple #5
0
int Eventspushcmd(lua_State* L)
{
	Rocket::Core::StringList list;
	const char *cmds = luaL_checkstring(L, 1);

	Rocket::Core::StringUtilities::ExpandString( list, cmds, ';' );
	for ( size_t i = 0; i < list.size(); ++i )
	{
		Rocket_AddEvent( new RocketEvent_t( list[ i ] ) );
	}

	return 0;
}
Exemple #6
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());
	}
}
Exemple #7
0
int Eventspushelement(lua_State* L)
{
	Rocket::Core::StringList list;
	const char *cmds = luaL_checkstring(L, 1);
	Rocket::Core::Element *element = LuaType<Rocket::Core::Element>::check(L, 2);

	if (element == NULL)
	{
		return 0;
	}

	Rocket::Core::StringUtilities::ExpandString( list, cmds, ';' );
	for ( size_t i = 0; i < list.size(); ++i )
	{
		Rocket_AddEvent( new RocketEvent_t( element, list[ i ] ) );
	}

	return 0;
}
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
	Rocket::Core::StringList commands;
	Rocket::Core::StringUtilities::ExpandString(commands, value, ';');
	for (size_t i = 0; i < commands.size(); ++i)
	{
		// Check for a generic 'load' or 'exit' command.
		Rocket::Core::StringList values;
		Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

		if (values.empty())
			return;

		if (values[0] == "goto" &&
 			values.size() > 1)
		{
			// Load the window, and if successful close the old window.
			if (LoadWindow(values[1]))
				event.GetTargetElement()->GetOwnerDocument()->Close();
		}
		else if (values[0] == "load" &&
 			values.size() > 1)
		{
			// Load the window.
			LoadWindow(values[1]);
		}
		else if (values[0] == "close")
		{
			Rocket::Core::ElementDocument* target_document = NULL;

			if (values.size() > 1)
				target_document = context->GetDocument(values[1].CString());
			else
				target_document = event.GetTargetElement()->GetOwnerDocument();

			if (target_document != NULL)
				target_document->Close();
		}
		else if (values[0] == "exit")
		{
			Shell::RequestExit();
		}
		else if (values[0] == "pause")
		{
			GameDetails::SetPaused(true);
		}
		else if (values[0] == "unpause")
		{
			GameDetails::SetPaused(false);
		}
		else
		{
			if (event_handler != NULL)
				event_handler->ProcessEvent(event, commands[i]);
		}
	}
}
void FileFormatter::FormatData(Rocket::Core::String& formatted_data, const Rocket::Core::StringList& raw_data)
{
	if (raw_data.size() == 3)
	{
		// Add spacers for the depth.
		int depth = atoi(raw_data[1].CString());
		for (int i = 0; i < depth; ++i)
			formatted_data += "<spacer />";

		// If the file has 1 or more children, add an expand button.
		if (raw_data[2] != "0")
			formatted_data += "<datagridexpand />";
		else
			formatted_data += "<spacer />";

		// Lastly, write the filename.
		formatted_data += raw_data[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( "" );
		}
	}
}
Exemple #11
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());
            }
         }
      }
   }
}
Exemple #12
0
void GuiManager::OnGuiEvent(Rocket::Core::Event &ev, const Rocket::Core::String &script)
{
	UNUSED(ev)
	Rocket::Core::StringList commands;
	Rocket::Core::StringUtilities::ExpandString(commands, script, ';');
	for (size_t i = 0; i < commands.size(); ++i)
	{
		Rocket::Core::StringList values;
		Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');
		if (values.empty())
			return;

		if (values[0] == "goto" && values.size() > 1)
		{
			if (values[1] == "credits")
				gFlow->Credits();
			else if (values[1] == "menu")
				gFlow->Menu();
			else if (values[1] == "options")
				gFlow->Options();
			else if (values[1] == "game")
				gFlow->DoLoad("game_level1.scene");
		}
		else if (values[0] == "exit")
		{
			pSystem->Shutdown();
		}
		else if (values[0] == "toggle" && values.size() > 1)
		{
			if (values[1] == "sfx")
			{
				if (gGameData->IsSfxEnabled())
				{
					gGameData->SetSfxVolume(pSoundSystem->GetSfxVolume());
					pSoundSystem->SetSfxVolume(0.0f);
					gGameData->SetSfxEnabled(false);
				}
				else
				{
					pSoundSystem->SetSfxVolume(gGameData->GetSfxVolume());
					gGameData->SetSfxEnabled(true);
				}
			}
			else if (values[1] == "bgm")
			{
				if (gGameData->IsBgmEnabled())
				{
					gGameData->SetBgmVolume(pSoundSystem->GetMusicVolume());
					pSoundSystem->SetMusicVolume(0.0f);
					gGameData->SetBgmEnabled(false);
				}
				else
				{
					pSoundSystem->SetMusicVolume(gGameData->GetBgmVolume());
					gGameData->SetBgmEnabled(true);
				}
			}
			else if (values[1] == "fullscreen")
			{
				//this->ReleaseGUI();

				if (gGameData->IsFullScreenEnabled())
				{
					gGameData->SetFullScreenEnabled(false);
					pScreen->ToggleFullscreen();
					//pSystem->Shutdown();
				}
				else
				{
					gGameData->SetFullScreenEnabled(true);
					pScreen->ToggleFullscreen();
					//pSystem->Shutdown();
				}

				//this->InitializeGUI();
				//this->ReloadGUI();
			}
		}
	}
}
// 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);
	}
}
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    Rocket::Core::StringList commands;
    Rocket::Core::StringUtilities::ExpandString(commands, value, ';');

    if(commands.size() == 0)
    {
        //send only the event to event handlers
        for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
            if(it->second != NULL)
                it->second->ProcessEvent(event, "");
    }
    else
    {
        for (size_t i = 0; i < commands.size(); ++i)
        {
            // Check for a generic 'load' or 'exit' command.
            Rocket::Core::StringList values;
            Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

            //if (values.empty())
            //	return;

            if (values[0] == "goto" &&
                    values.size() > 1)
            {
                // Load the window, and if successful close the old window.
                if (LoadWindow(values[1]))
                    event.GetTargetElement()->GetOwnerDocument()->Close();
            }
            else if (values[0] == "load" &&
                     values.size() > 1)
            {
                // Load the window.
                LoadWindow(values[1]);
            }
            else if (values[0] == "close")
            {
                Rocket::Core::ElementDocument* target_document = NULL;

                if (values.size() > 1)
                    target_document = Context->GetDocument(values[1].CString());
                else
                    target_document = event.GetTargetElement()->GetOwnerDocument();

                if (target_document != NULL)
                    target_document->Close();
            }
            else if (values[0] == "exit")
            {
                Shell::RequestExit();
            }
            /*
            		else if (values[0] == "pause")
            		{
            			GameDetails::SetPaused(true);
            		}
            		else if (values[0] == "unpause")
            		{
            			GameDetails::SetPaused(false);
            		}
            */
            else
            {
                //send the event to all windows
                for(EventHandlerMap::iterator it = event_handlers.begin(); it != event_handlers.end(); it++)
                    if(it->second != NULL)
                        it->second->ProcessEvent(event, commands[i]);

                /*
                if (event_handler != NULL)
                {
                	event_handler->ProcessEvent(event, commands[i]);
                }
                */
            }
        }
    }
}