Skip to content

Commit 40eb381

Browse files
authored
Add files via upload
1 parent 0203df9 commit 40eb381

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4091
-0
lines changed

MapEditor.pro

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2016-02-16T00:25:31
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = MapEditor
12+
TEMPLATE = app
13+
14+
15+
SOURCES += main.cpp\
16+
mainwindow.cpp \
17+
tilebuffer.cpp \
18+
tilemap.cpp \
19+
tiledmapeditor.cpp \
20+
tileselector.cpp \
21+
animationbuffer.cpp \
22+
animationeditor.cpp \
23+
tiledselectablewidget.cpp
24+
25+
HEADERS += mainwindow.h \
26+
tilebuffer.h \
27+
tilemap.h \
28+
tiledmapeditor.h \
29+
tileselector.h \
30+
animationbuffer.h \
31+
animationeditor.h \
32+
tiledselectablewidget.h
33+
34+
FORMS += mainwindow.ui
35+
36+
RESOURCES += \
37+
menuicons.qrc

MapEditor.pro.user

+334
Large diffs are not rendered by default.

MapEditor.pro.user.2dd027d

+269
Large diffs are not rendered by default.

animationbuffer.cpp

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "animationbuffer.h"
2+
3+
AnimationBuffer::AnimationBuffer()
4+
{
5+
timer = new QTimer(this);
6+
connect(timer,SIGNAL(timeout()),this,SLOT(UpdateAnimations()));
7+
timer->start(ANIMATION_INTERVAL);
8+
}
9+
10+
AnimationBuffer::~AnimationBuffer()
11+
{
12+
timer->stop();
13+
}
14+
15+
void AnimationBuffer::setTileBuffer(TileBuffer *buf)
16+
{
17+
Tiles = buf;
18+
}
19+
20+
QPixmap *AnimationBuffer::getFramePixmap(int AnimationIndex)
21+
{
22+
if (AnimationIndex >= Animations.size()) return NULL;
23+
if (Animations[AnimationIndex].Frames.size() <= 0 ) return NULL;
24+
return Tiles->getTilePixmapAt( Animations[AnimationIndex].Frames[
25+
abs( Animations[AnimationIndex].CurrentFrame)]
26+
);
27+
}
28+
29+
QPixmap *AnimationBuffer::getFirstFramePixmap(int AnimationIndex)
30+
{
31+
if (AnimationIndex >= Animations.size()) return NULL;
32+
if (Animations[AnimationIndex].Frames.size() <= 0 ) return NULL;
33+
return Tiles->getTilePixmapAt( Animations[AnimationIndex].Frames[0]);
34+
}
35+
36+
void AnimationBuffer::syncAllAnimations()
37+
{
38+
for (int i=0; i<Animations.size(); i++)
39+
{
40+
Animations[i].delay = 0;
41+
Animations[i].CurrentFrame = 0;
42+
}
43+
}
44+
45+
void AnimationBuffer::clear()
46+
{
47+
Animations.clear();
48+
}
49+
50+
void AnimationBuffer::UpdateAnimations()
51+
{
52+
bool hasSomethingChanged = false;
53+
for (int i=0; i<Animations.size(); i++)
54+
{
55+
if (Animations[i].Fps <= 0) continue;
56+
57+
Animations[i].delay++;
58+
if (Animations[i].delay >= (1000/ANIMATION_INTERVAL)/(Animations[i].Fps))
59+
{
60+
Animations[i].delay = 0;
61+
Animations[i].CurrentFrame ++;
62+
if (Animations[i].CurrentFrame >= Animations[i].Frames.size())
63+
{
64+
if (Animations[i].isPingPong)
65+
Animations[i].CurrentFrame = - Animations[i].Frames.size()+2; else
66+
Animations[i].CurrentFrame = 0;
67+
}
68+
hasSomethingChanged = true;
69+
}
70+
}
71+
if (hasSomethingChanged) emit onAnimationUpdate();
72+
}

