Skip to content

Commit

Permalink
fix rooms tab in level gen, make the auto refresh automatic 500ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Mar 10, 2024
1 parent 718b287 commit 96eca05
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 42 deletions.
6 changes: 4 additions & 2 deletions include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ namespace S2Plugin
struct MemoryField
{
std::string name;
size_t size{0};

MemoryFieldType type{MemoryFieldType::None};
bool isPointer{false};

Expand All @@ -166,6 +164,10 @@ namespace S2Plugin
{
return name == other.name;
}

private:
size_t size{0};
friend class Configuration;
};

struct RoomCode
Expand Down
4 changes: 1 addition & 3 deletions include/QtHelpers/WidgetSpelunkyRooms.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

namespace S2Plugin
{
class ViewToolbar;
struct ToolTipRect;

class WidgetSpelunkyRooms : public QWidget
{
Q_OBJECT

public:
WidgetSpelunkyRooms(const std::string& fieldName, ViewToolbar* toolbar, QWidget* parent = nullptr);
WidgetSpelunkyRooms(const std::string& fieldName, QWidget* parent = nullptr);

QSize minimumSizeHint() const override;
QSize sizeHint() const override;
Expand All @@ -27,7 +26,6 @@ namespace S2Plugin

private:
QString mFieldName;
ViewToolbar* mToolbar;
bool mIsMetaData = false;
size_t mOffset{0};
QFont mFont;
Expand Down
20 changes: 6 additions & 14 deletions src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ void S2Plugin::Configuration::processJSON(ordered_json& j)
}
for (const auto& [key, jsonValue] : j["struct_alignments"].items())
{
// TODO add warning if wrong value, allowed range: 0-8
mAlignments.insert({key, jsonValue.get<uint8_t>()});
}
for (const auto& [key, jsonArray] : j["refs"].items())
Expand Down Expand Up @@ -743,20 +744,11 @@ int S2Plugin::Configuration::getAlingment(const std::string& typeName) const
}
}
auto itr = mAlignments.find(typeName);
if (itr == mAlignments.end())
{
dprintf("alignment not found for (%s)\n", typeName.c_str());
return sizeof(uintptr_t);
}
else
{
if (itr->second > sizeof(uintptr_t))
{
dprintf("wrong alignment provided (%d) for struct (%s), allowed range: 0-8\n", itr->second, itr->first.c_str());
return sizeof(uintptr_t);
}
if (itr != mAlignments.end())
return itr->second;
}

dprintf("alignment not found for (%s)\n", typeName.c_str());
return sizeof(uintptr_t);
}

size_t S2Plugin::Configuration::getTypeSize(const std::string& typeName, bool entitySubclass)
Expand Down Expand Up @@ -806,7 +798,7 @@ size_t S2Plugin::MemoryField::get_size() const

