/* * Copyright 2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "MapUI.h" // Sigmod includes #include "../sigmod/Map.h" #include "../sigmod/MapWarp.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Sprite.h" #include "../sigmod/Tile.h" Sigmodr::MapUI::MapUI(Sigmod::Map* map, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(map, new Sigmod::Map(*map)); varMap->setMap(map); connect(varMap, SIGNAL(changed()), this, SIGNAL(changed())); } Sigmodr::MapUI::~MapUI() { } void Sigmodr::MapUI::initGui() { varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Outdoor], QVariant::fromValue(Sigmod::Map::Outdoor)); varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Dungeon], QVariant::fromValue(Sigmod::Map::Dungeon)); varType->addItem(Sigmod::Map::TypeStr[Sigmod::Map::Building], QVariant::fromValue(Sigmod::Map::Building)); } void Sigmodr::MapUI::refreshGui() { const bool blockedFlyWarp = varFlyWarp->blockSignals(true); varFlyWarp->clear(); for (int i = 0; i < qobject_cast(original())->warpCount(); ++i) { const Sigmod::MapWarp* warp = qobject_cast(original())->warp(i); varFlyWarp->addItem(warp->name(), warp->id()); } varFlyWarp->blockSignals(blockedFlyWarp); } void Sigmodr::MapUI::setGui() { varName->setText(qobject_cast(modified())->name()); boxFlyWarp->setChecked((qobject_cast(modified())->flyWarp() == -1) ? Qt::Unchecked : Qt::Checked); varFlyWarp->setCurrentIndex(varFlyWarp->findData(qobject_cast(modified())->flyWarp())); varType->setCurrentIndex(qobject_cast(modified())->type()); varMap->reset(); } void Sigmodr::MapUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::MapUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::MapUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); qobject_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Sigmodr::MapUI::on_boxFlyWarp_toggled() { qobject_cast(modified())->setFlyWarp(-1); } void Sigmodr::MapUI::on_varFlyWarp_activated(const int flyWarp) { qobject_cast(modified())->setFlyWarp(varFlyWarp->itemData(flyWarp).toInt()); } void Sigmodr::MapUI::on_varType_activated(const int type) { qobject_cast(modified())->setType(varType->itemData(type).value()); }