animationbuffer.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef ANIMATIONBUFFER_H
2+
#define ANIMATIONBUFFER_H
3+
4+
#include <QPixmap>
5+
#include <QVector>
6+
#include <QtCore>
7+
8+
#include "tilebuffer.h"
9+
10+
//enum AnimationType {
11+
12+
//};
13+
14+
#define ANIMATION_INTERVAL 20 //w milisekundach (1/1000s)
15+
16+
struct Animation {
17+
int Fps;
18+
QVector<int> Frames; //każda klatka animacji jest indexem z TileBuffer'a
19+
bool isPingPong;
20+
21+
int CurrentFrame;
22+
int delay;
23+
};
24+
25+
class AnimationBuffer : public QObject
26+
{
27+
Q_OBJECT
28+
29+
public:
30+
AnimationBuffer();
31+
~AnimationBuffer();
32+
void setTileBuffer(TileBuffer *buf);
33+
QPixmap *getFramePixmap(int AnimationIndex);
34+
QPixmap *getFirstFramePixmap(int AnimationIndex);
35+
void syncAllAnimations();
36+
void clear();
37+
38+
QVector<Animation> Animations;
39+
40+
private:
41+
TileBuffer *Tiles;
42+
QTimer *timer;
43+
44+
public slots:
45+
void UpdateAnimations();
46+
47+
signals:
48+
void onAnimationUpdate();
49+
};
50+
51+
52+
53+
#endif // ANIMATIONBUFFER_H

