Ticket #96: progress_1_96_III.patch
File progress_1_96_III.patch, 14.1 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_objPosition; 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 { 83 return; 84 } 55 85 86 // Entities, Entity(1.*) 87 wxXmlNode* root = doc.GetRoot(); 88 if (root->GetName() != wxT("Entities")) 89 { 90 return; 91 } 92 // Template, position,orientation 93 const wxXmlNode* child = root->GetChildren(); 94 95 while (child) 96 { 97 if (child->GetName() != wxT("Entity")) 98 { 99 return; 100 } 101 //TODO Validate all attributes 102 child = child->GetNext(); 103 } 104 105 //Update selectedObjects?? 106 g_SelectedObjects.empty(); 107 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 108 109 // is the source code get here now you can add the objects to scene(preview) 110 // store id to move 111 child = root->GetChildren(); 112 113 while (child) 114 { 115 wxString objectId; 116 Position objectPos; 117 unsigned int actorSeed; 118 double orientation; 119 120 const wxXmlNode* xmlData = child->GetChildren(); 121 122 while (xmlData) 123 { 124 if (xmlData->GetName() == wxT("Template")) 125 { 126 objectId = xmlData->GetNodeContent(); 127 } 128 else if (xmlData->GetName() == wxT("Position")) 129 { 130 wxString x, z; 131 xmlData->GetAttribute(wxT("x"), &x); 132 xmlData->GetAttribute(wxT("z"), &z); 133 134 double aux,aux2; 135 x.ToDouble(&aux); 136 z.ToDouble(&aux2); 137 138 objectPos = Position(aux,0,aux2); 139 } 140 else if (xmlData->GetName() == wxT("Orientation")) 141 { 142 wxString y; 143 xmlData->GetAttribute(wxT("y"), &y); 144 y.ToDouble(&orientation); 145 } 146 147 xmlData = xmlData->GetNext(); 148 } 149 150 POST_MESSAGE(ObjectPreview, ((std::wstring)objectId.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), objectPos, false, Position(), orientation, 0, false)); 151 152 child = child->GetNext(); 153 } 154 155 //Set state paste for preview the new objects 156 this->SetState(&Pasting); 157 } 158 159 void OnMovingPaste() 160 { 161 //Move the preview(s) object(s) 162 POST_MESSAGE(MoveObjectPreview, ((m_objPosition))); 163 } 164 165 void OnPasteEnd(bool canceled) 166 { 167 if (canceled) 168 { 169 //delete previews objects 170 POST_MESSAGE(ObjectPreview, (_T(""), GetScenarioEditor().GetObjectSettings().GetSettings(), Position(), false, Position(), 0, 0, true)); 171 } 172 else 173 { 174 //Create new Objects and delete preview objects 175 POST_MESSAGE(ObjectPreviewToEntity,()); 176 } 177 //when all is done set default state 178 this->SetState(&Waiting); 179 } 180 56 181 // TODO: keys to rotate/move object? 57 182 58 183 struct sWaiting : public State … … 167 292 obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); 168 293 return true; 169 294 } 295 else if (evt.GetModifiers() == wxMOD_CONTROL) 296 { 297 if (!g_SelectedObjects.empty()) 298 { 299 if (evt.GetKeyCode() == 'C') 300 { 301 //COPY current selections 302 AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); 303 info.Post(); 304 305 //In xmldata is the configuration 306 //now send to clipboard 307 if (wxTheClipboard->Open()) 308 { 309 wxString text(info.xmldata.c_str()); 310 wxTheClipboard->SetData(new wxTextDataObject(text)); 311 wxTheClipboard->Close(); 312 } 313 else 314 { 315 //TODO: Say something about couldnt open clipboard 316 } 317 return true; 318 } 319 } 320 if (evt.GetKeyCode() == 'V') 321 { 322 obj->OnPasteStart(); 323 return true; 324 } 325 } 170 326 else 171 327 return false; 172 328 } … … 335 491 } 336 492 } 337 493 SelectSimilar; 494 495 struct sPasting : public State 496 { 497 bool OnMouse(TransformObject* obj, wxMouseEvent& evt) 498 { 499 if (evt.Moving()) 500 { 501 //Move the object 502 obj->m_objPosition = Position(evt.GetPosition()); 503 obj->OnMovingPaste(); 504 return true; 505 } 506 else if (evt.LeftDown()) 507 { 508 //Place the object and update 509 obj->OnPasteEnd(false); 510 return true; 511 } 512 else 513 return false; 514 } 515 bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type) 516 { 517 if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) 518 { 519 obj->OnPasteEnd(true); 520 return true; 521 } 522 else 523 return false; 524 } 525 } 526 Pasting; 338 527 }; 339 528 340 529 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 MESSAGEHANDLER(ObjectPreviewToEntity) 368 { 369 UNUSED2(msg); 370 371 if (g_PreviewEntitiesID.size() == 0) 372 { 373 return; 374 } 375 376 CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY); 377 ENSURE(cmpTemplateManager); 378 379 //I need to re create the objects finally delete preview objects 380 std::vector<entity_id_t>::const_iterator i; 381 for (i = g_PreviewEntitiesID.begin(); i != g_PreviewEntitiesID.end(); i++) 382 { 383 //Get template 384 entity_id_t ent = *i; 385 std::string templateName = cmpTemplateManager->GetCurrentTemplateName(ent); 386 std::wstring wTemplateName(templateName.begin() + 8, templateName.end()); 387 //Create new entity 388 entity_id_t new_ent = g_Game->GetSimulation2()->AddEntity(wTemplateName); 389 if (new_ent == INVALID_ENTITY) 390 continue; 391 392 //get position, get rotation 393 CmpPtr<ICmpPosition> cmpPositionNew(*g_Game->GetSimulation2(), new_ent); 394 CmpPtr<ICmpPosition> cmpPositionOld(*g_Game->GetSimulation2(), ent); 395 396 if (cmpPositionNew && cmpPositionOld) 397 { 398 CVector3D pos = cmpPositionOld->GetPosition(); 399 cmpPositionNew->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z)); 400 401 //now rotate 402 CFixedVector3D rotation = cmpPositionOld->GetRotation(); 403 cmpPositionNew->SetYRotation(rotation.Y); 404 } 405 406 //get owner 407 CmpPtr<ICmpOwnership> cmpOwnershipNew(*g_Game->GetSimulation2(), new_ent); 408 CmpPtr<ICmpOwnership> cmpOwnershipOld(*g_Game->GetSimulation2(), ent); 409 if (cmpOwnershipNew && cmpOwnershipOld) 410 { 411 cmpOwnershipNew->SetOwner(cmpOwnershipOld->GetOwner()); 412 } 413 414 //getVisual 415 CmpPtr<ICmpVisual> cmpVisualNew(*g_Game->GetSimulation2(), new_ent); 416 CmpPtr<ICmpVisual> cmpVisualOld(*g_Game->GetSimulation2(), ent); 417 if (cmpVisualNew && cmpVisualOld) 418 { 419 cmpVisualNew->SetActorSeed(cmpVisualOld->GetActorSeed()); 420 } 421 422 g_Game->GetSimulation2()->DestroyEntity(ent); 423 } 424 g_PreviewEntitiesID.clear(); 425 } 426 427 MESSAGEHANDLER(MoveObjectPreview) 428 { 429 if (g_PreviewEntitiesID.size()==0) 430 { 431 return; 432 } 433 434 //TODO:Change pivot 435 entity_id_t pivot = *g_PreviewEntitiesID.begin(); 436 437 // All selected objects move relative to a pivot object, 438 // so get its position and whether it's floating 439 CVector3D pivotPos(0, 0, 0); 440 bool pivotFloating = false; 441 442 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), pivot); 443 if (cmpPosition && cmpPosition->IsInWorld()) 444 { 445 pivotFloating = cmpPosition->IsFloating(); 446 CFixedVector3D pivotFixed = cmpPosition->GetPosition(); 447 pivotPos = CVector3D(pivotFixed.X.ToFloat(), pivotFixed.Y.ToFloat(), pivotFixed.Z.ToFloat()); 448 } 449 450 // Calculate directional vector of movement for pivot object, 451 // we apply the same movement to all objects 452 CVector3D targetPos = GetUnitPos(msg->pos, pivotFloating); 453 CVector3D dir = targetPos - pivotPos; 454 455 for (size_t i = 0; i < g_PreviewEntitiesID.size(); ++i) 456 { 457 entity_id_t id = (entity_id_t)g_PreviewEntitiesID[i]; 458 CVector3D posFinal = CVector3D(0, 0, 0); 459 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); 460 if (cmpPosition && cmpPosition->IsInWorld()) 461 { 462 // Calculate this object's position 463 CFixedVector3D posFixed = cmpPosition->GetPosition(); 464 CVector3D pos = CVector3D(posFixed.X.ToFloat(), posFixed.Y.ToFloat(), posFixed.Z.ToFloat()); 465 posFinal = pos + dir; 466 } 467 cmpPosition->JumpTo(entity_pos_t::FromFloat(posFinal.X), entity_pos_t::FromFloat(posFinal.Z)); 468 } 469 } 470 314 471 MESSAGEHANDLER(ObjectPreview) 315 472 { 316 473 // If the selection has changed... 317 if (*msg->id != g_PreviewUnitName )474 if (*msg->id != g_PreviewUnitName || (!msg->cleanObjectPreviews)) 318 475 { 319 476 // Delete old entity 320 if (g_PreviewEntityID != INVALID_ENTITY) 321 g_Game->GetSimulation2()->DestroyEntity(g_PreviewEntityID); 477 if (g_PreviewEntityID != INVALID_ENTITY && msg->cleanObjectPreviews) 478 { 479 //Time to delete all preview objects 480 if (g_PreviewEntitiesID.size() > 0) 481 { 482 std::vector<entity_id_t>::const_iterator i; 483 for (i = g_PreviewEntitiesID.begin(); i != g_PreviewEntitiesID.end(); i++) 484 { 485 g_Game->GetSimulation2()->DestroyEntity(*i); 486 } 487 g_PreviewEntitiesID.clear(); 488 } 489 } 322 490 323 491 // Create the new entity 324 492 if ((*msg->id).empty()) 325 493 g_PreviewEntityID = INVALID_ENTITY; 326 494 else 495 { 327 496 g_PreviewEntityID = g_Game->GetSimulation2()->AddLocalEntity(L"preview|" + *msg->id); 497 g_PreviewEntitiesID.push_back(g_PreviewEntityID); 498 } 499 328 500 329 501 g_PreviewUnitName = *msg->id; 330 502 } -
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 // Moving Preview(s) object together, default is using the firs element in vector 341 MESSAGE(MoveObjectPreview, 342 ((Position,pos)) 343 ); 344 337 345 // Preview object in the game world - creates a temporary unit at the given 338 346 // position, and removes it when the preview is next changed 339 347 MESSAGE(ObjectPreview, … … 344 352 ((Position, target)) 345 353 ((float, angle)) 346 354 ((unsigned int, actorseed)) 355 ((bool, cleanObjectPreviews)) 347 356 ); 348 357 349 358 COMMAND(CreateObject, NOMERGE, … … 590 599 ((sObjectSettings, settings)) 591 600 ); 592 601 602 QUERY(GetObjectMapSettings, 603 ((std::vector<ObjectID>, ids)) 604 , 605 ((std::wstring, xmldata)) 606 ); 607 608 593 609 QUERY(GetPlayerObjects, 594 610 ((int, player)) 595 611 ,