Skip to content

Commit

Permalink
Editor: Added health and item test settings
Browse files Browse the repository at this point in the history
These settings can be assigned at supported engines to specify initial health or reserved item while testing levels.
  • Loading branch information
Wohlstand committed Jan 4, 2025
1 parent 02f54ba commit 39dd926
Show file tree
Hide file tree
Showing 13 changed files with 422 additions and 110 deletions.
16 changes: 15 additions & 1 deletion Editor/common_features/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ void Items::getItemGFX(const obj_wld_generic *inObj, QPixmap &outImg, bool whole
TPL_getItemGFX(inObj, outImg, whole, targetSize, imgType);
}

void Items::getItemGFXCW(int itemType, unsigned long ItemID, QPixmap &outImg, bool whole, QSize targetSize)
{
LevelEdit *l_edit = MainWinConnect::pMainWin->activeLvlEditWin();
WorldEdit *w_edit = MainWinConnect::pMainWin->activeWldEditWin();
QGraphicsScene *scene = nullptr;

if(l_edit)
scene = l_edit->scene;
else if(w_edit)
scene = w_edit->scene;

getItemGFX(itemType, ItemID, outImg, scene, whole, targetSize);
}

void Items::getItemGFX(int itemType, unsigned long ItemID, QPixmap &outImg, QGraphicsScene *scene, bool whole, QSize targetSize)
{
LvlScene *scene_lvl = dynamic_cast<LvlScene *>(scene);
Expand Down Expand Up @@ -224,7 +238,7 @@ QString Items::getTilesetToolTip(int itemType, unsigned long ItemID, QGraphicsSc
return "";
}

int Items::getItemType(QString type)
int Items::getItemType(const QString &type)
{
int target = 0;

Expand Down
15 changes: 13 additions & 2 deletions Editor/common_features/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
class Items
{
public:

/*!
* \brief Retreives sprite or single frame of the requested element using currently active window, no scene needed
* \param [__in] itemType Type of the element (Block, BGO, NPC, Terrain tile, World map scenery, Path tile, Level tile)
* \param [__in] ItemID ID of requested element
* \param [__out] outImg Target Pixmap where will be stored requested sprite
* \param [__in] whole Retreive entire srite, overwise single default frame will be retured
* \param [__in] targetSize Scale image to requested size, if 0:0 sent, image will be returned as-is
*/
static void getItemGFXCW(int itemType, unsigned long ItemID, QPixmap &outImg, bool whole=false, QSize targetSize=QSize(0,0));

/*!
* \brief Retreives sprite or single frame of the requested element
* \param [__in] itemType Type of the element (Block, BGO, NPC, Terrain tile, World map scenery, Path tile, Level tile)
Expand All @@ -19,7 +30,7 @@ class Items
* \param [__in] whole Retreive entire srite, overwise single default frame will be retured
* \param [__in] targetSize Scale image to requested size, if 0:0 sent, image will be returned as-is
*/
static void getItemGFX(int itemType, unsigned long ItemID, QPixmap &outImg, QGraphicsScene *scene=NULL, bool whole=false, QSize targetSize=QSize(0,0));
static void getItemGFX(int itemType, unsigned long ItemID, QPixmap &outImg, QGraphicsScene *scene=nullptr, bool whole=false, QSize targetSize=QSize(0,0));

/*!
* \brief Retreives sprite or single frame of the block object configuration
Expand Down Expand Up @@ -65,7 +76,7 @@ class Items
* \param type String contains a word which specifies item type
* \return Item type ID enumerated value
*/
static int getItemType(QString type);
static int getItemType(const QString &type);
};

#endif // ITEMS_H
8 changes: 8 additions & 0 deletions Editor/main_window/_settings/settings_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,14 @@ void MainWindow::loadSettings()
GlobalSettings::testing.p1_state = settings.value("p1-state", 1).toInt();
GlobalSettings::testing.p1_vehicleID = settings.value("p1-vehicle-id", 0).toInt();
GlobalSettings::testing.p1_vehicleType = settings.value("p1-vehicle-type", 0).toInt();
GlobalSettings::testing.p1_health = settings.value("p1-health", 0).toInt();
GlobalSettings::testing.p1_item = settings.value("p1-item", 0).toInt();
GlobalSettings::testing.p2_char = settings.value("p2-char", 1).toInt();
GlobalSettings::testing.p2_state = settings.value("p2-state", 1).toInt();
GlobalSettings::testing.p2_vehicleID = settings.value("p2-vehicle-id", 0).toInt();
GlobalSettings::testing.p2_vehicleType = settings.value("p2-vehicle-type", 0).toInt();
GlobalSettings::testing.p2_health = settings.value("p2-health", 0).toInt();
GlobalSettings::testing.p2_item = settings.value("p2-item", 0).toInt();
}
settings.endGroup();

Expand Down Expand Up @@ -423,10 +427,14 @@ void MainWindow::saveSettings()
settings.setValue("p1-state", GlobalSettings::testing.p1_state);
settings.setValue("p1-vehicle-id", GlobalSettings::testing.p1_vehicleID);
settings.setValue("p1-vehicle-type", GlobalSettings::testing.p1_vehicleType);
settings.setValue("p1-health", GlobalSettings::testing.p1_health);
settings.setValue("p1-item", GlobalSettings::testing.p1_item);
settings.setValue("p2-char", GlobalSettings::testing.p2_char);
settings.setValue("p2-state", GlobalSettings::testing.p2_state);
settings.setValue("p2-vehicle-id", GlobalSettings::testing.p2_vehicleID);
settings.setValue("p2-vehicle-type", GlobalSettings::testing.p2_vehicleType);
settings.setValue("p2-health", GlobalSettings::testing.p2_health);
settings.setValue("p2-item", GlobalSettings::testing.p2_item);
}
settings.endGroup();

