Minor changes in TileMap extension

This commit is contained in:
Florian Rival
2014-09-15 18:58:08 +02:00
parent 8f8acbf891
commit 2b8ce73ae2
12 changed files with 131 additions and 126 deletions

1
.gitignore vendored
View File

@@ -35,6 +35,7 @@
*.a
*.so
*.bc
*.debhelper.log
/Binaries/Output/Release_Linux/**
!/Binaries/Output/Release_Linux/Start Game Develop.sh
!/Binaries/Output/Release_Linux/CppPlatform/

View File

@@ -1,12 +0,0 @@
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms
dh_fixperms

View File

@@ -7,6 +7,7 @@
#if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
#include <wx/wx.h> //Must be placed first, otherwise we get nice errors relative to "cannot convert 'const TCHAR*'..." in wx/msw/winundef.h
#endif
#include <algorithm>
#include "GDCore/Tools/Localization.h"
#include "GDCore/BuiltinExtensions/SpriteExtension/SpriteObject.h"
#include "GDCore/BuiltinExtensions/SpriteExtension/Animation.h"
@@ -284,6 +285,12 @@ bool SpriteObject::RemoveAnimation(unsigned int nb)
return true;
}
void SpriteObject::SwapAnimations(unsigned int firstIndex, unsigned int secondIndex)
{
if ( firstIndex < animations.size() && secondIndex < animations.size() && firstIndex != secondIndex)
std::swap(animations[firstIndex], animations[secondIndex]);
}
/**
* Function destroying an extension Object.
* Game Develop does not delete directly extension object
@@ -303,4 +310,4 @@ gd::Object * CreateSpriteObject(std::string name)
return new SpriteObject(name);
}
}
}

View File

@@ -104,6 +104,11 @@ public :
*/
bool HasNoAnimations() const { return animations.empty(); }
/**
* \brief Swap the position of two sprites
*/
void SwapAnimations(unsigned int firstIndex, unsigned int secondIndex);
/**
* \brief Return a read-only reference to the vector containing all the animation of the object.
*/
@@ -127,4 +132,4 @@ GD_CORE_API void DestroySpriteObject(gd::Object * object);
GD_CORE_API gd::Object * CreateSpriteObject(std::string name);
}
#endif // GDCORE_SPRITEOBJECT_H
#endif // GDCORE_SPRITEOBJECT_H

View File

