mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
Add portraits delegate
This commit is contained in:
parent
051886c98e
commit
55900ceb66
@ -1066,9 +1066,8 @@ std::string CGHeroInstance::getBiographyTextID() const
|
||||
return biographyCustomTextId;
|
||||
if (type)
|
||||
return type->getBiographyTextID();
|
||||
|
||||
assert(0);
|
||||
return "";
|
||||
|
||||
return ""; //for random hero
|
||||
}
|
||||
|
||||
CGHeroInstance::ArtPlacementMap CGHeroInstance::putArtifact(ArtifactPosition pos, CArtifactInstance * art)
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "Animation.h"
|
||||
|
||||
#include "BitmapHandler.h"
|
||||
#include "graphics.h"
|
||||
|
||||
#include "../lib/vcmi_endian.h"
|
||||
#include "../lib/filesystem/Filesystem.h"
|
||||
@ -585,8 +586,8 @@ void Animation::init()
|
||||
|
||||
JsonPath resID = JsonPath::builtin("SPRITES/" + name);
|
||||
|
||||
//if(vstd::contains(graphics->imageLists, resID.getName()))
|
||||
//initFromJson(graphics->imageLists[resID.getName()]);
|
||||
if(vstd::contains(graphics->imageLists, resID.getName()))
|
||||
initFromJson(graphics->imageLists[resID.getName()]);
|
||||
|
||||
auto configList = CResourceHandler::get()->getResourcesWithName(resID);
|
||||
|
||||
|
@ -35,6 +35,7 @@ set(editor_SRCS
|
||||
inspector/questwidget.cpp
|
||||
inspector/heroskillswidget.cpp
|
||||
inspector/PickObjectDelegate.cpp
|
||||
inspector/portraitwidget.cpp
|
||||
resourceExtractor/ResourceConverter.cpp
|
||||
)
|
||||
|
||||
@ -74,6 +75,7 @@ set(editor_HEADERS
|
||||
inspector/questwidget.h
|
||||
inspector/heroskillswidget.h
|
||||
inspector/PickObjectDelegate.h
|
||||
inspector/portraitwidget.h
|
||||
resourceExtractor/ResourceConverter.h
|
||||
)
|
||||
|
||||
@ -99,6 +101,7 @@ set(editor_FORMS
|
||||
inspector/rewardswidget.ui
|
||||
inspector/questwidget.ui
|
||||
inspector/heroskillswidget.ui
|
||||
inspector/portraitwidget.ui
|
||||
)
|
||||
|
||||
set(editor_TS
|
||||
|
@ -11,6 +11,7 @@
|
||||
//code is copied from vcmiclient/Graphics.h with minimal changes
|
||||
|
||||
#include "../lib/GameConstants.h"
|
||||
#include "../lib/filesystem/ResourcePath.h"
|
||||
#include <QImage>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "rewardswidget.h"
|
||||
#include "questwidget.h"
|
||||
#include "heroskillswidget.h"
|
||||
#include "portraitwidget.h"
|
||||
#include "PickObjectDelegate.h"
|
||||
#include "../mapcontroller.h"
|
||||
|
||||
@ -286,7 +287,7 @@ void Inspector::updateProperties(CGHeroInstance * o)
|
||||
}
|
||||
addProperty("Name", o->getNameTranslated(), false);
|
||||
addProperty("Biography", o->getBiographyTranslated(), new MessageDelegate, false);
|
||||
addProperty("Portrait", o->customPortraitSource, false);
|
||||
addProperty("Portrait", PropertyEditorPlaceholder(), new PortraitDelegate(*o), false);
|
||||
|
||||
auto * delegate = new HeroSkillsDelegate(*o);
|
||||
addProperty("Skills", PropertyEditorPlaceholder(), delegate, false);
|
||||
|
135
mapeditor/inspector/portraitwidget.cpp
Normal file
135
mapeditor/inspector/portraitwidget.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* portraitwidget.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 "portraitwidget.h"
|
||||
#include "ui_portraitwidget.h"
|
||||
#include "../../lib/CHeroHandler.h"
|
||||
#include "../Animation.h"
|
||||
|
||||
PortraitWidget::PortraitWidget(CGHeroInstance & h, QWidget *parent):
|
||||
QDialog(parent),
|
||||
ui(new Ui::PortraitWidget),
|
||||
hero(h),
|
||||
portraitIndex(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->portraitView->setScene(&scene);
|
||||
ui->portraitView->fitInView(scene.itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
PortraitWidget::~PortraitWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void PortraitWidget::obtainData()
|
||||
{
|
||||
portraitIndex = VLC->heroh->getById(hero.getPortraitSource())->getIndex();
|
||||
if(hero.customPortraitSource.isValid())
|
||||
{
|
||||
ui->isDefault->setChecked(true);
|
||||
}
|
||||
|
||||
drawPortrait();
|
||||
}
|
||||
|
||||
void PortraitWidget::commitChanges()
|
||||
{
|
||||
if(portraitIndex == VLC->heroh->getById(HeroTypeID(hero.subID))->getIndex())
|
||||
hero.customPortraitSource = HeroTypeID::NONE;
|
||||
else
|
||||
hero.customPortraitSource = VLC->heroh->getByIndex(portraitIndex)->getId();
|
||||
}
|
||||
|
||||
void PortraitWidget::drawPortrait()
|
||||
{
|
||||
static Animation portraitAnimation(AnimationPath::builtin("PortraitsLarge").getOriginalName());
|
||||
portraitAnimation.preload();
|
||||
auto icon = VLC->heroTypes()->getByIndex(portraitIndex)->getIconIndex();
|
||||
pixmap = QPixmap::fromImage(*portraitAnimation.getImage(icon));
|
||||
scene.addPixmap(pixmap);
|
||||
ui->portraitView->fitInView(scene.itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void PortraitWidget::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
ui->portraitView->fitInView(scene.itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void PortraitWidget::on_isDefault_toggled(bool checked)
|
||||
{
|
||||
if(checked)
|
||||
{
|
||||
ui->buttonNext->setEnabled(false);
|
||||
ui->buttonPrev->setEnabled(false);
|
||||
portraitIndex = VLC->heroh->getById(HeroTypeID(hero.subID))->getIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->buttonNext->setEnabled(true);
|
||||
ui->buttonPrev->setEnabled(true);
|
||||
}
|
||||
drawPortrait();
|
||||
}
|
||||
|
||||
|
||||
void PortraitWidget::on_buttonNext_clicked()
|
||||
{
|
||||
if(portraitIndex < VLC->heroh->size() - 1)
|
||||
++portraitIndex;
|
||||
else
|
||||
portraitIndex = 0;
|
||||
|
||||
drawPortrait();
|
||||
}
|
||||
|
||||
|
||||
void PortraitWidget::on_buttonPrev_clicked()
|
||||
{
|
||||
if(portraitIndex > 0)
|
||||
--portraitIndex;
|
||||
else
|
||||
portraitIndex = VLC->heroh->size() - 1;
|
||||
|
||||
drawPortrait();
|
||||
}
|
||||
|
||||
PortraitDelegate::PortraitDelegate(CGHeroInstance & h): hero(h), QStyledItemDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * PortraitDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return new PortraitWidget(hero, parent);
|
||||
}
|
||||
|
||||
void PortraitDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if(auto * ed = qobject_cast<PortraitWidget *>(editor))
|
||||
{
|
||||
ed->obtainData();
|
||||
}
|
||||
else
|
||||
{
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
}
|
||||
|
||||
void PortraitDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
if(auto * ed = qobject_cast<PortraitWidget *>(editor))
|
||||
{
|
||||
ed->commitChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
}
|
64
mapeditor/inspector/portraitwidget.h
Normal file
64
mapeditor/inspector/portraitwidget.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* portraitwidget.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
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
|
||||
namespace Ui {
|
||||
class PortraitWidget;
|
||||
}
|
||||
|
||||
class PortraitWidget : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PortraitWidget(CGHeroInstance &, QWidget *parent = nullptr);
|
||||
~PortraitWidget();
|
||||
|
||||
void obtainData();
|
||||
void commitChanges();
|
||||
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
|
||||
private slots:
|
||||
void on_isDefault_toggled(bool checked);
|
||||
|
||||
void on_buttonNext_clicked();
|
||||
|
||||
void on_buttonPrev_clicked();
|
||||
|
||||
private:
|
||||
void drawPortrait();
|
||||
|
||||
Ui::PortraitWidget *ui;
|
||||
QGraphicsScene scene;
|
||||
QPixmap pixmap;
|
||||
|
||||
CGHeroInstance & hero;
|
||||
int portraitIndex;
|
||||
};
|
||||
|
||||
class PortraitDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QStyledItemDelegate::QStyledItemDelegate;
|
||||
|
||||
PortraitDelegate(CGHeroInstance &);
|
||||
|
||||
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||
|
||||
private:
|
||||
CGHeroInstance & hero;
|
||||
};
|
96
mapeditor/inspector/portraitwidget.ui
Normal file
96
mapeditor/inspector/portraitwidget.ui
Normal file
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PortraitWidget</class>
|
||||
<widget class="QDialog" name="PortraitWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>286</width>
|
||||
<height>305</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Portrait</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="portraitView">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>116</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonNext">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::UpArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="buttonPrev">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::DownArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="isDefault">
|
||||
<property name="text">
|
||||
<string>Default</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user