Changeset View
Changeset View
Standalone View
Standalone View
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | QUERYHANDLER(GetObjectSettings) | ||||
CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id)); | CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id)); | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
{ | { | ||||
int32_t player = cmpOwnership->GetOwner(); | int32_t player = cmpOwnership->GetOwner(); | ||||
if (player != -1) | if (player != -1) | ||||
settings.player = player; | settings.player = player; | ||||
} | } | ||||
// TODO: selections | std::vector<std::vector<std::wstring>> variantgroups; | ||||
std::set<std::wstring> selections_set; | |||||
/* | CmpPtr<ICmpVisual> cmpVisualActor(*simulation, view->GetEntityId(msg->id)); | ||||
// Get the unit's possible variants and selected variants | if (cmpVisualActor) | ||||
{ | |||||
CUnit* unit = cmpVisualActor->GetUnit(); | |||||
if (unit) | |||||
{ | |||||
std::vector<std::vector<CStr> > groups = unit->GetObject().m_Base->GetVariantGroups(); | std::vector<std::vector<CStr>> groups = unit->GetObject().m_Base->GetVariantGroups(); | ||||
const std::set<CStr>& selections = unit->GetActorSelections(); | const std::set<CStr>& selections = unit->GetActorSelections(); | ||||
// Iterate over variant groups | |||||
std::vector<std::vector<std::wstring> > variantgroups; | |||||
std::set<std::wstring> selections_set; | |||||
variantgroups.reserve(groups.size()); | variantgroups.reserve(groups.size()); | ||||
for (size_t i = 0; i < groups.size(); ++i) | for (size_t i = 0; i < groups.size(); ++i) | ||||
{ | { | ||||
// Copy variants into output structure | // Copy variants into output structure | ||||
std::vector<std::wstring> group; | std::vector<std::wstring> subgroup; | ||||
group.reserve(groups[i].size()); | subgroup.reserve(groups[i].size()); | ||||
int choice = -1; | int choice = -1; | ||||
for (size_t j = 0; j < groups[i].size(); ++j) | for (size_t j = 0; j < groups[i].size(); ++j) | ||||
{ | { | ||||
group.push_back(CStrW(groups[i][j])); | subgroup.push_back(wstring_from_utf8(groups[i][j])); | ||||
// Find the first string in 'selections' that matches one of this | // Find the first string in 'selections' that matches one of this | ||||
// group's variants | // group's variants | ||||
if (choice == -1) | if (choice == -1) | ||||
if (selections.find(groups[i][j]) != selections.end()) | if (selections.find(groups[i][j]) != selections.end()) | ||||
choice = (int)j; | choice = (int)j; | ||||
} | } | ||||
// Assuming one of the variants was selected (which it really ought | // Assuming one of the variants was selected (which it really ought | ||||
// to be), remember that one's name | // to be), remember that one's name | ||||
if (choice != -1) | if (choice != -1) | ||||
selections_set.insert(CStrW(groups[i][choice])); | selections_set.insert(wstring_from_utf8(groups[i][choice])); | ||||
variantgroups.push_back(group); | variantgroups.push_back(subgroup); | ||||
} | |||||
} | |||||
} | } | ||||
settings.variantgroups = variantgroups; | settings.variantGroups = variantgroups; | ||||
settings.selections = std::vector<std::wstring> (selections_set.begin(), selections_set.end()); // convert set->vector | settings.selections = std::vector<std::wstring> (selections_set.begin(), selections_set.end()); // convert set->vector | ||||
*/ | |||||
msg->settings = settings; | msg->settings = settings; | ||||
} | } | ||||
QUERYHANDLER(GetObjectMapSettings) | QUERYHANDLER(GetObjectMapSettings) | ||||
{ | { | ||||
std::vector<entity_id_t> ids = *msg->ids; | std::vector<entity_id_t> ids = *msg->ids; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | void Do() | ||||
m_PlayerOld = 0; | m_PlayerOld = 0; | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
{ | { | ||||
int32_t player = cmpOwnership->GetOwner(); | int32_t player = cmpOwnership->GetOwner(); | ||||
if (player != -1) | if (player != -1) | ||||
m_PlayerOld = player; | m_PlayerOld = player; | ||||
} | } | ||||
// TODO: selections | CmpPtr<ICmpVisual> cmpVisualActor(*simulation, view->GetEntityId(msg->id)); | ||||
// m_SelectionsOld = unit->GetActorSelections(); | if (cmpVisualActor) | ||||
{ | |||||
CUnit* unit = cmpVisualActor->GetUnit(); | |||||
if (unit) | |||||
{ | |||||
Silier: remove { } | |||||
m_SelectionsOld = unit->GetActorSelections(); | |||||
} | |||||
} | |||||
m_PlayerNew = (player_id_t)settings.player; | m_PlayerNew = (player_id_t)settings.player; | ||||
std::vector<std::wstring> selections = *settings.selections; | std::vector<std::wstring> selections = *settings.selections; | ||||
for (std::vector<std::wstring>::iterator it = selections.begin(); it != selections.end(); ++it) | for (std::vector<std::wstring>::iterator it = selections.begin(); it != selections.end(); ++it) | ||||
{ | { | ||||
m_SelectionsNew.insert(CStrW(*it).ToUTF8()); | m_SelectionsNew.insert(CStrW(*it).ToUTF8()); | ||||
} | } | ||||
Redo(); | Redo(); | ||||
} | } | ||||
void Redo() | void Redo() | ||||
{ | { | ||||
Set(m_PlayerNew, m_SelectionsNew); | Set(m_PlayerNew, m_SelectionsNew); | ||||
} | } | ||||
void Undo() | void Undo() | ||||
{ | { | ||||
Set(m_PlayerOld, m_SelectionsOld); | Set(m_PlayerOld, m_SelectionsOld); | ||||
} | } | ||||
private: | private: | ||||
void Set(player_id_t player, const std::set<CStr>& UNUSED(selections)) | void Set(player_id_t player, const std::set<CStr>& selections) | ||||
{ | { | ||||
AtlasView* view = AtlasView::GetView(msg->view); | AtlasView* view = AtlasView::GetView(msg->view); | ||||
CSimulation2* simulation = view->GetSimulation2(); | CSimulation2* simulation = view->GetSimulation2(); | ||||
CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id)); | CmpPtr<ICmpOwnership> cmpOwnership(*simulation, view->GetEntityId(msg->id)); | ||||
if (cmpOwnership) | if (cmpOwnership) | ||||
cmpOwnership->SetOwner(player); | cmpOwnership->SetOwner(player); | ||||
// TODO: selections | CmpPtr<ICmpVisual> cmpVisualActor(*simulation, view->GetEntityId(msg->id)); | ||||
// unit->SetActorSelections(selections); | if (cmpVisualActor) | ||||
{ | |||||
CUnit* unit = cmpVisualActor->GetUnit(); | |||||
if (unit) | |||||
{ | |||||
Done Inline Actionsremove { } Silier: remove { } | |||||
unit->SetActorSelections(selections); | |||||
} | |||||
} | |||||
} | } | ||||
}; | }; | ||||
END_COMMAND(SetObjectSettings); | END_COMMAND(SetObjectSettings); | ||||
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// | ||||
static CStrW g_PreviewUnitName; | static CStrW g_PreviewUnitName; | ||||
static entity_id_t g_PreviewEntityID = INVALID_ENTITY; | static entity_id_t g_PreviewEntityID = INVALID_ENTITY; | ||||
▲ Show 20 Lines • Show All 749 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
remove { }