@@ -25,7 +25,7 @@ freely, subject to the following restrictions:
*/
/**
* Contributors to the extension:
* Florian Rival ( Minor changes, added offsets, HTML5 port )
* Florian Rival (Minor changes)
*/
#include "GDCpp/ExtensionBase.h"
@@ -222,4 +222,4 @@ extern "C" ExtensionBase * GD_EXTENSION_API CreateGDExtension() {
extern "C" void GD_EXTENSION_API DestroyGDExtension(ExtensionBase * p) {
delete p;
}
#endif
#endif

View File

@@ -30,10 +30,10 @@ freely, subject to the following restrictions:
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/dcbuffer.h>
#include <wx/textdlg.h>
#include <wx/textdlg.h>
#include <wx/settings.h>
#include <wx/config.h>
#include <wx/msgdlg.h>
#include <wx/msgdlg.h>
#include "GDCore/Tools/Log.h"
#include "GDCore/Tools/Localization.h"
@@ -208,13 +208,13 @@ void TileMapObjectEditor::OnTileInsertionModeChanged(wxCommandEvent& event)
void TileMapObjectEditor::OnClearLayerToolClicked(wxCommandEvent& event)
{
if(wxMessageBox(_("Are you sure to clear the whole layer ?"), _("Confirm"), wxYES_NO|wxICON_QUESTION|wxNO_DEFAULT, this) == wxYES)
if(wxMessageBox(_("Are you sure you want to clear the whole layer ?"), _("Confirm"), wxYES_NO|wxICON_QUESTION|wxNO_DEFAULT, this) == wxYES)
m_tileMapPanel->FillLayer(m_tileMapPanel->GetCurrentLayer(), -1);
}
void TileMapObjectEditor::OnFillLayerToolClicked(wxCommandEvent& event)
{
if(wxMessageBox(_("Are you sure to fill the whole layer with that tile ?"), _("Confirm"), wxYES_NO|wxICON_QUESTION|wxNO_DEFAULT, this) == wxYES)
if(wxMessageBox(_("Are you sure you want to fill the whole layer with that tile ?"), _("Confirm"), wxYES_NO|wxICON_QUESTION|wxNO_DEFAULT, this) == wxYES)
m_tileMapPanel->FillLayer(m_tileMapPanel->GetCurrentLayer(), m_tileSetPanel->GetSelectedTile());
}

View File

@@ -27,7 +27,7 @@ freely, subject to the following restrictions:
#include "TileMapPanel.h"
#include <iostream>
#include <algorithm>
#include <algorithm>
#include <wx/dcbuffer.h>
#include "GDCore/IDE/CommonBitmapManager.h"
@@ -89,9 +89,9 @@ void TileMapPanel::FillLayer(int layer, int tile)
if(!m_tilemap)
return;
for(int col = 0; col < m_tilemap->GetColumnsCount(); col++)
for (int col = 0; col < m_tilemap->GetColumnsCount(); col++)
{
for(int row = 0; row < m_tilemap->GetRowsCount(); row++)
for (int row = 0; row < m_tilemap->GetRowsCount(); row++)
{
m_tilemap->SetTile(layer, col, row, tile);
}
@@ -102,11 +102,11 @@ void TileMapPanel::FillLayer(int layer, int tile)
void TileMapPanel::Update()
{
if(!m_tilemap || !m_tileset)
if (!m_tilemap || !m_tileset)
return;
SetScrollRate(1, 1);
SetVirtualSize(m_tilemap->GetColumnsCount() * m_tileset->tileSize.x, m_tilemap->GetRowsCount() * m_tileset->tileSize.y);
Refresh();
}
@@ -154,7 +154,7 @@ void TileMapPanel::OnPaint(wxPaintEvent& event)
{
if(m_tilemap->GetTile(layer, col, row) == -1)
continue;
dc.DrawBitmap(m_tileset->GetTileBitmap(m_tilemap->GetTile(layer, col, row)), GetPositionOfTile(col, row).x, GetPositionOfTile(col, row).y);
}
}
@@ -166,10 +166,10 @@ void TileMapPanel::OnPaint(wxPaintEvent& event)
dc.SetBrush(wxBrush(wxColour(128, 128, 255, 128)));
dc.SetPen(wxPen(wxColor(128, 128, 255, 255), 1));
wxPoint topLeftPos(GetPositionOfTile(std::min(m_beginCol, m_endCol),
wxPoint topLeftPos(GetPositionOfTile(std::min(m_beginCol, m_endCol),
std::min(m_beginRow, m_endRow)));
wxPoint bottomRightPos(GetPositionOfTile(std::max(m_beginCol + 1, m_endCol + 1),
wxPoint bottomRightPos(GetPositionOfTile(std::max(m_beginCol + 1, m_endCol + 1),
std::max(m_beginRow + 1, m_endRow + 1)));
wxSize rectSize(bottomRightPos.x - topLeftPos.x, bottomRightPos.y - topLeftPos.y);
@@ -301,4 +301,4 @@ void TileMapPanel::GetTileAt(wxPoint position, int &tileCol, int &tileRow)
{
tileCol = (int)(position.x / m_tileset->tileSize.x);
tileRow = (int)(position.y / m_tileset->tileSize.y);
}
}

View File

@@ -31,8 +31,9 @@ class TileMap;
class TileSet;
/**
* Proxy for the TileMap
* Note: needed because the TileMap includes wxBitmap at edittime which is not avaible in the preview compilation.
* \brief Lightweight proxy class for the TileMap
* \note Needed because TileMap includes wx/bitmap.h which is not avaible when
* compiling for runtime.
*/
class TileMapProxy
{
@@ -51,8 +52,9 @@ private:
};
/**
* Proxy for the TileSet
* Note: needed for the same reason as the TileMap
* \brief Lightweight proxy class for the TileSet
* \note Needed because TileSet includes wx/bitmap.h which is not avaible when
* compiling for runtime.
*/
class TileSetProxy
{

View File

@@ -31,83 +31,85 @@ freely, subject to the following restrictions:
namespace TileMapExtension
{
sf::VertexArray GenerateVertexArray(TileSet &tileSet, TileMap &tileMap)
{
sf::VertexArray vertexArray(sf::Quads);
int tileWidth = tileSet.tileSize.x;
int tileHeight = tileSet.tileSize.y;
if(tileSet.IsDirty())
return vertexArray;
int vertexs = 0;
for(int layer = 0; layer < 3; layer++)
{
for(int col = 0; col < tileMap.GetColumnsCount(); col++)
{
for(int row = 0; row < tileMap.GetRowsCount(); row++)
{
if(tileMap.GetTile(layer, col, row) == -1)
continue;
vertexs += 4;
TileTextureCoords coords = tileSet.GetTileTextureCoords(tileMap.GetTile(layer, col, row));
{
sf::Vertex vertex(sf::Vector2f(col * tileWidth, row * tileHeight), coords.topLeft);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f(col * tileWidth, (row + 1) * tileHeight), coords.bottomLeft);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, (row + 1) * tileHeight), coords.bottomRight);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, row * tileHeight), coords.topRight);
vertexArray.append(vertex);
}
}
}
}
std::cout << "Generated " << vertexs << " vertexes." << std::endl;
sf::VertexArray GenerateVertexArray(TileSet &tileSet, TileMap &tileMap)
{
sf::VertexArray vertexArray(sf::Quads);
int tileWidth = tileSet.tileSize.x;
int tileHeight = tileSet.tileSize.y;
if(tileSet.IsDirty())
return vertexArray;
}
std::vector<Polygon2d> GenerateHitboxes(TileSet &tileSet, TileMap &tileMap)
int vertexs = 0;
for(int layer = 0; layer < 3; layer++)
{
std::vector<Polygon2d> hitboxes;
int tileWidth = tileSet.tileSize.x;
int tileHeight = tileSet.tileSize.y;
if(tileSet.IsDirty())
return hitboxes;
std::cout << "Generating Hitboxes" << std::endl;
for(int layer = 0; layer < 3; layer++)
for(int col = 0; col < tileMap.GetColumnsCount(); col++)
{
for(int col = 0; col < tileMap.GetColumnsCount(); col++)
for(int row = 0; row < tileMap.GetRowsCount(); row++)
{
for(int row = 0; row < tileMap.GetRowsCount(); row++)
{
if(tileMap.GetTile(layer, col, row) == -1 || !tileSet.GetTileHitbox(tileMap.GetTile(layer, col, row)).collidable)
continue;
if(tileMap.GetTile(layer, col, row) == -1)
continue;
std::vector<Polygon2d>::iterator newHitboxIt = hitboxes.insert(hitboxes.begin(), tileSet.GetTileHitbox(tileMap.GetTile(layer, col, row)).hitbox);
std::cout << "Collision mask at " << col * tileWidth << ";" << row * tileHeight << std::endl;
newHitboxIt->Move(col * tileWidth, row * tileHeight);
vertexs += 4;
TileTextureCoords coords = tileSet.GetTileTextureCoords(tileMap.GetTile(layer, col, row));
{
sf::Vertex vertex(sf::Vector2f(col * tileWidth, row * tileHeight), coords.topLeft);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f(col * tileWidth, (row + 1) * tileHeight), coords.bottomLeft);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, (row + 1) * tileHeight), coords.bottomRight);
vertexArray.append(vertex);
}
{
sf::Vertex vertex(sf::Vector2f((col + 1) * tileWidth, row * tileHeight), coords.topRight);
vertexArray.append(vertex);
}
}
}
std::cout << "Hitbox:OK" << std::endl;
return hitboxes;
}
std::cout << "Generated " << vertexs << " vertexes." << std::endl;
return vertexArray;
}
std::vector<Polygon2d> GenerateHitboxes(TileSet &tileSet, TileMap &tileMap)
{
std::vector<Polygon2d> hitboxes;
int tileWidth = tileSet.tileSize.x;
int tileHeight = tileSet.tileSize.y;
if(tileSet.IsDirty())
return hitboxes;
std::cout << "Generating Hitboxes" << std::endl;
for(int layer = 0; layer < 3; layer++)
{
for(int col = 0; col < tileMap.GetColumnsCount(); col++)
{
for(int row = 0; row < tileMap.GetRowsCount(); row++)
{
if(tileMap.GetTile(layer, col, row) == -1 || !tileSet.GetTileHitbox(tileMap.GetTile(layer, col, row)).collidable)
continue;
std::vector<Polygon2d>::iterator newHitboxIt = hitboxes.insert(hitboxes.begin(), tileSet.GetTileHitbox(tileMap.GetTile(layer, col, row)).hitbox);
std::cout << "Collision mask at " << col * tileWidth << ";" << row * tileHeight << std::endl;
newHitboxIt->Move(col * tileWidth, row * tileHeight);
}
}
}
std::cout << "Hitbox:OK" << std::endl;
return hitboxes;
}
}

