/* * 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 "CoinListObjectUI.h" // Pokemod includes #include "../pokemod/CoinListObject.h" #include "../pokemod/Item.h" #include "../pokemod/Pokemod.h" #include "../pokemod/Species.h" Pokemodr::CoinListObjectUI::CoinListObjectUI(Pokemod::CoinListObject* object, QWidget* parent) : ObjectUI(parent), m_lastType(-1) { setupUi(this); setObjects(object, new Pokemod::CoinListObject(*object)); } Pokemodr::CoinListObjectUI::~CoinListObjectUI() { } void Pokemodr::CoinListObjectUI::initGui() { connect(varType, SIGNAL(activated(const int)), this, SLOT(setGui())); varType->addItems(Pokemod::CoinListObject::TypeStr); } void Pokemodr::CoinListObjectUI::setGui() { bool resetObjects = (static_cast(modified())->type() != m_lastType); varType->setCurrentIndex(static_cast(modified())->type()); m_lastType = static_cast(modified())->type(); if (resetObjects) { varObject->clear(); if (static_cast(modified())->type() == Pokemod::CoinListObject::Item) { for (int i = 0; i < pokemod()->itemCount(); ++i) { const Pokemod::Item* item = pokemod()->item(i); varObject->addItem(item->name(), item->id()); } varAmount->setMaximum(INT_MAX); } else { for (int i = 0; i < pokemod()->speciesCount(); ++i) { const Pokemod::Species* species = pokemod()->species(i); varObject->addItem(species->name(), species->id()); } varAmount->setMaximum(1); } } varObject->setCurrentIndex(varObject->findData(static_cast(modified())->object())); varAmount->setValue(static_cast(modified())->amount()); varCost->setValue(static_cast(modified())->cost()); } void Pokemodr::CoinListObjectUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void Pokemodr::CoinListObjectUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void Pokemodr::CoinListObjectUI::on_varType_activated(const int type) { static_cast(modified())->setType(type); } void Pokemodr::CoinListObjectUI::on_varObject_activated(const int obey) { static_cast(modified())->setObject(varObject->itemData(obey).toInt()); } void Pokemodr::CoinListObjectUI::on_varAmount_valueChanged(const int amount) { static_cast(modified())->setAmount(amount); } void Pokemodr::CoinListObjectUI::on_varCost_valueChanged(const int cost) { static_cast(modified())->setCost(cost); }