animationeditor.cpp

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#include "animationeditor.h"
2+
3+
AnimationEditor::AnimationEditor(QWidget *parent) : QWidget(parent)
4+
{
5+
isMouseHovering=false;
6+
isMouseDown = false;
7+
setMouseTracking(true);
8+
BiggestAnimation = 0;
9+
MouseHoverIndex =-1;
10+
PlusIconImg = new QPixmap(":/new/prefix1/add.png");
11+
}
12+
13+
AnimationEditor::~AnimationEditor()
14+
{
15+
16+
}
17+
18+
void AnimationEditor::setTileBuffer(TileBuffer *tilebuffer)
19+
{
20+
Buffer = tilebuffer;
21+
TileSizeX = Buffer->getTileSizeX();
22+
TileSizeY = Buffer->getTileSizeY();
23+
CursorTiles.clear();
24+
this->repaint();
25+
}
26+
27+
void AnimationEditor::setAnimationBuffer(AnimationBuffer *animbuffer)
28+
{
29+
AnimBuffer = animbuffer;
30+
CursorTiles.clear();
31+
this->repaint();
32+
}
33+
34+
void AnimationEditor::paintEvent(QPaintEvent *)
35+
{
36+
37+
QPainter pt(this);
38+
39+
pt.fillRect(this->rect(),Qt::SolidPattern);
40+
41+
pt.drawLine(TileSizeX + 3, 0, TileSizeX + 2, this->height());
42+
43+
if (Buffer->getCount() > 0)
44+
{
45+
if (AnimBuffer->Animations.size() > 0){
46+
47+
for (int i=0;i<AnimBuffer->Animations.size(); i++)
48+
{
49+
if (AnimBuffer->Animations[i].Frames.size() > 0)
50+
pt.drawPixmap(0,i*TileSizeY, *AnimBuffer->getFramePixmap(i));
51+
52+
for (int j=0;j<AnimBuffer->Animations[i].Frames.size(); j++)
53+
{
54+
pt.drawPixmap(j*TileSizeX + TileSizeX + 5, i*TileSizeY, *Buffer->getTilePixmapAt( AnimBuffer->Animations[i].Frames[j] ) );
55+
}
56+
}
57+
58+
pt.setPen(Qt::red);
59+
pt.drawRect(GrabbedAreaRect);
60+
if (isMouseHovering && ! isMouseDown)
61+
{
62+
//pt.setPen(Qt::darkRed);
63+
pt.drawRect(HiglightRect);
64+
}
65+
}
66+
}
67+
if (MouseHoverIndex >= 0)
68+
{
69+
if (MouseHoverIndex >= AnimBuffer->Animations.size())
70+
pt.drawPixmap(TileSizeX + 5 +TileSizeX/2 - PlusIconImg->width()/2
71+
, AnimBuffer->Animations.size()*TileSizeY + TileSizeY/2 - PlusIconImg->height()/2 ,
72+
*PlusIconImg);
73+
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);
77+
}
78+
}
79+
80+
void AnimationEditor::mouseMoveEvent(QMouseEvent *ev)
81+
{
82+
if (ev->pos().y()/TileSizeY >= AnimBuffer->Animations.size())
83+
{
84+
MouseHoverIndex = AnimBuffer->Animations.size();
85+
} else
86+
if (ev->pos().x() <= TileSizeX)
87+
{
88+
if (isMouseDown)
89+
{
90+
GrabbedAreaRect.setLeft(0/*(ev->x()/TileSizeX)*TileSizeX*/);
91+
GrabbedAreaRect.setTop((ev->y()/TileSizeY)*TileSizeY);
92+
GrabbedAreaRect.setWidth(TileSizeX);
93+
GrabbedAreaRect.setHeight(TileSizeY);
94+
}else
95+
{
96+
HiglightRect.setLeft(0/*(ev->x()/TileSizeX)*TileSizeX*/);
97+
HiglightRect.setTop((ev->y()/TileSizeY)*TileSizeY);
98+
HiglightRect.setWidth(TileSizeX);
99+
HiglightRect.setHeight(TileSizeY);
100+
}
101+
isMouseHovering = true;
102+
isMouseDown = ev->buttons() & Qt::LeftButton;
103+
MouseHoverIndex = -1;
104+
} else
105+
MouseHoverIndex = (ev->y()/TileSizeY);
106+
this->repaint();
107+
}
108+
109+
void AnimationEditor::mousePressEvent(QMouseEvent *ev)
110+
{
111+
if (ev->pos().x() <= TileSizeX)
112+
{
113+
if (ev->pos().y()/TileSizeY >= AnimBuffer->Animations.size()) return;
114+
GrabbedAreaRect.setLeft(0/*(ev->x()/TileSizeX)*TileSizeX*/);
115+
GrabbedAreaRect.setTop((ev->y()/TileSizeY)*TileSizeY);
116+
GrabbedAreaRect.setWidth(TileSizeX);
117+
GrabbedAreaRect.setHeight(TileSizeY);
118+
isMouseDown = true;
119+
} else
120+
if (CursorTiles.size() > 0 )
121+
{
122+
int index = ev->pos().y()/TileSizeY;
123+
124+
if (index >= AnimBuffer->Animations.size())
125+
{
126+
AddAnimation();
127+
index = AnimBuffer->Animations.size()-1;
128+
}
129+
130+
AddFramesFromCursorTo(index);
131+
132+
if ( BiggestAnimation < AnimBuffer->Animations[index].Frames.size() )
133+
BiggestAnimation = AnimBuffer->Animations[index].Frames.size();
134+
}
135+
136+
this->setMinimumHeight(TileSizeY*(AnimBuffer->Animations.size()+1));
137+
this->setMinimumWidth(TileSizeX + 5 + BiggestAnimation*TileSizeX);
138+
139+
MouseHoverIndex =-1;
140+
this->repaint();
141+
}
142+
143+
void AnimationEditor::mouseReleaseEvent(QMouseEvent *ev)
144+
{
145+
isMouseDown = false;
146+
if (ev->pos().x() <= TileSizeX)
147+
{
148+
emit onAnimationSelected();
149+
}
150+
MouseHoverIndex =-1;
151+
this->repaint();
152+
}
153+
154+
void AnimationEditor::leaveEvent(QEvent *)
155+
{
156+
isMouseHovering = false;
157+
isMouseDown = false;
158+
MouseHoverIndex =-1;
159+
this->repaint();
160+
}
161+
162+
void AnimationEditor::setCursorTiles(QVector<QVector<int> > cur)
163+
{
164+
CursorTiles.clear();
165+
CursorTiles = cur;
166+
}
167+
168+
int AnimationEditor::getSelectedAnimation()
169+
{
170+
if (AnimBuffer->Animations.size() <= 0) return -1;
171+
return GrabbedAreaRect.top()/TileSizeY;
172+
}
173+
174+
void AnimationEditor::AddAnimation()
175+
{
176+
AnimBuffer->Animations.append(Animation());
177+
int index = AnimBuffer->Animations.size()-1;
178+
AnimBuffer->Animations[index].Fps=5;
179+
AnimBuffer->Animations[index].isPingPong=false;
180+
AnimBuffer->Animations[index].CurrentFrame = 0;
181+
AnimBuffer->Animations[index].delay = 0;
182+
AnimBuffer->syncAllAnimations();
183+
}
184+
185+
void AnimationEditor::AddFramesFromCursorTo(int AnimationIndex)
186+
{
187+
for (int j=0;j<CursorTiles.size(); j++)
188+
for (int i=0;i<CursorTiles[j].size(); i++)
189+
{
190+
AnimBuffer->Animations[AnimationIndex].Frames.append(CursorTiles[j][i]);
191+
}
192+
AnimBuffer->syncAllAnimations();
193+
}
194+

0 commit comments

Comments
 (0)