1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Add rumors

This commit is contained in:
nordsoft 2023-09-08 17:54:34 +02:00
parent 0148662847
commit 320cd6bf16
12 changed files with 323 additions and 4 deletions

View File

@ -20,6 +20,7 @@ set(editor_SRCS
mapsettings/victoryconditions.cpp
mapsettings/loseconditions.cpp
mapsettings/eventsettings.cpp
mapsettings/rumorsettings.cpp
playersettings.cpp
playerparams.cpp
scenelayer.cpp
@ -55,6 +56,7 @@ set(editor_HEADERS
mapsettings/victoryconditions.h
mapsettings/loseconditions.h
mapsettings/eventsettings.h
mapsettings/rumorsettings.h
playersettings.h
playerparams.h
scenelayer.h
@ -80,6 +82,7 @@ set(editor_FORMS
mapsettings/victoryconditions.ui
mapsettings/loseconditions.ui
mapsettings/eventsettings.ui
mapsettings/rumorsettings.ui
playersettings.ui
playerparams.ui
validator.ui

View File

@ -107,7 +107,7 @@ void EventSettings::on_timedEventAdd_clicked()
void EventSettings::on_timedEventRemove_clicked()
{
if(auto * item = ui->eventsList->currentItem())
ui->eventsList->removeItemWidget(item);
ui->eventsList->takeItem(ui->eventsList->row(item));
}

View File

@ -14,6 +14,18 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>

View File

@ -14,6 +14,18 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">

View File

@ -14,6 +14,18 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="leftMargin">

View File

@ -68,6 +68,7 @@ MapSettings::MapSettings(MapController & ctrl, QWidget *parent) :
ui->victory->initialize(*controller.map());
ui->lose->initialize(*controller.map());
ui->events->initialize(*controller.map());
ui->rumors->initialize(*controller.map());
}
MapSettings::~MapSettings()
@ -98,6 +99,7 @@ void MapSettings::on_pushButton_clicked()
ui->victory->update(*controller.map());
ui->lose->update(*controller.map());
ui->events->update(*controller.map());
ui->rumors->update(*controller.map());
controller.commitChangeWithoutRedraw();

View File

@ -35,7 +35,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -49,7 +49,7 @@
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
<number>3</number>
</property>
<item>
<widget class="GeneralSettings" name="general" native="true"/>
@ -92,7 +92,7 @@
<item>
<widget class="QTabWidget" name="tabWidget_2">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_7">
<attribute name="title">
@ -151,6 +151,25 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_11">
<attribute name="title">
<string>Rumors</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="leftMargin">
<number>12</number>
</property>
<property name="rightMargin">
<number>12</number>
</property>
<property name="bottomMargin">
<number>12</number>
</property>
<item>
<widget class="RumorSettings" name="rumors" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@ -337,6 +356,12 @@
<header>mapsettings/eventsettings.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>RumorSettings</class>
<extends>QWidget</extends>
<header>mapsettings/rumorsettings.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -14,6 +14,18 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_7">
<property name="text">

View File

@ -0,0 +1,81 @@
/*
* rumorsettings.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "rumorsettings.h"
#include "ui_rumorsettings.h"
RumorSettings::RumorSettings(QWidget *parent) :
AbstractSettings(parent),
ui(new Ui::RumorSettings)
{
ui->setupUi(this);
}
RumorSettings::~RumorSettings()
{
delete ui;
}
void RumorSettings::initialize(const CMap & map)
{
for(auto & rumor : map.rumors)
{
auto * item = new QListWidgetItem(QString::fromStdString(rumor.name));
item->setData(Qt::UserRole, QVariant(QString::fromStdString(rumor.text)));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->rumors->addItem(item);
}
}
void RumorSettings::update(CMap & map)
{
map.rumors.clear();
for(int i = 0; i < ui->rumors->count(); ++i)
{
Rumor rumor;
rumor.name = ui->rumors->item(i)->text().toStdString();
rumor.text = ui->rumors->item(i)->data(Qt::UserRole).toString().toStdString();
map.rumors.push_back(rumor);
}
}
void RumorSettings::on_message_textChanged()
{
if(auto item = ui->rumors->currentItem())
item->setData(Qt::UserRole, QVariant(ui->message->toPlainText()));
}
void RumorSettings::on_add_clicked()
{
auto * item = new QListWidgetItem(tr("New rumor"));
item->setData(Qt::UserRole, QVariant(""));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->rumors->addItem(item);
emit ui->rumors->itemActivated(item);
}
void RumorSettings::on_remove_clicked()
{
if(auto item = ui->rumors->currentItem())
{
ui->message->setPlainText("");
ui->rumors->takeItem(ui->rumors->row(item));
}
}
void RumorSettings::on_rumors_itemSelectionChanged()
{
if(auto item = ui->rumors->currentItem())
ui->message->setPlainText(item->data(Qt::UserRole).toString());
}

View File

@ -0,0 +1,43 @@
/*
* rumorsettings.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#ifndef RUMORSETTINGS_H
#define RUMORSETTINGS_H
#include "abstractsettings.h"
namespace Ui {
class RumorSettings;
}
class RumorSettings : public AbstractSettings
{
Q_OBJECT
public:
explicit RumorSettings(QWidget *parent = nullptr);
~RumorSettings();
void initialize(const CMap & map) override;
void update(CMap & map) override;
private slots:
void on_message_textChanged();
void on_add_clicked();
void on_remove_clicked();
void on_rumors_itemSelectionChanged();
private:
Ui::RumorSettings *ui;
};
#endif // RUMORSETTINGS_H

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RumorSettings</class>
<widget class="QWidget" name="RumorSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>538</width>
<height>470</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Tavern rumors</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="add">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remove">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>0</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="rumors">
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="message"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -14,6 +14,18 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="rightMargin">