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 9608 for ps


Ignore:
Timestamp:
06/10/11 01:45:12 (14 years ago)
Author:
ben
Message:

Adds player editor to Atlas scenario editor. See #91
Fixes object panel so the list of players updates correctly.
Atlas map settings are now observable and shared between various panels.
Fixes panels for maps missing settings (caused JSON error)
Changes map reader so that entities with invalid players cause a warning but are not added to the game. That prevents further errors. Fixes #869
Uses map size choices from simulation/data/map_sizes.json instead of multiple locations. Fixes #787
Prepares Atlas map settings for undo/redo support

Location:
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp

    r9599 r9608  
    2020#include "Map.h"
    2121
    22 #include "General/Datafile.h"
     22#include "AtlasObject/AtlasObject.h"
     23#include "AtlasScript/ScriptInterface.h"
     24#include "GameInterface/Messages.h"
     25#include "ScenarioEditor/ScenarioEditor.h"
    2326#include "ScenarioEditor/Tools/Common/Tools.h"
    24 #include "ScenarioEditor/ScenarioEditor.h"
    25 #include "AtlasScript/ScriptInterface.h"
    26 
    27 #include "GameInterface/Messages.h"
    2827
    2928#include "wx/busyinfo.h"
     
    3635    ID_MapReveal,
    3736    ID_MapType,
    38     ID_MapNumPlayers,
     37    ID_MapTeams,
    3938    ID_MapKW_Demo,
    4039    ID_MapKW_Hidden,
     
    5958    SimPaused
    6059};
     60
    6161bool IsPlaying(int s) { return (s == SimPlaying || s == SimPlayingFast || s == SimPlayingSlow); }
     62
     63// TODO: Some of these helper things should be moved out of this file
     64// and into shared locations
    6265
    6366// Helper function for adding tooltips
     
    7982};
    8083
    81 // TODO: Some of these helper things should be moved out of this file
    82 // and into shared locations
    83 
    84 class MapSettings : public wxPanel
     84class MapSettingsControl : public wxPanel
    8585{
    8686public:
    87     MapSettings(wxWindow* parent, ScenarioEditor& scenarioEditor);
     87    MapSettingsControl(wxWindow* parent, ScenarioEditor& scenarioEditor);
    8888    void CreateWidgets();
    8989    void ReadFromEngine();
     
    9797    }
    9898
    99     void OnEditSpin(wxSpinEvent& WXUNUSED(evt))
    100     {
    101         SendToEngine();
    102     }
    103 
    104     static const size_t MAX_NUM_PLAYERS = 8;
    105 
    106     AtObj m_MapSettings;
    10799    std::set<std::wstring> m_MapSettingsKeywords;
    108 
    109100    std::vector<wxChoice*> m_PlayerCivChoices;
    110 
    111101    ScenarioEditor& m_ScenarioEditor;
     102    Observable<AtObj>& m_MapSettings;
    112103
    113104    DECLARE_EVENT_TABLE();
    114105};
    115106
    116 BEGIN_EVENT_TABLE(MapSettings, wxPanel)
    117     EVT_TEXT(ID_MapName, MapSettings::OnEdit)
    118     EVT_TEXT(ID_MapDescription, MapSettings::OnEdit)
    119     EVT_CHECKBOX(wxID_ANY, MapSettings::OnEdit)
    120     EVT_CHOICE(wxID_ANY, MapSettings::OnEdit)
    121     EVT_SPINCTRL(ID_MapNumPlayers, MapSettings::OnEditSpin)
     107BEGIN_EVENT_TABLE(MapSettingsControl, wxPanel)
     108    EVT_TEXT(ID_MapName, MapSettingsControl::OnEdit)
     109    EVT_TEXT(ID_MapDescription, MapSettingsControl::OnEdit)
     110    EVT_CHECKBOX(wxID_ANY, MapSettingsControl::OnEdit)
     111    EVT_CHOICE(wxID_ANY, MapSettingsControl::OnEdit)
    122112END_EVENT_TABLE();
    123113
    124 MapSettings::MapSettings(wxWindow* parent, ScenarioEditor& scenarioEditor)
    125     : wxPanel(parent, wxID_ANY), m_ScenarioEditor(scenarioEditor)
     114MapSettingsControl::MapSettingsControl(wxWindow* parent, ScenarioEditor& scenarioEditor)
     115    : wxPanel(parent, wxID_ANY), m_ScenarioEditor(scenarioEditor), m_MapSettings(scenarioEditor.GetMapSettings())
    126116{
    127117    wxStaticBoxSizer* sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Map settings"));
     
    129119}
    130120
    131 void MapSettings::CreateWidgets()
     121void MapSettingsControl::CreateWidgets()
    132122{
    133123    wxSizer* sizer = GetSizer();
     
    146136            _("Short description used on the map selection screen")), wxSizerFlags().Expand());
    147137
     138    sizer->AddSpacer(5);
     139
    148140    wxArrayString gameTypes;
    149141    gameTypes.Add(_T("conquest"));
    150142    gameTypes.Add(_T("endless"));
    151143
    152     wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 2);
     144    wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 2, 5, 5);
    153145    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Reveal map")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    154146    gridSizer->Add(new wxCheckBox(this, ID_MapReveal, wxEmptyString));
    155147    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Game type")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    156148    gridSizer->Add(new wxChoice(this, ID_MapType, wxDefaultPosition, wxDefaultSize, gameTypes));
     149    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Lock teams")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
     150    gridSizer->Add(new wxCheckBox(this, ID_MapTeams, wxEmptyString));
    157151    gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Num players")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    158     wxSpinCtrl* numPlayersSpin = new wxSpinCtrl(this, ID_MapNumPlayers, wxEmptyString, wxDefaultPosition, wxSize(40, -1));
    159     numPlayersSpin->SetValue(MAX_NUM_PLAYERS);
    160     numPlayersSpin->SetRange(1, MAX_NUM_PLAYERS);
    161     gridSizer->Add(numPlayersSpin);
    162 
    163152    sizer->Add(gridSizer);
    164153
    165 
    166     wxArrayString civNames;
    167     wxArrayString civCodes;
    168     AtlasMessage::qGetCivData qryCiv;
    169     qryCiv.Post();
    170     std::vector<std::string> civData = *qryCiv.data;
    171     for (size_t i = 0; i < civData.size(); ++i)
    172     {
    173         AtObj civ = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), civData[i]);
    174         civNames.Add(wxString(civ["Name"]));
    175         civCodes.Add(wxString(civ["Code"]));
    176     }
    177 
    178     wxCollapsiblePane* playersPane = new wxCollapsiblePane(this, wxID_ANY, _("Player settings"), wxDefaultPosition, wxDefaultSize, wxCP_NO_TLW_RESIZE);
    179     wxFlexGridSizer* playersPaneSizer = new wxFlexGridSizer(2);
    180     playersPaneSizer->AddGrowableCol(1);
    181     playersPaneSizer->Add(new wxStaticText(playersPane->GetPane(), wxID_ANY, _T("")));
    182     playersPaneSizer->Add(new wxStaticText(playersPane->GetPane(), wxID_ANY, _("Civ")));
    183     for (size_t i = 0; i < MAX_NUM_PLAYERS; ++i)
    184     {
    185         wxString idStr;
    186         idStr << (i+1);
    187         playersPaneSizer->Add(new wxStaticText(playersPane->GetPane(), wxID_ANY, idStr), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT).Border(wxRIGHT, 2));
    188         wxChoice* civChoice = new wxChoice(playersPane->GetPane(), wxID_ANY);
    189         for (size_t j = 0; j < civNames.Count(); ++j)
    190             civChoice->Append(civNames[j], new wxStringClientData(civCodes[j]));
    191         m_PlayerCivChoices.push_back(civChoice);
    192         playersPaneSizer->Add(civChoice);
    193 
    194         // TODO: Team
    195         // TODO: Resources?
    196     }
    197     playersPane->GetPane()->SetSizer(playersPaneSizer);
    198     sizer->Add(playersPane, wxSizerFlags().Expand());
     154    sizer->AddSpacer(5);
    199155
    200156    wxStaticBoxSizer* keywordsSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Keywords"));
    201     wxFlexGridSizer* kwGridSizer = new wxFlexGridSizer(2, 2);
     157    wxFlexGridSizer* kwGridSizer = new wxFlexGridSizer(2, 2, 5, 5);
    202158    kwGridSizer->Add(new wxStaticText(this, wxID_ANY, _("Demo")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    203159    kwGridSizer->Add(new wxCheckBox(this, ID_MapKW_Demo, wxEmptyString));
     
    208164}
    209165
    210 void MapSettings::ReadFromEngine()
     166void MapSettingsControl::ReadFromEngine()
    211167{
    212168    AtlasMessage::qGetMapSettings qry;
    213169    qry.Post();
    214     m_MapSettings = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qry.settings);
     170    if (!(*qry.settings).empty())
     171    {
     172        // Prevent error if there's no map settings to parse
     173        m_MapSettings = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qry.settings);
     174    }
    215175
    216176    m_MapSettingsKeywords.clear();
     
    229189        wxDynamicCast(FindWindow(ID_MapType), wxChoice)->SetSelection(0);
    230190
    231     size_t numPlayers = m_MapSettings["PlayerData"]["item"].count();
    232     wxDynamicCast(FindWindow(ID_MapNumPlayers), wxSpinCtrl)->SetValue(numPlayers);
    233 
    234     AtIter player = m_MapSettings["PlayerData"]["item"];
    235     for (size_t i = 0; i < numPlayers && i < MAX_NUM_PLAYERS; ++i, ++player)
    236     {
    237         wxChoice* choice = m_PlayerCivChoices[i];
    238         choice->Enable(true);
    239         wxString civCode(player["Civ"]);
    240         for (size_t j = 0; j < choice->GetCount(); ++j)
    241         {
    242             wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(j));
    243             if (str->GetData() == civCode)
    244             {
    245                 choice->SetSelection(j);
    246                 break;
    247             }
    248         }
    249     }
    250     for (size_t i = numPlayers; i < MAX_NUM_PLAYERS; ++i)
    251     {
    252         wxChoice* choice = m_PlayerCivChoices[i];
    253         choice->SetSelection(0);
    254         choice->Enable(false);
    255     }
     191    wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->SetValue(wxString(m_MapSettings["LockTeams"]) == L"true");
    256192
    257193    wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->SetValue(m_MapSettingsKeywords.count(L"demo") != 0);
     
    259195}
    260196
    261 AtObj MapSettings::UpdateSettingsObject()
     197AtObj MapSettingsControl::UpdateSettingsObject()
    262198{
    263199    m_MapSettings.set("Name", wxDynamicCast(FindWindow(ID_MapName), wxTextCtrl)->GetValue());
     
    268204
    269205    m_MapSettings.set("GameType", wxDynamicCast(FindWindow(ID_MapType), wxChoice)->GetStringSelection());
    270 
    271     AtIter oldPlayer = m_MapSettings["PlayerData"]["item"];
    272     AtObj players;
    273     players.set("@array", L"");
    274     size_t numPlayers = (size_t)wxDynamicCast(FindWindow(ID_MapNumPlayers), wxSpinCtrl)->GetValue();
    275     for (size_t i = 0; i < numPlayers && i < MAX_NUM_PLAYERS; ++i)
    276     {
    277         wxChoice* choice = m_PlayerCivChoices[i];
    278         choice->Enable(true);
    279         AtObj player = *oldPlayer;
    280         if (choice->GetSelection() >= 0)
    281         {
    282             wxStringClientData* str = dynamic_cast<wxStringClientData*>(choice->GetClientObject(choice->GetSelection()));
    283             player.set("Civ", str->GetData());
    284         }
    285         players.add("item", player);
    286         if (oldPlayer.defined())
    287             ++oldPlayer;
    288     }
    289     for (size_t i = numPlayers; i < MAX_NUM_PLAYERS; ++i)
    290     {
    291         wxChoice* choice = m_PlayerCivChoices[i];
    292         choice->Enable(false);
    293     }
    294     m_MapSettings.set("PlayerData", players);
    295206
    296207    if (wxDynamicCast(FindWindow(ID_MapKW_Demo), wxCheckBox)->GetValue())
     
    303214    else
    304215        m_MapSettingsKeywords.erase(L"hidden");
     216
     217    m_MapSettings.setBool("LockTeams", wxDynamicCast(FindWindow(ID_MapTeams), wxCheckBox)->GetValue());
    305218
    306219    AtObj keywords;
     
    313226}
    314227
    315 void MapSettings::SendToEngine()
     228void MapSettingsControl::SendToEngine()
    316229{
    317230    UpdateSettingsObject();
     
    321234    // TODO: would be nice if we supported undo for settings changes
    322235
    323     POST_MESSAGE(SetMapSettings, (json));
     236    POST_COMMAND(SetMapSettings, (json));
    324237}
    325238
     
    328241    : Sidebar(scenarioEditor, sidebarContainer, bottomBarContainer), m_SimState(SimInactive)
    329242{
    330     m_MapSettings = new MapSettings(this, m_ScenarioEditor);
    331     m_MainSizer->Add(m_MapSettings, wxSizerFlags().Expand());
     243    m_MapSettingsCtrl = new MapSettingsControl(this, m_ScenarioEditor);
     244    m_MainSizer->Add(m_MapSettingsCtrl, wxSizerFlags().Expand());
    332245
    333246    {
     
    336249        sizer->Add(new wxChoice(this, ID_RandomScript), wxSizerFlags().Expand());
    337250
    338         wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 2);
     251        sizer->AddSpacer(5);
     252
     253        wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 2, 5, 5);
    339254        gridSizer->AddGrowableCol(1);
    340255
    341256        wxChoice* sizeChoice = new wxChoice(this, ID_RandomSize);
    342         AtObj sizes(Datafile::ReadList("mapsizes"));
    343         for (AtIter s = sizes["size"]; s.defined(); ++s)
    344         {
    345             long tiles = 0;
    346             wxString(s["@tiles"]).ToLong(&tiles);
    347             sizeChoice->Append(wxString(s["@name"]), (void*)(intptr_t)tiles);
    348         }
    349         sizeChoice->SetSelection(0);
    350257        gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Map size")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    351258        gridSizer->Add(sizeChoice, wxSizerFlags().Expand());
     
    353260        gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Random seed")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));
    354261        wxBoxSizer* seedSizer = new wxBoxSizer(wxHORIZONTAL);
    355         seedSizer->Add(new wxTextCtrl(this, ID_RandomSeed, _T("0")), wxSizerFlags(1).Expand());
    356         seedSizer->Add(new wxButton(this, ID_RandomReseed, _("R"), wxDefaultPosition, wxSize(24, -1)));
     262        seedSizer->Add(Tooltipped(new wxTextCtrl(this, ID_RandomSeed, _T("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC)), _("Seed value for random map")), wxSizerFlags(1).Expand());
     263        seedSizer->Add(Tooltipped(new wxButton(this, ID_RandomReseed, _("R"), wxDefaultPosition, wxSize(24, -1)), _("New random seed")));
    357264        gridSizer->Add(seedSizer, wxSizerFlags().Expand());
    358265
    359266        sizer->Add(gridSizer, wxSizerFlags().Expand());
     267
     268        sizer->AddSpacer(5);
    360269
    361270        sizer->Add(new wxButton(this, ID_RandomGenerate, _("Generate map")), wxSizerFlags().Expand());
     
    391300void MapSidebar::OnFirstDisplay()
    392301{
    393     m_MapSettings->CreateWidgets();
    394     m_MapSettings->ReadFromEngine();
    395 
    396     // Load the RMS script list:
    397 
     302    // We do this here becase messages are used which requires simulation to be init'd
     303    m_MapSettingsCtrl->CreateWidgets();
     304    m_MapSettingsCtrl->ReadFromEngine();
     305
     306    // Load the map sizes list
     307    AtlasMessage::qGetMapSizes qrySizes;
     308    qrySizes.Post();
     309    AtObj sizes = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qrySizes.sizes);
     310    wxChoice* sizeChoice = wxDynamicCast(FindWindow(ID_RandomSize), wxChoice);
     311    for (AtIter s = sizes["Sizes"]["item"]; s.defined(); ++s)
     312    {
     313        long tiles = 0;
     314        wxString(s["Tiles"]).ToLong(&tiles);
     315        sizeChoice->Append(wxString(s["Name"]), (void*)(intptr_t)tiles);
     316    }
     317    sizeChoice->SetSelection(0);
     318
     319    // Load the RMS script list
    398320    AtlasMessage::qGetRMSData qry;
    399321    qry.Post();
    400322    std::vector<std::string> scripts = *qry.data;
    401 
    402323    wxChoice* scriptChoice = wxDynamicCast(FindWindow(ID_RandomScript), wxChoice);
    403324    scriptChoice->Clear();
     
    415336void MapSidebar::OnMapReload()
    416337{
    417     m_MapSettings->ReadFromEngine();
     338    m_MapSettingsCtrl->ReadFromEngine();
    418339}
    419340
     
    519440    // since it's mixing data from three different sources
    520441
    521     AtObj settings = m_MapSettings->UpdateSettingsObject();
     442    AtObj settings = m_MapSettingsCtrl->UpdateSettingsObject();
    522443
    523444    AtObj scriptSettings = dynamic_cast<AtObjClientData*>(scriptChoice->GetClientObject(scriptChoice->GetSelection()))->GetValue();
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.h

    r9566 r9608  
    2020#include "wx/collpane.h"
    2121
    22 class MapSettings;
     22class MapSettingsControl;
    2323
    2424class MapSidebar : public Sidebar
     
    3333
    3434private:
    35     MapSettings* m_MapSettings;
     35    MapSettingsControl* m_MapSettingsCtrl;
    3636
    3737    void OnCollapse(wxCollapsiblePaneEvent& evt);
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Object/Object.cpp

    r9570 r9608  
    2121
    2222#include "Buttons/ToolButton.h"
     23#include "General/Datafile.h"
    2324#include "ScenarioEditor/ScenarioEditor.h"
    2425#include "ScenarioEditor/Tools/Common/ObjectSettings.h"
    2526#include "ScenarioEditor/Tools/Common/MiscState.h"
     27#include "AtlasScript/ScriptInterface.h"
    2628#include "VariationControl.h"
    2729
     
    3335{
    3436    ID_ObjectType = 1,
     37    ID_PlayerSelect,
    3538    ID_SelectObject,
    3639    ID_ToggleViewer,
     
    5659{
    5760public:
    58     ObjectBottomBar(wxWindow* parent, Observable<ObjectSettings>& objectSettings, ObjectSidebarImpl* p);
     61    ObjectBottomBar(wxWindow* parent, ScenarioEditor& scenarioEditor, Observable<ObjectSettings>& objectSettings, Observable<AtObj>& mapSettings, ObjectSidebarImpl* p);
    5962
    6063    void OnFirstDisplay();
     
    7679
    7780    ObjectSidebarImpl* p;
     81
     82    ScenarioEditor& m_ScenarioEditor;
    7883
    7984    DECLARE_EVENT_TABLE();
     
    118123    m_MainSizer->Add(new wxButton(this, ID_ToggleViewer, _("Switch to Actor Viewer")), wxSizerFlags().Expand());
    119124
    120     m_BottomBar = new ObjectBottomBar(bottomBarContainer, scenarioEditor.GetObjectSettings(), p);
     125    m_BottomBar = new ObjectBottomBar(bottomBarContainer, scenarioEditor, scenarioEditor.GetObjectSettings(), scenarioEditor.GetMapSettings(), p);
    121126
    122127    p->m_ToolConn = scenarioEditor.GetToolManager().GetCurrentTool().RegisterObserver(0, &ObjectSidebar::OnToolChange, this);
     
    220225{
    221226public:
    222     PlayerComboBox(wxWindow* parent, wxArrayString& choices, Observable<ObjectSettings>& objectSettings)
    223         : wxComboBox(parent, -1, choices[objectSettings.GetPlayerID()], wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY)
    224         , m_ObjectSettings(objectSettings)
    225     {
    226         m_Conn = m_ObjectSettings.RegisterObserver(1, &PlayerComboBox::OnObjectSettingsChange, this);
     227    PlayerComboBox(wxWindow* parent, Observable<ObjectSettings>& objectSettings, Observable<AtObj>& mapSettings)
     228        : wxComboBox(parent, ID_PlayerSelect, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, wxCB_READONLY)
     229        , m_ObjectSettings(objectSettings), m_MapSettings(mapSettings)
     230    {
     231        m_ObjectConn = m_ObjectSettings.RegisterObserver(1, &PlayerComboBox::OnObjectSettingsChange, this);
     232        m_MapConn = m_MapSettings.RegisterObserver(1, &PlayerComboBox::OnMapSettingsChange, this);
     233    }
     234
     235    void SetPlayers(wxArrayString& names)
     236    {
     237        m_Players = names;
     238        OnMapSettingsChange(m_MapSettings);
    227239    }
    228240
    229241private:
    230242
    231     ObservableScopedConnection m_Conn;
     243    ObservableScopedConnection m_ObjectConn;
    232244    Observable<ObjectSettings>& m_ObjectSettings;
     245    ObservableScopedConnection m_MapConn;
     246    Observable<AtObj>& m_MapSettings;
     247    wxArrayString m_Players;
    233248
    234249    void OnObjectSettingsChange(const ObjectSettings& settings)
     
    237252    }
    238253
     254    void OnMapSettingsChange(const AtObj& settings)
     255    {
     256        // Adjust displayed number of players
     257        Clear();
     258        size_t numPlayers = settings["PlayerData"]["item"].count();
     259        for (size_t i = 0; i <= numPlayers; ++i)
     260        {
     261            Append(m_Players[i]);
     262        }
     263
     264        if (m_ObjectSettings.GetPlayerID() > numPlayers)
     265        {
     266            // Invalid player
     267            SetSelection((long)numPlayers);
     268        }
     269        else
     270        {
     271            SetSelection((long)m_ObjectSettings.GetPlayerID());
     272        }
     273    }
     274
    239275    void OnSelect(wxCommandEvent& evt)
    240276    {
    241277        m_ObjectSettings.SetPlayerID(evt.GetInt());
    242         m_ObjectSettings.NotifyObserversExcept(m_Conn);
     278        m_ObjectSettings.NotifyObserversExcept(m_ObjectConn);
    243279    }
    244280
     
    251287//////////////////////////////////////////////////////////////////////////
    252288
    253 ObjectBottomBar::ObjectBottomBar(wxWindow* parent, Observable<ObjectSettings>& objectSettings, ObjectSidebarImpl* p)
    254     : wxPanel(parent, wxID_ANY), p(p)
     289ObjectBottomBar::ObjectBottomBar(wxWindow* parent, ScenarioEditor& scenarioEditor,  Observable<ObjectSettings>& objectSettings, Observable<AtObj>& mapSettings, ObjectSidebarImpl* p)
     290    : wxPanel(parent, wxID_ANY), p(p), m_ScenarioEditor(scenarioEditor)
    255291{
    256292    m_ViewerWireframe = false;
     
    277313    wxSizer* viewerAnimSizer = new wxStaticBoxSizer(wxVERTICAL, m_ViewerPanel, _("Animation"));
    278314
    279     wxString animChoices[] = {
    280         _T("idle"), _T("walk"), _T("run"), _T("melee"), _T("death"), _T("build"),
    281         _T("gather_fruit"), _T("gather_grain"), _T("gather_meat"), _T("gather_tree"),
    282         _T("gather_rock"), _T("gather_ore"), _T("gather_ruins"), _T("gather_treasure")
    283     }; // TODO: this list should come from the actor
    284     wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimation, wxDefaultPosition, wxDefaultSize, sizeof(animChoices)/sizeof(animChoices[0]), animChoices);
     315    // TODO: this list should come from the actor
     316    wxArrayString animChoices;
     317    AtObj anims (Datafile::ReadList("animations"));
     318    for (AtIter a = anims["item"]; a.defined(); ++a)
     319    {
     320        animChoices.Add(wxString(*a));
     321    }
     322    wxChoice* viewerAnimSelector = new wxChoice(m_ViewerPanel, ID_ViewerAnimation, wxDefaultPosition, wxDefaultSize, animChoices);
    285323    viewerAnimSelector->SetSelection(0);
    286324    viewerAnimSizer->Add(viewerAnimSelector, wxSizerFlags().Expand());
     
    302340    wxSizer* playerVariationSizer = new wxBoxSizer(wxVERTICAL);
    303341
    304     wxArrayString players;
    305     // TODO: get proper player names
    306     players.Add(_("Gaia"));
    307     players.Add(_("Player 1"));
    308     players.Add(_("Player 2"));
    309     players.Add(_("Player 3"));
    310     players.Add(_("Player 4"));
    311     players.Add(_("Player 5"));
    312     players.Add(_("Player 6"));
    313     players.Add(_("Player 7"));
    314     players.Add(_("Player 8"));
    315     wxComboBox* playerSelect = new PlayerComboBox(this, players, objectSettings);
    316342    // TODO: make this a wxChoice instead
     343    wxComboBox* playerSelect = new PlayerComboBox(this, objectSettings, mapSettings);
    317344    playerVariationSizer->Add(playerSelect);
    318345
     
    330357void ObjectBottomBar::OnFirstDisplay()
    331358{
     359    // We use messages here because the simulation is not init'd otherwise (causing a crash)
     360
     361    // Get player names
     362    wxArrayString players;
     363    AtlasMessage::qGetPlayerDefaults qryPlayers;
     364    qryPlayers.Post();
     365    AtObj playerData = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qryPlayers.defaults);
     366    AtObj playerDefs = *playerData["PlayerData"];
     367    for (AtIter p = playerDefs["item"]; p.defined(); ++p)
     368    {
     369        players.Add(wxString(p["Name"]));
     370    }
     371    wxDynamicCast(FindWindow(ID_PlayerSelect), PlayerComboBox)->SetPlayers(players);
     372
    332373    // Initialise the game with the default settings
    333374    POST_MESSAGE(SetViewParamB, (AtlasMessage::eRenderView::ACTOR, L"wireframe", m_ViewerWireframe));
  • ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp

    r9570 r9608  
    2121
    2222#include "Buttons/ToolButton.h"
    23 #include "General/Datafile.h"
    2423#include "ScenarioEditor/ScenarioEditor.h"
    2524#include "ScenarioEditor/Tools/Common/Brushes.h"
    2625#include "ScenarioEditor/Tools/Common/MiscState.h"
     26#include "AtlasScript/ScriptInterface.h"
    2727
    2828#include "GameInterface/Messages.h"
     
    139139    std::vector<size_t> sizeTiles;
    140140
    141     AtObj sizes(Datafile::ReadList("mapsizes"));
    142     for (AtIter s = sizes["size"]; s.defined(); ++s)
     141    // Load the map sizes list
     142    AtlasMessage::qGetMapSizes qrySizes;
     143    qrySizes.Post();
     144    AtObj sizes = AtlasObject::LoadFromJSON(m_ScenarioEditor.GetScriptInterface().GetContext(), *qrySizes.sizes);
     145    for (AtIter s = sizes["Sizes"]["item"]; s.defined(); ++s)
    143146    {
    144147        long tiles = 0;
    145         wxString(s["@tiles"]).ToLong(&tiles);
    146         sizeNames.Add(wxString(s["@name"]));
     148        wxString(s["Tiles"]).ToLong(&tiles);
     149        sizeNames.Add(wxString(s["Name"]));
    147150        sizeTiles.push_back((size_t)tiles);
    148151    }
Note: See TracChangeset for help on using the changeset viewer.