Ticket #96: progress_1_96_IV.patch
File progress_1_96_IV.patch, 14.5 KB (added by , 10 years ago) |
---|
-
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp
49 49 + (m_ScreenPos.type1.y-m_Target.type1.y)*(m_ScreenPos.type1.y-m_Target.type1.y); 50 50 bool useTarget = (dragDistSq >= 16*16); 51 51 if (preview) 52 POST_MESSAGE(ObjectPreview, ((std::wstring)m_ObjectID.wc_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle, m_ActorSeed ));52 POST_MESSAGE(ObjectPreview, ((std::wstring)m_ObjectID.wc_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle, m_ActorSeed, true)); 53 53 else 54 54 { 55 55 POST_COMMAND(CreateObject, ((std::wstring)m_ObjectID.wc_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle, m_ActorSeed)); -
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
23 23 #include "Common/MiscState.h" 24 24 #include "Common/ObjectSettings.h" 25 25 #include "GameInterface/Messages.h" 26 #include <wx/clipbrd.h> 27 #include <wx/xml/xml.h> 28 #include <wx/sstream.h> 26 29 27 30 using AtlasMessage::Position; 28 31 … … 33 36 int m_dx, m_dy; 34 37 AtlasMessage::ObjectID m_lastSelected; 35 38 wxPoint m_startPoint; 39 Position m_entPosition; 36 40 37 41 // TODO: If we don't plan to change hotkeys, just replace with evt.ShiftDown(), etc. 38 42 static const wxKeyCode SELECTION_ADD_HOTKEY = WXK_SHIFT; … … 52 56 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 53 57 } 54 58 59 void OnPasteStart() 60 { 61 //PASTE 62 wxString entities; 63 if (wxTheClipboard->Open()) 64 { 65 if (wxTheClipboard->IsSupported(wxDF_TEXT)) 66 { 67 wxTextDataObject data; 68 wxTheClipboard->GetData(data); 69 entities = data.GetText(); 70 } 71 wxTheClipboard->Close(); 72 } 73 else 74 { 75 //TODO: Show something when the clipboard couldnt open 76 } 77 78 //First do we need to check if it is a correct xml string 79 wxInputStream* is = new wxStringInputStream(entities); 80 wxXmlDocument doc; 81 if (!doc.Load(*is)) 82 return; 55 83 84 // Entities, Entity(1.*) 85 wxXmlNode* root = doc.GetRoot(); 86 if (root->GetName() != wxT("Entities")) 87 return; 88 89 // Template, position,orientation 90 const wxXmlNode* child = root->GetChildren(); 91 92 while (child) 93 { 94 if (child->GetName() != wxT("Entity")) 95 return; 96 97 //TODO Validate all attributes 98 child = child->GetNext(); 99 } 100 101 //Update selectedObjects?? 102 g_SelectedObjects.empty(); 103 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 104 105 // is the source code get here now you can add the objects to scene(preview) 106 // store id to move 107 child = root->GetChildren(); 108 109 while (child) 110 { 111 wxString templateName; 112 Position entityPos; 113 double orientation = 0; 114 115 const wxXmlNode* xmlData = child->GetChildren(); 116 117 while (xmlData) 118 { 119 if (xmlData->GetName() == wxT("Template")) 120 templateName = xmlData->GetNodeContent(); 121 else if (xmlData->GetName() == wxT("Position")) 122 { 123 wxString x, z; 124 xmlData->GetAttribute(wxT("x"), &x); 125 xmlData->GetAttribute(wxT("z"), &z); 126 127 double aux,aux2; 128 x.ToDouble(&aux); 129 z.ToDouble(&aux2); 130 131 entityPos = Position(aux, 0, aux2); 132 } 133 else if (xmlData->GetName() == wxT("Orientation")) 134 { 135 wxString y; 136 xmlData->GetAttribute(wxT("y"), &y); 137 y.ToDouble(&orientation); 138 } 139 140 xmlData = xmlData->GetNext(); 141 } 142 143 POST_MESSAGE(ObjectPreview, ((std::wstring)templateName.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), entityPos, false, Position(), orientation, 0, false)); 144 145 child = child->GetNext(); 146 } 147 148 //Set state paste for preview the new objects 149 this->SetState(&Pasting); 150 } 151 152 void OnMovingPaste() 153 { 154 //Move the preview(s) object(s) 155 POST_MESSAGE(MoveObjectPreview, ((m_entPosition))); 156 } 157 158 void OnPasteEnd(bool canceled) 159 { 160 if (canceled) 161 //delete previews objects 162 POST_MESSAGE(ObjectPreview, (_T(""), GetScenarioEditor().GetObjectSettings().GetSettings(), Position(), false, Position(), 0, 0, true)); 163 else 164 { 165 //Create new Objects and delete preview objects 166 POST_MESSAGE(ObjectPreviewToEntity, ()); 167 168 AtlasMessage::qGetCurrentSelection currentSelection; 169 currentSelection.Post(); 170 171 g_SelectedObjects = *currentSelection.ids; 172 } 173 174 175 //when all is done set default state 176 this->SetState(&Waiting); 177 } 178 56 179 // TODO: keys to rotate/move object? 57 180 58 181 struct sWaiting : public State … … 167 290 obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); 168 291 return true; 169 292 } 170 else 171 return false; 293 else if (evt.GetModifiers() == wxMOD_CONTROL) 294 { 295 if (!g_SelectedObjects.empty()) 296 { 297 if (evt.GetKeyCode() == 'C') 298 { 299 //COPY current selections 300 AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); 301 info.Post(); 302 303 //In xmldata is the configuration 304 //now send to clipboard 305 if (wxTheClipboard->Open()) 306 { 307 wxString text(info.xmldata.c_str()); 308 wxTheClipboard->SetData(new wxTextDataObject(text)); 309 wxTheClipboard->Close(); 310 } 311 else 312 { 313 //TODO: Say something about couldnt open clipboard 314 } 315 return true; 316 } 317 } 318 else if (evt.GetKeyCode() == 'V') 319 { 320 obj->OnPasteStart(); 321 return true; 322 } 323 } 324 325 return false; 172 326 } 173 327 } 174 328 Waiting; … … 335 489 } 336 490 } 337 491 SelectSimilar; 492 493 struct sPasting : public State 494 { 495 bool OnMouse(TransformObject* obj, wxMouseEvent& evt) 496 { 497 if (evt.Moving()) 498 { 499 //Move the object 500 obj->m_entPosition = Position(evt.GetPosition()); 501 obj->OnMovingPaste(); 502 return true; 503 } 504 else if (evt.LeftDown()) 505 { 506 //Place the object and update 507 obj->OnPasteEnd(false); 508 return true; 509 } 510 else 511 return false; 512 } 513 bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type) 514 { 515 if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) 516 { 517 obj->OnPasteEnd(true); 518 return true; 519 } 520 else 521 return false; 522 } 523 } 524 Pasting; 338 525 }; 339 526 340 527 IMPLEMENT_DYNAMIC_CLASS(TransformObject, StateDrivenTool<TransformObject>); -
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
49 49 #include "simulation2/components/ICmpTemplateManager.h" 50 50 #include "simulation2/components/ICmpVisual.h" 51 51 #include "simulation2/helpers/Selection.h" 52 #include "ps/XML/XMLWriter.h" 52 53 53 54 54 namespace AtlasMessage { 55 55 56 56 namespace … … 218 218 msg->settings = settings; 219 219 } 220 220 221 QUERYHANDLER(GetObjectMapSettings) 222 { 223 std::vector<entity_id_t> ids = *msg->ids; 224 225 CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); 226 ENSURE(cmpTemplateManager); 227 228 XML_Start(); 229 { 230 XML_Element("Entities"); 231 { 232 for (size_t i = 0; i < ids.size(); i++) 233 { 234 entity_id_t id = (entity_id_t)ids[i]; 235 XML_Element("Entity"); 236 { 237 //Template name 238 XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id)); 239 240 //Player 241 CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), id); 242 if (cmpOwnership) 243 XML_Setting("Player", (int)cmpOwnership->GetOwner()); 244 245 //Adding position to make some relative position later 246 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); 247 if (cmpPosition) 248 { 249 CFixedVector3D pos = cmpPosition->GetPosition(); 250 CFixedVector3D rot = cmpPosition->GetRotation(); 251 { 252 XML_Element("Position"); 253 XML_Attribute("x", pos.X); 254 XML_Attribute("z", pos.Z); 255 // TODO: height offset etc 256 } 257 { 258 XML_Element("Orientation"); 259 XML_Attribute("y", rot.Y); 260 // TODO: X, Z maybe 261 } 262 } 263 } 264 } 265 } 266 } 267 268 const CStr& data = XML_GetOutput(); 269 msg->xmldata = std::wstring(data.begin(), data.end()); 270 } 271 272 221 273 BEGIN_COMMAND(SetObjectSettings) 222 274 { 223 275 player_id_t m_PlayerOld, m_PlayerNew; … … 283 335 284 336 static CStrW g_PreviewUnitName; 285 337 static entity_id_t g_PreviewEntityID = INVALID_ENTITY; 338 static std::vector<entity_id_t> g_PreviewEntitiesID; 286 339 287 340 static CVector3D GetUnitPos(const Position& pos, bool floating) 288 341 { … … 311 364 return vec; 312 365 } 313 366 367 QUERYHANDLER(GetCurrentSelection) 368 { 369 msg->ids = g_Selection; 370 } 371 372 MESSAGEHANDLER(ObjectPreviewToEntity) 373 { 374 UNUSED2(msg); 375 376 if (g_PreviewEntitiesID.size() == 0) 377 return; 378 379 CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); 380 ENSURE(cmpTemplateManager); 381 382 PlayerColorMap playerColor; 383 384 //I need to re create the objects finally delete preview objects 385 std::vector<entity_id_t>::const_iterator i; 386 for (i = g_PreviewEntitiesID.begin(); i != g_PreviewEntitiesID.end(); i++) 387 { 388 //Get template 389 entity_id_t ent = *i; 390 std::string templateName = cmpTemplateManager->GetCurrentTemplateName(ent); 391 std::wstring wTemplateName(templateName.begin() + 8, templateName.end()); 392 //Create new entity 393 entity_id_t new_ent = g_Game->GetSimulation2()->AddEntity(wTemplateName); 394 if (new_ent == INVALID_ENTITY) 395 continue; 396 397 //get position, get rotation 398 CmpPtr<ICmpPosition> cmpPositionNew(*g_Game->GetSimulation2(), new_ent); 399 CmpPtr<ICmpPosition> cmpPositionOld(*g_Game->GetSimulation2(), ent); 400 401 if (cmpPositionNew && cmpPositionOld) 402 { 403 CVector3D pos = cmpPositionOld->GetPosition(); 404 cmpPositionNew->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z)); 405 406 //now rotate 407 CFixedVector3D rotation = cmpPositionOld->GetRotation(); 408 cmpPositionNew->SetYRotation(rotation.Y); 409 } 410 411 //get owner 412 CmpPtr<ICmpOwnership> cmpOwnershipNew(*g_Game->GetSimulation2(), new_ent); 413 CmpPtr<ICmpOwnership> cmpOwnershipOld(*g_Game->GetSimulation2(), ent); 414 if (cmpOwnershipNew && cmpOwnershipOld) 415 cmpOwnershipNew->SetOwner(cmpOwnershipOld->GetOwner()); 416 417 //getVisual 418 CmpPtr<ICmpVisual> cmpVisualNew(*g_Game->GetSimulation2(), new_ent); 419 CmpPtr<ICmpVisual> cmpVisualOld(*g_Game->GetSimulation2(), ent); 420 if (cmpVisualNew && cmpVisualOld) 421 cmpVisualNew->SetActorSeed(cmpVisualOld->GetActorSeed()); 422 423 //Update g_selectedObject and higligth 424 g_Selection.push_back(new_ent); 425 CmpPtr<ICmpSelectable> cmpSelectable(*g_Game->GetSimulation2(), new_ent); 426 if (cmpSelectable) 427 cmpSelectable->SetSelectionHighlight(GetOwnerPlayerColor(playerColor, new_ent), true); 428 429 g_Game->GetSimulation2()->DestroyEntity(ent); 430 } 431 g_PreviewEntitiesID.clear(); 432 433 } 434 435 MESSAGEHANDLER(MoveObjectPreview) 436 { 437 if (g_PreviewEntitiesID.size()==0) 438 return; 439 440 //TODO:Change pivot 441 entity_id_t referenceEntity = *g_PreviewEntitiesID.begin(); 442 443 // All selected objects move relative to a pivot object, 444 // so get its position and whether it's floating 445 CFixedVector3D referencePos; 446 447 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), referenceEntity); 448 if (cmpPosition && cmpPosition->IsInWorld()) 449 referencePos = cmpPosition->GetPosition(); 450 451 452 // Calculate directional vector of movement for pivot object, 453 // we apply the same movement to all objects 454 CVector3D targetPos = GetUnitPos(msg->pos, true); 455 CFixedVector3D fTargetPos(entity_pos_t::FromFloat(targetPos.X), entity_pos_t::FromFloat(targetPos.Y), entity_pos_t::FromFloat(targetPos.Z)); 456 CFixedVector3D dir = fTargetPos - referencePos; 457 458 for (size_t i = 0; i < g_PreviewEntitiesID.size(); ++i) 459 { 460 entity_id_t id = (entity_id_t)g_PreviewEntitiesID[i]; 461 CFixedVector3D posFinal; 462 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); 463 if (cmpPosition && cmpPosition->IsInWorld()) 464 { 465 // Calculate this object's position 466 CFixedVector3D posFixed = cmpPosition->GetPosition(); 467 posFinal = posFixed + dir; 468 } 469 cmpPosition->JumpTo(posFinal.X, posFinal.Z); 470 } 471 } 472 314 473 MESSAGEHANDLER(ObjectPreview) 315 474 { 316 475 // If the selection has changed... 317 if (*msg->id != g_PreviewUnitName )476 if (*msg->id != g_PreviewUnitName || (!msg->cleanObjectPreviews)) 318 477 { 319 478 // Delete old entity 320 if (g_PreviewEntityID != INVALID_ENTITY) 321 g_Game->GetSimulation2()->DestroyEntity(g_PreviewEntityID); 479 if (g_PreviewEntityID != INVALID_ENTITY && msg->cleanObjectPreviews) 480 { 481 //Time to delete all preview objects 482 if (g_PreviewEntitiesID.size() > 0) 483 { 484 std::vector<entity_id_t>::const_iterator i; 485 for (i = g_PreviewEntitiesID.begin(); i != g_PreviewEntitiesID.end(); i++) 486 { 487 g_Game->GetSimulation2()->DestroyEntity(*i); 488 } 489 g_PreviewEntitiesID.clear(); 490 } 491 } 322 492 323 493 // Create the new entity 324 494 if ((*msg->id).empty()) 325 495 g_PreviewEntityID = INVALID_ENTITY; 326 496 else 497 { 327 498 g_PreviewEntityID = g_Game->GetSimulation2()->AddLocalEntity(L"preview|" + *msg->id); 499 g_PreviewEntitiesID.push_back(g_PreviewEntityID); 500 } 501 328 502 329 503 g_PreviewUnitName = *msg->id; 330 504 } -
source/tools/atlas/GameInterface/Messages.h
334 334 SHAREABLE_STRUCT(sObjectSettings); 335 335 #endif 336 336 337 // transform de local entity to a real entity 338 MESSAGE(ObjectPreviewToEntity,); 339 340 //Query for get selected objects 341 QUERY(GetCurrentSelection, 342 , //No inputs 343 ((std::vector<ObjectID>, ids)) 344 ); 345 346 // Moving Preview(s) object together, default is using the firs element in vector 347 MESSAGE(MoveObjectPreview, 348 ((Position,pos)) 349 ); 350 337 351 // Preview object in the game world - creates a temporary unit at the given 338 352 // position, and removes it when the preview is next changed 339 353 MESSAGE(ObjectPreview, … … 344 358 ((Position, target)) 345 359 ((float, angle)) 346 360 ((unsigned int, actorseed)) 361 ((bool, cleanObjectPreviews)) 347 362 ); 348 363 349 364 COMMAND(CreateObject, NOMERGE, … … 590 605 ((sObjectSettings, settings)) 591 606 ); 592 607 608 QUERY(GetObjectMapSettings, 609 ((std::vector<ObjectID>, ids)) 610 , 611 ((std::wstring, xmldata)) 612 ); 613 614 593 615 QUERY(GetPlayerObjects, 594 616 ((int, player)) 595 617 ,