/* * 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 "CoinListUI.h" // Pokemod includes #include "../pokemod/CoinList.h" #include "../pokemod/Item.h" #include "../pokemod/ItemEffect.h" #include "../pokemod/Pokemod.h" CoinListUI::CoinListUI(CoinList* coinList, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(coinList, new CoinList(*coinList)); init(); } CoinListUI::~CoinListUI() { } void CoinListUI::refreshGui() { varValue->clear(); for (int i = 0; i < static_cast(original()->pokemod())->itemCount(); ++i) { const Item* item = static_cast(original()->pokemod())->item(i); for (int j = 0; j < item->effectCount(); ++j) { const ItemEffect* effect = item->effect(j); if (effect->effect() == ItemEffect::E_CoinCase) { varValue->addItem(item->name()); varValue->setItemData(varValue->count() - 1, effect->value1()); } } } } void CoinListUI::setGui() { varName->setText(static_cast(modified())->name()); varValue->setCurrentIndex(varValue->findData(static_cast(modified())->value())); } void CoinListUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void CoinListUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void CoinListUI::on_varName_textChanged(const QString& name) { static_cast(modified())->setName(name); } void CoinListUI::on_varValue_currentIndexChanged(const int value) { static_cast(modified())->setValue(varValue->itemData(value).toInt()); }