Expand Down
4 changes: 4 additions & 0 deletions Editor/main_window/global_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ struct SETTINGS_TestSettings
int p1_state = 1;
int p1_vehicleID = 0;
int p1_vehicleType = 0;
int p1_health = -1;
int p1_item = 0;
int p2_char = 2;
int p2_state = 1;
int p2_vehicleID = 0;
int p2_vehicleType = 0;
int p2_health = -1;
int p2_item = 0;
};

struct SETTINGS_ScreenGrabSettings
Expand Down
16 changes: 16 additions & 0 deletions Editor/main_window/testing/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ void MainWindow::initTesting()
t.p2_vehicleType = vehicleType;
}
});

QObject::connect(&g_intEngine, &IntEngineSignals::enginePlayerStateUpdated2,
this, [](int playerID, int health, int reservedItem)
{
auto &t =GlobalSettings::testing;
if(playerID == 0)
{
t.p1_health = health;
t.p1_item = reservedItem;
}
else if(playerID == 1)
{
t.p2_health = health;
t.p2_item = reservedItem;
}
});
}

void MainWindow::updateTestingCaps()
Expand Down
110 changes: 107 additions & 3 deletions Editor/main_window/testing/testing_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "ui_testing_settings.h"
#include <mainwindow.h>
#include <main_window/global_settings.h>
#include <editing/_dialogs/itemselectdialog.h>
#include <data_configs/data_configs.h>
#include <common_features/items.h>

#include <QMessageBox>

