Ticket #96: progress_1_96.diff

File progress_1_96.diff, 7.5 KB (added by trompetin17, 10 years ago)
  • source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp

     
    4949            + (m_ScreenPos.type1.y-m_Target.type1.y)*(m_ScreenPos.type1.y-m_Target.type1.y);
    5050        bool useTarget = (dragDistSq >= 16*16);
    5151        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));
    5353        else
    5454        {
    5555            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

     
    2323#include "Common/MiscState.h"
    2424#include "Common/ObjectSettings.h"
    2525#include "GameInterface/Messages.h"
     26#include <wx/clipbrd.h>
     27#include <wx/xml/xml.h>
     28#include <wx/sstream.h>
    2629
    2730using AtlasMessage::Position;
    2831
     
    5255        POST_MESSAGE(SetSelectionPreview, (g_SelectedObjects));
    5356    }
    5457
     58    void TransformObject::OnPasteStart()
     59    {
     60        //PASTE
     61        wxString entities;
     62        if (wxTheClipboard->Open())
     63        {
     64            if (wxTheClipboard->IsSupported(wxDF_TEXT))
     65            {
     66                wxTextDataObject data;
     67                wxTheClipboard->GetData(data);
     68                entities = data.GetText();
     69            }
     70        }
     71        else
     72        {
     73            //TODO: Show something when the clipboard couldnt open
     74        }
     75       
     76        //First do we need to check if it is a correct xml string
     77        wxInputStream* is = new wxStringInputStream(entities);
     78        wxXmlDocument doc;
     79        if (!doc.Load(*is))
     80        {
     81            return;
     82        }
    5583
     84        // Entities, Entity(1.*)
     85        wxXmlNode* root = doc.GetRoot();
     86        if (root->GetName() != wxT("Entities"))
     87        {
     88            return;
     89        }
     90        //  Template, position,orientation
     91        const wxXmlNode* child = root->GetChildren();
     92
     93        while (child)
     94        {
     95            if (child->GetName() != wxT("Entity"))
     96            {
     97                return;
     98            }
     99            //TODO Validate all attributes
     100            child = child->GetNext();
     101        }
     102       
     103        //Update selectedObjects??
     104        g_SelectedObjects.empty();
     105
     106        // is the source code get here now you can add the objects to scene(preview)
     107        // store id to move
     108        child = root->GetChildren();
     109       
     110        while (child)
     111        {
     112            wxString objectId;
     113            Position objectPos;
     114            unsigned int actorSeed;
     115            const wxXmlNode* xmlData = child->GetChildren();
     116            while (xmlData)
     117            {
     118                if (xmlData->GetName() == wxT("Template"))
     119                {
     120                    objectId = xmlData->GetContent();
     121                }
     122                else if (xmlData->GetName() == wxT("Position"))
     123                {
     124                    wxString x, z;
     125                    xmlData->GetAttribute(wxT("x"), &x);
     126                    xmlData->GetAttribute(wxT("z"), &z);
     127
     128                    objectPos = Position();
     129                    //x.ToDouble(&objectPos.)
     130                }
     131            }
     132
     133            //POST_MESSAGE(ObjectPreview, ((std::wstring)m_ObjectID.wc_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle, m_ActorSeed));
     134        }
     135
     136
     137        //Send new Object
     138        //Set state paste for preview the new objects
     139    }
     140
     141    void TransformObject::OnPasteEnd()
     142    {
     143        //when all is done set default state
     144        this->SetState(&this->Waiting);
     145    }
     146
    56147    // TODO: keys to rotate/move object?
    57148
    58149    struct sWaiting : public State
     
    167258                obj->GetScenarioEditor().GetObjectSettings().NotifyObservers();
    168259                return true;
    169260            }
     261            else if (evt.GetModifiers() == wxMOD_CONTROL)
     262            {
     263                if (!g_SelectedObjects.empty())
     264                {
     265                    if (evt.GetKeyCode() == 'C')
     266                    {
     267                        //COPY current selections
     268                        AtlasMessage::qGetObjectMapSettings info(g_SelectedObjects);
     269                        info.Post();
     270
     271                        //In xmldata is the configuration
     272                        //now send to clipboard
     273                        if (wxTheClipboard->Open())
     274                        {
     275                            wxString text(info.xmldata.c_str());
     276                            wxTheClipboard->SetData(new wxTextDataObject(text));
     277                            wxTheClipboard->Close();
     278                        }
     279                        else
     280                        {
     281                            //TODO: Say something about couldnt open clipboard
     282                        }
     283
     284                    }
     285                    else if (evt.GetKeyCode() == 'V')
     286                    {
     287                        obj->OnPasteStart();
     288                    }
     289                }
     290            }
    170291            else
    171292                return false;
    172293        }
  • source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp

     
    4949#include "simulation2/components/ICmpTemplateManager.h"
    5050#include "simulation2/components/ICmpVisual.h"
    5151#include "simulation2/helpers/Selection.h"
     52#include "ps/XML/XMLWriter.h"
    5253
    5354
    5455namespace AtlasMessage {
     
    218219    msg->settings = settings;
    219220}
    220221
     222QUERYHANDLER(GetObjectMapSettings)
     223{
     224    std::vector<entity_id_t> ids = *msg->ids;
     225   
     226    CmpPtr<ICmpTemplateManager> cmpTemplateManager(*g_Game->GetSimulation2(), SYSTEM_ENTITY);
     227    ENSURE(cmpTemplateManager);
     228
     229    XML_Start();
     230    {
     231        XML_Element("Entities");
     232        {
     233            for (size_t i = 0; i < ids.size(); ++i)
     234            {
     235                entity_id_t id = (entity_id_t)ids[i];
     236                XML_Element("Entity");
     237                {
     238                    //Template name
     239                    XML_Setting("Template", cmpTemplateManager->GetCurrentTemplateName(id));
     240
     241                    //Player
     242                    CmpPtr<ICmpOwnership> cmpOwnership(*g_Game->GetSimulation2(), id);
     243                    if (cmpOwnership)
     244                        XML_Setting("Player", (int)cmpOwnership->GetOwner());
     245
     246                    //Adding position to make some relative position later
     247                    CmpPtr<ICmpPosition> cmpPosition(*g_Game->GetSimulation2(), id);
     248                    if (cmpPosition)
     249                    {
     250                        CFixedVector3D pos = cmpPosition->GetPosition();
     251                        CFixedVector3D rot = cmpPosition->GetRotation();
     252                        {
     253                            XML_Element("Position");
     254                            XML_Attribute("x", pos.X);
     255                            XML_Attribute("z", pos.Z);
     256                            // TODO: height offset etc
     257                        }
     258                        {
     259                            XML_Element("Orientation");
     260                            XML_Attribute("y", rot.Y);
     261                            // TODO: X, Z maybe
     262                        }
     263                    }
     264                }
     265            }
     266        }
     267    }
     268   
     269    const CStr& data = XML_GetOutput();
     270    msg->xmldata = std::wstring(data.begin(), data.end());
     271}
     272
    221273BEGIN_COMMAND(SetObjectSettings)
    222274{
    223275    player_id_t m_PlayerOld, m_PlayerNew;
     
    317369    if (*msg->id != g_PreviewUnitName)
    318370    {
    319371        // Delete old entity
    320         if (g_PreviewEntityID != INVALID_ENTITY)
     372        if (g_PreviewEntityID != INVALID_ENTITY  && msg->deleteLastPreview)
    321373            g_Game->GetSimulation2()->DestroyEntity(g_PreviewEntityID);
    322374
    323375        // Create the new entity
  • source/tools/atlas/GameInterface/Messages.h

     
    344344        ((Position, target))
    345345        ((float, angle))
    346346        ((unsigned int, actorseed))
     347        ((bool, deleteLastPreview)) // use with "paste" option
    347348        );
    348349
    349350COMMAND(CreateObject, NOMERGE,
     
    590591        ((sObjectSettings, settings))
    591592        );
    592593
     594QUERY(GetObjectMapSettings,
     595        ((std::vector<ObjectID>, ids))
     596        ,
     597        ((std::wstring,xmldata))
     598        );
     599
    593600QUERY(GetPlayerObjects,
    594601        ((int, player))
    595602        ,