Skip to content

Commit 4c80d01

Browse files
committed
Adding major changes to the whole project.
1 parent 977d3ae commit 4c80d01

31 files changed

+2538
-412
lines changed

MapEditor.pro

+16-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
1111
TARGET = MapEditor
1212
TEMPLATE = app
1313

14+
TRANSLATIONS += \
15+
translations/MapEditor_en.ts \
16+
translations/MapEditor_pl.ts \
1417

1518
SOURCES += main.cpp\
1619
mainwindow.cpp \
@@ -20,7 +23,11 @@ SOURCES += main.cpp\
2023
tileselector.cpp \
2124
animationbuffer.cpp \
2225
animationeditor.cpp \
23-
tiledselectablewidget.cpp
26+
tiledselectablewidget.cpp \
27+
neweventdialog.cpp \
28+
eventmatrix.cpp \
29+
entirelevel.cpp \
30+
levelundostack.cpp
2431

2532
HEADERS += mainwindow.h \
2633
tilebuffer.h \
@@ -29,9 +36,14 @@ HEADERS += mainwindow.h \
2936
tileselector.h \
3037
animationbuffer.h \
3138
animationeditor.h \
32-
tiledselectablewidget.h
33-
34-
FORMS += mainwindow.ui
39+
tiledselectablewidget.h \
40+
neweventdialog.h \
41+
eventmatrix.h \
42+
entirelevel.h \
43+
levelundostack.h
44+
45+
FORMS += mainwindow.ui \
46+
neweventdialog.ui
3547

3648
RESOURCES += \
3749
menuicons.qrc

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
This is a general purpose map editor for 2D games. It can be used to create game levels using texture tiles. You can simply build a multi layer maps, create animations and add multiple events or annotations to the map.
33

