/* * 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 "MapWildListUI.h" // Pokemod includes #include "../pokemod/Item.h" #include "../pokemod/ItemEffect.h" #include "../pokemod/Pokemod.h" #include "../pokemod/MapWildList.h" #include "../pokemod/Time.h" MapWildListUI::MapWildListUI(MapWildList* wildList, QWidget* parent) : ObjectUI(parent) { setupUi(this); QMetaObject::connectSlotsByName(this); setObjects(wildList, new MapWildList(*wildList)); init(); } MapWildListUI::~MapWildListUI() { } void MapWildListUI::initGui() { varControl->addItems(MapWildList::ControlStr); } void MapWildListUI::refreshGui() { varValue->clear(); varScope->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_Fish) varValue->addItem(item->name(), effect->value2()); else if (effect->effect() == ItemEffect::E_Scope) varScope->addItem(item->name(), effect->value2()); } } varTimes->clear(); for (int i = 0; i < static_cast(original()->pokemod())->timeCount(); ++i) { const Time* time = static_cast(original()->pokemod())->time(i); QListWidgetItem* widgetItem = new QListWidgetItem(time->name(), varTimes); widgetItem->setData(Qt::UserRole, time->id()); } } void MapWildListUI::setGui() { varControl->setCurrentIndex(static_cast(modified())->control()); varValue->setEnabled(static_cast(modified())->control() == MapWildList::Fishing); varValue->setCurrentIndex(varValue->findData(static_cast(modified())->value())); for (int i = 0; i < varTimes->count(); ++i) { QListWidgetItem* widgetItem = varTimes->item(i); widgetItem->setSelected(static_cast(modified())->time(widgetItem->data(Qt::UserRole).toInt())); } boxScope->setChecked(static_cast(modified())->scope() == INT_MAX); varScope->setCurrentIndex(varScope->findData(static_cast(modified())->scope())); } void MapWildListUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void MapWildListUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void MapWildListUI::on_varControl_currentIndexChanged(const int control) { static_cast(modified())->setControl(control); } void MapWildListUI::on_varValue_currentIndexChanged(const int value) { static_cast(modified())->setValue(varValue->itemData(value).toInt()); } void MapWildListUI::on_varTimes_itemSelectionChanged() { for (int i = 0; i < varTimes->count(); ++i) { const QListWidgetItem* widgetItem = varTimes->item(i); static_cast(modified())->setTime(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected()); } } void MapWildListUI::on_boxScope_toggled(const bool scopeUsed) { if (!scopeUsed) static_cast(modified())->setScope(INT_MAX); } void MapWildListUI::on_varScope_currentIndexChanged(const int scope) { static_cast(modified())->setScope(varScope->itemData(scope).toInt()); }