/* * 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 "MapWarpUI.h" // Pokemod includes #include "../pokemod/Map.h" #include "../pokemod/MapWarp.h" #include "../pokemod/Pokemod.h" Pokemodr::MapWarpUI::MapWarpUI(Pokemod::MapWarp* warp, QWidget* parent) : ObjectUI(parent), m_lastMap(-1) { setupUi(this); setObjects(warp, new Pokemod::MapWarp(*warp)); } Pokemodr::MapWarpUI::~MapWarpUI() { } void Pokemodr::MapWarpUI::initGui() { varType->addItems(Pokemod::MapWarp::TypeStr); } void Pokemodr::MapWarpUI::refreshGui() { varCoordinate->setMaximum(static_cast(original()->parent())->size()); varToMap->clear(); for (int i = 0; i < pokemod()->mapCount(); ++i) { const Pokemod::Map* map = pokemod()->map(i); varToMap->addItem(map->name(), map->id()); } } void Pokemodr::MapWarpUI::setGui() { const bool resetWarps = (static_cast(modified())->toMap() != m_lastMap); varName->setText(static_cast(modified())->name()); varCoordinate->setValue(static_cast(modified())->coordinate()); varType->setCurrentIndex(static_cast(modified())->type()); varToMap->setCurrentIndex(varToMap->findData(static_cast(modified())->toMap())); m_lastMap = static_cast(modified())->toMap(); if (resetWarps) { varToWarp->clear(); const Pokemod::Map* map = pokemod()->mapById(static_cast(modified())->toMap()); if (map) { for (int i = 0; i < map->warpCount(); ++i) { const Pokemod::MapWarp* warp = map->warp(i); varToWarp->addItem(warp->name(), warp->id()); } } } varToWarp->setCurrentIndex(varToMap->findData(static_cast(modified())->toWarp())); varScript->setValue(static_cast(modified())->script()); } void Pokemodr::MapWarpUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void Pokemodr::MapWarpUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void Pokemodr::MapWarpUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); static_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Pokemodr::MapWarpUI::on_varCoordinate_valueChanged(const QPoint& coordinate) { static_cast(modified())->setCoordinate(coordinate); } void Pokemodr::MapWarpUI::on_varType_activated(const int type) { static_cast(modified())->setType(type); } void Pokemodr::MapWarpUI::on_varToMap_activated(const int toMap) { static_cast(modified())->setToMap(toMap); } void Pokemodr::MapWarpUI::on_varToWarp_activated(const int toWarp) { static_cast(modified())->setToWarp(toWarp); } void Pokemodr::MapWarpUI::on_varScript_valueChanged(const Pokemod::Script& script) { static_cast(modified())->setScript(script); }