summaryrefslogtreecommitdiffstats
path: root/pokemodr/MapWildListUI.cpp
blob: c2fad681835b01e75d7ca1a3fa99d3954245e8d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
 * 
 * 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 <http://www.gnu.org/licenses/>.
 */

// 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<const Pokemod*>(original()->pokemod())->itemCount(); ++i)
    {
        const Item* item = static_cast<const Pokemod*>(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<const Pokemod*>(original()->pokemod())->timeCount(); ++i)
    {
        const Time* time = static_cast<const Pokemod*>(original()->pokemod())->time(i);
        QListWidgetItem* widgetItem = new QListWidgetItem(time->name(), varTimes);
        widgetItem->setData(Qt::UserRole, time->id());
    }
}

void MapWildListUI::setGui()
{
    varControl->setCurrentIndex(static_cast<MapWildList*>(modified())->control());
    varValue->setEnabled(static_cast<MapWildList*>(modified())->control() == MapWildList::Fishing);
    varValue->setCurrentIndex(varValue->findData(static_cast<MapWildList*>(modified())->value()));
    for (int i = 0; i < varTimes->count(); ++i)
    {
        QListWidgetItem* widgetItem = varTimes->item(i);
        widgetItem->setSelected(static_cast<MapWildList*>(modified())->time(widgetItem->data(Qt::UserRole).toInt()));
    }
    boxScope->setChecked(static_cast<MapWildList*>(modified())->scope() == INT_MAX);
    varScope->setCurrentIndex(varScope->findData(static_cast<MapWildList*>(modified())->scope()));
}

void MapWildListUI::apply()
{
    *static_cast<MapWildList*>(original()) = *static_cast<MapWildList*>(modified());
    emit(changed(false));
}

void MapWildListUI::discard()
{
    *static_cast<MapWildList*>(modified()) = *static_cast<MapWildList*>(original());
    setGui();
    emit(changed(false));
}

void MapWildListUI::on_varControl_currentIndexChanged(const int control)
{
    static_cast<MapWildList*>(modified())->setControl(control);
}

void MapWildListUI::on_varValue_currentIndexChanged(const int value)
{
    static_cast<MapWildList*>(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<MapWildList*>(modified())->setTime(widgetItem->data(Qt::UserRole).toInt(), widgetItem->isSelected());
    }
}

void MapWildListUI::on_boxScope_toggled(const bool scopeUsed)
{
    if (!scopeUsed)
        static_cast<MapWildList*>(modified())->setScope(INT_MAX);
}

void MapWildListUI::on_varScope_currentIndexChanged(const int scope)
{
    static_cast<MapWildList*>(modified())->setScope(varScope->itemData(scope).toInt());
}