-
Notifications
You must be signed in to change notification settings - Fork 4
/
itemattributeeditor.cpp
151 lines (134 loc) · 5.11 KB
/
itemattributeeditor.cpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <QPushButton>
#include "itemattributeeditor.h"
#include "itemmodel.h"
#include "tibiahandler.h"
#include "formathandler.h"
extern TibiaHandler g_tibiaHandler;
extern FormatHandler g_formatHandler;
ItemAttributeEditor::ItemAttributeEditor( QWidget *parent ) : QDialog( parent ), ui( new Ui::ItemAttributeEditorClass )
{
ui->setupUi( this );
ui->buttonBox->button( QDialogButtonBox::Apply )->setIcon( QIcon( ":/TibiaEditor/Resources/apply.png" ) );
itemModel = new ItemModel( this );
ui->itemView->setModel( itemModel );
if( g_formatHandler.isLoaded() ) {
for( DatFormatMap::const_iterator it = g_formatHandler.getFormatsBegin(); it != g_formatHandler.getFormatsEnd(); it++ )
ui->comboVersions->insertItem( 0, it.value()->getName(), QVariant::fromValue( it.key() ) );
} else
ui->comboVersions->insertItem( 0, tr( "No Formats" ) );
QObject::connect( ui->selectedItems, SIGNAL( toggled( bool ) ), this, SLOT( onSelectionChanged( bool ) ) );
QObject::connect( ui->selectedOutfits, SIGNAL( toggled( bool ) ), this, SLOT( onSelectionChanged( bool ) ) );
QObject::connect( ui->selectedEffects, SIGNAL( toggled( bool ) ), this, SLOT( onSelectionChanged( bool ) ) );
QObject::connect( ui->selectedProjectiles, SIGNAL( toggled( bool ) ), this, SLOT( onSelectionChanged( bool ) ) );
QObject::connect( ui->buttonBox, SIGNAL( clicked( QAbstractButton * ) ), this, SLOT( onButtonClicked( QAbstractButton * ) ) );
}
ItemAttributeEditor::~ItemAttributeEditor( void )
{
if( itemModel ) {
itemModel->clear();
delete itemModel;
}
delete ui;
}
void ItemAttributeEditor::setItems( const ItemList& list )
{
items = list;
}
void ItemAttributeEditor::setOutfits( const ItemList& list )
{
outfits = list;
}
void ItemAttributeEditor::setEffects( const ItemList& list )
{
effects = list;
}
void ItemAttributeEditor::setProjectiles( const ItemList& list )
{
projectiles = list;
}
void ItemAttributeEditor::updateItems( void )
{
if( itemModel ) {
ItemList itemList;
if( ui->selectedItems->isChecked() )
itemList += items;
if( ui->selectedOutfits->isChecked() )
itemList += outfits;
if( ui->selectedEffects->isChecked() )
itemList += effects;
if( ui->selectedProjectiles->isChecked() )
itemList += projectiles;
itemModel->setItemList( itemList );
}
}
void ItemAttributeEditor::onSelectionChanged( bool )
{
g_tibiaHandler.getOutputWidget()->addLine( QColor( Qt::darkBlue ), tr( "Selected Items Changed." ) );
updateItems( );
}
void ItemAttributeEditor::on_comboVersions_currentIndexChanged( int index )
{
qint32 version = ui->comboVersions->itemData( index, Qt::UserRole ).toInt();
DatFormat *datFormat = g_formatHandler.getFormatByClient( version );
if( datFormat ) {
ui->itemAttributes->setFormat( datFormat );
}
}
void ItemAttributeEditor::onButtonClicked( QAbstractButton *button )
{
switch( ui->buttonBox->buttonRole( button ) ) {
case QDialogButtonBox::ApplyRole: {
PropertyList properties;
ui->itemAttributes->getAttributes( properties );
if( ui->selectedItems->isChecked() ) {
foreach( TibiaItem* item, items )
setProperties( item, properties );
}
if( ui->selectedOutfits->isChecked() ) {
foreach( TibiaItem* item, outfits )
setProperties( item, properties );
}
if( ui->selectedEffects->isChecked() ) {
foreach( TibiaItem* item, effects )
setProperties( item, properties );
}
if( ui->selectedProjectiles->isChecked() ) {
foreach( TibiaItem* item, projectiles )
setProperties( item, properties );
}
close();
}
break;
case QDialogButtonBox::RejectRole:
close();
break;
case QDialogButtonBox::ResetRole:
ui->itemAttributes->onResetContents();
break;
}
}
void ItemAttributeEditor::setProperties( TibiaItem *item, const PropertyList& properties )
{
if( ui->buttonSelected->isChecked() ) {
PropertyList itemProperties = item->getProperties();
for( PropertyList::const_iterator it = properties.begin(); it != properties.end(); it++ ) {
if( !ui->buttonToggle->isChecked() ) {
if( !item->hasHeader( (*it).header ) )
itemProperties.push_back( *it );
else {
int index = itemProperties.indexOf( *it );
if( index != -1 )
itemProperties.replace( index, *it );
}
} else { // Toggle is enabled, remove if it has it, add if it doesnt
if( !item->hasHeader( (*it).header ) )
itemProperties.push_back( *it );
else
itemProperties.removeOne( *it );
}
}
qSort( itemProperties );
emit changeItem( g_tibiaHandler.getItemFile(), item, itemProperties );
} else if( ui->buttonAll->isChecked() )
emit changeItem( g_tibiaHandler.getItemFile(), item, properties );
}