Ticket #1163: 1163.3.diff

File 1163.3.diff, 6.5 KB (added by trompetin17, 9 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    181181                return true;
    182182            else if (evt.LeftUp())
    183183            {
    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                }
    187193                // Go back to preview mode
    188194                SET_STATE(Waiting);
    189195                obj->m_ObjPos = obj->m_ScreenPos = obj->m_Target;
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    366359        {
    367360            if (evt.LeftUp())
    368361            {
     362                AtlasMessage::qCanPlaceObject canPlaceObject;
     363                canPlaceObject.Post();
     364
     365                if (!canPlaceObject.response)
     366                {
     367                    ScenarioEditor::GetCommandProc().FinaliseLastCommand();
     368                    ScenarioEditor::GetCommandProc().Undo();
     369                }
    369370                SET_STATE(Waiting);
    370371                return true;
    371372            }
     
    536537            }
    537538            else if (evt.LeftDown())
    538539            {
    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
    541546                return true;
    542547            }
    543548            else
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4848#include "simulation2/components/ICmpSelectable.h"
    4949#include "simulation2/components/ICmpTemplateManager.h"
    5050#include "simulation2/components/ICmpVisual.h"
     51#include "simulation2/components/ICmpObstruction.h"
    5152#include "simulation2/helpers/Selection.h"
    5253#include "ps/XML/XMLWriter.h"
    5354
     
    6162    }
    6263}
    6364
     65//Helpers for object constraints
     66bool CanPlaceObjectEntityHelper(entity_id_t ent)
     67{
     68    CmpPtr<ICmpObstruction> cmpObstruction(*g_Game->GetSimulation2(), ent);
     69    if (cmpObstruction)
     70    {
     71        //use default passClasName.
     72        ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default");
     73        if (result != ICmpObstruction::FOUNDATION_CHECK_SUCCESS)
     74            return false;
     75    }
     76    return true;
     77}
     78
     79void CheckObstructionAndUpdateVisual(entity_id_t id)
     80{
     81    //Check build Constraint
     82    CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
     83    if (cmpVisual)
     84    {
     85        if (!CanPlaceObjectEntityHelper(id))
     86            cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1));
     87        else
     88            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     89    }
     90}
     91
     92bool CanPlaceObjectListHelper(std::vector<entity_id_t>::const_iterator start, std::vector<entity_id_t>::const_iterator end)
     93{
     94    for (std::vector<entity_id_t>::const_iterator i = start; i != end; i++)
     95    {
     96        if (!CanPlaceObjectEntityHelper(*i))
     97            return false;
     98    }
     99    return true;
     100}
     101
    64102QUERYHANDLER(GetObjectsList)
    65103{
    66104    std::vector<sObjectsListItem> objects;
     
    375413    msg->ids = g_Selection;
    376414}
    377415
     416QUERYHANDLER(CanPlaceObject)
     417{
     418    if (!g_PreviewEntitiesID.empty())
     419        msg->response = CanPlaceObjectListHelper(g_PreviewEntitiesID.begin(), g_PreviewEntitiesID.end());
     420    else if (!g_Selection.empty())
     421        msg->response = CanPlaceObjectListHelper(g_Selection.begin(), g_Selection.end());
     422    else
     423        msg->response = true;
     424}
     425
    378426MESSAGEHANDLER(ObjectPreviewToEntity)
    379427{
    380428    UNUSED2(msg);
     
    473521            posFinal = posFixed + dir;
    474522        }
    475523        cmpPosition->JumpTo(posFinal.X, posFinal.Z);
     524
     525        //Check build Constraint
     526        CheckObstructionAndUpdateVisual(id);
    476527    }
    477528}
    478529
     
    543594        CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
    544595        if (cmpOwnership)
    545596            cmpOwnership->SetOwner((player_id_t)msg->settings->player);
     597
     598        //Check build Constraint
     599        CheckObstructionAndUpdateVisual(g_PreviewEntityID);
    546600    }
    547601}
    548602
     
    736790        ObjectPositionMap::iterator it;
    737791        for (it = map.begin(); it != map.end(); ++it)
    738792        {
    739             CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first);
     793            entity_id_t id = (entity_id_t)it->first;
     794            CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
    740795            if (!cmpPosition)
    741796                return;
    742797
     
    743798            // Set 2D position, ignoring height
    744799            CVector3D pos = it->second;
    745800            cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
     801
     802            //Check build Constraint
     803            CheckObstructionAndUpdateVisual(id);
    746804        }
    747805    }
    748806
  • source/tools/atlas/GameInterface/Messages.h

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2015 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    345349    ((std::vector<ObjectID>, ids))
    346350    );
    347351
     352// Check if current preview(s) object(s) can create or current selection move can place
     353QUERY(CanPlaceObject,
     354    , //No inputs
     355    ((bool, response))
     356    );
    348357// Moving Preview(s) object together, default is using the firs element in vector
    349358MESSAGE(MoveObjectPreview,
    350359        ((Position,pos))