if (size == 0)
{
// no entity sub class
// no entity sub class, shouldn't be needed

if (jsonName.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion src/Data/CPPGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void S2Plugin::CPPGenerator::generate(const std::string& typeName, CPPSyntaxHigh
if (field.type == MemoryFieldType::Skip)
{
variableType = "uint8_t";
variableName = "skip[" + std::to_string(field.size) + "]";
variableName = "skip[" + std::to_string(field.get_size()) + "]";
}
else if (auto str = Configuration::getCPPTypeName(field.type); !str.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion src/QtHelpers/TreeViewMemoryFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ QStandardItem* S2Plugin::TreeViewMemoryFields::addMemoryField(const MemoryField&
case MemoryFieldType::UTF8StringFixedSize:
{
returnField = createAndInsertItem(field, fieldNameOverride, parent, offset);
returnField->setData(field.size, gsRoleSize);
returnField->setData(field.get_size(), gsRoleSize);
break;
}
case MemoryFieldType::State8:
Expand Down
4 changes: 2 additions & 2 deletions src/QtHelpers/WidgetSpelunkyRooms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ static const uint32_t gsMarginVer = 5;
static constexpr size_t gsBufferSize = 8 * 16 * 2; // 8x16 rooms * 2 bytes per room
static constexpr size_t gsHalfBufferSize = 8 * 16 * 1; // 8x16 rooms * 1 byte/bool per room

S2Plugin::WidgetSpelunkyRooms::WidgetSpelunkyRooms(const std::string& fieldName, ViewToolbar* toolbar, QWidget* parent)
: QWidget(parent), mFieldName(QString::fromStdString(fieldName)), mToolbar(toolbar)
S2Plugin::WidgetSpelunkyRooms::WidgetSpelunkyRooms(const std::string& fieldName, QWidget* parent)
: QWidget(parent), mFieldName(QString::fromStdString(fieldName))
{
mFont = QFont("Courier", 11);
mTextAdvance = QFontMetrics(mFont).size(Qt::TextSingleLine, "00");
Expand Down
36 changes: 19 additions & 17 deletions src/Views/ViewLevelGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ S2Plugin::ViewLevelGen::ViewLevelGen(ViewToolbar* toolbar, QWidget* parent) : QW
mMainTreeView->setColumnWidth(gsColMemoryOffset, 125);
mMainTreeView->setColumnWidth(gsColMemoryOffsetDelta, 75);
mMainTreeView->setColumnWidth(gsColType, 100);
toggleAutoRefresh(Qt::Checked);
}

void S2Plugin::ViewLevelGen::initializeUI()
{
mMainLayout = new QVBoxLayout(this);
mRefreshLayout = new QHBoxLayout(this);
mMainLayout = new QVBoxLayout();
mRefreshLayout = new QHBoxLayout();
mMainLayout->addLayout(mRefreshLayout);

mMainTabWidget = new QTabWidget(this);
Expand All @@ -43,13 +44,14 @@ void S2Plugin::ViewLevelGen::initializeUI()
QObject::connect(mAutoRefreshTimer.get(), &QTimer::timeout, this, &ViewLevelGen::autoRefreshTimerTrigger);

mAutoRefreshCheckBox = new QCheckBox("Auto-refresh every", this);
mAutoRefreshCheckBox->setCheckState(Qt::Checked);
mRefreshLayout->addWidget(mAutoRefreshCheckBox);
QObject::connect(mAutoRefreshCheckBox, &QCheckBox::clicked, this, &ViewLevelGen::toggleAutoRefresh);

mAutoRefreshIntervalLineEdit = new QLineEdit(this);
mAutoRefreshIntervalLineEdit->setFixedWidth(50);
mAutoRefreshIntervalLineEdit->setValidator(new QIntValidator(100, 5000, this));
mAutoRefreshIntervalLineEdit->setText("2000");
mAutoRefreshIntervalLineEdit->setText("500");
mRefreshLayout->addWidget(mAutoRefreshIntervalLineEdit);
QObject::connect(mAutoRefreshIntervalLineEdit, &QLineEdit::textChanged, this, &ViewLevelGen::autoRefreshIntervalChanged);

Expand Down Expand Up @@ -97,7 +99,7 @@ void S2Plugin::ViewLevelGen::initializeUI()
{
if (field.type == MemoryFieldType::LevelGenRoomsPointer || field.type == MemoryFieldType::LevelGenRoomsMetaPointer)
{
auto roomWidget = new WidgetSpelunkyRooms(field.name, mToolbar, this);
auto roomWidget = new WidgetSpelunkyRooms(field.name, this);
if (field.type == MemoryFieldType::LevelGenRoomsMetaPointer)
{
roomWidget->setIsMetaData();
Expand All @@ -123,19 +125,19 @@ void S2Plugin::ViewLevelGen::refreshLevelGen()
{
mMainTreeView->updateTree();

// TODO: update rooms tab
// for (const auto& field : Configuration::get()->typeFields(MemoryFieldType::LevelGen))
//{
// if (mMainTabWidget->currentWidget() == mTabRooms && (field.type == MemoryFieldType::LevelGenRoomsPointer || field.type == MemoryFieldType::LevelGenRoomsMetaPointer))
// {
// auto pointerOffset = mToolbar->levelGen()->offsetForField(field.name);
// if (pointerOffset != 0)
// {
// size_t offset = Script::Memory::ReadQword(pointerOffset);
// mRoomsWidgets.at(field.name)->setOffset(offset);
// }
// }
//}
if (mMainTabWidget->currentWidget() == mTabRooms)
{
auto offset = Spelunky2::get()->get_LevelGenPtr(); // TODO: save ptr to sturct on view open
for (const auto& field : Configuration::get()->typeFields(MemoryFieldType::LevelGen))
{
if (field.type == MemoryFieldType::LevelGenRoomsPointer || field.type == MemoryFieldType::LevelGenRoomsMetaPointer)
{
size_t pointerOffset = Script::Memory::ReadQword(offset);
mRoomsWidgets.at(field.name)->setOffset(pointerOffset);
}
offset += field.get_size();
}
}
}

void S2Plugin::ViewLevelGen::toggleAutoRefresh(int newLevelGen)
Expand Down
4 changes: 2 additions & 2 deletions src/Views/ViewState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ S2Plugin::ViewState::ViewState(ViewToolbar* toolbar, uintptr_t state, QWidget* p

void S2Plugin::ViewState::initializeUI()
{
mMainLayout = new QVBoxLayout(this);
mRefreshLayout = new QHBoxLayout(this);
mMainLayout = new QVBoxLayout();
mRefreshLayout = new QHBoxLayout();
mMainLayout->addLayout(mRefreshLayout);

mRefreshButton = new QPushButton("Refresh", this);
Expand Down

0 comments on commit 96eca05

Please sign in to comment.