make some performance improvements to event rendering
This commit is contained in:
parent
2a11760afd
commit
1151f9fc26
6 changed files with 52 additions and 52 deletions
|
@ -21,13 +21,12 @@ enum CommandId {
|
|||
ID_MagicFillCollision,
|
||||
ID_ResizeMap,
|
||||
ID_PaintBorder,
|
||||
ID_ScriptEditMap,
|
||||
ID_EventMove,
|
||||
ID_EventShift,
|
||||
ID_EventCreate,
|
||||
ID_EventDelete,
|
||||
ID_EventDuplicate,
|
||||
ID_EventSetData,
|
||||
ID_ScriptEditMap,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -110,7 +110,6 @@ private:
|
|||
signals:
|
||||
void mapChanged(Map *map);
|
||||
void mapNeedsRedrawing();
|
||||
void objectsChanged();
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
void updateSelectedEvents();
|
||||
void duplicateSelectedEvents();
|
||||
void redrawObject(DraggablePixmapItem *item);
|
||||
QList<DraggablePixmapItem *> *getObjects();
|
||||
QList<DraggablePixmapItem *> getObjects();
|
||||
|
||||
QGraphicsScene *scene = nullptr;
|
||||
QGraphicsPixmapItem *current_view = nullptr;
|
||||
|
@ -147,6 +147,8 @@ public:
|
|||
|
||||
bool selectingEvent = false;
|
||||
|
||||
void shouldReselectEvents();
|
||||
|
||||
private:
|
||||
void setConnectionItemsVisible(bool);
|
||||
void setBorderItemsVisible(bool, qreal = 1);
|
||||
|
|
|
@ -343,8 +343,6 @@ void EventCreate::redo() {
|
|||
editor->project->loadEventPixmaps(map->getAllEvents());
|
||||
editor->addMapEvent(event);
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
// select this event
|
||||
editor->selected_events->clear();
|
||||
editor->selectMapEvent(event->pixmapItem, false);
|
||||
|
@ -358,9 +356,7 @@ void EventCreate::undo() {
|
|||
}
|
||||
editor->selected_events->removeOne(event->pixmapItem);
|
||||
|
||||
editor->updateSelectedEvents();
|
||||
|
||||
map->objectsChanged();
|
||||
editor->shouldReselectEvents();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -399,12 +395,10 @@ void EventDelete::redo() {
|
|||
editor->selected_events->removeOne(event->pixmapItem);
|
||||
}
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
editor->selected_events->clear();
|
||||
if (nextSelectedEvent)
|
||||
editor->selected_events->append(nextSelectedEvent->pixmapItem);
|
||||
editor->updateSelectedEvents();
|
||||
editor->shouldReselectEvents();
|
||||
}
|
||||
|
||||
void EventDelete::undo() {
|
||||
|
@ -415,14 +409,12 @@ void EventDelete::undo() {
|
|||
editor->addMapEvent(event);
|
||||
}
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
// select these events
|
||||
editor->selected_events->clear();
|
||||
for (Event *event : selectedEvents) {
|
||||
editor->selected_events->append(event->pixmapItem);
|
||||
}
|
||||
editor->updateSelectedEvents();
|
||||
editor->shouldReselectEvents();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
@ -434,7 +426,6 @@ void EventDelete::undo() {
|
|||
EventDuplicate::EventDuplicate(Editor *editor, Map *map,
|
||||
QList<Event *> selectedEvents,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
//
|
||||
setText("Duplicate Event");
|
||||
|
||||
this->editor = editor;
|
||||
|
@ -458,14 +449,12 @@ void EventDuplicate::redo() {
|
|||
editor->addMapEvent(event);
|
||||
}
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
// select these events
|
||||
editor->selected_events->clear();
|
||||
for (Event *event : selectedEvents) {
|
||||
editor->selected_events->append(event->pixmapItem);
|
||||
}
|
||||
editor->updateSelectedEvents();
|
||||
editor->shouldReselectEvents();
|
||||
}
|
||||
|
||||
void EventDuplicate::undo() {
|
||||
|
@ -478,7 +467,7 @@ void EventDuplicate::undo() {
|
|||
editor->selected_events->removeOne(event->pixmapItem);
|
||||
}
|
||||
|
||||
map->objectsChanged();
|
||||
editor->shouldReselectEvents();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <QDir>
|
||||
#include <math.h>
|
||||
|
||||
static bool selectingEvent = false;
|
||||
static bool selectNewEvents = false;
|
||||
|
||||
Editor::Editor(Ui::MainWindow* ui)
|
||||
{
|
||||
|
@ -23,6 +23,16 @@ Editor::Editor(Ui::MainWindow* ui)
|
|||
this->settings = new Settings();
|
||||
this->playerViewRect = new MovableRect(&this->settings->playerViewRectEnabled, 30 * 8, 20 * 8, qRgb(255, 255, 255));
|
||||
this->cursorMapTileRect = new CursorTileRect(&this->settings->cursorTileRectEnabled, qRgb(255, 255, 255));
|
||||
|
||||
/// Instead of updating the selected events after every single undo action
|
||||
/// (eg when the user rolls back several at once), only reselect events when
|
||||
/// the index is changed.
|
||||
connect(&editGroup, &QUndoGroup::indexChanged, [this](int) {
|
||||
if (selectNewEvents) {
|
||||
updateSelectedEvents();
|
||||
selectNewEvents = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Editor::~Editor()
|
||||
|
@ -1097,7 +1107,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
|
||||
QList<Event *> selectedEvents;
|
||||
|
||||
for (DraggablePixmapItem *item : *(getObjects())) {
|
||||
for (DraggablePixmapItem *item : getObjects()) {
|
||||
selectedEvents.append(item->event);
|
||||
}
|
||||
selection_origin = QPoint(x, y);
|
||||
|
@ -1760,16 +1770,10 @@ Tileset* Editor::getCurrentMapPrimaryTileset()
|
|||
return project->getTileset(tilesetLabel);
|
||||
}
|
||||
|
||||
QList<DraggablePixmapItem *> *Editor::getObjects() {
|
||||
QList<DraggablePixmapItem *> *list = new QList<DraggablePixmapItem *>;
|
||||
for (Event *event : map->getAllEvents()) {
|
||||
for (QGraphicsItem *child : events_group->childItems()) {
|
||||
DraggablePixmapItem *item = static_cast<DraggablePixmapItem *>(child);
|
||||
if (item->event == event) {
|
||||
list->append(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
QList<DraggablePixmapItem *> Editor::getObjects() {
|
||||
QList<DraggablePixmapItem *> list;
|
||||
for (QGraphicsItem *child : events_group->childItems()) {
|
||||
list.append(static_cast<DraggablePixmapItem *>(child));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -1792,10 +1796,15 @@ void Editor::redrawObject(DraggablePixmapItem *item) {
|
|||
}
|
||||
}
|
||||
|
||||
void Editor::shouldReselectEvents() {
|
||||
selectNewEvents = true;
|
||||
}
|
||||
|
||||
void Editor::updateSelectedEvents() {
|
||||
for (DraggablePixmapItem *item : *(getObjects())) {
|
||||
for (DraggablePixmapItem *item : getObjects()) {
|
||||
redrawObject(item);
|
||||
}
|
||||
|
||||
emit selectedObjectsChanged();
|
||||
}
|
||||
|
||||
|
@ -1870,6 +1879,11 @@ void Editor::deleteEvent(Event *event) {
|
|||
Map *map = project->getMap(event->get("map_name"));
|
||||
if (map) {
|
||||
map->removeEvent(event);
|
||||
if (event->pixmapItem) {
|
||||
events_group->removeFromGroup(event->pixmapItem);
|
||||
delete event->pixmapItem;
|
||||
event->pixmapItem = nullptr;
|
||||
}
|
||||
}
|
||||
//selected_events->removeAll(event);
|
||||
//updateSelectedObjects();
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include <QSignalBlocker>
|
||||
#include <QSet>
|
||||
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
|
@ -533,7 +535,6 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
|
||||
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||
connect(editor->map, SIGNAL(mapNeedsRedrawing()), this, SLOT(onMapNeedsRedrawing()));
|
||||
connect(editor->map, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
|
||||
|
||||
setRecentMap(map_name);
|
||||
updateMapList();
|
||||
|
@ -616,16 +617,13 @@ void MainWindow::openWarpMap(QString map_name, QString warp_num) {
|
|||
QList<Event*> warp_events = editor->map->events["warp_event_group"];
|
||||
if (warp_events.length() > warpNum) {
|
||||
Event *warp_event = warp_events.at(warpNum);
|
||||
QList<DraggablePixmapItem *> *all_events = editor->getObjects();
|
||||
for (DraggablePixmapItem *item : *all_events) {
|
||||
for (DraggablePixmapItem *item : editor->getObjects()) {
|
||||
if (item->event == warp_event) {
|
||||
editor->selected_events->clear();
|
||||
editor->selected_events->append(item);
|
||||
editor->updateSelectedEvents();
|
||||
}
|
||||
}
|
||||
|
||||
delete all_events;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1497,7 +1495,7 @@ void MainWindow::updateObjects() {
|
|||
bool hasBGs = false;
|
||||
bool hasHealspots = false;
|
||||
|
||||
for (DraggablePixmapItem *item : *editor->getObjects())
|
||||
for (DraggablePixmapItem *item : editor->getObjects())
|
||||
{
|
||||
QString event_type = item->event->get("event_type");
|
||||
|
||||
|
@ -1548,18 +1546,17 @@ void MainWindow::updateObjects() {
|
|||
|
||||
// Should probably just pass layout and let the editor work it out
|
||||
void MainWindow::updateSelectedObjects() {
|
||||
QList<DraggablePixmapItem *> *all_events = editor->getObjects();
|
||||
QList<DraggablePixmapItem *> *events = nullptr;
|
||||
QList<DraggablePixmapItem *> all_events = editor->getObjects();
|
||||
QList<DraggablePixmapItem *> events;
|
||||
|
||||
if (editor->selected_events && editor->selected_events->length()) {
|
||||
events = editor->selected_events;
|
||||
events = *editor->selected_events;
|
||||
} else {
|
||||
events = new QList<DraggablePixmapItem*>;
|
||||
if (all_events && all_events->length()) {
|
||||
DraggablePixmapItem *selectedEvent = all_events->first();
|
||||
if (all_events.length()) {
|
||||
DraggablePixmapItem *selectedEvent = all_events.first();
|
||||
editor->selected_events->append(selectedEvent);
|
||||
editor->redrawObject(selectedEvent);
|
||||
events->append(selectedEvent);
|
||||
events.append(selectedEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1571,7 +1568,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
bool quantityEnabled = projectConfig.getHiddenItemQuantityEnabled();
|
||||
bool underfootEnabled = projectConfig.getHiddenItemRequiresItemfinderEnabled();
|
||||
bool respawnDataEnabled = projectConfig.getHealLocationRespawnDataEnabled();
|
||||
for (DraggablePixmapItem *item : *events) {
|
||||
for (DraggablePixmapItem *item : events) {
|
||||
EventPropertiesFrame *frame = new EventPropertiesFrame(item->event);
|
||||
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
|
@ -1607,7 +1604,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
else { event_offs = 1; }
|
||||
frame->ui->label_name->setText(QString("%1 Id").arg(event_type));
|
||||
|
||||
if (events->count() == 1)
|
||||
if (events.count() == 1)
|
||||
{
|
||||
frame->ui->spinBox_index->setValue(editor->project->getMap(map_name)->events.value(event_group_type).indexOf(item->event) + event_offs);
|
||||
frame->ui->spinBox_index->setMinimum(event_offs);
|
||||
|
@ -1901,9 +1898,9 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
isProgrammaticEventTabChange = true;
|
||||
|
||||
if (events->length() == 1)
|
||||
if (events.length() == 1)
|
||||
{
|
||||
QString event_group_type = (*events)[0]->event->get("event_group_type");
|
||||
QString event_group_type = events[0]->event->get("event_group_type");
|
||||
|
||||
if (event_group_type == "object_event_group") {
|
||||
scrollTarget = ui->scrollArea_Objects;
|
||||
|
@ -1932,7 +1929,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
}
|
||||
ui->tabWidget_EventType->removeTab(ui->tabWidget_EventType->indexOf(ui->tab_Multiple));
|
||||
}
|
||||
else if (events->length() > 1)
|
||||
else if (events.length() > 1)
|
||||
{
|
||||
ui->tabWidget_EventType->addTab(ui->tab_Multiple, "Multiple");
|
||||
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Multiple);
|
||||
|
@ -1940,7 +1937,7 @@ void MainWindow::updateSelectedObjects() {
|
|||
|
||||
isProgrammaticEventTabChange = false;
|
||||
|
||||
if (events->length() != 0)
|
||||
if (events.length() != 0)
|
||||
{
|
||||
if (target->children().length())
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue