This repository was archived by the owner on Oct 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinmapitemdialog.cpp
More file actions
155 lines (135 loc) · 5.61 KB
/
Copy pathinmapitemdialog.cpp
File metadata and controls
155 lines (135 loc) · 5.61 KB
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
152
153
154
155
#include "inmapitemdialog.h"
#include "ui_inmapitemdialog.h"
#include "mapinfo.h"
#include "mapmanager.h"
#include "mapitem.h"
#include "mapbase.h"
#include "sprite.h"
#include <QPushButton>
#include <QDebug>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QSlider>
InMapItemDialog::InMapItemDialog(MapInfo* mapinfo,MapManager* manager,MapItem* mapitem,QWidget *parent) :
QDialog(parent),
mapInfo(mapinfo),
mapManager(manager),
returnItem(mapitem),
selectScene(new QGraphicsScene(this)),
selectRect(0),
baseItems(new Sprite()),
ui(new Ui::InMapItemDialog)
{
ui->setupUi(this);
if(returnItem){
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("修改"));
this->change = true;
}else{
ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("确定"));
this->change = false;
}
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("取消"));
ui->tileHeight->setSingleStep(DEF_MAPBASE_HEIGHT);
ui->tileHeight->setPageStep(DEF_MAPBASE_HEIGHT);
ui->tileWidth->setSingleStep(DEF_MAPBASE_WIDTH);
ui->tileWidth->setPageStep(DEF_MAPBASE_WIDTH);
connect(ui->tileWidth,SIGNAL(sliderReleased()),this,SLOT(rule_slider()));
connect(ui->tileHeight,SIGNAL(sliderReleased()),this,SLOT(rule_slider()));
connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(ok_click()));
connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(cancel_click()));
connect(ui->tileWidth,SIGNAL(sliderMoved(int)),ui->tileWidthLabel,SLOT(setNum(int)));
connect(ui->tileHeight,SIGNAL(sliderMoved(int)),ui->tileHeightLabel,SLOT(setNum(int)));
connect(ui->tileWidth,SIGNAL(valueChanged(int)),ui->tileWidthLabel,SLOT(setNum(int)));
connect(ui->tileHeight,SIGNAL(valueChanged(int)),ui->tileHeightLabel,SLOT(setNum(int)));
ui->itemView->setScene(selectScene);
baseItems->setPixmap(this->mapInfo->base);
connect(baseItems,SIGNAL(onMouseRelease(qreal,qreal,Qt::MouseButtons)),this,SLOT(select_item_on_mouse_press(qreal,qreal,Qt::MouseButtons)));
this->selectScene->addItem(baseItems);
if(this->returnItem){ //判断是否是修改MapItem对象
this->ui->checkTypeBox->setValue(this->returnItem->checkType);
this->ui->crossTypeBox->setValue(this->returnItem->crossType);
this->ui->tileWidth->setValue(this->returnItem->getWidth());
this->ui->tileWidthLabel->setNum(this->returnItem->getWidth());
this->ui->tileHeight->setValue(this->returnItem->getHeight());
this->ui->tileHeightLabel->setNum(this->returnItem->getHeight());
this->ui->xSpinBox->setValue(this->returnItem->mapX);
this->ui->ySpinBox->setValue(this->returnItem->mapY);
this->ui->zSpinBox->setValue(this->returnItem->mapZ);
this->ui->specialSpinBox->setValue(this->returnItem->special);
this->ui->staminaSpinBox->setValue(this->returnItem->breakType);
this->ui->itemNameEdit->setText(this->returnItem->typeName);
this->changeSelectBase(this->returnItem->hindex,this->returnItem->vindex);
this->ui->itemView->centerOn(this->selectRect);
}else{
this->returnItem = new MapItem(this->mapInfo->base);
select_item_on_mouse_press(1.0,1.0,0); // 默认选择贴图1,1
}
}
InMapItemDialog::~InMapItemDialog()
{
delete ui;
delete baseItems;
if(selectRect)delete selectRect;
delete selectScene;
}
void InMapItemDialog::closeEvent(QCloseEvent *)
{
this->cancel_click();
}
//实现插入MapItem 返回 0表示取消插入
MapItem* InMapItemDialog::createMapItem()
{
this->exec();
if(this->returnItem)qDebug() <<"typename:" << returnItem->typeName;
return returnItem;
}
void InMapItemDialog::ok_click()
{
returnItem->typeName = this->ui->itemNameEdit->text();
returnItem->setIColnum(this->ui->tileWidth->value() / returnItem->sizeH);
returnItem->setIRownum(this->ui->tileHeight->value() / returnItem->sizeV);
returnItem->mapX = this->ui->xSpinBox->value();
returnItem->mapY = this->ui->ySpinBox->value();
returnItem->mapZ = this->ui->zSpinBox->value();
returnItem->checkType = this->ui->checkTypeBox->value();
returnItem->crossType = this->ui->crossTypeBox->value();
returnItem->special = this->ui->specialSpinBox->value();
qDebug() << "onOkClick";
}
void InMapItemDialog::cancel_click()
{
qDebug() << "onCancelClick";
if(!isChange())delete this->returnItem;
this->returnItem = 0;
}
//贴图区-物件单击
void InMapItemDialog::select_item_on_mouse_press(qreal x,qreal y,Qt::MouseButtons button)
{
qDebug()<<" select_itme";
int _hindex = int( x / DEF_MAPBASE_WIDTH);
int _vindex = int( y / DEF_MAPBASE_HEIGHT);
this->changeSelectBase(_hindex,_vindex);
this->returnItem->hindex =_hindex;
this->returnItem->vindex =_vindex;
}
//在选择区选择时加入的选区范围图示
void InMapItemDialog::changeSelectBase(int mhindex,int mvindex)
{
if(this->selectRect)delete this->selectRect;
this->selectRect = this->selectScene->addRect( mhindex * DEF_MAPBASE_WIDTH,
mvindex * DEF_MAPBASE_HEIGHT ,
ui->tileWidth->value() ,
ui->tileHeight->value() ,
QPen(Qt::DashLine) ,
QBrush(Qt::blue,Qt::Dense7Pattern)
);
}
void InMapItemDialog::rule_slider()
{
QSlider* sender = static_cast<QSlider* >(this->sender());
sender->setValue(sender->value() - sender->value() % sender->singleStep());
}
bool InMapItemDialog::isChange()
{
return this->change;
}