Ticket #1163: 1163.2.diff
File 1163.2.diff, 6.5 KB (added by , 9 years ago) |
---|
-
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp
1 /* Copyright (C) 201 3Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 181 181 return true; 182 182 else if (evt.LeftUp()) 183 183 { 184 obj->m_Target = Position(evt.GetPosition()); 185 // Create the actual object 186 obj->SendObjectMsg(false); 184 AtlasMessage::qCanPlaceObject canPlaceObject; 185 canPlaceObject.Post(); 186 187 if (canPlaceObject.response) 188 { 189 obj->m_Target = Position(evt.GetPosition()); 190 // Create the actual object 191 obj->SendObjectMsg(false); 192 } 187 193 // Go back to preview mode 188 194 SET_STATE(Waiting); 189 195 obj->m_ObjPos = obj->m_ScreenPos = obj->m_Target; -
source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 366 359 { 367 360 if (evt.LeftUp()) 368 361 { 362 AtlasMessage::qCanPlaceObject canPlaceObject; 363 canPlaceObject.Post(); 364 365 if (!canPlaceObject.response) 366 { 367 ScenarioEditor::GetCommandProc().FinaliseLastCommand(); 368 ScenarioEditor::GetCommandProc().Undo(); 369 } 369 370 SET_STATE(Waiting); 370 371 return true; 371 372 } … … 536 537 } 537 538 else if (evt.LeftDown()) 538 539 { 539 //Place the object and update 540 obj->OnPasteEnd(false); 540 AtlasMessage::qCanPlaceObject canPlaceObject; 541 canPlaceObject.Post(); 542 543 if (canPlaceObject.response) 544 obj->OnPasteEnd(false); //Place the object and update 545 541 546 return true; 542 547 } 543 548 else -
source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 48 48 #include "simulation2/components/ICmpSelectable.h" 49 49 #include "simulation2/components/ICmpTemplateManager.h" 50 50 #include "simulation2/components/ICmpVisual.h" 51 #include "simulation2/components/ICmpObstruction.h" 51 52 #include "simulation2/helpers/Selection.h" 52 53 #include "ps/XML/XMLWriter.h" 53 54 … … 61 62 } 62 63 } 63 64 65 //Helpers for object constraints 66 bool CanPlaceObjectEntityHelper(entity_id_t ent) 67 { 68 CmpPtr<ICmpObstruction> cmpObstruction(*g_Game->GetSimulation2(), ent); 69 if (!cmpObstruction) 70 return true; 71 else 72 { 73 //use default passClasName. 74 ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default"); 75 if (result != ICmpObstruction::FOUNDATION_CHECK_SUCCESS) 76 return false; 77 } 78 return true; 79 } 80 81 void CheckObstructionAndUpdateVisual(entity_id_t id) 82 { 83 //Check build Constraint 84 CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id); 85 if (cmpVisual) 86 { 87 if (!CanPlaceObjectEntityHelper(id)) 88 cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1)); 89 else 90 cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1)); 91 } 92 } 93 94 bool CanPlaceObjectListHelper(std::vector<entity_id_t>::const_iterator start, std::vector<entity_id_t>::const_iterator end) 95 { 96 for (std::vector<entity_id_t>::const_iterator i = start; i != end; i++) 97 { 98 if (!CanPlaceObjectEntityHelper(*i)) 99 return false; 100 } 101 return true; 102 } 103 64 104 QUERYHANDLER(GetObjectsList) 65 105 { 66 106 std::vector<sObjectsListItem> objects; … … 375 415 msg->ids = g_Selection; 376 416 } 377 417 418 QUERYHANDLER(CanPlaceObject) 419 { 420 if (!g_PreviewEntitiesID.empty()) 421 msg->response = CanPlaceObjectListHelper(g_PreviewEntitiesID.begin(), g_PreviewEntitiesID.end()); 422 else if (!g_Selection.empty()) 423 msg->response = CanPlaceObjectListHelper(g_Selection.begin(), g_Selection.end()); 424 else 425 msg->response = true; //by default 426 } 427 378 428 MESSAGEHANDLER(ObjectPreviewToEntity) 379 429 { 380 430 UNUSED2(msg); … … 473 523 posFinal = posFixed + dir; 474 524 } 475 525 cmpPosition->JumpTo(posFinal.X, posFinal.Z); 526 527 //Check build Constraint 528 CheckObstructionAndUpdateVisual(id); 476 529 } 477 530 } 478 531 … … 543 596 CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID); 544 597 if (cmpOwnership) 545 598 cmpOwnership->SetOwner((player_id_t)msg->settings->player); 599 600 //Check build Constraint 601 CheckObstructionAndUpdateVisual(g_PreviewEntityID); 546 602 } 547 603 } 548 604 … … 736 792 ObjectPositionMap::iterator it; 737 793 for (it = map.begin(); it != map.end(); ++it) 738 794 { 739 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first); 795 entity_id_t id = (entity_id_t)it->first; 796 CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id); 740 797 if (!cmpPosition) 741 798 return; 742 799 … … 743 800 // Set 2D position, ignoring height 744 801 CVector3D pos = it->second; 745 802 cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z)); 803 804 //Check build Constraint 805 CheckObstructionAndUpdateVisual(id); 746 806 } 747 807 } 748 808 -
source/tools/atlas/GameInterface/Messages.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 345 349 ((std::vector<ObjectID>, ids)) 346 350 ); 347 351 352 // Check if current preview(s) object(s) can create or current selection move can place 353 QUERY(CanPlaceObject, 354 , //No inputs 355 ((bool, response)) 356 ); 348 357 // Moving Preview(s) object together, default is using the firs element in vector 349 358 MESSAGE(MoveObjectPreview, 350 359 ((Position,pos))