mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-28 23:06:24 +02:00
Resources in time events
This commit is contained in:
parent
446c61cce1
commit
ad8d7016b6
@ -100,6 +100,7 @@ void EventSettings::on_timedEventAdd_clicked()
|
||||
auto * item = new QListWidgetItem(QString::fromStdString(event.name));
|
||||
item->setData(Qt::UserRole, toVariant(event));
|
||||
ui->eventsList->addItem(item);
|
||||
on_eventsList_itemActivated(item);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,6 +20,8 @@ TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
|
||||
const auto params = t->data(Qt::UserRole).toMap();
|
||||
ui->eventNameText->setText(params.value("name").toString());
|
||||
ui->eventMessageText->setPlainText(params.value("message").toString());
|
||||
@ -36,7 +38,17 @@ TimedEvent::TimedEvent(QListWidgetItem * t, QWidget *parent) :
|
||||
item->setCheckState(isAffected ? Qt::Checked : Qt::Unchecked);
|
||||
ui->playersAffected->addItem(item);
|
||||
}
|
||||
//result.resources = resourcesFromVariant(v.value("resources"));
|
||||
|
||||
ui->resources->setRowCount(GameConstants::RESOURCE_QUANTITY);
|
||||
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||
{
|
||||
auto name = QString::fromStdString(GameConstants::RESOURCE_NAMES[i]);
|
||||
int val = params.value("resources").toMap().value(name).toInt();
|
||||
ui->resources->setItem(i, 0, new QTableWidgetItem(name));
|
||||
auto nval = new QTableWidgetItem(QString::number(val));
|
||||
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
|
||||
ui->resources->setItem(i, 1, nval);
|
||||
}
|
||||
|
||||
show();
|
||||
}
|
||||
@ -46,12 +58,6 @@ TimedEvent::~TimedEvent()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TimedEvent::on_eventResources_clicked()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TimedEvent::on_TimedEvent_finished(int result)
|
||||
{
|
||||
@ -71,7 +77,32 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
||||
players |= 1 << i;
|
||||
}
|
||||
descriptor["players"] = QVariant::fromValue(players);
|
||||
|
||||
auto res = target->data(Qt::UserRole).toMap().value("resources").toMap();
|
||||
for(int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
||||
{
|
||||
auto * itemType = ui->resources->item(i, 0);
|
||||
auto * itemQty = ui->resources->item(i, 1);
|
||||
res[itemType->text()] = QVariant::fromValue(itemQty->text().toInt());
|
||||
}
|
||||
descriptor["resources"] = res;
|
||||
|
||||
target->setData(Qt::UserRole, descriptor);
|
||||
target->setText(ui->eventNameText->text());
|
||||
}
|
||||
|
||||
|
||||
void TimedEvent::on_pushButton_clicked()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void TimedEvent::on_resources_itemDoubleClicked(QTableWidgetItem *item)
|
||||
{
|
||||
if(item && item->column() == 1)
|
||||
{
|
||||
ui->resources->editItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,13 @@ public:
|
||||
~TimedEvent();
|
||||
|
||||
private slots:
|
||||
void on_eventResources_clicked();
|
||||
|
||||
void on_TimedEvent_finished(int result);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_resources_itemDoubleClicked(QTableWidgetItem *item);
|
||||
|
||||
private:
|
||||
Ui::TimedEvent *ui;
|
||||
QListWidgetItem * target;
|
||||
|
@ -102,6 +102,13 @@
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Affected players</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="playersAffected">
|
||||
<property name="sizePolicy">
|
||||
@ -112,19 +119,91 @@
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<width>120</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="eventResources">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Resources</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="resources">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>20</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>60</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>16</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>16</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>type</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>qty</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user