예제 #1
0
AtObj ActorEditorListCtrl::DoExport()
{
	AtObj out;

	AtObj group;

	for (size_t i = 0; i < m_ListData.size(); ++i)
	{
		if (IsRowBlank((int)i))
		{
			if (group.defined())
				out.add("group", group);
			group = AtObj();
		}
		else
		{
			AtObj variant = AtlasObject::TrimEmptyChildren(m_ListData[i]);
			group.add("variant", variant);
		}
	}

	if (group.defined())
		out.add("group", group);

	return out;
}
예제 #2
0
AtObj PlayerSettingsControl::UpdateSettingsObject()
{
	// Update player data in the map settings
	AtObj players;
	players.set("@array", L"");

	wxASSERT(m_NumPlayers <= MAX_NUM_PLAYERS);

	for (size_t i = 0; i < m_NumPlayers; ++i)
	{
		PlayerPageControls controls = m_PlayerControls[i];

		AtObj player;

		// name
		wxTextCtrl* text = controls.name;
		if (text->IsEnabled())
			player.set("Name", text->GetValue());

		// civ
		wxChoice* choice = controls.civ;
		if (choice->IsEnabled() && choice->GetSelection() >= 0)
		{
			wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection()));
			player.set("Civ", str->GetData());
		}

		// colour
		if (controls.colour->IsEnabled())
		{
			wxColour colour = controls.colour->GetBackgroundColour();
			AtObj clrObj;
			clrObj.setInt("r", (int)colour.Red());
			clrObj.setInt("g", (int)colour.Green());
			clrObj.setInt("b", (int)colour.Blue());
			player.set("Colour", clrObj);
		}

		// player type
		choice = controls.ai;
		if (choice->IsEnabled())
		{
			if (choice->GetSelection() > 0)
			{
				// ai - get id
				wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection()));
				player.set("AI", str->GetData());
			}
			else // human
				player.set("AI", _T(""));
		}

		// resources
		AtObj resObj;
		if (controls.food->IsEnabled())
			resObj.setInt("food", controls.food->GetValue());
		if (controls.wood->IsEnabled())
			resObj.setInt("wood", controls.wood->GetValue());
		if (controls.metal->IsEnabled())
			resObj.setInt("metal", controls.metal->GetValue());
		if (controls.stone->IsEnabled())
			resObj.setInt("stone", controls.stone->GetValue());
		if (resObj.defined())
			player.set("Resources", resObj);

		// population limit
		if (controls.pop->IsEnabled())
			player.setInt("PopulationLimit", controls.pop->GetValue());

		// team
		choice = controls.team;
		if (choice->IsEnabled() && choice->GetSelection() >= 0)
			player.setInt("Team", choice->GetSelection() - 1);

		// camera
		AtObj camObj;
		if (controls.page->IsCameraDefined())
		{
			sCameraInfo cam = controls.page->GetCamera();
			AtObj camPos;
			camPos.setDouble("x", cam.pX);
			camPos.setDouble("y", cam.pY);
			camPos.setDouble("z", cam.pZ);
			camObj.set("Position", camPos);

			AtObj camRot;
			camRot.setDouble("x", cam.rX);
			camRot.setDouble("y", cam.rY);
			camRot.setDouble("z", cam.rZ);
			camObj.set("Rotation", camRot);
		}
		player.set("StartingCamera", camObj);

		players.add("item", player);
	}
	
	m_MapSettings.set("PlayerData", players);

	return m_MapSettings;
}
예제 #3
0
void PlayerSettingsControl::ReadFromEngine()
{
	AtlasMessage::qGetMapSettings qry;
	qry.Post();

	if (!(*qry.settings).empty())
	{
		// Prevent error if there's no map settings to parse
		m_MapSettings = AtlasObject::LoadFromJSON(*qry.settings);
	}
	else
	{
		// Use blank object, it will be created next
		m_MapSettings = AtObj();
	}

	AtIter player = m_MapSettings["PlayerData"]["item"];
	if (!m_MapSettings.defined() || !player.defined() || player.count() == 0)
	{
		// Player data missing - set number of players to max
		m_NumPlayers = MAX_NUM_PLAYERS;
	}
	else
		m_NumPlayers = player.count();

	wxASSERT(m_NumPlayers <= MAX_NUM_PLAYERS && m_NumPlayers != 0);

	// To prevent recursion, don't handle GUI events right now
	m_InGUIUpdate = true;

	wxDynamicCast(FindWindow(ID_NumPlayers), wxSpinCtrl)->SetValue(m_NumPlayers);

	// Remove / add extra player pages as needed
	m_Players->ResizePlayers(m_NumPlayers);

	// Update player controls with player data
	AtIter playerDefs = m_PlayerDefaults["item"];
	if (playerDefs.defined())
		++playerDefs;	// skip gaia

	for (size_t i = 0; i < MAX_NUM_PLAYERS; ++i)
	{
		const PlayerPageControls& controls = m_PlayerControls[i];

		// name
		wxString name(_("Unknown"));
		bool defined = player["Name"].defined();
		if (defined)
			name = wxString(player["Name"]);
		else if (playerDefs["Name"].defined())
			name = wxString(playerDefs["Name"]);

		controls.name->SetValue(name);
		wxDynamicCast(FindWindowById(ID_DefaultName, controls.page), DefaultCheckbox)->SetValue(defined);

		// civ
		wxChoice* choice = controls.civ;
		wxString civCode;
		defined = player["Civ"].defined();
		if (defined)
			civCode = wxString(player["Civ"]);
		else
			civCode = wxString(playerDefs["Civ"]);

		for (size_t j = 0; j < choice->GetCount(); ++j)
		{
			wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j));
			if (str->GetData() == civCode)
			{
				choice->SetSelection(j);
				break;
			}
		}
		wxDynamicCast(FindWindowById(ID_DefaultCiv, controls.page), DefaultCheckbox)->SetValue(defined);

		// colour
		wxColour colour;
		AtObj clrObj = *player["Colour"];
		defined = clrObj.defined();
		if (!defined)
			clrObj = *playerDefs["Colour"];
		colour = wxColor((*clrObj["r"]).getInt(), (*clrObj["g"]).getInt(), (*clrObj["b"]).getInt());
		controls.colour->SetBackgroundColour(colour);
		wxDynamicCast(FindWindowById(ID_DefaultColour, controls.page), DefaultCheckbox)->SetValue(defined);

		// player type
		wxString aiID;
		defined = player["AI"].defined();
		if (defined)
			aiID = wxString(player["AI"]);
		else
			aiID = wxString(playerDefs["AI"]);

		choice = controls.ai;
		if (!aiID.empty())
		{
			// AI
			for (size_t j = 0; j < choice->GetCount(); ++j)
			{
				wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j));
				if (str->GetData() == aiID)
				{
					choice->SetSelection(j);
					break;
				}
			}
		}
		else // Human
			choice->SetSelection(0);
		wxDynamicCast(FindWindowById(ID_DefaultAI, controls.page), DefaultCheckbox)->SetValue(defined);

		// resources
		AtObj resObj = *player["Resources"];
		defined = resObj.defined() && resObj["food"].defined();
		if (defined)
			controls.food->SetValue(wxString(resObj["food"]));
		else
			controls.food->SetValue(0);
		wxDynamicCast(FindWindowById(ID_DefaultFood, controls.page), DefaultCheckbox)->SetValue(defined);

		defined = resObj.defined() && resObj["wood"].defined();
		if (defined)
			controls.wood->SetValue(wxString(resObj["wood"]));
		else
			controls.wood->SetValue(0);
		wxDynamicCast(FindWindowById(ID_DefaultWood, controls.page), DefaultCheckbox)->SetValue(defined);

		defined = resObj.defined() && resObj["metal"].defined();
		if (defined)
			controls.metal->SetValue(wxString(resObj["metal"]));
		else
			controls.metal->SetValue(0);
		wxDynamicCast(FindWindowById(ID_DefaultMetal, controls.page), DefaultCheckbox)->SetValue(defined);

		defined = resObj.defined() && resObj["stone"].defined();
		if (defined)
			controls.stone->SetValue(wxString(resObj["stone"]));
		else
			controls.stone->SetValue(0);
		wxDynamicCast(FindWindowById(ID_DefaultStone, controls.page), DefaultCheckbox)->SetValue(defined);

		// population limit
		defined = player["PopulationLimit"].defined();
		if (defined)
			controls.pop->SetValue(wxString(player["PopulationLimit"]));
		else
			controls.pop->SetValue(0);
		wxDynamicCast(FindWindowById(ID_DefaultPop, controls.page), DefaultCheckbox)->SetValue(defined);

		// team
		defined = player["Team"].defined();
		if (defined)
			controls.team->SetSelection((*player["Team"]).getInt() + 1);
		else
			controls.team->SetSelection(0);
		wxDynamicCast(FindWindowById(ID_DefaultTeam, controls.page), DefaultCheckbox)->SetValue(defined);

		// camera
		if (player["StartingCamera"].defined())
		{
			sCameraInfo info;
			// Don't use wxAtof because it depends on locales which
			//	may cause problems with decimal points
			//	see: http://www.wxwidgets.org/docs/faqgtk.htm#locale
			AtObj camPos = *player["StartingCamera"]["Position"];
			info.pX = (float)(*camPos["x"]).getDouble();
			info.pY = (float)(*camPos["y"]).getDouble();
			info.pZ = (float)(*camPos["z"]).getDouble();
			AtObj camRot = *player["StartingCamera"]["Rotation"];
			info.rX = (float)(*camRot["x"]).getDouble();
			info.rY = (float)(*camRot["y"]).getDouble();
			info.rZ = (float)(*camRot["z"]).getDouble();
			
			controls.page->SetCamera(info, true);
		}
		else
			controls.page->SetCamera(sCameraInfo(), false);

		// Only increment AtIters if they are defined
		if (player.defined())
			++player;
		if (playerDefs.defined())
			++playerDefs;
	}

	// Send default properties to engine, since they might not be set
	SendToEngine();

	m_InGUIUpdate = false;
}