Ticket #1163: 1163.diff

File 1163.diff, 6.6 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
     
    366366        {
    367367            if (evt.LeftUp())
    368368            {
     369                AtlasMessage::qCanPlaceObject canPlaceObject;
     370                canPlaceObject.Post();
     371
     372                if (!canPlaceObject.response)
     373                {
     374                    ScenarioEditor::GetCommandProc().FinaliseLastCommand();
     375                    ScenarioEditor::GetCommandProc().Undo();
     376                }
    369377                SET_STATE(Waiting);
    370378                return true;
    371379            }
     
    536544            }
    537545            else if (evt.LeftDown())
    538546            {
    539                 //Place the object and update
    540                 obj->OnPasteEnd(false);
     547                AtlasMessage::qCanPlaceObject canPlaceObject;
     548                canPlaceObject.Post();
     549
     550                if (canPlaceObject.response)
     551                    obj->OnPasteEnd(false); //Place the object and update
     552
    541553                return true;
    542554            }
    543555            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        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
     81void CheckObstructionAndUpdateVisual(entity_id_t id)
     82{
     83    //Check build Constraint
     84    CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
     85    if(cmpVisual)
     86    {
     87        //use default passClasName and by false.
     88        if (!CanPlaceObjectEntityHelper(id))
     89            cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1));
     90        else
     91            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     92    }
     93}
     94
     95bool CanPlaceObjectListHelper(std::vector<entity_id_t>::const_iterator start, std::vector<entity_id_t>::const_iterator end)
     96{
     97    std::vector<entity_id_t>::const_iterator i;
     98    for (i = start; i != end; i++)
     99    {
     100        entity_id_t ent = *i;
     101        if (!CanPlaceObjectEntityHelper(ent))
     102            return false;
     103    }
     104    return true;
     105}
     106
    64107QUERYHANDLER(GetObjectsList)
    65108{
    66109    std::vector<sObjectsListItem> objects;
     
    375418    msg->ids = g_Selection;
    376419}
    377420
     421QUERYHANDLER(CanPlaceObject)
     422{
     423    msg->response = true; //by default
     424
     425    if (g_PreviewEntitiesID.size() > 0)
     426    {
     427        msg->response = CanPlaceObjectListHelper(g_PreviewEntitiesID.begin(), g_PreviewEntitiesID.end());
     428    }
     429    else if (g_Selection.size() > 0)
     430    {
     431        msg->response = CanPlaceObjectListHelper(g_Selection.begin(), g_Selection.end());
     432    }
     433}
     434
    378435MESSAGEHANDLER(ObjectPreviewToEntity)
    379436{
    380437    UNUSED2(msg);
     
    473530            posFinal = posFixed + dir;
    474531        }
    475532        cmpPosition->JumpTo(posFinal.X, posFinal.Z);
     533
     534        //Check build Constraint
     535        CheckObstructionAndUpdateVisual(id);
    476536    }
    477537}
    478538
     
    543603        CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
    544604        if (cmpOwnership)
    545605            cmpOwnership->SetOwner((player_id_t)msg->settings->player);
     606
     607        //Check build Constraint
     608        CheckObstructionAndUpdateVisual(g_PreviewEntityID);
    546609    }
    547610}
    548611
     
    736799        ObjectPositionMap::iterator it;
    737800        for (it = map.begin(); it != map.end(); ++it)
    738801        {
    739             CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first);
     802            entity_id_t id = (entity_id_t)it->first;
     803            CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
    740804            if (!cmpPosition)
    741805                return;
    742806
     
    743807            // Set 2D position, ignoring height
    744808            CVector3D pos = it->second;
    745809            cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
     810
     811            //Check build Constraint
     812            CheckObstructionAndUpdateVisual(id);
    746813        }
    747814    }
    748815
  • 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))