Expand All @@ -12,10 +14,11 @@ TestingSettings::TestingSettings(QWidget *parent) :
{
ui->setupUi(this);

MainWindow* mw = qobject_cast<MainWindow*>(this->parent());
if(mw)
m_mw = qobject_cast<MainWindow*>(this->parent());

if(m_mw)
{
QList<obj_player>& plr = mw->configs.main_characters;
QList<obj_player>& plr = m_mw->configs.main_characters;
ui->p1_character->clear();
ui->p2_character->clear();

Expand Down Expand Up @@ -56,14 +59,26 @@ TestingSettings::TestingSettings(QWidget *parent) :
ui->ex_physdebug->setChecked(GlobalSettings::testing.xtra_physdebug);
ui->ex_freedom->setChecked(GlobalSettings::testing.xtra_worldfreedom);
ui->ex_starsNum->setValue(GlobalSettings::testing.xtra_starsNum);

ui->p1_character->setCurrentIndex(GlobalSettings::testing.p1_char-1);
ui->p1_state->setCurrentIndex(GlobalSettings::testing.p1_state-1);
ui->p1_vehicleID->setCurrentIndex(GlobalSettings::testing.p1_vehicleID);
ui->p1_vehicleType->setCurrentIndex(GlobalSettings::testing.p1_vehicleType);
ui->p1_health_en->setChecked(GlobalSettings::testing.p1_health > 0);
if(GlobalSettings::testing.p1_health > 0)
ui->p1_health->setValue(GlobalSettings::testing.p1_health);
m_curItemP1 = GlobalSettings::testing.p1_item;
updateNpcButton(ui->p1_reserved, m_curItemP1);

ui->p2_character->setCurrentIndex(GlobalSettings::testing.p2_char-1);
ui->p2_state->setCurrentIndex(GlobalSettings::testing.p2_state-1);
ui->p2_vehicleID->setCurrentIndex(GlobalSettings::testing.p2_vehicleID);
ui->p2_vehicleType->setCurrentIndex(GlobalSettings::testing.p2_vehicleType);
ui->p2_health_en->setChecked(GlobalSettings::testing.p2_health > 0);
if(GlobalSettings::testing.p2_health > 0)
ui->p2_health->setValue(GlobalSettings::testing.p2_health);
m_curItemP2 = GlobalSettings::testing.p2_item;
updateNpcButton(ui->p2_reserved, m_curItemP2);

switch(GlobalSettings::testing.numOfPlayers)
{
Expand All @@ -85,6 +100,15 @@ TestingSettings::TestingSettings(QWidget *parent) :
default:
case ConfStatus::ENGINE_MOONDUST:
ui->initialState->setVisible(false); // Not implemented at Moondust Engine yet
// Not implemented at Moondust Engine yet
ui->p1_health_en->setVisible(false);
ui->p1_health->setVisible(false);
ui->p1_reserved_label->setVisible(false);
ui->p1_reserved->setVisible(false);
ui->p2_health_en->setVisible(false);
ui->p2_health->setVisible(false);
ui->p2_reserved_label->setVisible(false);
ui->p2_reserved->setVisible(false);
break;

case ConfStatus::ENGINE_THEXTECH:
Expand All @@ -102,13 +126,29 @@ TestingSettings::TestingSettings(QWidget *parent) :
ui->ex_flyup ->setVisible(false);
ui->ex_debug ->setVisible(false);
ui->ex_physdebug ->setVisible(false);
ui->p1_health_en->setVisible(false);
ui->p1_health->setVisible(false);
ui->p1_reserved_label->setVisible(false);
ui->p1_reserved->setVisible(false);
ui->p2_health_en->setVisible(false);
ui->p2_health->setVisible(false);
ui->p2_reserved_label->setVisible(false);
ui->p2_reserved->setVisible(false);
break;

case ConfStatus::ENGINE_38A:
ui->extraSettings->setVisible(false);
ui->initialState->setVisible(false);
ui->cheats->setVisible(false);
ui->debug->setVisible(false);
ui->p1_health_en->setVisible(false);
ui->p1_health->setVisible(false);
ui->p1_reserved_label->setVisible(false);
ui->p1_reserved->setVisible(false);
ui->p2_health_en->setVisible(false);
ui->p2_health->setVisible(false);
ui->p2_reserved_label->setVisible(false);
ui->p2_reserved->setVisible(false);
break;
}
}
Expand Down Expand Up @@ -141,10 +181,15 @@ void TestingSettings::on_buttonBox_accepted()
GlobalSettings::testing.p1_state = (ui->p1_state->currentIndex()+1);
GlobalSettings::testing.p1_vehicleID = (ui->p1_vehicleID->currentIndex());
GlobalSettings::testing.p1_vehicleType = (ui->p1_vehicleType->currentIndex());
GlobalSettings::testing.p1_health = ui->p1_health_en->isChecked() ? (ui->p1_health->value()) : -1;
GlobalSettings::testing.p1_item = m_curItemP1;

GlobalSettings::testing.p2_char = (ui->p2_character->currentIndex()+1);
GlobalSettings::testing.p2_state = (ui->p2_state->currentIndex()+1);
GlobalSettings::testing.p2_vehicleID = (ui->p2_vehicleID->currentIndex());
GlobalSettings::testing.p2_vehicleType = (ui->p2_vehicleType->currentIndex());
GlobalSettings::testing.p2_health = ui->p2_health_en->isChecked() ? (ui->p2_health->value()) : -1;
GlobalSettings::testing.p2_item = m_curItemP2;
this->close();
}