44
[![YouTube video](http://img.youtube.com/vi/3WjJj5PqOD4/0.jpg)](http://www.youtube.com/watch?v=3WjJj5PqOD4)
5-
http://www.youtube.com/watch?v=3WjJj5PqOD4
5+
6+
http://www.youtube.com/watch?Compile=v
7+
8+
9+
### Compiling
610

711
This is Qt application, so to compile it, simply install QtCreator for your platform and open the MapEditor.pro file. Alternatively you can compile it using `qmake` and `make`.

animationbuffer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ AnimationBuffer::AnimationBuffer()
1010
AnimationBuffer::~AnimationBuffer()
1111
{
1212
timer->stop();
13+
this->clear();
1314
}
1415

1516
void AnimationBuffer::setTileBuffer(TileBuffer *buf)

animationeditor.cpp

+87-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ AnimationEditor::AnimationEditor(QWidget *parent) : QWidget(parent)
88
BiggestAnimation = 0;
99
MouseHoverIndex =-1;
1010
PlusIconImg = new QPixmap(":/new/prefix1/add.png");
11+
DeleteIconImg = new QPixmap(":/new/prefix1/ics/1455649000_Erase.png");
1112
}
1213

1314
AnimationEditor::~AnimationEditor()
@@ -28,34 +29,50 @@ void AnimationEditor::setAnimationBuffer(AnimationBuffer *animbuffer)
2829
{
2930
AnimBuffer = animbuffer;
3031
CursorTiles.clear();
32+
this->setMinimumHeight(TileSizeY*(AnimBuffer->Animations.size()+1));
33+
34+
BiggestAnimation=0;
35+
for(int i=0;i<AnimBuffer->Animations.count();i++)
36+
if ( BiggestAnimation < AnimBuffer->Animations[i].Frames.size() )
37+
BiggestAnimation = AnimBuffer->Animations[i].Frames.size();
38+
39+
this->setMinimumWidth(TileSizeX*2 + 5 + BiggestAnimation*TileSizeX);
3140
this->repaint();
3241
}
3342

3443
void AnimationEditor::paintEvent(QPaintEvent *)
3544
{
3645

3746
QPainter pt(this);
47+
QPixmap *frame;
3848

3949
pt.fillRect(this->rect(),Qt::SolidPattern);
4050

4151
pt.drawLine(TileSizeX + 3, 0, TileSizeX + 2, this->height());
4252

4353
if (Buffer->getCount() > 0)
4454
{
45-
if (AnimBuffer->Animations.size() > 0){
46-
55+
if (AnimBuffer->Animations.size() > 0)
56+
{
4757
for (int i=0;i<AnimBuffer->Animations.size(); i++)
4858
{
4959
if (AnimBuffer->Animations[i].Frames.size() > 0)
50-
pt.drawPixmap(0,i*TileSizeY, *AnimBuffer->getFramePixmap(i));
60+
{
61+
frame = AnimBuffer->getFramePixmap(i);
62+
if (frame != NULL)
63+
pt.drawPixmap(0,i*TileSizeY, *frame);
64+
}
5165

5266
for (int j=0;j<AnimBuffer->Animations[i].Frames.size(); j++)
5367
{
54-
pt.drawPixmap(j*TileSizeX + TileSizeX + 5, i*TileSizeY, *Buffer->getTilePixmapAt( AnimBuffer->Animations[i].Frames[j] ) );
68+
frame = Buffer->getTilePixmapAt( AnimBuffer->Animations[i].Frames[j] );
69+
if (frame != NULL)
70+
pt.drawPixmap(j*TileSizeX + TileSizeX + 5, i*TileSizeY, *frame );
5571
}
5672
}
5773

5874
pt.setPen(Qt::red);
75+
pt.setBrush(QColor(255,250,250,45));
5976
pt.drawRect(GrabbedAreaRect);
6077
if (isMouseHovering && ! isMouseDown)
6178
{
@@ -64,16 +81,30 @@ void AnimationEditor::paintEvent(QPaintEvent *)
6481
}
6582
}
6683
}
84+
6785
if (MouseHoverIndex >= 0)
6886
{
87+
6988
if (MouseHoverIndex >= AnimBuffer->Animations.size())
89+
{
7090
pt.drawPixmap(TileSizeX + 5 +TileSizeX/2 - PlusIconImg->width()/2
7191
, AnimBuffer->Animations.size()*TileSizeY + TileSizeY/2 - PlusIconImg->height()/2 ,
7292
*PlusIconImg);
93+
}
7394
else
74-
pt.drawPixmap(AnimBuffer->Animations[MouseHoverIndex].Frames.size()*TileSizeX+TileSizeX+5 + TileSizeX/2 - PlusIconImg->width()/2 ,
75-
MouseHoverIndex*TileSizeY + TileSizeY/2 - PlusIconImg->height()/2 ,
76-
*PlusIconImg);
95+
{
96+
if ((RemoveIndex < AnimBuffer->Animations[MouseHoverIndex].Frames.size()))
97+
{
98+
if ((RemoveIndex >=0))
99+
pt.drawPixmap(TileSizeX+5+ RemoveIndex*TileSizeX + TileSizeX/2 - DeleteIconImg->width()/2 ,
100+
MouseHoverIndex*TileSizeY + TileSizeY/2 - DeleteIconImg->height()/2 ,
101+
*DeleteIconImg);
102+
}
103+
else
104+
pt.drawPixmap(AnimBuffer->Animations[MouseHoverIndex].Frames.size()*TileSizeX+TileSizeX+5 + TileSizeX/2 - PlusIconImg->width()/2 ,
105+
MouseHoverIndex*TileSizeY + TileSizeY/2 - PlusIconImg->height()/2 ,
106+
*PlusIconImg);
107+
}
77108
}
78109
}
79110

@@ -82,7 +113,9 @@ void AnimationEditor::mouseMoveEvent(QMouseEvent *ev)
82113
if (ev->pos().y()/TileSizeY >= AnimBuffer->Animations.size())
83114
{
84115
MouseHoverIndex = AnimBuffer->Animations.size();
116+
HiglightRect.moveTo(-1000,-1000);
85117
} else
118+
{
86119
if (ev->pos().x() <= TileSizeX)
87120
{
88121
if (isMouseDown)
@@ -100,9 +133,15 @@ void AnimationEditor::mouseMoveEvent(QMouseEvent *ev)
100133
}
101134
isMouseHovering = true;
102135
isMouseDown = ev->buttons() & Qt::LeftButton;
103-
MouseHoverIndex = -1;
136+
// MouseHoverIndex = -1;
137+
RemoveIndex = -1;
104138
} else
105-
MouseHoverIndex = (ev->y()/TileSizeY);
139+
{
140+
RemoveIndex = ((ev->x()-TileSizeX-5)/TileSizeX);
141+
HiglightRect.moveTo(-1000,-1000);
142+
}
143+
MouseHoverIndex = (ev->y()/TileSizeY);
144+
}
106145
this->repaint();
107146
}
108147

