allow numbers for gfx constants, code cleanup

This commit is contained in:
garak 2022-10-13 21:03:26 -04:00
parent 00504817db
commit d433641bee
4 changed files with 11 additions and 17 deletions

View file

@ -215,7 +215,16 @@ QSet<QString> ObjectEvent::getExpectedFields() {
} }
void ObjectEvent::loadPixmap(Project *project) { void ObjectEvent::loadPixmap(Project *project) {
EventGraphics *eventGfx = project->eventGraphicsMap.value(gfx, nullptr); EventGraphics *eventGfx = project->eventGraphicsMap.value(this->gfx, nullptr);
if (!eventGfx) {
// Invalid gfx constant.
// If this is a number, try to use that instead.
bool ok;
int altGfx = this->gfx.toInt(&ok);
if (ok && (altGfx < project->gfxDefines.count())) {
eventGfx = project->eventGraphicsMap.value(project->gfxDefines.key(altGfx, "NULL"), nullptr);
}
}
if (!eventGfx || eventGfx->spritesheet.isNull()) { if (!eventGfx || eventGfx->spritesheet.isNull()) {
// No sprite associated with this gfx constant. // No sprite associated with this gfx constant.
// Use default sprite instead. // Use default sprite instead.

View file

@ -1973,7 +1973,6 @@ Tileset* Editor::getCurrentMapPrimaryTileset()
} }
QList<DraggablePixmapItem *> Editor::getObjects() { QList<DraggablePixmapItem *> Editor::getObjects() {
// TODO: why using this instead of map->getAllEvents()?
QList<DraggablePixmapItem *> list; QList<DraggablePixmapItem *> list;
for (QGraphicsItem *child : events_group->childItems()) { for (QGraphicsItem *child : events_group->childItems()) {
list.append(static_cast<DraggablePixmapItem *>(child)); list.append(static_cast<DraggablePixmapItem *>(child));
@ -2231,7 +2230,6 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) {
this->ui->toolButton_Select->setChecked(true); this->ui->toolButton_Select->setChecked(true);
} }
// TODO: why do the old objects not get cleared?
bool multiSelect = event->modifiers() & Qt::ControlModifier; bool multiSelect = event->modifiers() & Qt::ControlModifier;
if (!selectingEvent && !multiSelect && selected_events->length() > 1) { if (!selectingEvent && !multiSelect && selected_events->length() > 1) {
DraggablePixmapItem *first = selected_events->first(); DraggablePixmapItem *first = selected_events->first();

View file

@ -1946,10 +1946,6 @@ void MainWindow::updateObjects() {
} }
void MainWindow::updateSelectedObjects() { void MainWindow::updateSelectedObjects() {
// TODO: make events and/or frames list static? don't want to clear and
// re-add children frames if they are already there in a multi-select
// because QVBoxLayout::addWidget() is taking a lot of time
// TODO: frame->setActive(false) on old frames, (true) on active ones
QList<DraggablePixmapItem *> all_events = editor->getObjects(); QList<DraggablePixmapItem *> all_events = editor->getObjects();
QList<DraggablePixmapItem *> events; QList<DraggablePixmapItem *> events;
@ -2057,7 +2053,6 @@ void MainWindow::updateSelectedObjects() {
delete target->layout(); delete target->layout();
} }
// TODO: necessary? keep layout just remove widgets?
if (!events.empty()) { if (!events.empty()) {
QVBoxLayout *layout = new QVBoxLayout; QVBoxLayout *layout = new QVBoxLayout;
target->setLayout(layout); target->setLayout(layout);

View file

@ -110,9 +110,6 @@ void EventFrame::initCustomAttributesTable() {
this->layout_contents->addWidget(customAttributes); this->layout_contents->addWidget(customAttributes);
} }
// TODO: only do this when pixmap item is deleted (ie, when switching between maps or in displayMapEvents())
// perhaps connect to object destroyed signal from draggablepixamapitem to signal need reconnect
// ie, mark connections dirty and need redo
void EventFrame::connectSignals() { void EventFrame::connectSignals() {
this->connected = true; this->connected = true;
@ -123,7 +120,7 @@ void EventFrame::connectSignals() {
this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, delta, 0, this->spinner_x->getActionId())); this->event->getMap()->editHistory.push(new EventMove(QList<Event *>() << this->event, delta, 0, this->spinner_x->getActionId()));
} }
}); });
// TODO: make sure item is always existing here!, will need to reconnect this when item is deleted? is item ever deleted?
connect(this->event->getPixmapItem(), &DraggablePixmapItem::xChanged, this->spinner_x, &NoScrollSpinBox::setValue); connect(this->event->getPixmapItem(), &DraggablePixmapItem::xChanged, this->spinner_x, &NoScrollSpinBox::setValue);
this->spinner_y->disconnect(); this->spinner_y->disconnect();
@ -332,8 +329,6 @@ void ObjectFrame::connectSignals() {
}); });
} }
// TODO: how often do i really need to call findText() it seems slow
// when the frame has already been initialized, shouldn't need to again
void ObjectFrame::initialize() { void ObjectFrame::initialize() {
if (this->initialized) return; if (this->initialized) return;
@ -461,7 +456,6 @@ void CloneObjectFrame::initialize() {
// sprite // sprite
this->combo_sprite->setCurrentText(this->clone->getGfx()); this->combo_sprite->setCurrentText(this->clone->getGfx());
// TODO: update this with object gfx change?
// target id // target id
this->spinner_target_id->setMinimum(1); this->spinner_target_id->setMinimum(1);
@ -655,7 +649,6 @@ void TriggerFrame::populate(Project *project) {
// script // script
QStringList scriptLabels = this->trigger->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); QStringList scriptLabels = this->trigger->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
scriptLabels.removeDuplicates(); scriptLabels.removeDuplicates();
// TODO: are there any additional labels?
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);
@ -799,7 +792,6 @@ void SignFrame::populate(Project *project) {
// script // script
QStringList scriptLabels = this->sign->getMap()->eventScriptLabels() + project->getGlobalScriptLabels(); QStringList scriptLabels = this->sign->getMap()->eventScriptLabels() + project->getGlobalScriptLabels();
scriptLabels.removeDuplicates(); scriptLabels.removeDuplicates();
// TODO: are there any additional labels?
this->scriptCompleter = new QCompleter(scriptLabels, this); this->scriptCompleter = new QCompleter(scriptLabels, this);
this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive); this->scriptCompleter->setCaseSensitivity(Qt::CaseInsensitive);