Expand Down Expand Up @@ -256,3 +301,62 @@ void TestingSettings::refreshVehicleTypes()
if(p2_sel_backup <= ui->p2_vehicleType->count())
ui->p2_vehicleType->setCurrentIndex(p2_sel_backup);
}

void TestingSettings::updateNpcButton(QPushButton *button, int npcId)
{
QString npcTitle;
QPixmap icon;

LevelEdit *edit = m_mw->activeLvlEditWin();

if(npcId > 0)
{
auto &source = edit ? edit->scene->m_localConfigNPCs : m_mw->configs.main_npc;

if(source.contains(npcId))
{
auto it = source[npcId];
npcTitle = it.setup.name;
Items::getItemGFXCW(ItemTypes::LVL_NPC, npcId, icon, false, QSize(16, 16));
}
}

if(npcTitle.isEmpty())
npcTitle = tr("<Unknown>", "Unknown NPC from the list");

button->setText(npcId <= 0 ? tr("[No item]", "Reserve box of player contains no item") : QString("NPC-%1 (%2)").arg(npcId).arg(npcTitle));

if(!icon.isNull())
button->setIcon(QIcon(icon.scaledToHeight(16)));
}

void TestingSettings::on_p1_reserved_clicked()
{
if(!m_mw)
return;

ItemSelectDialog *npcList = new ItemSelectDialog(&m_mw->configs, ItemSelectDialog::TAB_NPC, 0, 0, 0, m_curItemP1, 0, 0, 0, 0, 0, this);
util::DialogToCenter(npcList, true);

if(npcList->exec() == QDialog::Accepted)
{
m_curItemP1 = npcList->npcID;
updateNpcButton(ui->p1_reserved, m_curItemP1);
}
}

void TestingSettings::on_p2_reserved_clicked()
{
if(!m_mw)
return;

ItemSelectDialog *npcList = new ItemSelectDialog(&m_mw->configs, ItemSelectDialog::TAB_NPC, 0, 0, 0, m_curItemP2, 0, 0, 0, 0, 0, this);
util::DialogToCenter(npcList, true);

if(npcList->exec() == QDialog::Accepted)
{
m_curItemP2 = npcList->npcID;
updateNpcButton(ui->p2_reserved, m_curItemP2);
}
}

10 changes: 10 additions & 0 deletions Editor/main_window/testing/testing_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ namespace Ui {
class TestingSettings;
}

class MainWindow;

class TestingSettings : public QDialog
{
Q_OBJECT

int m_curItemP1 = 0;
int m_curItemP2 = 0;
MainWindow* m_mw = nullptr;
public:
explicit TestingSettings(QWidget *parent = 0);
~TestingSettings();
Expand All @@ -20,6 +25,9 @@ private slots:
void on_buttonBox_accepted();
void reloadStates1(int index);
void reloadStates2(int index);
void on_p1_reserved_clicked();
void on_p2_reserved_clicked();

signals:
void windowShown();

Expand All @@ -31,6 +39,8 @@ private slots:

void refreshVehicleID();
void refreshVehicleTypes();

void updateNpcButton(QPushButton *button, int npcId);
};

#endif // TESTING_SETTINGS_H
Loading

0 comments on commit 39dd926

Please sign in to comment.