/* * 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 "SpeciesUI.h" // Sigmod includes #include "../sigmod/EggGroup.h" #include "../sigmod/Rules.h" #include "../sigmod/Sigmod.h" #include "../sigmod/Skin.h" #include "../sigmod/Species.h" #include "../sigmod/Sprite.h" #include "../sigmod/Type.h" Sigmodr::SpeciesUI::SpeciesUI(Sigmod::Species* species, QWidget* parent) : ObjectUI(parent) { setupUi(this); setObjects(species, new Sigmod::Species(*species)); } Sigmodr::SpeciesUI::~SpeciesUI() { } void Sigmodr::SpeciesUI::initGui() { connect(varBaseStat, SIGNAL(activated(const int)), this, SLOT(setGui())); connect(varEVStat, SIGNAL(activated(const int)), this, SLOT(setGui())); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fluctuating], QVariant::fromValue(Sigmod::Species::Fluctuating)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fading], QVariant::fromValue(Sigmod::Species::Fading)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Slow], QVariant::fromValue(Sigmod::Species::Slow)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Normal], QVariant::fromValue(Sigmod::Species::Normal)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Fast], QVariant::fromValue(Sigmod::Species::Fast)); varGrowth->addItem(Sigmod::Species::StyleStr[Sigmod::Species::Erratic], QVariant::fromValue(Sigmod::Species::Erratic)); varEffortValue->setMaximum(sigmod()->rules()->maxEVPerStat() ? sigmod()->rules()->maxEVPerStat() : INT_MAX); } void Sigmodr::SpeciesUI::refreshGui() { varBaseStat->clear(); varEVStat->clear(); const bool isSplit = sigmod()->rules()->specialSplit(); const QStringList& statNames = (isSplit ? Sigmod::StatGSCStr : Sigmod::StatRBYStr); varBaseStat->addItem(statNames[Sigmod::ST_HP], QVariant::fromValue(Sigmod::ST_HP)); varBaseStat->addItem(statNames[Sigmod::ST_Attack], QVariant::fromValue(Sigmod::ST_Attack)); varBaseStat->addItem(statNames[Sigmod::ST_Defense], QVariant::fromValue(Sigmod::ST_Defense)); varBaseStat->addItem(statNames[Sigmod::ST_Speed], QVariant::fromValue(Sigmod::ST_Speed)); if (isSplit) { varBaseStat->addItem(statNames[Sigmod::ST_SpecialAttack], QVariant::fromValue(Sigmod::ST_SpecialAttack)); varBaseStat->addItem(statNames[Sigmod::ST_SpecialDefense], QVariant::fromValue(Sigmod::ST_SpecialDefense)); } else varBaseStat->addItem(statNames[Sigmod::ST_Special], QVariant::fromValue(Sigmod::ST_Special)); if (sigmod()->rules()->effortValuesAllowed()) { varEVStat->addItem(statNames[Sigmod::ST_HP], QVariant::fromValue(Sigmod::ST_HP)); varEVStat->addItem(statNames[Sigmod::ST_Attack], QVariant::fromValue(Sigmod::ST_Attack)); varEVStat->addItem(statNames[Sigmod::ST_Defense], QVariant::fromValue(Sigmod::ST_Defense)); varEVStat->addItem(statNames[Sigmod::ST_Speed], QVariant::fromValue(Sigmod::ST_Speed)); if (isSplit) { varEVStat->addItem(statNames[Sigmod::ST_SpecialAttack], QVariant::fromValue(Sigmod::ST_SpecialAttack)); varEVStat->addItem(statNames[Sigmod::ST_SpecialDefense], QVariant::fromValue(Sigmod::ST_SpecialDefense)); } else varEVStat->addItem(statNames[Sigmod::ST_Special], QVariant::fromValue(Sigmod::ST_Special)); } else boxEffortValues->setEnabled(false); if (!sigmod()->rules()->maxHeldItems()) boxItemChance->setEnabled(false); int maxHeight = 0; int maxWidth = 0; const bool blockedMaleFront = varMaleFront->blockSignals(true); varMaleFront->clear(); const bool blockedMaleBack = varMaleBack->blockSignals(true); varMaleBack->clear(); const bool blockedFemaleFront = varFemaleFront->blockSignals(true); varFemaleFront->clear(); const bool blockedFemaleBack = varFemaleBack->blockSignals(true); varFemaleBack->clear(); for (int i = 0; i < sigmod()->spriteCount(); ++i) { const Sigmod::Sprite* sprite = sigmod()->sprite(i); QPixmap icon; icon.loadFromData(sprite->sprite()); maxHeight = qMax(maxHeight, icon.height()); maxWidth = qMax(maxWidth, icon.width()); varMaleFront->addItem(icon, sprite->name(), sprite->id()); varMaleBack->addItem(icon, sprite->name(), sprite->id()); varFemaleFront->addItem(icon, sprite->name(), sprite->id()); varFemaleBack->addItem(icon, sprite->name(), sprite->id()); } varMaleFront->blockSignals(blockedMaleFront); varMaleBack->blockSignals(blockedMaleBack); varFemaleFront->blockSignals(blockedFemaleFront); varFemaleBack->blockSignals(blockedFemaleBack); const QSize maxSize(maxWidth, maxHeight); varMaleFront->setIconSize(maxSize); varMaleBack->setIconSize(maxSize); varFemaleFront->setIconSize(maxSize); varFemaleBack->setIconSize(maxSize); const bool blockedSkin = varSkin->blockSignals(true); varSkin->clear(); for (int i = 0; i < sigmod()->skinCount(); ++i) { const Sigmod::Skin* skin = sigmod()->skin(i); varSkin->addItem(skin->name(), skin->id()); } varSkin->blockSignals(blockedSkin); if (sigmod()->rules()->genderAllowed()) { const bool blockedEggSpecies = varEggSpecies->blockSignals(true); varEggSpecies->clear(); const bool blockedEggGroups = varEggGroups->blockSignals(true); varEggGroups->clear(); if (sigmod()->rules()->breedingAllowed()) { for (int i = 0; i < sigmod()->speciesCount(); ++i) { const Sigmod::Species* species = sigmod()->species(i); varEggSpecies->addItem(species->name(), species->id()); } for (int i = 0; i < sigmod()->eggGroupCount(); ++i) { const Sigmod::EggGroup* eggGroup = sigmod()->eggGroup(i); QListWidgetItem* widgetItem = new QListWidgetItem(eggGroup->name(), varEggGroups); widgetItem->setData(Qt::UserRole, eggGroup->id()); } } else { boxEggSpecies->setEnabled(false); varEggSteps->setEnabled(false); boxEggGroups->setEnabled(false); } varEggSpecies->blockSignals(blockedEggSpecies); varEggGroups->blockSignals(blockedEggGroups); } else { tabGenetics->setEnabled(false); boxFemaleSprites->setEnabled(false); } const bool blockedTypes = varTypes->blockSignals(true); varTypes->clear(); for (int i = 0; i < sigmod()->typeCount(); ++i) { const Sigmod::Type* type = sigmod()->type(i); QListWidgetItem* widgetItem = new QListWidgetItem(type->name(), varTypes); widgetItem->setData(Qt::UserRole, type->id()); } varTypes->blockSignals(blockedTypes); } void Sigmodr::SpeciesUI::setGui() { varName->setText(qobject_cast(modified())->name()); varBaseStatValue->setValue(qobject_cast(modified())->baseStat(varBaseStat->itemData(varBaseStat->currentIndex()).value())); varEffortValue->setValue(qobject_cast(modified())->effortValue(varEVStat->itemData(varEVStat->currentIndex()).value())); varGrowth->setCurrentIndex(qobject_cast(modified())->growth()); varExperienceValue->setValue(qobject_cast(modified())->experienceValue()); varCatchValue->setValue(qobject_cast(modified())->catchValue()); varMaxHoldWeight->setValue(qobject_cast(modified())->maxHoldWeight()); varRunChance->setValue(qobject_cast(modified())->runChance()); varItemChance->setValue(qobject_cast(modified())->itemChance()); varEncyclopediaNumber->setValue(qobject_cast(modified())->encyclopediaNumber()); varWeight->setValue(qobject_cast(modified())->weight()); varHeight->setValue(qobject_cast(modified())->height()); varEncyclopediaEntry->setText(qobject_cast(modified())->encyclopediaEntry()); varMaleFront->setCurrentIndex(varMaleFront->findData(qobject_cast(modified())->frontMaleSprite())); varMaleBack->setCurrentIndex(varMaleBack->findData(qobject_cast(modified())->backMaleSprite())); if (sigmod()->rules()->genderAllowed()) { varFemaleFront->setCurrentIndex(varFemaleFront->findData(qobject_cast(modified())->frontFemaleSprite())); varFemaleBack->setCurrentIndex(varFemaleBack->findData(qobject_cast(modified())->backFemaleSprite())); } varSkin->setCurrentIndex(varSkin->findData(qobject_cast(modified())->skin())); boxGenderChance->setChecked((qobject_cast(modified())->genderFactor() < 0) ? Qt::Checked : Qt::Unchecked); varGenderChance->setValue(qobject_cast(modified())->genderFactor()); varEggSpecies->setCurrentIndex(varEggSpecies->findData(qobject_cast(modified())->eggSpecies())); varEggSteps->setValue(qobject_cast(modified())->eggSteps()); varEvolution->setValue(qobject_cast(modified())->evolution()); for (int i = 0; i < varTypes->count(); ++i) { QListWidgetItem* widgetItem = varTypes->item(i); widgetItem->setSelected(qobject_cast(modified())->type(widgetItem->data(Qt::UserRole).toInt())); } for (int i = 0; i < varEggGroups->count(); ++i) { QListWidgetItem* widgetItem = varEggGroups->item(i); widgetItem->setSelected(qobject_cast(modified())->eggGroup(widgetItem->data(Qt::UserRole).toInt())); } } void Sigmodr::SpeciesUI::apply() { *qobject_cast(original()) = *qobject_cast(modified()); emit(changed(false)); } void Sigmodr::SpeciesUI::discard() { *qobject_cast(modified()) = *qobject_cast(original()); setGui(); emit(changed(false)); } void Sigmodr::SpeciesUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); qobject_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void Sigmodr::SpeciesUI::on_varBaseStatValue_valueChanged(const int baseStat) { qobject_cast(modified())->setBaseStat(varBaseStat->itemData(varBaseStat->currentIndex()).value(), baseStat); } void Sigmodr::SpeciesUI::on_varEffortValue_valueChanged(const int effortValue) { qobject_cast(modified())->setEffortValue(varEVStat->itemData(varEVStat->currentIndex()).value(), effortValue); } void Sigmodr::SpeciesUI::on_varGrowth_activated(const int growth) { qobject_cast(modified())->setGrowth(QVariant(growth).value()); } void Sigmodr::SpeciesUI::on_varExperienceValue_valueChanged(const int experienceValue) { qobject_cast(modified())->setExperienceValue(experienceValue); } void Sigmodr::SpeciesUI::on_varCatchValue_valueChanged(const int catchValue) { qobject_cast(modified())->setCatchValue(catchValue); } void Sigmodr::SpeciesUI::on_varMaxHoldWeight_valueChanged(const int maxHoldWeight) { qobject_cast(modified())->setMaxHoldWeight(maxHoldWeight); } void Sigmodr::SpeciesUI::on_varRunChance_valueChanged(const Sigcore::Fraction& runChance) { qobject_cast(modified())->setRunChance(runChance); } void Sigmodr::SpeciesUI::on_varItemChance_valueChanged(const Sigcore::Fraction& itemChance) { qobject_cast(modified())->setItemChance(itemChance); } void Sigmodr::SpeciesUI::on_varEncyclopediaNumber_valueChanged(const int encyclopediaNumber) { qobject_cast(modified())->setEncyclopediaNumber(encyclopediaNumber); } void Sigmodr::SpeciesUI::on_varWeight_valueChanged(const int weight) { qobject_cast(modified())->setWeight(weight); } void Sigmodr::SpeciesUI::on_varHeight_valueChanged(const int height) { qobject_cast(modified())->setHeight(height); } void Sigmodr::SpeciesUI::on_varEncyclopediaEntry_textChanged(const QString& encyclopediaEntry) { qobject_cast(modified())->setEncyclopediaEntry(encyclopediaEntry); } void Sigmodr::SpeciesUI::on_varMaleFront_currentIndexChanged(const int maleFront) { qobject_cast(modified())->setFrontMaleSprite(varMaleFront->itemData(maleFront).toInt()); } void Sigmodr::SpeciesUI::on_varMaleBack_currentIndexChanged(const int maleBack) { qobject_cast(modified())->setBackMaleSprite(varMaleBack->itemData(maleBack).toInt()); } void Sigmodr::SpeciesUI::on_varFemaleFront_currentIndexChanged(const int femaleFront) { qobject_cast(modified())->setFrontFemaleSprite(varFemaleFront->itemData(femaleFront).toInt()); } void Sigmodr::SpeciesUI::on_varFemaleBack_currentIndexChanged(const int femaleBack) { qobject_cast(modified())->setBackFemaleSprite(varFemaleBack->itemData(femaleBack).toInt()); } void Sigmodr::SpeciesUI::on_varSkin_currentIndexChanged(const int skin) { qobject_cast(modified())->setSkin(varSkin->itemData(skin).toInt()); } void Sigmodr::SpeciesUI::on_boxGenderChance_clicked(const bool genderChance) { qobject_cast(modified())->setGenderFactor(Sigcore::Fraction((genderChance ? 1 : -1), 1)); } void Sigmodr::SpeciesUI::on_varGenderChance_valueChanged(const Sigcore::Fraction& genderChance) { qobject_cast(modified())->setGenderFactor(genderChance); } void Sigmodr::SpeciesUI::on_varEggSpecies_activated(const int eggSpecies) { qobject_cast(modified())->setEggSpecies(varEggSpecies->itemData(eggSpecies).toInt()); } void Sigmodr::SpeciesUI::on_varEggSteps_valueChanged(const int eggSteps) { qobject_cast(modified())->setEggSteps(eggSteps); } void Sigmodr::SpeciesUI::on_varEvolution_valueChanged(const Sigcore::Script& evolution) { qobject_cast(modified())->setEvolution(evolution); } void Sigmodr::SpeciesUI::on_varTypes_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setType(item->data(Qt::UserRole).toInt(), item->isSelected()); } void Sigmodr::SpeciesUI::on_varEggGroups_itemClicked(QListWidgetItem* item) { qobject_cast(modified())->setEggGroup(item->data(Qt::UserRole).toInt(), !item->isSelected()); }