This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 9617 for ps


Ignore:
Timestamp:
06/14/11 01:32:41 (14 years ago)
Author:
ben
Message:

Adds AI control to Atlas player panel
Adds camera control to Atlas player panel
Changes map reader to handle per-player starting camera position. See #55
Adds entity name filter to Atlas object panel
Fixes bug in Atlas map settings (caused crash when object panel was not loaded)

Location:
ps/trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/Player.js

    r8652 r9617  
    2626    this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class
    2727    this.phase = "village";
     28    this.startCam = undefined;
    2829};
    2930
     
    226227};
    227228
     229Player.prototype.GetStartingCamera = function()
     230{
     231    return this.startCam;
     232}
     233
     234Player.prototype.SetStartingCamera = function(pos)
     235{
     236    this.startCam = pos;
     237}
     238
     239Player.prototype.HasStartingCamera = function()
     240{
     241    return (this.startCam !== undefined);
     242}
     243
    228244/**
    229245 * Keep track of population effects of all entities that
  • ps/trunk/binaries/data/mods/public/simulation/helpers/Player.js

    r9602 r9617  
    129129                player.SetDiplomacy(diplomacy);
    130130            }
     131           
     132            if (getSetting(pData, pDefs, "StartingCamera") !== undefined)
     133            {
     134                player.SetStartingCamera(getSetting(pData, pDefs, "StartingCamera"));
     135            }
    131136        }
    132137        else
  • ps/trunk/source/graphics/MapReader.cpp

    r9609 r9617  
    7575    pSimulation2 = pSimulation2_;
    7676    m_PlayerID = playerID_;
    77 
    78     m_CameraStartupTarget = INVALID_ENTITY;
     77    m_StartingCameraTarget = INVALID_ENTITY;
    7978
    8079    filename_xml = pathname.ChangeExtension(L".xml");
     
    147146    pSimulation2 = pSimulation2_;
    148147    m_PlayerID = playerID_;
    149 
    150     m_CameraStartupTarget = INVALID_ENTITY;
     148    m_StartingCameraTarget = INVALID_ENTITY;
    151149
    152150    // delete all existing entities
     
    285283        *pLightEnv = m_LightEnv;
    286284
    287     if (pGameView)
    288     {
     285    CmpPtr<ICmpPlayerManager> cmpPlayerManager(*pSimulation2, SYSTEM_ENTITY);
     286
     287    if (pGameView && !cmpPlayerManager.null())
     288    {
     289        // Default to global camera (with constraints)
    289290        pGameView->ResetCameraTarget(pGameView->GetCamera()->GetFocus());
    290 
    291         if (m_CameraStartupTarget != INVALID_ENTITY)
    292         {
    293             CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, m_CameraStartupTarget);
     291       
     292        CmpPtr<ICmpPlayer> cmpPlayer(*pSimulation2, cmpPlayerManager->GetPlayerByID(m_PlayerID));
     293        if (!cmpPlayer.null() && cmpPlayer->HasStartingCamera())
     294        {
     295            // Use player starting camera
     296            CFixedVector3D pos = cmpPlayer->GetStartingCamera();
     297            pGameView->ResetCameraTarget(CVector3D(pos.X.ToFloat(), pos.Y.ToFloat(), pos.Z.ToFloat()));
     298        }
     299        else if (m_StartingCameraTarget != INVALID_ENTITY)
     300        {
     301            // Point camera at entity
     302            CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, m_StartingCameraTarget);
    294303            if (!cmpPosition.null())
    295304            {
     
    679688void CXMLReader::ReadCamera(XMBElement parent)
    680689{
     690    // defaults if we don't find player starting camera
    681691#define EL(x) int el_##x = xmb_file.GetElementID(#x)
    682692#define AT(x) int at_##x = xmb_file.GetAttributeID(#x)
     
    850860
    851861    CSimulation2& sim = *m_MapReader.pSimulation2;
    852     CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim.GetSimContext(), SYSTEM_ENTITY);
     862    CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim, SYSTEM_ENTITY);
    853863
    854864    while (entity_idx < entities.Count)
     
    908918
    909919        entity_id_t ent = sim.AddEntity(TemplateName, EntityUid);
    910         if (ent == INVALID_ENTITY)
    911         {
     920        entity_id_t player = cmpPlayerManager->GetPlayerByID(PlayerID);
     921        if (ent == INVALID_ENTITY || player == INVALID_ENTITY)
     922        {   // Don't add entities with invalid player IDs
    912923            LOGERROR(L"Failed to load entity template '%ls'", TemplateName.c_str());
    913924        }
    914         else if (cmpPlayerManager->GetPlayerByID(PlayerID) != INVALID_ENTITY)
    915         {   // Don't add entities with invalid player IDs
    916             // TODO: Is a warning OK or should it just silently fail?
    917 
     925        else
     926        {
    918927            CmpPtr<ICmpPosition> cmpPosition(sim, ent);
    919928            if (!cmpPosition.null())
     
    928937                cmpOwner->SetOwner(PlayerID);
    929938
    930             if (boost::algorithm::ends_with(TemplateName, L"civil_centre"))
     939            if (PlayerID == m_MapReader.m_PlayerID && (boost::algorithm::ends_with(TemplateName, L"civil_centre") || m_MapReader.m_StartingCameraTarget == INVALID_ENTITY))
    931940            {
    932                 // HACK: we special-case civil centre files to initialise the camera.
    933                 // This ought to be based on a more generic mechanism for indicating
    934                 // per-player camera start locations.
    935                 if (m_MapReader.m_CameraStartupTarget == INVALID_ENTITY && PlayerID == m_MapReader.m_PlayerID && !cmpPosition.null())
    936                     m_MapReader.m_CameraStartupTarget = ent;
     941                // Focus on civil centre or first entity owned by player
     942                m_MapReader.m_StartingCameraTarget = ent;
    937943            }
    938944        }
     
    12021208        LOGWARNING(L"CMapReader::ParseEntities() failed to get 'entities' property");
    12031209
     1210    CSimulation2& sim = *pSimulation2;
     1211    CmpPtr<ICmpPlayerManager> cmpPlayerManager(sim, SYSTEM_ENTITY);
     1212
    12041213    size_t entity_idx = 0;
    12051214    size_t num_entities = entities.size();
     
    12131222
    12141223        entity_id_t ent = pSimulation2->AddEntity(currEnt.templateName, currEnt.entityID);
    1215         // Check that entity was added
    1216         if (ent == INVALID_ENTITY)
    1217         {
     1224        entity_id_t player = cmpPlayerManager->GetPlayerByID(currEnt.playerID);
     1225        if (ent == INVALID_ENTITY || player == INVALID_ENTITY)
     1226        {   // Don't add entities with invalid player IDs
    12181227            LOGERROR(L"Failed to load entity template '%ls'", currEnt.templateName.c_str());
    12191228        }
    12201229        else
    12211230        {
    1222             CmpPtr<ICmpPosition> cmpPosition(*pSimulation2, ent);
     1231            CFixedVector3D Position;
     1232            Position.X = fixed::FromFloat(currEnt.positionX);
     1233            Position.Z = fixed::FromFloat(currEnt.positionZ);
     1234
     1235            CmpPtr<ICmpPosition> cmpPosition(sim, ent);
    12231236            if (!cmpPosition.null())
    12241237            {
    1225                 cmpPosition->JumpTo(entity_pos_t::FromFloat(currEnt.positionX), entity_pos_t::FromFloat(currEnt.positionZ));
     1238                cmpPosition->JumpTo(Position.X, Position.Z);
    12261239                cmpPosition->SetYRotation(entity_angle_t::FromFloat(currEnt.orientationY));
    12271240                // TODO: other parts of the position
    12281241            }
    12291242
    1230             CmpPtr<ICmpOwnership> cmpOwner(*pSimulation2, ent);
     1243            CmpPtr<ICmpOwnership> cmpOwner(sim, ent);
    12311244            if (!cmpOwner.null())
    12321245                cmpOwner->SetOwner(currEnt.playerID);
    12331246
    1234             if (boost::algorithm::ends_with(currEnt.templateName, L"civil_centre"))
     1247            if (currEnt.playerID == m_PlayerID && (boost::algorithm::ends_with(currEnt.templateName, L"civil_centre") || m_StartingCameraTarget == INVALID_ENTITY))
    12351248            {
    1236                 // HACK: we special-case civil centre files to initialise the camera.
    1237                 // This ought to be based on a more generic mechanism for indicating
    1238                 // per-player camera start locations.
    1239                 if (m_CameraStartupTarget == INVALID_ENTITY && currEnt.playerID == m_PlayerID && !cmpPosition.null())
    1240                     m_CameraStartupTarget = ent;
    1241 
     1249                // Focus on civil centre or first entity owned by player
     1250                m_StartingCameraTarget = currEnt.entityID;
    12421251            }
    12431252        }
     
    13281337{
    13291338    // parse camera settings from map data
    1330     // defaults if we don't find camera
     1339    // defaults if we don't find player starting camera
    13311340    float declination = DEGTORAD(30.f), rotation = DEGTORAD(-45.f);
    13321341    CVector3D translation = CVector3D(100, 150, -100);
  • ps/trunk/source/graphics/MapReader.h

    r9220 r9617  
    138138    bool only_xml;
    139139    u32 file_format_version;
    140     entity_id_t m_CameraStartupTarget;
     140    entity_id_t m_StartingCameraTarget;
     141    CVector3D m_StartingCamera;
    141142
    142143    // UnpackTerrain generator state
  • ps/trunk/source/simulation2/Simulation2.cpp

    r9609 r9617  
    626626    return data;
    627627}
     628
     629std::string CSimulation2::GetAIData()
     630{
     631    ScriptInterface& scriptInterface = GetScriptInterface();
     632    std::vector<CScriptValRooted> aiData = ICmpAIManager::GetAIs(scriptInterface);
     633   
     634    // Build single JSON string with array of AI data
     635    CScriptValRooted ais;
     636    if (!scriptInterface.Eval("({})", ais) || !scriptInterface.SetProperty(ais.get(), "AIData", aiData))
     637        return std::string();
     638   
     639    return scriptInterface.StringifyJSON(ais.get());
     640}
  • ps/trunk/source/simulation2/Simulation2.h

    r9609 r9617  
    234234    std::string GetMapSizes();
    235235
     236    /**
     237     * Get AI data
     238     *
     239     * @return string containing JSON format data
     240     */
     241    std::string GetAIData();
     242
    236243private:
    237244    CSimulation2Impl* m;
  • ps/trunk/source/simulation2/components/ICmpPlayer.cpp

    r7655 r9617  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2020#include "ICmpPlayer.h"
    2121
     22#include "maths/FixedVector3D.h"
    2223#include "simulation2/system/InterfaceScripted.h"
    2324#include "simulation2/scripting/ScriptComponent.h"
     
    5253        return m_Script.Call<CColor>("GetColour");
    5354    }
     55
     56    virtual CFixedVector3D GetStartingCamera()
     57    {
     58        return m_Script.Call<CFixedVector3D>("GetStartingCamera");
     59    }
     60
     61    virtual bool HasStartingCamera()
     62    {
     63        return m_Script.Call<bool>("HasStartingCamera");
     64    }
    5465};
    5566
  • ps/trunk/source/simulation2/components/ICmpPlayer.h

    r7655 r9617  
    1 /* Copyright (C) 2010 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    2222
    2323struct CColor;
     24class CFixedVector3D;
    2425
    2526/**
     
    3637
    3738    virtual CColor GetColour() = 0;
     39    virtual CFixedVector3D GetStartingCamera() = 0;
     40
     41    virtual bool HasStartingCamera() = 0;
    3842
    3943    DECLARE_INTERFACE_TYPE(Player)
  • ps/trunk/source/tools/atlas/AtlasObject/AtlasObject.h

    r9566 r9617  
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    154154    void set(const char* key, AtObj& data);
    155155    void setBool(const char* key, bool value);
     156    void setDouble(const char* key, double value);
    156157    void setInt(const char* key, int value);
    157158    void setString(const wchar_t* value);
  • ps/trunk/source/tools/atlas/AtlasObject/AtlasObjectImpl.cpp

    r9566 r9617  
    1 /* Copyright (C) 2009 Wildfire Games.
     1/* Copyright (C) 2011 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
     
    176176}
    177177
     178void AtObj::setDouble(const char* key, double value)
     179{
     180    std::wstringstream str;
     181    str << value;
     182    AtNode* o = new AtNode(str.str().c_str());
     183    o->children.insert(AtNode::child_pairtype("@number", AtNode::Ptr(new AtNode())));
     184
     185    if (!p)
     186        p = new AtNode();
     187
     188    p = p->setChild(key, AtNode::Ptr(o));
     189}
     190
    178191void AtObj::setInt(const char* key, int value)
    179192{
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp

    r9608 r9617  
    449449    wxString size;
    450450    size << (intptr_t)sizeChoice->GetClientData(sizeChoice->GetSelection());
    451     AtObj sizeObj;
    452     sizeObj.setString(size);
    453     sizeObj.set("@number", L"");
    454     settings.set("Size", sizeObj);
    455 
    456     AtObj seedObj;
    457     seedObj.setString(wxDynamicCast(FindWindow(ID_RandomSeed), wxTextCtrl)->GetValue());
    458     seedObj.set("@number", L"");
    459     settings.set("Seed", seedObj);
     451    settings.setInt("Size", wxAtoi(size));
     452
     453    settings.setInt("Seed", wxAtoi(wxDynamicCast(FindWindow(ID_RandomSeed), wxTextCtrl)->GetValue()));
    460454
    461455    std::string json = AtlasObject::SaveToJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), settings);
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp

    r9608 r9617  
    3535{
    3636    ID_ObjectType = 1,
     37    ID_ObjectFilter,
    3738    ID_PlayerSelect,
    3839    ID_SelectObject,
     
    111112: Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer), p(new ObjectSidebarImpl())
    112113{
     114    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
     115    sizer->Add(new wxStaticText(this, wxID_ANY, _("Filter")), wxSizerFlags().Align(wxALIGN_CENTER));
     116    wxTextCtrl* objectFilter = new wxTextCtrl(this, ID_ObjectFilter);
     117    sizer->Add(objectFilter, wxSizerFlags().Expand().Proportion(1));
     118    m_MainSizer->Add(sizer, wxSizerFlags().Expand());
     119
    113120    wxArrayString strings;
    114121    strings.Add(_("Entities"));
     
    159166    p->m_Objects = *qry.objects;
    160167    // Display first group of objects
    161     SetObjectFilter(0);
    162 }
    163 
    164 void ObjectSidebar::SetObjectFilter(int type)
    165 {
     168    FilterObjects();
     169}
     170
     171void ObjectSidebar::FilterObjects()
     172{
     173    int filterType = wxDynamicCast(FindWindow(ID_ObjectType), wxChoice)->GetSelection();
     174    wxString filterName = wxDynamicCast(FindWindow(ID_ObjectFilter), wxTextCtrl)->GetValue();
     175
    166176    p->m_ObjectListBox->Freeze();
    167177    p->m_ObjectListBox->Clear();
    168178    for (std::vector<AtlasMessage::sObjectsListItem>::iterator it = p->m_Objects.begin(); it != p->m_Objects.end(); ++it)
    169179    {
    170         if (it->type == type)
     180        if (it->type == filterType)
    171181        {
    172182            wxString id = it->id.c_str();
    173183            wxString name = it->name.c_str();
    174             p->m_ObjectListBox->Append(name, new wxStringClientData(id));
     184
     185            if (name.Lower().Find(filterName.Lower()) != wxNOT_FOUND)
     186            {
     187                p->m_ObjectListBox->Append(name, new wxStringClientData(id));
     188            }
    175189        }
    176190    }
     
    186200}
    187201
    188 void ObjectSidebar::OnSelectType(wxCommandEvent& evt)
    189 {
    190     // Switch between displayed lists of objects (e.g. entities vs actors)
    191     SetObjectFilter(evt.GetSelection());
     202void ObjectSidebar::OnSelectType(wxCommandEvent& WXUNUSED(evt))
     203{
     204    FilterObjects();
    192205}
    193206
     
    214227}
    215228
     229void ObjectSidebar::OnSelectFilter(wxCommandEvent& WXUNUSED(evt))
     230{
     231    FilterObjects();
     232}
     233
    216234BEGIN_EVENT_TABLE(ObjectSidebar, Sidebar)
    217235    EVT_CHOICE(ID_ObjectType, ObjectSidebar::OnSelectType)
     236    EVT_TEXT(ID_ObjectFilter, ObjectSidebar::OnSelectFilter)
    218237    EVT_LISTBOX(ID_SelectObject, ObjectSidebar::OnSelectObject)
    219238    EVT_BUTTON(ID_ToggleViewer, ObjectSidebar::ToggleViewer)
     
    257276        Clear();
    258277        size_t numPlayers = settings["PlayerData"]["item"].count();
    259         for (size_t i = 0; i <= numPlayers; ++i)
     278        for (size_t i = 0; i <= numPlayers && i < m_Players.Count(); ++i)
    260279        {
    261280            Append(m_Players[i]);
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.h

    r9559 r9617  
    2626    ObjectSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarContainer, wxWindow* bottomBarContainer);
    2727    ~ObjectSidebar();
    28     void SetObjectFilter(int type);
     28    void FilterObjects();
    2929
    3030protected:
     
    3636    void ToggleViewer(wxCommandEvent& evt);
    3737    void OnSelectType(wxCommandEvent& evt);
     38    void OnSelectFilter(wxCommandEvent& evt);
    3839    void OnSelectObject(wxCommandEvent& evt);
    3940
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.cpp

    r9608 r9617  
    2222#include "AtlasObject/AtlasObject.h"
    2323#include "AtlasScript/ScriptInterface.h"
    24 #include "GameInterface/Messages.h"
    2524#include "ScenarioEditor/ScenarioEditor.h"
    2625
     
    3534    ID_PlayerStone,
    3635    ID_PlayerPop,
    37     ID_PlayerColour
    38 };
    39 
    40 // Controls present on each player page
    41 struct PlayerPageControls
    42 {
    43     wxTextCtrl* name;
    44     wxChoice* civ;
    45     wxButton* colour;
    46     wxSpinCtrl* food;
    47     wxSpinCtrl* wood;
    48     wxSpinCtrl* stone;
    49     wxSpinCtrl* metal;
    50     wxSpinCtrl* pop;
    51     wxChoice* team;
     36    ID_PlayerColour,
     37    ID_PlayerHuman,
     38    ID_PlayerAI,
     39    ID_CameraSet,
     40    ID_CameraView,
     41    ID_CameraClear
    5242};
    5343
     
    7161        : wxPanel(parent, wxID_ANY), m_ScenarioEditor(scenarioEditor), m_Name(name), m_PlayerID(playerID)
    7262    {
     63
     64        m_Controls.page = this;
    7365
    7466        Freeze();
     
    9486        gridSizer->Add(Tooltipped(colourButton, _("Set player colour")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT));
    9587        m_Controls.colour = colourButton;
     88        gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Default AI")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
     89        wxChoice* aiChoice = new wxChoice(this, wxID_ANY);
     90        gridSizer->Add(Tooltipped(aiChoice, _("Select default AI")), wxSizerFlags(1).Expand().Align(wxALIGN_RIGHT));
     91        m_Controls.ai = aiChoice;
    9692
    9793        playerInfoSizer->Add(gridSizer, wxSizerFlags(1).Expand());
     
    143139
    144140        // TODO: possibly have advanced panel where each player's diplomacy can be set?
    145 
    146141        // Advanced panel
    147142        /*wxCollapsiblePane* advPane = new wxCollapsiblePane(this, wxID_ANY, _("Advanced"));
     
    151146        sizer->Add(diplomacySizer, wxSizerFlags().Expand());
    152147
     148        /////////////////////////////////////////////////////////////////////////
     149        // Camera
     150        wxStaticBoxSizer* cameraSizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Starting Camera"));
     151        wxButton* cameraSet = new wxButton(this, ID_CameraSet, _("Set"));
     152        cameraSizer->Add(Tooltipped(cameraSet, _("Set player camera to this view")), wxSizerFlags(1));
     153        wxButton* cameraView = new wxButton(this, ID_CameraView, _("View"));
     154        cameraView->Enable(false);
     155        cameraSizer->Add(Tooltipped(cameraView, _("View the player camera")), wxSizerFlags(1));
     156        wxButton* cameraClear = new wxButton(this, ID_CameraClear, _("Clear"));
     157        cameraClear->Enable(false);
     158        cameraSizer->Add(Tooltipped(cameraClear, _("Clear player camera")), wxSizerFlags(1));
     159
     160        sizer->Add(cameraSizer, wxSizerFlags().Expand());
     161
    153162        Layout();
    154163        Thaw();
     
    173182    {
    174183        return m_PlayerID;
     184    }
     185
     186    bool IsCameraDefined()
     187    {
     188        return m_CameraDefined;
     189    }
     190
     191    sCameraInfo GetCamera()
     192    {
     193        return m_Camera;
     194    }
     195
     196    void SetCamera(sCameraInfo info, bool isDefined = true)
     197    {
     198        m_Camera = info;
     199        m_CameraDefined = isDefined;
     200
     201        // Enable/disable controls
     202        wxDynamicCast(FindWindow(ID_CameraView), wxButton)->Enable(isDefined);
     203        wxDynamicCast(FindWindow(ID_CameraClear), wxButton)->Enable(isDefined);
    175204    }
    176205
     
    194223    }
    195224
    196     ScenarioEditor& m_ScenarioEditor;
     225    void OnCameraSet(wxCommandEvent& evt)
     226    {
     227        AtlasMessage::qGetView qryView;
     228        qryView.Post();
     229        SetCamera(qryView.info, true);
     230
     231        // Pass event on to next handler
     232        evt.Skip();
     233    }
     234
     235    void OnCameraView(wxCommandEvent& WXUNUSED(evt))
     236    {
     237        POST_MESSAGE(SetView, (m_Camera));
     238    }
     239
     240    void OnCameraClear(wxCommandEvent& evt)
     241    {
     242        SetCamera(sCameraInfo(), false);
     243
     244        // Pass event on to next handler
     245        evt.Skip();
     246    }
     247
     248    sCameraInfo m_Camera;
     249    bool m_CameraDefined;
    197250    wxString m_Name;
    198251    size_t m_PlayerID;
    199 
     252    ScenarioEditor& m_ScenarioEditor;
     253   
    200254    PlayerPageControls m_Controls;
    201255
     
    205259BEGIN_EVENT_TABLE(PlayerNotebookPage, wxPanel)
    206260    EVT_BUTTON(ID_PlayerColour, PlayerNotebookPage::OnColour)
     261    EVT_BUTTON(ID_CameraSet, PlayerNotebookPage::OnCameraSet)
     262    EVT_BUTTON(ID_CameraView, PlayerNotebookPage::OnCameraView)
     263    EVT_BUTTON(ID_CameraClear, PlayerNotebookPage::OnCameraClear)
    207264END_EVENT_TABLE();
    208265
     
    332389BEGIN_EVENT_TABLE(PlayerSettingsControl, wxPanel)
    333390    EVT_BUTTON(ID_PlayerColour, PlayerSettingsControl::OnEdit)
     391    EVT_BUTTON(ID_CameraSet, PlayerSettingsControl::OnEdit)
     392    EVT_BUTTON(ID_CameraClear, PlayerSettingsControl::OnEdit)
    334393    EVT_CHOICE(wxID_ANY, PlayerSettingsControl::OnEdit)
    335394    EVT_TEXT(wxID_ANY, PlayerSettingsControl::OnEdit)
     
    383442    }
    384443
     444    // Load AI data
     445    ArrayOfAIData ais(AIData::CompareAIData);
     446    AtlasMessage::qGetAIData qryAI;
     447    qryAI.Post();
     448    AtObj aiData = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qryAI.data);
     449    for (AtIter a = aiData["AIData"]["item"]; a.defined(); ++a)
     450    {
     451        ais.Add(new AIData(wxString(a["id"]), wxString(a["data"]["name"])));
     452    }
     453
    385454    // Create player pages
    386455    AtIter player = m_PlayerDefaults["item"];
     
    396465        for (size_t j = 0; j < civNames.Count(); ++j)
    397466            civChoice->Append(civNames[j], new wxStringClientData(civCodes[j]));
     467        civChoice->SetSelection(0);
     468
     469        // Populate ai choice box
     470        wxChoice* aiChoice = controls.ai;
     471        aiChoice->Append(_("<None>"), new wxStringClientData());
     472        for (size_t j = 0; j < ais.Count(); ++j)
     473            aiChoice->Append(ais[j]->GetName(), new wxStringClientData(ais[j]->GetID()));
     474        aiChoice->SetSelection(0);
    398475    }
    399476
     
    418495        // Prevent error if there's no map settings to parse
    419496        m_MapSettings = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qry.settings);
     497    }
     498    else
     499    {   // Use blank object, it will be created next
     500        m_MapSettings = AtObj();
    420501    }
    421502
     
    481562        controls.colour->SetBackgroundColour(colour);
    482563
     564        // player type
     565        wxString aiID;
     566        if (player["AI"].defined())
     567            aiID = wxString(player["AI"]);
     568        else
     569            aiID = wxString(playerDefs["AI"]);
     570
     571        choice = controls.ai;
     572        if (!aiID.empty())
     573        {   // AI
     574            for (size_t j = 0; j < choice->GetCount(); ++j)
     575            {
     576                wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j));
     577                if (str->GetData() == aiID)
     578                {
     579                    choice->SetSelection(j);
     580                    break;
     581                }
     582            }
     583        }
     584        else
     585        {   // Human
     586            choice->SetSelection(0);
     587        }
     588
    483589        // resources
    484590        AtObj resObj = *player["Resources"];
     
    514620        else
    515621            controls.team->SetSelection(0);
     622
     623        // camera
     624        if (player["StartingCamera"].defined())
     625        {
     626            AtObj cam = *player["StartingCamera"];
     627            sCameraInfo info;
     628            info.pX = wxAtof(*cam["x"]);
     629            info.pY = wxAtof(*cam["y"]);
     630            info.pZ = wxAtof(*cam["z"]);
     631           
     632            controls.page->SetCamera(info, true);
     633        }
     634        else
     635            controls.page->SetCamera(sCameraInfo(), false);
    516636
    517637    }
     
    556676        clrObj.setInt("b", (int)colour.Blue());
    557677        player.set("Colour", clrObj);
     678
     679        // player type
     680        choice = controls.ai;
     681        if (choice->GetSelection() > 0)
     682        {   // ai - get id
     683            wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection()));
     684            player.set("AI", str->GetData());
     685        }
     686        else
     687        {   // human
     688            player.set("AI", _T(""));
     689        }
    558690
    559691        // resources
     
    582714        }
    583715
     716        // camera
     717        if (controls.page->IsCameraDefined())
     718        {
     719            sCameraInfo cam = controls.page->GetCamera();
     720            AtObj camObj;
     721            camObj.setDouble("x", cam.pX);
     722            camObj.setDouble("y", cam.pY);
     723            camObj.setDouble("z", cam.pZ);
     724            player.set("StartingCamera", camObj);
     725        }
     726
    584727        players.add("item", player);
    585728        if (oldPlayer.defined())
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Player/Player.h

    r9608 r9617  
    1818#include "../Common/Sidebar.h"
    1919
     20#include "GameInterface/Messages.h"
     21
    2022#include "wx/collpane.h"
    2123
     24using namespace AtlasMessage;
     25
     26class PlayerNotebookPage;
    2227class PlayerSettingsControl;
    2328
     
    4146    DECLARE_EVENT_TABLE();
    4247};
     48
     49// Controls present on each player page
     50struct PlayerPageControls
     51{
     52    PlayerNotebookPage* page;
     53
     54    wxTextCtrl* name;
     55    wxChoice* civ;
     56    wxButton* colour;
     57    wxSpinCtrl* food;
     58    wxSpinCtrl* wood;
     59    wxSpinCtrl* stone;
     60    wxSpinCtrl* metal;
     61    wxSpinCtrl* pop;
     62    wxChoice* team;
     63    wxChoice* ai;
     64};
     65
     66// Definitions for keeping AI data sorted
     67class AIData
     68{
     69public:
     70    AIData(const wxString& id, const wxString& name)
     71        : m_ID(id), m_Name(name)
     72    {
     73    }
     74   
     75    wxString& GetID()
     76    {
     77        return m_ID;
     78    }
     79
     80    wxString& GetName()
     81    {
     82        return m_Name;
     83    }
     84
     85    static int CompareAIData(AIData* ai1, AIData* ai2)
     86    {
     87        return ai1->m_Name.Cmp(ai2->m_Name);
     88    }
     89
     90private:
     91    wxString m_ID;
     92    wxString m_Name;
     93};
     94WX_DEFINE_SORTED_ARRAY(AIData*, ArrayOfAIData);
  • ps/trunk/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp

    r8911 r9617  
    220220}
    221221
    222 
    223 }
     222QUERYHANDLER(GetView)
     223{
     224    CVector3D focus = g_Game->GetView()->GetCamera()->GetFocus();
     225
     226    sCameraInfo info;
     227
     228    info.pX = focus.X;
     229    info.pY = focus.Y;
     230    info.pZ = focus.Z;
     231
     232    // TODO: Rotation
     233
     234    msg->info = info;
     235}
     236
     237MESSAGEHANDLER(SetView)
     238{
     239    if (g_Game->GetView()->GetCinema()->IsPlaying())
     240        return;
     241
     242    CGameView* view = g_Game->GetView();
     243    view->ResetCameraTarget(view->GetCamera()->GetFocus());
     244
     245    sCameraInfo cam = msg->info;
     246
     247    view->ResetCameraTarget(CVector3D(cam.pX, cam.pY, cam.pZ));
     248}
     249
     250}
  • ps/trunk/source/tools/atlas/GameInterface/Handlers/PlayerHandlers.cpp

    r9247 r9617  
    3636}
    3737
     38QUERYHANDLER(GetAIData)
     39{
     40    msg->data = g_Game->GetSimulation2()->GetAIData();
    3841}
     42
     43}
  • ps/trunk/source/tools/atlas/GameInterface/Messages.h

    r9609 r9617  
    184184        );
    185185
     186QUERY(GetAIData,
     187        ,
     188        ((std::string, data))
     189        );
     190
    186191//////////////////////////////////////////////////////////////////////////
    187192
     
    362367
    363368MESSAGE(CameraReset, );
     369
     370QUERY(GetView,
     371        ,
     372        ((sCameraInfo, info))
     373        );
     374
     375MESSAGE(SetView,
     376        ((sCameraInfo, info))
     377        );
    364378
    365379//////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.