/* * 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 "TileUI.h" // PokeModr includes #include "FileDialog.h" // Pokemod includes #include "../pokemod/Tile.h" #include "../pokemod/Pokemod.h" TileUI::TileUI(Tile* tile, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(tile, new Tile(*tile)); init(); } TileUI::~TileUI() { } void TileUI::initGui() { varAccessibility->addItems(Pokemod::DirectionStr.mid(0, Pokemod::D_End)); varHMType->addItems(Pokemod::HMStr); varForce->addItems(Tile::ForceStr); varDirection->addItems(Pokemod::DirectionStr.mid(0, Pokemod::D_End)); } void TileUI::refreshGui() { varHMUnder->clear(); for (int i = 0; i < static_cast(original()->pokemod())->tileCount(); ++i) { const Tile* tile = static_cast(original()->pokemod())->tile(i); if (tile->id() != static_cast(original())->id()) { varHMUnder->addItem(tile->sprite(), tile->name()); varHMUnder->setItemData(varHMUnder->count() - 1, tile->id()); } } } void TileUI::setGui() { varName->setText(static_cast(modified())->name()); varSprite->setIcon(static_cast(modified())->sprite()); for (int i = 0; i < varAccessibility->count(); ++i) varAccessibility->item(i)->setSelected(static_cast(modified())->from(i)); varWildChance->setValue(static_cast(modified())->wildChance()); boxHMs->setChecked((static_cast(modified())->hmType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varHMType->setCurrentIndex(static_cast(modified())->hmType()); varHMUnder->setCurrentIndex(varHMUnder->findData(static_cast(modified())->under())); varHMUnder->setEnabled((static_cast(modified())->hmType() == Pokemod::HM_Whirlpool) || (static_cast(modified())->hmType() == Pokemod::HM_Cut) || (static_cast(modified())->hmType() == Pokemod::HM_RockSmash)); boxForces->setChecked((static_cast(modified())->forceType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varForce->setCurrentIndex(static_cast(modified())->forceType()); varDirection->setCurrentIndex(static_cast(modified())->forceDirection()); varDirection->setEnabled((static_cast(modified())->forceType() != Tile::Stop) && (static_cast(modified())->forceType() != Tile::Slip)); } void TileUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void TileUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void TileUI::on_varName_textChanged(const QString& name) { static_cast(modified())->setName(name); } void TileUI::on_varSprite_pressed() { FileDialog* dialog = new FileDialog(QSize(64, 64)); if (dialog->exec() == QDialog::Accepted) { static_cast(modified())->setSprite(QPixmap(dialog->selectedFile())); setGui(); } delete dialog; } void TileUI::on_varWild_valueChanged(const Fraction& wildChance) { static_cast(modified())->setWildChance(wildChance); } void TileUI::on_varAccessibility_itemSelectionChanged() { for (int i = 0; i < varAccessibility->count(); ++i) { const QListWidgetItem* widgetItem = varAccessibility->item(i); static_cast(modified())->setFrom(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); } } void TileUI::on_boxHMs_toggled(const bool hm) { if (!hm) { varHMType->setCurrentIndex(-1); varHMUnder->setCurrentIndex(-1); setGui(); emit(changed(true)); } } void TileUI::on_varHMType_currentIndexChanged(const int hmType) { static_cast(modified())->setHmType(hmType); } void TileUI::on_varHMUnder_currentIndexChanged(const int hmUnder) { static_cast(modified())->setUnder(varHMUnder->itemData(hmUnder, Qt::UserRole).toInt()); } void TileUI::on_boxForces_toggled(const bool forces) { if (!forces) { varForce->setCurrentIndex(-1); varDirection->setCurrentIndex(-1); setGui(); emit(changed(true)); } } void TileUI::on_varForce_currentIndexChanged(const int force) { static_cast(modified())->setForceType(force); } void TileUI::on_varDirection_currentIndexChanged(const int direction) { static_cast(modified())->setForceDirection(direction); }