Ticket #96: progress_1_96_V.patch
File progress_1_96_V.patch, 16.9 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 } 55 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; 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.clear(); 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 long playerId; 114 double orientation = 0; 115 116 const wxXmlNode* xmlData = child->GetChildren(); 117 118 while (xmlData) 119 { 120 if (xmlData->GetName() == wxT("Template")) 121 templateName = xmlData->GetNodeContent(); 122 else if (xmlData->GetName() == wxT("Position")) 123 { 124 wxString x, z; 125 xmlData->GetAttribute(wxT("x"), &x); 126 xmlData->GetAttribute(wxT("z"), &z); 127 128 double aux, aux2; 129 x.ToDouble(&aux); 130 z.ToDouble(&aux2); 131 132 entityPos = Position(aux, 0, aux2); 133 } 134 else if (xmlData->GetName() == wxT("Orientation")) 135 { 136 wxString y; 137 xmlData->GetAttribute(wxT("y"), &y); 138 y.ToDouble(&orientation); 139 } 140 else if (xmlData->GetName() == wxT("Player")) 141 { 142 wxString x; 143 x = xmlData->GetNodeContent(); 144 x.ToLong(&playerId); 145 } 146 147 xmlData = xmlData->GetNext(); 148 } 149 150 //Update current Ownership 151 this->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerId); 152 this->GetScenarioEditor().GetObjectSettings().NotifyObservers(); 153 154 POST_MESSAGE(ObjectPreview, ((std::wstring)templateName.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), entityPos, false, Position(), orientation, 0, false)); 155 156 child = child->GetNext(); 157 } 158 159 //Set state paste for preview the new objects 160 this->SetState(&Pasting); 161 162 //Update the objects to current mouse position 163 OnMovingPaste(); 164 } 165 166 void OnMovingPaste() 167 { 168 //Move the preview(s) object(s) 169 POST_MESSAGE(MoveObjectPreview, ((m_entPosition))); 170 } 171 172 void OnPasteEnd(bool canceled) 173 { 174 if (canceled) 175 //delete previews objects 176 POST_MESSAGE(ObjectPreview, (_T(""), GetScenarioEditor().GetObjectSettings().GetSettings(), Position(), false, Position(), 0, 0, true)); 177 else 178 { 179 //Create new Objects and delete preview objects 180 POST_MESSAGE(ObjectPreviewToEntity, ()); 181 182 AtlasMessage::qGetCurrentSelection currentSelection; 183 currentSelection.Post(); 184 185 g_SelectedObjects = *currentSelection.ids; 186 } 187 188 189 //when all is done set default state 190 this->SetState(&Waiting); 191 } 192 56 193 // TODO: keys to rotate/move object? 57 194 58 195 struct sWaiting : public State … … 132 269 133 270 // Dragging with right mouse button -> rotate objects to look 134 271 // at mouse 135 Position pos 272 Position pos(evt.GetPosition()); 136 273 for (size_t i = 0; i < g_SelectedObjects.size(); ++i) 137 274 POST_COMMAND(RotateObject, (g_SelectedObjects[i], true, pos, 0.f)); 138 275 … … 140 277 } 141 278 else if (evt.Moving()) 142 279 { 280 //Save position for smooth paste position 281 obj->m_entPosition = Position(evt.GetPosition()); 282 143 283 // Prevent certain events from reaching game UI in this mode 144 284 // to prevent selection ring confusion 145 285 return true; … … 167 307 obj->GetScenarioEditor().GetObjectSettings().NotifyObservers(); 168 308 return true; 169 309 } 170 else 171 return false; 310 else if (evt.GetModifiers() == wxMOD_CONTROL) 311 { 312 if (evt.GetKeyCode() == 'C') 313 { 314 if (!g_SelectedObjects.empty()) 315 { 316 //COPY current selections 317 AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects); 318 info.Post(); 319 320 //In xmldata is the configuration 321 //now send to clipboard 322 if (wxTheClipboard->Open()) 323 { 324 wxString text(info.xmldata.c_str()); 325 wxTheClipboard->SetData(new wxTextDataObject(text)); 326 wxTheClipboard->Close(); 327 } 328 else 329 { 330 //TODO: Say something about couldnt open clipboard 331 } 332 return true; 333 } 334 } 335 else if (evt.GetKeyCode() == 'V') 336 { 337 obj->OnPasteStart(); 338 return true; 339 } 340 } 341 342 return false; 172 343 } 173 344 } 174 345 Waiting; … … 184 355 } 185 356 else if (evt.Dragging()) 186 357 { 187 Position pos 358 Position pos(evt.GetPosition() + wxPoint(obj->m_dx, obj->m_dy)); 188 359 189 360 POST_COMMAND(MoveObjects, (g_SelectedObjects, obj->m_lastSelected, pos)); 190 361 return true; … … 241 412 { 242 413 for (size_t i = 0; i < ids.size(); ++i) 243 414 { 244 std::vector<AtlasMessage::ObjectID>::iterator it = 415 std::vector<AtlasMessage::ObjectID>::iterator it = std::find(g_SelectedObjects.begin(), g_SelectedObjects.end(), ids[i]); 245 416 bool objectIsSelected = (it != g_SelectedObjects.end()); 246 417 if (selectionRemove) 247 418 { … … 298 469 qry.Post(); 299 470 300 471 std::vector<AtlasMessage::ObjectID> ids = *qry.ids; 301 472 302 473 if (!selectionAdd && !selectionRemove) 303 474 { 304 475 // Just copy new selections (clears list if no selections) … … 308 479 { 309 480 for (size_t i = 0; i < ids.size(); ++i) 310 481 { 311 std::vector<AtlasMessage::ObjectID>::iterator it = 482 std::vector<AtlasMessage::ObjectID>::iterator it = std::find(g_SelectedObjects.begin(), g_SelectedObjects.end(), ids[i]); 312 483 bool objectIsSelected = (it != g_SelectedObjects.end()); 313 484 if (selectionRemove) 314 485 { … … 335 506 } 336 507 } 337 508 SelectSimilar; 509 510 struct sPasting : public State 511 { 512 bool OnMouse(TransformObject* obj, wxMouseEvent& evt) 513 { 514 if (evt.Moving()) 515 { 516 //Move the object 517 obj->m_entPosition = Position(evt.GetPosition()); 518 obj->OnMovingPaste(); 519 return true; 520 } 521 else if (evt.LeftDown()) 522 { 523 //Place the object and update 524 obj->OnPasteEnd(false); 525 return true; 526 } 527 else 528 return false; 529 } 530 bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type) 531 { 532 if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) 533 { 534 obj->OnPasteEnd(true); 535 return true; 536 } 537 else 538 return false; 539 } 540 } 541 Pasting; 338 542 }; 339 543 340 544 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 ,