mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Some code cleaning up
This commit is contained in:
parent
061ac414e8
commit
700e957cdb
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* CGameInfo.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 "CGameInfo.h"
|
||||
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
|
||||
const CGameInfo * CGI;
|
||||
CClientState * CCS = nullptr;
|
||||
CServerHandler * CSH;
|
||||
|
||||
|
||||
CGameInfo::CGameInfo()
|
||||
{
|
||||
generaltexth = nullptr;
|
||||
mh = nullptr;
|
||||
townh = nullptr;
|
||||
globalServices = nullptr;
|
||||
}
|
||||
|
||||
void CGameInfo::setFromLib()
|
||||
{
|
||||
globalServices = VLC;
|
||||
modh = VLC->modh;
|
||||
generaltexth = VLC->generaltexth;
|
||||
creh = VLC->creh;
|
||||
townh = VLC->townh;
|
||||
heroh = VLC->heroh;
|
||||
objh = VLC->objh;
|
||||
spellh = VLC->spellh;
|
||||
skillh = VLC->skillh;
|
||||
objtypeh = VLC->objtypeh;
|
||||
obstacleHandler = VLC->obstacleHandler;
|
||||
battleFieldHandler = VLC->battlefieldsHandler;
|
||||
}
|
||||
|
||||
const ArtifactService * CGameInfo::artifacts() const
|
||||
{
|
||||
return globalServices->artifacts();
|
||||
}
|
||||
|
||||
const BattleFieldService * CGameInfo::battlefields() const
|
||||
{
|
||||
return globalServices->battlefields();
|
||||
}
|
||||
|
||||
const CreatureService * CGameInfo::creatures() const
|
||||
{
|
||||
return globalServices->creatures();
|
||||
}
|
||||
|
||||
const FactionService * CGameInfo::factions() const
|
||||
{
|
||||
return globalServices->factions();
|
||||
}
|
||||
|
||||
const HeroClassService * CGameInfo::heroClasses() const
|
||||
{
|
||||
return globalServices->heroClasses();
|
||||
}
|
||||
|
||||
const HeroTypeService * CGameInfo::heroTypes() const
|
||||
{
|
||||
return globalServices->heroTypes();
|
||||
}
|
||||
|
||||
#if SCRIPTING_ENABLED
|
||||
const scripting::Service * CGameInfo::scripts() const
|
||||
{
|
||||
return globalServices->scripts();
|
||||
}
|
||||
#endif
|
||||
|
||||
const spells::Service * CGameInfo::spells() const
|
||||
{
|
||||
return globalServices->spells();
|
||||
}
|
||||
|
||||
const SkillService * CGameInfo::skills() const
|
||||
{
|
||||
return globalServices->skills();
|
||||
}
|
||||
|
||||
const ObstacleService * CGameInfo::obstacles() const
|
||||
{
|
||||
return globalServices->obstacles();
|
||||
}
|
||||
|
||||
|
||||
void CGameInfo::updateEntity(Metatype metatype, int32_t index, const JsonNode & data)
|
||||
{
|
||||
logGlobal->error("CGameInfo::updateEntity call is not expected.");
|
||||
}
|
||||
|
||||
spells::effects::Registry * CGameInfo::spellEffects()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const spells::effects::Registry * CGameInfo::spellEffects() const
|
||||
{
|
||||
return globalServices->spellEffects();
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* CGameInfo.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 <vcmi/Services.h>
|
||||
|
||||
#include "../lib/ConstTransitivePtr.h"
|
||||
|
||||
class CModHandler;
|
||||
class CMapHandler;
|
||||
class CHeroHandler;
|
||||
class CCreatureHandler;
|
||||
class CSpellHandler;
|
||||
class CSkillHandler;
|
||||
class CBuildingHandler;
|
||||
class CObjectHandler;
|
||||
class CSoundHandler;
|
||||
class CMusicHandler;
|
||||
class CObjectClassesHandler;
|
||||
class CTownHandler;
|
||||
class CGeneralTextHandler;
|
||||
class CConsoleHandler;
|
||||
class CCursorHandler;
|
||||
class CGameState;
|
||||
class IMainVideoPlayer;
|
||||
class CServerHandler;
|
||||
class BattleFieldHandler;
|
||||
class ObstacleHandler;
|
||||
|
||||
class CMap;
|
||||
|
||||
|
||||
//a class for non-mechanical client GUI classes
|
||||
class CClientState
|
||||
{
|
||||
public:
|
||||
CSoundHandler * soundh;
|
||||
CMusicHandler * musich;
|
||||
CConsoleHandler * consoleh;
|
||||
CCursorHandler * curh;
|
||||
IMainVideoPlayer * videoh;
|
||||
};
|
||||
extern CClientState * CCS;
|
||||
|
||||
/// CGameInfo class
|
||||
/// for allowing different functions for accessing game informations
|
||||
class CGameInfo : public Services
|
||||
{
|
||||
public:
|
||||
const ArtifactService * artifacts() const override;
|
||||
const CreatureService * creatures() const override;
|
||||
const FactionService * factions() const override;
|
||||
const HeroClassService * heroClasses() const override;
|
||||
const HeroTypeService * heroTypes() const override;
|
||||
#if SCRIPTING_ENABLED
|
||||
const scripting::Service * scripts() const override;
|
||||
#endif
|
||||
const spells::Service * spells() const override;
|
||||
const SkillService * skills() const override;
|
||||
const ObstacleService * obstacles() const override;
|
||||
const BattleFieldService * battlefields() const override;
|
||||
|
||||
void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
|
||||
|
||||
const spells::effects::Registry * spellEffects() const override;
|
||||
spells::effects::Registry * spellEffects() override;
|
||||
|
||||
|
||||
ConstTransitivePtr<CModHandler> modh; //public?
|
||||
ConstTransitivePtr<BattleFieldHandler> battleFieldHandler;
|
||||
ConstTransitivePtr<CHeroHandler> heroh;
|
||||
ConstTransitivePtr<CCreatureHandler> creh;
|
||||
ConstTransitivePtr<CSpellHandler> spellh;
|
||||
ConstTransitivePtr<CSkillHandler> skillh;
|
||||
ConstTransitivePtr<CObjectHandler> objh;
|
||||
ConstTransitivePtr<CObjectClassesHandler> objtypeh;
|
||||
ConstTransitivePtr<ObstacleHandler> obstacleHandler;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CMapHandler * mh;
|
||||
CTownHandler * townh;
|
||||
|
||||
void setFromLib();
|
||||
|
||||
CGameInfo();
|
||||
private:
|
||||
const Services * globalServices;
|
||||
};
|
||||
extern const CGameInfo* CGI;
|
@ -1,7 +0,0 @@
|
||||
#include "StdInc.h"
|
||||
#include "radiopushbutton.h"
|
||||
|
||||
RadioPushButton::RadioPushButton()
|
||||
{
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#ifndef RADIOPUSHBUTTON_H
|
||||
#define RADIOPUSHBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class RadioPushButton : public QPushButton
|
||||
{
|
||||
public:
|
||||
RadioPushButton();
|
||||
};
|
||||
|
||||
#endif // RADIOPUSHBUTTON_H
|
@ -1,59 +0,0 @@
|
||||
#include "StdInc.h"
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#include "spoiler.h"
|
||||
|
||||
Spoiler::Spoiler(const QString & title, const int animationDuration, QWidget *parent) : QWidget(parent), animationDuration(animationDuration)
|
||||
{
|
||||
toggleButton.setStyleSheet("QToolButton { border: none; }");
|
||||
toggleButton.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
toggleButton.setArrowType(Qt::ArrowType::RightArrow);
|
||||
toggleButton.setText(title);
|
||||
toggleButton.setCheckable(true);
|
||||
toggleButton.setChecked(false);
|
||||
|
||||
headerLine.setFrameShape(QFrame::HLine);
|
||||
headerLine.setFrameShadow(QFrame::Sunken);
|
||||
headerLine.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
|
||||
|
||||
contentArea.setStyleSheet("QScrollArea { background-color: white; border: none; }");
|
||||
contentArea.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
// start out collapsed
|
||||
contentArea.setMaximumHeight(0);
|
||||
contentArea.setMinimumHeight(0);
|
||||
// let the entire widget grow and shrink with its content
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(this, "maximumHeight"));
|
||||
toggleAnimation.addAnimation(new QPropertyAnimation(&contentArea, "maximumHeight"));
|
||||
// don't waste space
|
||||
mainLayout.setVerticalSpacing(0);
|
||||
mainLayout.setContentsMargins(0, 0, 0, 0);
|
||||
int row = 0;
|
||||
mainLayout.addWidget(&toggleButton, row, 0, 1, 1, Qt::AlignLeft);
|
||||
mainLayout.addWidget(&headerLine, row++, 2, 1, 1);
|
||||
mainLayout.addWidget(&contentArea, row, 0, 1, 3);
|
||||
setLayout(&mainLayout);
|
||||
QObject::connect(&toggleButton, &QToolButton::clicked, [this](const bool checked) {
|
||||
toggleButton.setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
|
||||
toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
|
||||
toggleAnimation.start();
|
||||
});
|
||||
}
|
||||
|
||||
void Spoiler::setContentLayout(QLayout & contentLayout)
|
||||
{
|
||||
delete contentArea.layout();
|
||||
contentArea.setLayout(&contentLayout);
|
||||
const auto collapsedHeight = sizeHint().height() - contentArea.maximumHeight();
|
||||
auto contentHeight = contentLayout.sizeHint().height();
|
||||
for (int i = 0; i < toggleAnimation.animationCount() - 1; ++i) {
|
||||
QPropertyAnimation * spoilerAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(i));
|
||||
spoilerAnimation->setDuration(animationDuration);
|
||||
spoilerAnimation->setStartValue(collapsedHeight);
|
||||
spoilerAnimation->setEndValue(collapsedHeight + contentHeight);
|
||||
}
|
||||
QPropertyAnimation * contentAnimation = static_cast<QPropertyAnimation *>(toggleAnimation.animationAt(toggleAnimation.animationCount() - 1));
|
||||
contentAnimation->setDuration(animationDuration);
|
||||
contentAnimation->setStartValue(0);
|
||||
contentAnimation->setEndValue(contentHeight);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef SPOILER_H
|
||||
#define SPOILER_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QGridLayout>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QScrollArea>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
||||
class Spoiler : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QGridLayout mainLayout;
|
||||
QToolButton toggleButton;
|
||||
QFrame headerLine;
|
||||
QParallelAnimationGroup toggleAnimation;
|
||||
QScrollArea contentArea;
|
||||
int animationDuration{300};
|
||||
|
||||
public:
|
||||
explicit Spoiler(const QString & title = "", const int animationDuration = 300, QWidget *parent = 0);
|
||||
void setContentLayout(QLayout & contentLayout);
|
||||
};
|
||||
|
||||
#endif // SPOILER_H
|
Loading…
x
Reference in New Issue
Block a user