Ticket #1163: 1163.6.diff

File 1163.6.diff, 4.7 KB (added by trompetin17, 9 years ago)
  • 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                POST_MESSAGE(UpdateVisualSelectedObjects, ());
    369363                SET_STATE(Waiting);
    370364                return true;
    371365            }
  • 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
     
    4141#include "renderer/Renderer.h"
    4242#include "renderer/WaterManager.h"
    4343#include "simulation2/Simulation2.h"
     44#include "simulation2/components/ICmpObstruction.h"
    4445#include "simulation2/components/ICmpOwnership.h"
    4546#include "simulation2/components/ICmpPosition.h"
    4647#include "simulation2/components/ICmpPlayer.h"
     
    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        ICmpObstruction::EFoundationCheck result = cmpObstruction->CheckFoundation("default");
     72        if (result != ICmpObstruction::FOUNDATION_CHECK_SUCCESS)
     73            return false;
     74    }
     75    return true;
     76}
     77
     78void CheckObstructionAndUpdateVisual(entity_id_t id)
     79{
     80    // Check build Constraint
     81    CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), id);
     82    if (cmpVisual)
     83    {
     84        if (!CanPlaceObjectEntityHelper(id))
     85            cmpVisual->SetShadingColour(fixed::FromDouble(1.4), fixed::FromDouble(0.4), fixed::FromDouble(0.4), fixed::FromDouble(1));
     86        else
     87            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     88    }
     89}
     90
    6491QUERYHANDLER(GetObjectsList)
    6592{
    6693    std::vector<sObjectsListItem> objects;
     
    473500            posFinal = posFixed + dir;
    474501        }
    475502        cmpPosition->JumpTo(posFinal.X, posFinal.Z);
     503
     504        // Check build Constraint
     505        CheckObstructionAndUpdateVisual(id);
    476506    }
    477507}
    478508
     
    543573        CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), g_PreviewEntityID);
    544574        if (cmpOwnership)
    545575            cmpOwnership->SetOwner((player_id_t)msg->settings->player);
     576
     577        // Check build Constraint
     578        CheckObstructionAndUpdateVisual(g_PreviewEntityID);
    546579    }
    547580}
    548581
     
    680713    msg->ids = EntitySelection::PickSimilarEntities(*g_Game->GetSimulation2(), *g_Game->GetView()->GetCamera(), templateName, owner, false, true, true, false);
    681714}
    682715
     716MESSAGEHANDLER(UpdateVisualSelectedObjects)
     717{
     718    UNUSED(msg);
     719    if (g_Selection.empty())
     720        return;
    683721
     722    for (size_t i = 0; i < g_Selection.size(); ++i)
     723    {
     724        CmpPtr<ICmpVisual> cmpVisual(*g_Game->GetSimulation2(), g_Selection[i]);
     725        if (cmpVisual)
     726            cmpVisual->SetShadingColour(fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1), fixed::FromDouble(1));
     727    }
     728}
     729
    684730BEGIN_COMMAND(MoveObjects)
    685731{
    686732    // Mapping from object to position
     
    736782        ObjectPositionMap::iterator it;
    737783        for (it = map.begin(); it != map.end(); ++it)
    738784        {
    739             CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), (entity_id_t)it->first);
     785            entity_id_t id = (entity_id_t)it->first;
     786            CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
    740787            if (!cmpPosition)
    741788                return;
    742789
     
    743790            // Set 2D position, ignoring height
    744791            CVector3D pos = it->second;
    745792            cmpPosition->JumpTo(entity_pos_t::FromFloat(pos.X), entity_pos_t::FromFloat(pos.Z));
     793
     794            // Check build Constraint
     795            CheckObstructionAndUpdateVisual(id);
    746796        }
    747797    }
    748798
  • 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
     
    573577        ((std::vector<ObjectID>, ids))
    574578        );
    575579
     580MESSAGE(UpdateVisualSelectedObjects, );
     581
    576582COMMAND(MoveObjects, MERGE,
    577583        ((std::vector<ObjectID>, ids))
    578584        ((ObjectID, pivot))