View File

@@ -26,11 +26,11 @@ freely, subject to the following restrictions:
#include "TileSet.h"
#include <algorithm>
#include <algorithm>
#include <iostream>
#ifdef GD_IDE_ONLY
#include <wx/file.h>
#include <wx/filefn.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#endif
#include <GDCore/CommonTools.h>
@@ -91,8 +91,8 @@ void TileHitbox::UnserializeFrom(const gd::SerializerElement &element, sf::Vecto
hitbox.vertices.clear();
std::string defaultPolygonStr = "0;0|"
+ gd::ToString(defaultTileSize.x) + ";0|"
std::string defaultPolygonStr = "0;0|"
+ gd::ToString(defaultTileSize.x) + ";0|"
+ gd::ToString(defaultTileSize.x) + ";" + gd::ToString(defaultTileSize.y) + "|"
+ "0;" + gd::ToString(defaultTileSize.y);
std::string polygonStr = element.GetStringAttribute("polygon", defaultPolygonStr);
@@ -157,14 +157,14 @@ void TileSet::Generate()
{
m_dirty = true;
if(!m_tilesetTexture)
if (!m_tilesetTexture)
return;
std::cout << "Generating texture coords..." << std::endl;
//Calculates the number of rows and columns in the tileset
int columns(0), rows(0);
if(tileSize.x == 0 || tileSize.y == 0)
if (tileSize.x == 0 || tileSize.y == 0)
return;
columns = (m_tilesetTexture->texture.getSize().x + tileSpacing.x) / (tileSize.x + tileSpacing.x);
rows = (m_tilesetTexture->texture.getSize().y + tileSpacing.y) / (tileSize.y + tileSpacing.y);
@@ -203,7 +203,7 @@ void TileSet::Generate()
}
//Puts the default hitbox for new tiles (if there are more tiles than before)
if(GetTilesCount() > m_hitboxes.size())
if (GetTilesCount() > m_hitboxes.size())
m_hitboxes.insert(m_hitboxes.end(), (GetTilesCount()-m_hitboxes.size()), TileHitbox::Rectangle(tileSize));
std::cout << "OK" << std::endl;
@@ -213,7 +213,7 @@ void TileSet::Generate()
void TileSet::ResetHitboxes()
{
m_hitboxes.clear();
if(m_dirty)
if (m_dirty)
return;
m_hitboxes.assign(GetTilesCount(), TileHitbox::Rectangle(tileSize));
@@ -325,7 +325,7 @@ void TileSet::UnserializeFrom(const gd::SerializerElement &element)
tileSpacing.x = element.GetIntAttribute("tileSpacingX", 0);
tileSpacing.y = element.GetIntAttribute("tileSpacingY", 0);
if(element.HasChild("hitboxes"))
if (element.HasChild("hitboxes"))
{
gd::SerializerElement &tilesElem = element.GetChild("hitboxes");
tilesElem.ConsiderAsArrayOf("tileHitbox");

View File

@@ -34,7 +34,7 @@ freely, subject to the following restrictions:
#include "GDCore/Tools/HelpFileAccess.h"
#include "GDCpp/Project.h"
TileSetConfigurationEditor::TileSetConfigurationEditor(wxWindow* parent, TileSet &tileSet_, gd::Project & game_, gd::MainFrameWrapper & mainFrameWrapper) :
TileSetConfigurationEditor::TileSetConfigurationEditor(wxWindow* parent, TileSet &tileSet_, gd::Project & game_, gd::MainFrameWrapper & mainFrameWrapper) :
TileSetConfigurationEditorBase(parent),
tileSet(tileSet_),
game(game_),
@@ -44,16 +44,16 @@ TileSetConfigurationEditor::TileSetConfigurationEditor(wxWindow* parent, TileSet
resourcesEditorPnl->Refresh();
m_auimgr->AddPane( resourcesEditorPnl, wxAuiPaneInfo().Name( "ResourcesEditor" )
.Left()
.CloseButton(false)
.Caption(_( "Images bank's editor" ))
.MaximizeButton( true )
.MinimizeButton( false )
.CaptionVisible(true)
.MinSize(50, 50)
.BestSize(230,100)
.Show(true)
);
.Left()
.CloseButton(false)
.Caption(_( "Images bank's editor" ))
.MaximizeButton( true )
.MinimizeButton( false )
.CaptionVisible(true)
.MinSize(50, 50)
.BestSize(230,100)
.Show(true)
);
m_auimgr->Update();

View File

@@ -32,7 +32,7 @@ freely, subject to the following restrictions:
wxDEFINE_EVENT(TILE_SELECTION_CHANGED, TileSelectionEvent);
TileSetPanel::TileSetPanel(wxWindow* parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style) :
TileSetPanel::TileSetPanel(wxWindow* parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style) :
wxScrolledWindow(parent, id, pos, size, style),
m_tileset(NULL),
m_selectedCol(0),
@@ -59,7 +59,7 @@ int TileSetPanel::GetSelectedTile() const
{
if(!m_tileset || m_tileset->IsDirty())
return -1;
return m_tileset->GetTileIDFromCell(m_selectedCol, m_selectedRow);
}
@@ -137,7 +137,7 @@ void TileSetPanel::OnPaint(wxPaintEvent& event)
void TileSetPanel::OnLeftButtonPressed(wxMouseEvent& event)
{
if(!m_tileset || m_tileset->IsDirty())
if (!m_tileset || m_tileset->IsDirty())
return;
wxPoint mousePos = CalcUnscrolledPosition(event.GetPosition());
@@ -145,7 +145,7 @@ void TileSetPanel::OnLeftButtonPressed(wxMouseEvent& event)
//Select the tile
int selectedCol, selectedRow;
GetTileAt(mousePos, selectedCol, selectedRow);
if(selectedCol >= m_tileset->GetColumnsCount() || selectedRow >= m_tileset->GetRowsCount())
if (selectedCol >= m_tileset->GetColumnsCount() || selectedRow >= m_tileset->GetRowsCount())
return;
m_selectedCol = selectedCol;
m_selectedRow = selectedRow;
@@ -165,7 +165,7 @@ wxPoint TileSetPanel::GetPositionOfTile(int column, int row)
void TileSetPanel::GetTileAt(wxPoint position, int &tileCol, int &tileRow)
{
if(m_tileset->tileSize.x == 0 || m_tileset->tileSize.y == 0)
if (m_tileset->tileSize.x == 0 || m_tileset->tileSize.y == 0)
{
tileCol = 0;
tileRow = 0;
@@ -174,4 +174,4 @@ void TileSetPanel::GetTileAt(wxPoint position, int &tileCol, int &tileRow)
tileCol = (int)(position.x / (m_tileset->tileSize.x + m_tileset->tileSpacing.x));
tileRow = (int)(position.y / (m_tileset->tileSize.y + m_tileset->tileSpacing.y));
}
}