From 039f26f0c33448f96e1a677f33b889ec1ed98f1d Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sun, 11 Jun 2006 07:03:59 +0000 Subject: [PATCH] Fixed editor brokenness. # More useful environment (water, lighting) editing (now saved into the map files). Fixed no-PCH a bit. This was SVN commit r4002. --- build/premake/premake.lua | 2 + source/graphics/LightEnv.h | 5 - source/graphics/MapReader.cpp | 52 +++++++- source/graphics/MapReader.h | 5 +- source/graphics/MapWriter.cpp | 36 ++++-- source/graphics/MapWriter.h | 13 +- source/ps/World.cpp | 40 +++--- source/ps/XML/XMLWriter.cpp | 2 +- source/renderer/WaterManager.h | 1 + source/simulation/Entity.h | 2 +- .../atlas/AtlasUI/ActorEditor/ActorEditor.cpp | 2 +- .../AtlasUI/ArchiveViewer/ArchiveViewer.cpp | 1 + .../AtlasUI/ArchiveViewer/ArchiveViewer.h | 3 + .../AtlasUI/ArchiveViewer/FilePreviewer.cpp | 1 + .../ColourTester/ColourTesterColourCtrl.cpp | 2 + .../ColourTester/ColourTesterImageCtrl.h | 1 + .../CustomControls/Buttons/ToolButton.cpp | 2 + .../ColourDialog/ColourDialog.cpp | 55 ++++++++ .../ColourDialog/ColourDialog.h | 16 +++ .../EditableListCtrl/FieldEditCtrl.cpp | 1 + .../SnapSplitterWindow/SnapSplitterWindow.cpp | 2 +- .../AtlasUI/FileConverter/FileConverter.cpp | 2 + .../tools/atlas/AtlasUI/General/Observable.h | 6 + .../tools/atlas/AtlasUI/Misc/DLLInterface.cpp | 1 + source/tools/atlas/AtlasUI/Misc/stdafx.h | 35 ++++-- .../AtlasUI/ScenarioEditor/ScenarioEditor.cpp | 5 +- .../AtlasUI/ScenarioEditor/SectionLayout.h | 5 + .../Sections/Common/Sidebar.cpp | 2 +- .../Sections/Environment/Environment.cpp | 119 ++++++++++++++++-- .../ScenarioEditor/Sections/Map/Map.cpp | 2 + .../Sections/Terrain/Terrain.cpp | 2 + .../ScenarioEditor/Tools/Common/Brushes.cpp | 2 + .../ScenarioEditor/Tools/TransformObject.cpp | 2 +- .../Handlers/EnvironmentHandlers.cpp | 14 ++- .../GameInterface/Handlers/MapHandlers.cpp | 3 +- source/tools/atlas/GameInterface/Messages.h | 6 + source/tools/atlas/GameInterface/Register.cpp | 5 + .../tools/atlas/GameInterface/SharedTypes.h | 19 ++- 38 files changed, 402 insertions(+), 72 deletions(-) create mode 100644 source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp create mode 100644 source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h diff --git a/build/premake/premake.lua b/build/premake/premake.lua index 613174007b..49c5e83a6b 100755 --- a/build/premake/premake.lua +++ b/build/premake/premake.lua @@ -612,6 +612,8 @@ function setup_tests() tinsert(package.files, source_root.."lib/sysdep/win/error_dialog.rc") end + tinsert(package.buildflags, "use-library-dep-inputs") + package_create("test_1_run", "run") package.links = { "test_2_build" } -- This determines which project's executable to run diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index 48d9b74de6..18325b7915 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -27,11 +27,6 @@ class CLightEnv friend class CMapWriter; friend class CMapReader; friend class CXMLReader; -/* Trying to compile ScEd? ;) -friend class CEditorData; -friend class CMainFrame; -friend class CLightSettingsDlg; -*/ private: /** * m_Elevation: Height of sun above the horizon, in radians. diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 2918d63b01..2efb8ef3e3 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -14,6 +14,7 @@ #include "maths/MathUtil.h" #include "Camera.h" #include "graphics/Patch.h" +#include "renderer/WaterManager.h" #include "Model.h" #include "Terrain.h" @@ -35,16 +36,17 @@ CMapReader::CMapReader() // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful void CMapReader::LoadMap(const char* filename, CTerrain *pTerrain_, CUnitManager *pUnitMan_, - CLightEnv *pLightEnv_, CCamera *pCamera_) + WaterManager* pWaterMan_, CLightEnv *pLightEnv_, CCamera *pCamera_) { // latch parameters (held until DelayedLoadFinished) pTerrain = pTerrain_; pUnitMan = pUnitMan_; pLightEnv = pLightEnv_; pCamera = pCamera_; + pWaterMan = pWaterMan_; // [25ms] - unpacker.Read(filename,"PSMP"); + unpacker.Read(filename, "PSMP"); // check version if (unpacker.GetVersion() < FILE_READ_VERSION) { @@ -332,6 +334,13 @@ void CXMLReader::ReadEnvironment(XMBElement parent) EL(terrainambientcolour); EL(unitsambientcolour); EL(terrainshadowtransparency); + EL(water); + EL(waterbody); + EL(type); + EL(colour); + EL(height); + EL(shininess); + EL(waviness); AT(r); AT(g); AT(b); #undef AT #undef EL @@ -374,6 +383,45 @@ void CXMLReader::ReadEnvironment(XMBElement parent) { m_MapReader.m_LightEnv.SetTerrainShadowTransparency(CStr(element.getText()).ToFloat()); } + else if (element_name == el_water) + { + XERO_ITER_EL(element, waterbody) + { + debug_assert(waterbody.getNodeName() == el_waterbody); + XERO_ITER_EL(waterbody, waterelement) + { + int element_name = waterelement.getNodeName(); + if (element_name == el_type) + { + // TODO: implement this, when WaterManager supports it + } + else if (element_name == el_colour) + { + XMBAttributeList attrs = waterelement.getAttributes(); + m_MapReader.pWaterMan->m_WaterColor = CColor( + CStr(attrs.getNamedItem(at_r)).ToFloat(), + CStr(attrs.getNamedItem(at_g)).ToFloat(), + CStr(attrs.getNamedItem(at_b)).ToFloat(), + 1.f); + } + else if (element_name == el_height) + { + m_MapReader.pWaterMan->m_WaterHeight = CStr(waterelement.getText()).ToFloat(); + } + else if (element_name == el_shininess) + { + m_MapReader.pWaterMan->m_Shininess = CStr(waterelement.getText()).ToFloat(); + } + else if (element_name == el_waviness) + { + m_MapReader.pWaterMan->m_Waviness = CStr(waterelement.getText()).ToFloat(); + } + else + debug_warn("Invalid map XML data"); + } + + } + } else debug_warn("Invalid map XML data"); } diff --git a/source/graphics/MapReader.h b/source/graphics/MapReader.h index 0bf361c884..208f57239a 100644 --- a/source/graphics/MapReader.h +++ b/source/graphics/MapReader.h @@ -10,6 +10,7 @@ class CObjectEntry; class CTerrain; class CUnitManager; +class WaterManager; class CLightEnv; class CCamera; @@ -23,7 +24,8 @@ public: // constructor CMapReader(); // LoadMap: try to load the map from given file; reinitialise the scene to new data if successful - void LoadMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera); + void LoadMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, + WaterManager* pWaterMan, CLightEnv *pLightEnv, CCamera *pCamera); private: // UnpackTerrain: unpack the terrain from the input stream @@ -64,6 +66,7 @@ private: CFileUnpacker unpacker; CTerrain* pTerrain; CUnitManager* pUnitMan; + WaterManager* pWaterMan; CLightEnv* pLightEnv; CCamera* pCamera; CStr filename_xml; diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index 151eb2e01a..29e69b81bb 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -20,6 +20,7 @@ #include "graphics/Camera.h" #include "ps/Player.h" #include "graphics/Patch.h" +#include "renderer/WaterManager.h" #include "ps/XML/XMLWriter.h" #include "simulation/Entity.h" @@ -34,7 +35,8 @@ CMapWriter::CMapWriter() /////////////////////////////////////////////////////////////////////////////////////////////////// // SaveMap: try to save the current map to the given file -void CMapWriter::SaveMap(const char* filename, CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera) +void CMapWriter::SaveMap(const char* filename, CTerrain* pTerrain, CUnitManager* pUnitMan, + WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera) { CFilePacker packer(FILE_VERSION, "PSMP"); @@ -46,13 +48,13 @@ void CMapWriter::SaveMap(const char* filename, CTerrain *pTerrain, CUnitManager CStr filename_xml (filename); filename_xml = filename_xml.Left(filename_xml.Length()-4) + ".xml"; - WriteXML(filename_xml, pUnitMan, pLightEnv, pCamera); + WriteXML(filename_xml, pUnitMan, pWaterMan, pLightEnv, pCamera); } /////////////////////////////////////////////////////////////////////////////////////////////////// // GetHandleIndex: return the index of the given handle in the given list; or 0xffff if // handle isn't in list -static u16 GetHandleIndex(const Handle handle,const std::vector& handles) +static u16 GetHandleIndex(const Handle handle, const std::vector& handles) { const uint limit = MIN((uint)handles.size(), 0xFFFE); // paranoia for (uint i=0;iGetPatchesPerSide(); @@ -156,7 +158,7 @@ void CMapWriter::PackTerrain(CFilePacker& packer, CTerrain *pTerrain) -void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera) +void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera) { Handle h = vfs_open(filename, FILE_WRITE_TO_TARGET|FILE_NO_AIO); if (h <= 0) @@ -199,6 +201,23 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEn XML_Attribute("g", pLightEnv->m_UnitsAmbientColor.Y); XML_Attribute("b", pLightEnv->m_UnitsAmbientColor.Z); } + + { + XML_Element("Water"); + { + XML_Element("WaterBody"); + XML_Setting("Type", "default"); + { + XML_Element("Colour"); + XML_Attribute("r", pWaterMan->m_WaterColor.r); + XML_Attribute("g", pWaterMan->m_WaterColor.g); + XML_Attribute("b", pWaterMan->m_WaterColor.b); + } + XML_Setting("Height", pWaterMan->m_WaterHeight); + XML_Setting("Shininess", pWaterMan->m_Shininess); + XML_Setting("Waviness", pWaterMan->m_Waviness); + } + } } { @@ -306,7 +325,8 @@ void CMapWriter::WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEn /////////////////////////////////////////////////////////////////////////////////////////////////// // RewriteAllMaps -void CMapWriter::RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera) +void CMapWriter::RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan, + WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera) { VFSUtil::FileList files; VFSUtil::FindFiles("maps/scenarios", "*.pmp", files); @@ -315,13 +335,13 @@ void CMapWriter::RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLig { CMapReader* reader = new CMapReader; LDR_BeginRegistering(); - reader->LoadMap(*it, pTerrain, pUnitMan, pLightEnv, pCamera); + reader->LoadMap(*it, pTerrain, pUnitMan, pWaterMan, pLightEnv, pCamera); LDR_EndRegistering(); LDR_NonprogressiveLoad(); CStr n (*it); n.Replace("scenarios/", "scenarios/new/"); CMapWriter writer; - writer.SaveMap(n, pTerrain, pUnitMan, pLightEnv, pCamera); + writer.SaveMap(n, pTerrain, pUnitMan, pWaterMan, pLightEnv, pCamera); } } diff --git a/source/graphics/MapWriter.h b/source/graphics/MapWriter.h index 5d4b0e6fb9..f54d61969e 100644 --- a/source/graphics/MapWriter.h +++ b/source/graphics/MapWriter.h @@ -10,6 +10,7 @@ class CLightEnv; class CTerrain; class CUnitManager; class CCamera; +class WaterManager; class CMapWriter : public CMapIO { @@ -17,25 +18,25 @@ public: // constructor CMapWriter(); // SaveMap: try to save the current map to the given file - void SaveMap(const char* filename, CTerrain *pTerr, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera); + void SaveMap(const char* filename, CTerrain* pTerr, CUnitManager* pUnitMan, WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera); // RewriteAllMaps: for use during development: load/save all maps, to // update them to the newest format. - static void RewriteAllMaps(CTerrain *pTerrain, CUnitManager *pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera); + static void RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan, WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera); private: // PackMap: pack the current world into a raw data stream - void PackMap(CFilePacker& packer, CTerrain *pTerr, CUnitManager *pUnitMan, CLightEnv *pLightEnv); + void PackMap(CFilePacker& packer, CTerrain* pTerr, CUnitManager* pUnitMan, CLightEnv* pLightEnv); // PackTerrain: pack the terrain onto the end of the data stream - void PackTerrain(CFilePacker& packer, CTerrain *pTerrain); + void PackTerrain(CFilePacker& packer, CTerrain* pTerrain); // EnumTerrainTextures: build lists of textures used by map, and indices into this list // for each tile on the terrain - void EnumTerrainTextures(CTerrain *pTerrain, std::vector& textures, + void EnumTerrainTextures(CTerrain* pTerrain, std::vector& textures, std::vector& tileIndices); // WriteXML: output some other data (entities, etc) in XML format - void WriteXML(const char* filename, CUnitManager* pUnitMan, CLightEnv *pLightEnv, CCamera *pCamera); + void WriteXML(const char* filename, CUnitManager* pUnitMan, WaterManager* pWaterMan, CLightEnv* pLightEnv, CCamera* pCamera); }; #endif diff --git a/source/ps/World.cpp b/source/ps/World.cpp index 55f9132a4a..11e07f6eb2 100644 --- a/source/ps/World.cpp +++ b/source/ps/World.cpp @@ -1,27 +1,27 @@ #include "precompiled.h" -#include "CStr.h" -#include "CLogger.h" -#include "ps/Errors.h" - -#include "World.h" -#include "graphics/MapReader.h" -#include "Game.h" -#include "GameAttributes.h" -#include "graphics/Terrain.h" +#include "graphics/GameView.h" #include "graphics/LightEnv.h" +#include "graphics/MapReader.h" +#include "graphics/MapWriter.h" +#include "graphics/Terrain.h" +#include "graphics/Terrain.h" +#include "graphics/UnitManager.h" +#include "lib/timer.h" +#include "ps/CLogger.h" +#include "ps/CStr.h" +#include "ps/Errors.h" +#include "ps/Game.h" +#include "ps/GameAttributes.h" +#include "ps/Loader.h" +#include "ps/LoaderThunks.h" +#include "ps/World.h" +#include "renderer/Renderer.h" #include "simulation/BaseEntityCollection.h" #include "simulation/EntityManager.h" -#include "lib/timer.h" -#include "Loader.h" -#include "LoaderThunks.h" -#include "graphics/MapWriter.h" -#include "graphics/UnitManager.h" #include "simulation/EntityManager.h" -#include "simulation/Projectile.h" #include "simulation/LOSManager.h" -#include "graphics/GameView.h" -#include "graphics/Terrain.h" +#include "simulation/Projectile.h" #define LOG_CATEGORY "world" @@ -55,7 +55,8 @@ void CWorld::Initialize(CGameAttributes *pAttribs) try { reader = new CMapReader; - reader->LoadMap(mapfilename, m_Terrain, m_UnitManager, &g_LightEnv, m_pGame->GetView()->GetCamera()); + reader->LoadMap(mapfilename, m_Terrain, m_UnitManager, g_Renderer.GetWaterManager(), + &g_LightEnv, m_pGame->GetView()->GetCamera()); // fails immediately, or registers for delay loading } catch (PSERROR_File&) { delete reader; @@ -83,5 +84,6 @@ CWorld::~CWorld() void CWorld::RewriteMap() { - CMapWriter::RewriteAllMaps(m_Terrain, m_UnitManager, &g_LightEnv, m_pGame->GetView()->GetCamera()); + CMapWriter::RewriteAllMaps(m_Terrain, m_UnitManager, + g_Renderer.GetWaterManager(), &g_LightEnv, m_pGame->GetView()->GetCamera()); } diff --git a/source/ps/XML/XMLWriter.cpp b/source/ps/XML/XMLWriter.cpp index bbfd70b410..9df5403988 100644 --- a/source/ps/XML/XMLWriter.cpp +++ b/source/ps/XML/XMLWriter.cpp @@ -80,7 +80,7 @@ void XMLWriter_File::ElementEnd(const char* name, int type) switch (type) { case EL_ATTR: - m_Data += " />"; + m_Data += "/>"; break; case EL_TEXT: m_Data += ", public IEventTarget +class CEntity : public CJSComplex, public IEventTarget { friend class CEntityManager; diff --git a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp index 022e312b49..e74362630a 100644 --- a/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp +++ b/source/tools/atlas/AtlasUI/ActorEditor/ActorEditor.cpp @@ -7,7 +7,7 @@ #include "AtlasObject/AtlasObjectText.h" #include "General/Datafile.h" -#include "wx/ffile.h" +#include "wx/file.h" BEGIN_EVENT_TABLE(ActorEditor, AtlasWindow) EVT_MENU(ID_CreateEntity, OnCreateEntity) diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp index 4a931cfd3f..f193a98445 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.cpp @@ -17,6 +17,7 @@ using namespace DatafileIO; #include "wx/tooltip.h" #include "wx/msw/registry.h" #include "wx/progdlg.h" +#include "wx/regex.h" // Possible TODO: Remove duplication of AtlasWindow code diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h index ea5e3779b4..8d28cb691f 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/ArchiveViewer.h @@ -2,6 +2,9 @@ #include "SnapSplitterWindow/SnapSplitterWindow.h" #include "FilePreviewer.h" +#include "wx/filename.h" +#include "wx/listctrl.h" + namespace DatafileIO { class BARReader; diff --git a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp index c58a3a99c8..f809ddaaf4 100644 --- a/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp +++ b/source/tools/atlas/AtlasUI/ArchiveViewer/FilePreviewer.cpp @@ -6,6 +6,7 @@ #include "DatafileIO/DDT/DDT.h" #include "wx/sound.h" +#include "wx/image.h" using namespace DatafileIO; diff --git a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp index 868a17d829..17529bfec1 100644 --- a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp +++ b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp @@ -5,6 +5,8 @@ #include "ColourTesterImageCtrl.h" #include "General/Datafile.h" +#include "wx/colordlg.h" + #include ////////////////////////////////////////////////////////////////////////// diff --git a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.h b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.h index ad2484d6de..9a9085e3cf 100644 --- a/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.h +++ b/source/tools/atlas/AtlasUI/ColourTester/ColourTesterImageCtrl.h @@ -1,4 +1,5 @@ #include "wx/image.h" +#include "wx/filename.h" class ColourTesterImageCtrl : public wxWindow { diff --git a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp index 447ea257cf..a47950fb22 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp @@ -2,6 +2,8 @@ #include "wx/sysopt.h" #include "wx/wfstream.h" +#include "wx/filename.h" +#include "wx/image.h" #include "ToolButton.h" #include "ScenarioEditor/Tools/Common/Tools.h" diff --git a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp new file mode 100644 index 0000000000..93181d35b5 --- /dev/null +++ b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.cpp @@ -0,0 +1,55 @@ +#include "stdafx.h" + +#include "ColourDialog.h" + +ColourDialog::ColourDialog(wxWindow* parent, const wxString& customColourConfigPath, const wxColour& defaultColour) +: wxColourDialog(parent), m_ConfigPath(customColourConfigPath) +{ + GetColourData().SetColour(defaultColour); + + // Load custom colours from the config database + + wxRegEx re (_T("(\\d+) (\\d+) (\\d+)"), wxRE_ADVANCED); + + wxConfigBase* cfg = wxConfigBase::Get(false); + if (cfg) + { + for (int i = 0; i < 16; ++i) + { + wxString customColour; + if (cfg->Read(wxString::Format(_T("%s%d"), m_ConfigPath, i), &customColour) + && re.Matches(customColour)) + { + long r, g, b; + re.GetMatch(customColour, 1).ToLong(&r); + re.GetMatch(customColour, 2).ToLong(&g); + re.GetMatch(customColour, 3).ToLong(&b); + GetColourData().SetCustomColour(i, wxColour(r, g, b)); + } + } + } +} + +int ColourDialog::ShowModal() +{ + int ret = wxColourDialog::ShowModal(); + if (ret == wxID_OK) + { + // Save all the custom colours back into the config database + + wxConfigBase* cfg = wxConfigBase::Get(false); + if (cfg) + { + for (int i = 0; i < 16; ++i) + { + wxString name = wxString::Format(_T("%s%d"), m_ConfigPath, i); + wxColour colour = GetColourData().GetCustomColour(i); + + wxString customColour = wxString::Format(_T("%d %d %d"), colour.Red(), colour.Green(), colour.Blue()); + cfg->Write(name, customColour); + } + } + } + + return ret; +} \ No newline at end of file diff --git a/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h new file mode 100644 index 0000000000..fc7947c099 --- /dev/null +++ b/source/tools/atlas/AtlasUI/CustomControls/ColourDialog/ColourDialog.h @@ -0,0 +1,16 @@ +#ifndef COLOURDIALOG_H__ +#define COLOURDIALOG_H__ + +class ColourDialog : public wxColourDialog +{ +public: + // Typical customColourConfigPath would be "Scenario Editor/LightingColour" + ColourDialog(wxWindow* parent, const wxString& customColourConfigPath, const wxColour& defaultColour); + + int ShowModal(); + +private: + wxString m_ConfigPath; +}; + +#endif // COLOURDIALOG_H__ diff --git a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp index daf25b81cd..a3341507c7 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/EditableListCtrl/FieldEditCtrl.cpp @@ -18,6 +18,7 @@ #include "wx/colour.h" #include "wx/colordlg.h" #include "wx/regex.h" +#include "wx/filename.h" #include diff --git a/source/tools/atlas/AtlasUI/CustomControls/SnapSplitterWindow/SnapSplitterWindow.cpp b/source/tools/atlas/AtlasUI/CustomControls/SnapSplitterWindow/SnapSplitterWindow.cpp index 8ebf08759a..d8e5ec0a3a 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/SnapSplitterWindow/SnapSplitterWindow.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/SnapSplitterWindow/SnapSplitterWindow.cpp @@ -50,7 +50,7 @@ void SnapSplitterWindow::OnSashPosChanging(wxSplitterEvent& evt) } } -void SnapSplitterWindow::OnDoubleClick(wxSplitterEvent& evt) +void SnapSplitterWindow::OnDoubleClick(wxSplitterEvent& WXUNUSED(evt)) { int defaultPos = ConvertSashPosition(m_DefaultSashPosition); SetSashPosition(defaultPos); diff --git a/source/tools/atlas/AtlasUI/FileConverter/FileConverter.cpp b/source/tools/atlas/AtlasUI/FileConverter/FileConverter.cpp index 0181ab456c..1ed9ee4588 100644 --- a/source/tools/atlas/AtlasUI/FileConverter/FileConverter.cpp +++ b/source/tools/atlas/AtlasUI/FileConverter/FileConverter.cpp @@ -13,6 +13,8 @@ #include "wx/wfstream.h" #include "wx/progdlg.h" #include "wx/config.h" +#include "wx/regex.h" + using namespace DatafileIO; //#define QUIET diff --git a/source/tools/atlas/AtlasUI/General/Observable.h b/source/tools/atlas/AtlasUI/General/Observable.h index 96a6993103..398a1f64a3 100644 --- a/source/tools/atlas/AtlasUI/General/Observable.h +++ b/source/tools/atlas/AtlasUI/General/Observable.h @@ -43,6 +43,12 @@ public: } } + Observable* operator=(const T& rhs) + { + *dynamic_cast(this) = rhs; + return this; + } + private: boost::signal m_Signal; }; diff --git a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp index ae3fe4a750..5d069b2f0f 100644 --- a/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp +++ b/source/tools/atlas/AtlasUI/Misc/DLLInterface.cpp @@ -15,6 +15,7 @@ #include "wx/config.h" #include "wx/debugrpt.h" +#include "wx/file.h" // Shared memory allocation functions ATLASDLLIMPEXP void* ShareableMalloc(size_t n) diff --git a/source/tools/atlas/AtlasUI/Misc/stdafx.h b/source/tools/atlas/AtlasUI/Misc/stdafx.h index 128937984d..6226c38251 100644 --- a/source/tools/atlas/AtlasUI/Misc/stdafx.h +++ b/source/tools/atlas/AtlasUI/Misc/stdafx.h @@ -11,29 +11,40 @@ // Include useful wx headers #include "wx/wxprec.h" -#include "wx/listctrl.h" -#include "wx/docview.h" -#include "wx/cmdproc.h" -#include "wx/dialog.h" -#include "wx/filename.h" + #include "wx/artprov.h" -#include "wx/file.h" -#include "wx/dir.h" +#include "wx/cmdproc.h" #include "wx/colordlg.h" -#include "wx/regex.h" +#include "wx/config.h" +#include "wx/dialog.h" +#include "wx/dir.h" +#include "wx/dnd.h" +#include "wx/docview.h" +#include "wx/file.h" +#include "wx/filename.h" +#include "wx/filesys.h" +#include "wx/glcanvas.h" #include "wx/image.h" -#include "wx/splitter.h" +#include "wx/listctrl.h" +#include "wx/mstream.h" +#include "wx/progdlg.h" +#include "wx/regex.h" +#include "wx/sound.h" #include "wx/spinctrl.h" +#include "wx/splitter.h" +#include "wx/tooltip.h" +#include "wx/treectrl.h" +#include "wx/wfstream.h" +#include "wx/zstream.h" #include #include #include #include #include +#include +#include -#include -#include -#include #include #include diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index 2131b8e5f2..9555119266 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -5,6 +5,7 @@ #include "wx/glcanvas.h" #include "wx/evtloop.h" #include "wx/tooltip.h" +#include "wx/image.h" #include "General/AtlasEventLoop.h" @@ -202,6 +203,8 @@ public: return; } + // Global mouse event handlers (for camera motion) + if (evt.GetWheelRotation()) { float speed = 16.f; @@ -218,7 +221,7 @@ public: { if (evt.MiddleIsDown()) { - if (wxGetKeyState(WXK_CONTROL)) + if (wxGetKeyState(WXK_CONTROL) || evt.RightIsDown()) m_MouseState = ROTATEAROUND; else m_MouseState = SCROLL; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h index 1ad373c394..d1489cf070 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/SectionLayout.h @@ -1,3 +1,6 @@ +#ifndef SECTIONLAYOUT_H__ +#define SECTIONLAYOUT_H__ + class SnapSplitterWindow; class SectionLayout @@ -16,3 +19,5 @@ private: SnapSplitterWindow* m_HorizSplitter; SnapSplitterWindow* m_VertSplitter; }; + +#endif // SECTIONLAYOUT_H__ diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Common/Sidebar.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Common/Sidebar.cpp index 6081d2d778..752a3fa36d 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Common/Sidebar.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Common/Sidebar.cpp @@ -4,7 +4,7 @@ IMPLEMENT_DYNAMIC_CLASS(Sidebar, wxPanel) -Sidebar::Sidebar(wxWindow* sidebarContainer, wxWindow* bottomBarContainer) +Sidebar::Sidebar(wxWindow* sidebarContainer, wxWindow* WXUNUSED(bottomBarContainer)) : wxPanel(sidebarContainer), m_BottomBar(NULL), m_AlreadyDisplayed(false) { m_MainSizer = new wxBoxSizer(wxVERTICAL); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp index 0d3732d568..5ad976b922 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Environment/Environment.cpp @@ -4,24 +4,34 @@ #include "GameInterface/Messages.h" #include "ScenarioEditor/Tools/Common/Tools.h" +#include "General/Observable.h" +#include "CustomControls/ColourDialog/ColourDialog.h" -static AtlasMessage::sEnvironmentSettings g_EnvironmentSettings; +static Observable g_EnvironmentSettings; + +////////////////////////////////////////////////////////////////////////// class VariableSlider : public wxSlider { + static const int range = 1024; public: VariableSlider(wxWindow* parent, float& var, float min, float max) - : wxSlider(parent, -1, 0, 0, 1024), + : wxSlider(parent, -1, 0, 0, range), m_Var(var), m_Min(min), m_Max(max) { } void OnScroll(wxScrollEvent& evt) { - m_Var = m_Min + (m_Max - m_Min)*(evt.GetInt() / 1024.f); + m_Var = m_Min + (m_Max - m_Min)*(evt.GetInt() / (float)range); POST_COMMAND(SetEnvironmentSettings, (g_EnvironmentSettings)); } + void UpdateFromVar() + { + SetValue((m_Var - m_Min) * (range / (m_Max - m_Min))); + } + private: float& m_Var; float m_Min, m_Max; @@ -39,8 +49,100 @@ public: VariableSliderBox(wxWindow* parent, const wxString& label, float& var, float min, float max) : wxStaticBoxSizer(wxVERTICAL, parent, label) { - Add(new VariableSlider(parent, var, min, max)); + m_Slider = new VariableSlider(parent, var, min, max); + Add(m_Slider); + + m_Conn = g_EnvironmentSettings.RegisterObserver(0, &VariableSliderBox::OnSettingsChange, this); } + + ~VariableSliderBox() + { + m_Conn.disconnect(); + } + + void OnSettingsChange(const AtlasMessage::sEnvironmentSettings& WXUNUSED(env)) + { + m_Slider->UpdateFromVar(); + } + +private: + ObservableConnection m_Conn; + VariableSlider* m_Slider; +}; + +////////////////////////////////////////////////////////////////////////// + +class VariableColourButton : public wxButton +{ +public: + VariableColourButton(wxWindow* parent, AtlasMessage::Colour& colour) + : wxButton(parent, -1), m_Colour(colour) + { + UpdateDisplay(); + } + + void OnClick(wxCommandEvent& WXUNUSED(evt)) + { + ColourDialog dlg (NULL, _T("Scenario Editor/LightingColour"), + wxColour(m_Colour.r, m_Colour.g, m_Colour.b)); + + if (dlg.ShowModal() == wxID_OK) + { + wxColour& c = dlg.GetColourData().GetColour(); + m_Colour = AtlasMessage::Colour(c.Red(), c.Green(), c.Blue()); + UpdateDisplay(); + + POST_COMMAND(SetEnvironmentSettings, (g_EnvironmentSettings)); + } + } + + void UpdateDisplay() + { + SetBackgroundColour(wxColour(m_Colour.r, m_Colour.g, m_Colour.b)); + SetLabel(wxString::Format(_T("%02X %02X %02X"), m_Colour.r, m_Colour.g, m_Colour.b)); + + int y = 3*m_Colour.r + 6*m_Colour.g + 1*m_Colour.b; + if (y > 1280) + SetForegroundColour(wxColour(0, 0, 0)); + else + SetForegroundColour(wxColour(255, 255, 255)); + } + +private: + AtlasMessage::Colour& m_Colour; + + DECLARE_EVENT_TABLE(); +}; + +BEGIN_EVENT_TABLE(VariableColourButton, wxButton) + EVT_BUTTON(wxID_ANY, OnClick) +END_EVENT_TABLE() + +class VariableColourBox : public wxStaticBoxSizer +{ +public: + VariableColourBox(wxWindow* parent, const wxString& label, AtlasMessage::Colour& colour) + : wxStaticBoxSizer(wxVERTICAL, parent, label) + { + m_Button = new VariableColourButton(parent, colour); + Add(m_Button); + + m_Conn = g_EnvironmentSettings.RegisterObserver(0, &VariableColourBox::OnSettingsChange, this); + } + + ~VariableColourBox() + { + m_Conn.disconnect(); + } + + void OnSettingsChange(const AtlasMessage::sEnvironmentSettings& WXUNUSED(env)) + { + m_Button->UpdateDisplay(); + } + +private: + ObservableConnection m_Conn; + VariableColourButton* m_Button; }; ////////////////////////////////////////////////////////////////////////// @@ -48,14 +150,14 @@ public: EnvironmentSidebar::EnvironmentSidebar(wxWindow* sidebarContainer, wxWindow* bottomBarContainer) : Sidebar(sidebarContainer, bottomBarContainer) { - wxStaticText* warning = new wxStaticText(this, -1, _("WARNING: None of these settings are saved with the map, so don't do anything serious with them.")); - warning->Wrap(180); - m_MainSizer->Add(warning, wxSizerFlags().Border()); m_MainSizer->Add(new VariableSliderBox(this, _("Water height"), g_EnvironmentSettings.waterheight, 0, 1.2f)); m_MainSizer->Add(new VariableSliderBox(this, _("Water shininess"), g_EnvironmentSettings.watershininess, 0, 500.f)); m_MainSizer->Add(new VariableSliderBox(this, _("Water waviness"), g_EnvironmentSettings.waterwaviness, 0, 10.f)); m_MainSizer->Add(new VariableSliderBox(this, _("Sun rotation"), g_EnvironmentSettings.sunrotation, 0, 2*M_PI)); m_MainSizer->Add(new VariableSliderBox(this, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -M_PI/2, M_PI/2)); + m_MainSizer->Add(new VariableColourBox(this, _("Sun colour"), g_EnvironmentSettings.suncolour)); + m_MainSizer->Add(new VariableColourBox(this, _("Terrain ambient colour"), g_EnvironmentSettings.terraincolour)); + m_MainSizer->Add(new VariableColourBox(this, _("Object ambient colour"), g_EnvironmentSettings.unitcolour)); } void EnvironmentSidebar::OnFirstDisplay() @@ -64,5 +166,6 @@ void EnvironmentSidebar::OnFirstDisplay() qry.Post(); g_EnvironmentSettings = qry.settings; - // TODO: set defaults of controls + g_EnvironmentSettings.NotifyObservers(); + // TODO: reupdate everything when loading a new map... } diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp index e9a3517895..c44836bb3b 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp @@ -8,6 +8,8 @@ #include "GameInterface/Messages.h" +#include "wx/filename.h" + static void LoadMap(void*) { wxFileDialog dlg (NULL, wxFileSelectorPromptStr, Datafile::GetDataDirectory()+_T("/mods/official/maps/scenarios"), diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp index b27992745a..1f125b0aa4 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Terrain/Terrain.cpp @@ -12,6 +12,8 @@ #include "GameInterface/Messages.h" #include "wx/spinctrl.h" +#include "wx/listctrl.h" +#include "wx/image.h" class TextureNotebook; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.cpp index 7f60fc03fa..f69c1bbcaa 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Brushes.cpp @@ -4,6 +4,8 @@ #include "GameInterface/Messages.h" +#include "wx/spinctrl.h" + Brush::Brush() : m_Shape(CIRCLE), m_Size(4), m_Strength(1.f), m_IsActive(false) { diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp index 8a605cc699..9ab93941aa 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/TransformObject.cpp @@ -77,7 +77,7 @@ public: return false; } - bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type) + bool OnKey(TransformObject* WXUNUSED(obj), wxKeyEvent& evt, KeyEventType type) { if (type == KEY_CHAR && evt.GetKeyCode() == WXK_DELETE) { diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp index 2a9de45d18..e005bdc4f9 100644 --- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -23,7 +23,13 @@ sEnvironmentSettings GetSettings() s.sunrotation = g_LightEnv.GetRotation(); s.sunelevation = g_LightEnv.GetElevation(); - + +#define COLOUR(A, B) A = Colour(B.X*255, B.Y*255, B.Z*255) + COLOUR(s.suncolour, g_LightEnv.m_SunColor); + COLOUR(s.terraincolour, g_LightEnv.m_TerrainAmbientColor); + COLOUR(s.unitcolour, g_LightEnv.m_UnitsAmbientColor); +#undef COLOUR + return s; } @@ -36,6 +42,12 @@ void SetSettings(const sEnvironmentSettings& s) g_LightEnv.SetRotation(s.sunrotation); g_LightEnv.SetElevation(s.sunelevation); + +#define COLOUR(A, B) B = RGBColor(A.r/255.f, A.g/255.f, A.b/255.f) + COLOUR(s.suncolour, g_LightEnv.m_SunColor); + COLOUR(s.terraincolour, g_LightEnv.m_TerrainAmbientColor); + COLOUR(s.unitcolour, g_LightEnv.m_UnitsAmbientColor); +#undef COLOUR } BEGIN_COMMAND(SetEnvironmentSettings) diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index 8e571e4a4e..b009f46f60 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -12,6 +12,7 @@ #include "ps/Game.h" #include "ps/GameAttributes.h" #include "ps/Loader.h" +#include "renderer/Renderer.h" #include "simulation/LOSManager.h" #include "simulation/Simulation.h" @@ -108,7 +109,7 @@ MESSAGEHANDLER(SaveMap) CMapWriter writer; writer.SaveMap(CStr(L"maps/scenarios/" + *msg->filename), g_Game->GetWorld()->GetTerrain(), g_Game->GetWorld()->GetUnitManager(), - &g_LightEnv, g_Game->GetView()->GetCamera()); + g_Renderer.GetWaterManager(), &g_LightEnv, g_Game->GetView()->GetCamera()); } } diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 55e04ba298..59cd5fbe92 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -179,6 +179,12 @@ struct sEnvironmentSettings float sunrotation; // range 0..2pi float sunelevation; // range -pi/2 .. +pi/2 + Colour suncolour; + Colour terraincolour; + Colour unitcolour; + + // (Note: None of these are declared as Shareable<> - they're all sufficiently + // primitive types, and this makes it easier to manipulate them) }; SHAREABLE_STRUCT(sEnvironmentSettings); diff --git a/source/tools/atlas/GameInterface/Register.cpp b/source/tools/atlas/GameInterface/Register.cpp index 4a592cdb6e..5dd71e9384 100644 --- a/source/tools/atlas/GameInterface/Register.cpp +++ b/source/tools/atlas/GameInterface/Register.cpp @@ -1,5 +1,10 @@ #include "precompiled.h" +// We want to include Messages.h below, with some different definitions, +// even if it was already included by precompiled.h, so cheat and undefine +// its include-guard +#undef MESSAGES_H__ + #include "SharedTypes.h" #include "Shareable.h" diff --git a/source/tools/atlas/GameInterface/SharedTypes.h b/source/tools/atlas/GameInterface/SharedTypes.h index 8c3839277e..20d250b5d0 100644 --- a/source/tools/atlas/GameInterface/SharedTypes.h +++ b/source/tools/atlas/GameInterface/SharedTypes.h @@ -18,7 +18,7 @@ struct Position Position() : type(0) { type0.x = type0.y = type0.z = 0.f; } // Constructs a position with specified world-space coordinates - Position(float x_, float y_, float z_) : type(0) { type0.x = x_; type0.y = y_; type0.z = z_; } + Position(float x, float y, float z) : type(0) { type0.x = x; type0.y = y; type0.z = z; } // Constructs a position on the terrain underneath the screen-space coordinates Position(const wxPoint& pt); // (implementation in ScenarioEditor.cpp) @@ -44,9 +44,24 @@ struct Position void GetWorldSpace(CVector3D& vec, const CVector3D& prev) const; void GetScreenSpace(float& x, float& y) const; }; - SHAREABLE_STRUCT(Position); +struct Colour +{ + Colour() + : r(255), g(0), b(255) + { + } + + Colour(unsigned char r, unsigned char g, unsigned char b) + : r(r), g(g), b(b) + { + } + + unsigned char r, g, b; +}; +SHAREABLE_STRUCT(Colour); + } #endif // SHAREDTYPES_H__