Ticket #96: progress_1_92_II.patch
File progress_1_92_II.patch, 12.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 } 72 else 73 { 74 //TODO: Show something when the clipboard couldnt open 75 } 76 77 //First do we need to check if it is a correct xml string 78 wxInputStream* is = new wxStringInputStream(entities); 79 wxXmlDocument doc; 80 if (!doc.Load(*is)) 81 { 82 return; 83 } 55 84 85 // Entities, Entity(1.*) 86 wxXmlNode* root = doc.GetRoot(); 87 if (root->GetName() != wxT("Entities")) 88 { 89 return; 90 } 91 // Template, position,orientation 92 const wxXmlNode* child = root->GetChildren(); 93 94 while (child) 95 { 96 if (child->GetName() != wxT("Entity")) 97 { 98 return; 99 } 100 //TODO Validate all attributes 101 child = child->GetNext(); 102 } 103 104 //Update selectedObjects?? 105 g_SelectedObjects.empty(); 106 POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects)); 107 108 // is the source code get here now you can add the objects to scene(preview) 109 // store id to move 110 child = root->GetChildren(); 111 112 while (child) 113 { 114 wxString objectId; 115 Position objectPos; 116 unsigned int actorSeed; 117 double orientation; 118 119 const wxXmlNode* xmlData = child->GetChildren(); 120 121 while (xmlData) 122 { 123 if (xmlData->GetName() == wxT("Template")) 124 { 125 objectId = xmlData->GetNodeContent(); 126 } 127 else if (xmlData->GetName() == wxT("Position")) 128 { 129 wxString x, z; 130 xmlData->GetAttribute(wxT("x"), &x); 131 xmlData->GetAttribute(wxT("z"), &z); 132 133 double aux,aux2; 134 x.ToDouble(&aux); 135 z.ToDouble(&aux2); 136 137 objectPos = Position(aux,0,aux2); 138 } 139 else if (xmlData->GetName() == wxT("Orientation")) 140 { 141 wxString y; 142 xmlData->GetAttribute(wxT("y"), &y); 143 y.ToDouble(&orientation); 144 } 145 146 xmlData = xmlData->GetNext(); 147 } 148 149 POST_MESSAGE(ObjectPreview, ((std::wstring)objectId.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), objectPos, false, Position(), orientation, 0, false)); 150 151 child = child->GetNext(); 152 } 153 154 //Set state paste for preview the new objects 155 this->SetState(&Pasting); 156 } 157 158 void OnMovingPaste() 159 { 160 //Move the preview(s) object(s) 161 POST_MESSAGE(MoveObjectPreview, ((m_objPosition))); 162 } 163 164 void OnPasteEnd(bool canceled) 165 { 166 if (canceled) 167 { 168 //delete previews objects 169 POST_MESSAGE(ObjectPreview, (_T(""), GetScenarioEditor().GetObjectSettings().GetSettings(), Position(), false, Position(), 0, 0, true)); 170 } 171 else 172 { 173 //Create new Objects and delete preview objects 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 } 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 316 } 317 } 318 if (evt.GetKeyCode() == 'V') 319 { 320 obj->OnPasteStart(); 321 } 322 } 170 323 else 171 324 return false; 172 325 } … … 335 488 } 336 489 } 337 490 SelectSimilar; 491 492 struct sPasting : public State 493 { 494 bool OnMouse(TransformObject* obj, wxMouseEvent& evt) 495 { 496 if (evt.Moving()) 497 { 498 //Move the object 499 obj->m_objPosition = Position(evt.GetPosition()); 500 obj->OnMovingPaste(); 501 return true; 502 } 503 else if (evt.LeftDown()) 504 { 505 //Place the object and update 506 obj->OnPasteEnd(false); 507 return true; 508 } 509 else 510 return false; 511 } 512 bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type) 513 { 514 if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) 515 { 516 obj->OnPasteEnd(true); 517 return true; 518 } 519 else 520 return false; 521 } 522 } 523 Pasting; 338 524 }; 339 525 340 526 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(MoveObjectPreview) 368 { 369 if (g_PreviewEntitiesID.size()==0) 370 { 371 return; 372 } 373 374 //TODO:Change pivot 375 entity_id_t pivot = *g_PreviewEntitiesID.begin(); 376 377 // All selected objects move relative to a pivot object, 378 // so get its position and whether it's floating 379 CVector3D pivotPos(0, 0, 0); 380 bool pivotFloating = false; 381 382 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), pivot); 383 if (cmpPosition && cmpPosition->IsInWorld()) 384 { 385 pivotFloating = cmpPosition->IsFloating(); 386 CFixedVector3D pivotFixed = cmpPosition->GetPosition(); 387 pivotPos = CVector3D(pivotFixed.X.ToFloat(), pivotFixed.Y.ToFloat(), pivotFixed.Z.ToFloat()); 388 } 389 390 // Calculate directional vector of movement for pivot object, 391 // we apply the same movement to all objects 392 CVector3D targetPos = GetUnitPos(msg->pos, pivotFloating); 393 CVector3D dir = targetPos - pivotPos; 394 395 for (size_t i = 0; i < g_PreviewEntitiesID.size(); ++i) 396 { 397 entity_id_t id = (entity_id_t)g_PreviewEntitiesID[i]; 398 CVector3D posFinal = CVector3D(0, 0, 0); 399 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); 400 if (cmpPosition && cmpPosition->IsInWorld()) 401 { 402 // Calculate this object's position 403 CFixedVector3D posFixed = cmpPosition->GetPosition(); 404 CVector3D pos = CVector3D(posFixed.X.ToFloat(), posFixed.Y.ToFloat(), posFixed.Z.ToFloat()); 405 CVector3D posFinal = pos + dir; 406 407 cmpPosition->JumpTo(entity_pos_t::FromFloat(posFinal.X), entity_pos_t::FromFloat(posFinal.Z)); 408 } 409 } 410 } 411 314 412 MESSAGEHANDLER(ObjectPreview) 315 413 { 316 414 // If the selection has changed... 317 if (*msg->id != g_PreviewUnitName )415 if (*msg->id != g_PreviewUnitName || (!msg->cleanObjectPreviews)) 318 416 { 319 417 // Delete old entity 320 if (g_PreviewEntityID != INVALID_ENTITY) 321 g_Game->GetSimulation2()->DestroyEntity(g_PreviewEntityID); 418 if (g_PreviewEntityID != INVALID_ENTITY && msg->cleanObjectPreviews) 419 { 420 //Time to delete all preview objects 421 if (g_PreviewEntitiesID.size() > 0) 422 { 423 std::vector<entity_id_t>::const_iterator i; 424 for (i = g_PreviewEntitiesID.begin(); i != g_PreviewEntitiesID.end(); i++) 425 { 426 g_Game->GetSimulation2()->DestroyEntity(*i); 427 } 428 g_PreviewEntitiesID.clear(); 429 } 430 } 322 431 323 432 // Create the new entity 324 433 if ((*msg->id).empty()) 325 434 g_PreviewEntityID = INVALID_ENTITY; 326 435 else 436 { 327 437 g_PreviewEntityID = g_Game->GetSimulation2()->AddLocalEntity(L"preview|" + *msg->id); 438 g_PreviewEntitiesID.push_back(g_PreviewEntityID); 439 } 440 328 441 329 442 g_PreviewUnitName = *msg->id; 330 443 } -
source/tools/atlas/GameInterface/Messages.h
334 334 SHAREABLE_STRUCT(sObjectSettings); 335 335 #endif 336 336 337 // Moving Preview(s) object together, default is using the firs element in vector 338 MESSAGE(MoveObjectPreview, 339 ((Position,pos)) 340 ); 341 337 342 // Preview object in the game world - creates a temporary unit at the given 338 343 // position, and removes it when the preview is next changed 339 344 MESSAGE(ObjectPreview, … … 344 349 ((Position, target)) 345 350 ((float, angle)) 346 351 ((unsigned int, actorseed)) 352 ((bool, cleanObjectPreviews)) 347 353 ); 348 354 349 355 COMMAND(CreateObject, NOMERGE, … … 590 596 ((sObjectSettings, settings)) 591 597 ); 592 598 599 QUERY(GetObjectMapSettings, 600 ((std::vector<ObjectID>, ids)) 601 , 602 ((std::wstring, xmldata)) 603 ); 604 605 593 606 QUERY(GetPlayerObjects, 594 607 ((int, player)) 595 608 ,