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