@@ -117,24 +156,52 @@ void AnimationEditor::mousePressEvent(QMouseEvent *ev)
117156
GrabbedAreaRect.setHeight(TileSizeY);
118157
isMouseDown = true;
119158
} else
120-
if (CursorTiles.size() > 0 )
159+
{
160+
int index = ev->pos().y()/TileSizeY;
161+
162+
if (index < AnimBuffer->Animations.size())
121163
{
122-
int index = ev->pos().y()/TileSizeY;
164+
if (RemoveIndex >= AnimBuffer->Animations[index].Frames.size() )
165+
{
166+
if (CursorTiles.size() > 0 )
167+
{
168+
AddFramesFromCursorTo(index);
169+
emit editingFinished();
123170

124-
if (index >= AnimBuffer->Animations.size())
171+
if ( BiggestAnimation < AnimBuffer->Animations[index].Frames.size() )
172+
BiggestAnimation = AnimBuffer->Animations[index].Frames.size();
173+
}
174+
}
175+
else
176+
{
177+
if (RemoveIndex >= 0)
178+
{
179+
AnimBuffer->Animations[index].Frames.remove(RemoveIndex);
180+
if (AnimBuffer->Animations[index].Frames.size() <= 0)
181+
{
182+
AnimBuffer->Animations.remove(index);
183+
}
184+
emit editingFinished();
185+
AnimBuffer->syncAllAnimations();
186+
}
187+
}
188+
}
189+
else
190+
{
191+
// if (index >= AnimBuffer->Animations.size())
125192
{
126193
AddAnimation();
127194
index = AnimBuffer->Animations.size()-1;
195+
AddFramesFromCursorTo(index);
196+
emit editingFinished();
197+
if ( BiggestAnimation < AnimBuffer->Animations[index].Frames.size() )
198+
BiggestAnimation = AnimBuffer->Animations[index].Frames.size();
128199
}
129-
130-
AddFramesFromCursorTo(index);
131-
132-
if ( BiggestAnimation < AnimBuffer->Animations[index].Frames.size() )
133-
BiggestAnimation = AnimBuffer->Animations[index].Frames.size();
134200
}
201+
}
135202

136203
this->setMinimumHeight(TileSizeY*(AnimBuffer->Animations.size()+1));
137-
this->setMinimumWidth(TileSizeX + 5 + BiggestAnimation*TileSizeX);
204+
this->setMinimumWidth(TileSizeX*2 + 5 + BiggestAnimation*TileSizeX);
138205

139206
MouseHoverIndex =-1;
140207
this->repaint();
@@ -148,6 +215,7 @@ void AnimationEditor::mouseReleaseEvent(QMouseEvent *ev)
148215
emit onAnimationSelected();
149216
}
150217
MouseHoverIndex =-1;
218+
mouseMoveEvent(ev);
151219
this->repaint();
152220
}
153221

@@ -190,5 +258,6 @@ void AnimationEditor::AddFramesFromCursorTo(int AnimationIndex)
190258
AnimBuffer->Animations[AnimationIndex].Frames.append(CursorTiles[j][i]);
191259
}
192260
AnimBuffer->syncAllAnimations();
261+
emit editingFinished();
193262
}
194263

animationeditor.h

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class AnimationEditor : public QWidget
3030

3131
signals:
3232
void onAnimationSelected();
33+
void editingFinished();
3334

3435
public slots:
3536

@@ -48,7 +49,9 @@ public slots:
4849
QRect GrabbedAreaRect;
4950
int BiggestAnimation;
5051
int MouseHoverIndex; //-1 - brak, 0..animbuffer.size-1 - dodaj do animacji, animbuffer.size - dodaj animację
52+
int RemoveIndex; //-1 -dodaj, 0..animbuffer.size-1-usuń
5153
QPixmap *PlusIconImg;
54+
QPixmap *DeleteIconImg;
5255
};
5356

5457
#endif // ANIMATIONEDITOR_H

0 commit comments

Comments
 (0)