Skip to content

Commit

Permalink
no need for setVisible(true) right after creating. Added some initi…
Browse files Browse the repository at this point in the history
…al tree update, other minor things
  • Loading branch information
Mr-Auto committed May 3, 2024
1 parent 2d228f2 commit ad4cae6
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 125 deletions.
3 changes: 0 additions & 3 deletions src/QtHelpers/WidgetDatabaseView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ S2Plugin::WidgetDatabaseView::WidgetDatabaseView(MemoryFieldType type, QWidget*
mSearchLineEdit->setPlaceholderText("Search");
topLayout->addWidget(mSearchLineEdit);
QObject::connect(mSearchLineEdit, &QLineEdit::returnPressed, this, &WidgetDatabaseView::searchFieldReturnPressed);
mSearchLineEdit->setVisible(false);

auto labelButton = new QPushButton("Label", this);
QObject::connect(labelButton, &QPushButton::clicked, this, &WidgetDatabaseView::label);
Expand Down Expand Up @@ -128,9 +127,7 @@ S2Plugin::WidgetDatabaseView::WidgetDatabaseView(MemoryFieldType type, QWidget*
tabCompare->layout()->addWidget(mCompareTreeWidget);
}

mSearchLineEdit->setVisible(true);
mSearchLineEdit->setFocus();
mMainTreeView->setVisible(true);
}

QSize S2Plugin::WidgetDatabaseView::minimumSizeHint() const
Expand Down
2 changes: 1 addition & 1 deletion src/Views/ViewCharacterDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void S2Plugin::ViewCharacterDB::label() const
auto& characterDB = Spelunky2::get()->get_CharacterDB();
auto offset = characterDB.addressOfIndex(0); // ptr
uintptr_t indexOffset = model->data(model->index(0, gsColField), gsRoleMemoryAddress).toULongLong();
size_t index = (indexOffset - offset) / characterDB.characterSize();
uint8_t index = static_cast<uint8_t>((indexOffset - offset) / characterDB.characterSize());
if (index < characterDB.charactersCount())
{
name = '[' + characterDB.characterNamesStringList()[index].toStdString() + ']';
Expand Down
18 changes: 6 additions & 12 deletions src/Views/ViewEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

S2Plugin::ViewEntities::ViewEntities(QWidget* parent) : QWidget(parent)
{
auto mainLayout = new QVBoxLayout(this);
setWindowIcon(getCavemanIcon());
setWindowTitle("Entities");

auto mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);
auto config = Configuration::get();
mLayer0Offset = config->offsetForField(MemoryFieldType::State, "layer0", Spelunky2::get()->get_StatePtr());
mLayer1Offset = config->offsetForField(MemoryFieldType::State, "layer1", Spelunky2::get()->get_StatePtr());
Expand Down Expand Up @@ -66,19 +69,12 @@ S2Plugin::ViewEntities::ViewEntities(QWidget* parent) : QWidget(parent)
horLayout->addStretch();
mainLayout->addLayout(horLayout);
}

mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->setEnableChangeHighlighting(false);
mainLayout->addWidget(mMainTreeView);

setWindowIcon(getCavemanIcon());

mainLayout->setMargin(5);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColMemoryAddressDelta).disable(gsColMemoryAddress).disable(gsColComment);

setWindowTitle("Entities");
mMainTreeView->setVisible(true);
mainLayout->addWidget(mMainTreeView);

mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColMemoryAddressDelta).disable(gsColMemoryAddress).disable(gsColComment);
refreshEntities();
mFilterLineEdit->setFocus();
}
Expand Down Expand Up @@ -206,11 +202,9 @@ void S2Plugin::ViewEntities::refreshEntities()
checkbox.mCheckbox->setText(QString(checkbox.name + " (%1)").arg(field_count));
}
setWindowTitle(QString("%1 Entities").arg(totalEntities));

mMainTreeView->updateTableHeader();
mMainTreeView->setColumnWidth(gsColField, 145);
mMainTreeView->setColumnWidth(gsColValueHex, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddress, 125);
mMainTreeView->setColumnWidth(gsColType, 100);
mMainTreeView->setColumnWidth(gsColValue, 300);
mMainTreeView->updateTree();
Expand Down
126 changes: 56 additions & 70 deletions src/Views/ViewEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ S2Plugin::ViewEntity::ViewEntity(size_t entityOffset, QWidget* parent) : QWidget
initializeUI();
updateMemoryViewOffsetAndSize();

mSpelunkyLevel->paintFloor(QColor(160, 160, 160));
mSpelunkyLevel->paintEntity(mEntityPtr, QColor(222, 52, 235));
mSpelunkyLevel->update();
auto entityClassName = Entity{mEntityPtr}.entityClassName();

// the combobox is set as Entity by default, so we have to manually call interpretAsChanged
if (entityClassName == "Entity")
interpretAsChanged(QString::fromStdString(entityClassName));
Expand All @@ -57,7 +53,6 @@ void S2Plugin::ViewEntity::initializeUI()
mainLayout->addLayout(topLayout);

// TOP LAYOUT

auto autoRefresh = new WidgetAutorefresh("100", this);
QObject::connect(autoRefresh, &WidgetAutorefresh::refresh, this, &ViewEntity::refreshEntity);
topLayout->addWidget(autoRefresh);
Expand Down Expand Up @@ -92,82 +87,73 @@ void S2Plugin::ViewEntity::initializeUI()
QObject::connect(mMainTabWidget, &QTabWidget::currentChanged, this, &ViewEntity::tabChanged);
mainLayout->addWidget(mMainTabWidget);

auto tabFields = new QWidget();
mMainTreeView = new TreeViewMemoryFields();
auto tabMemory = new QWidget();
auto tabLevel = new QWidget();
auto tabCPP = new QWidget();
tabFields->setLayout(new QVBoxLayout());
tabFields->layout()->setMargin(0);
auto tabLevel = new QScrollArea();
mCPPTextEdit = new QTextEdit();

tabMemory->setLayout(new QHBoxLayout());
tabMemory->layout()->setMargin(0);
tabLevel->setLayout(new QVBoxLayout());
tabLevel->layout()->setMargin(0);
tabCPP->setLayout(new QVBoxLayout());
tabCPP->layout()->setMargin(0);

mMainTabWidget->addTab(tabFields, "Fields");
mMainTabWidget->addTab(mMainTreeView, "Fields");
mMainTabWidget->addTab(tabMemory, "Memory");
mMainTabWidget->addTab(tabLevel, "Level");
mMainTabWidget->addTab(tabCPP, "C++");
mMainTabWidget->addTab(mCPPTextEdit, "C++");

// TAB FIELDS
mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->setColumnWidth(gsColValue, 250);
mMainTreeView->setColumnWidth(gsColField, 175);
mMainTreeView->setColumnWidth(gsColValueHex, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddress, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddressDelta, 75);
mMainTreeView->setColumnWidth(gsColType, 100);
mMainTreeView->setVisible(false);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex);
mMainTreeView->updateTableHeader();
mMainTreeView->setDragDropMode(QAbstractItemView::DragDropMode::DragDrop);
mMainTreeView->setAcceptDrops(true);
QObject::connect(mMainTreeView, &TreeViewMemoryFields::entityOffsetDropped, this, &ViewEntity::entityOffsetDropped);
tabFields->layout()->addWidget(mMainTreeView);

{
mMainTreeView->setColumnWidth(gsColValue, 250);
mMainTreeView->setColumnWidth(gsColField, 175);
mMainTreeView->setColumnWidth(gsColValueHex, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddress, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddressDelta, 75);
mMainTreeView->setColumnWidth(gsColType, 100);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex);
mMainTreeView->updateTableHeader();
mMainTreeView->setDragDropMode(QAbstractItemView::DragDropMode::DragDrop);
mMainTreeView->setAcceptDrops(true);
QObject::connect(mMainTreeView, &TreeViewMemoryFields::entityOffsetDropped, this, &ViewEntity::entityOffsetDropped);
}
// TAB MEMORY
auto scroll = new QScrollArea(tabMemory);
mMemoryView = new WidgetMemoryView(scroll);
scroll->setStyleSheet("background-color: #fff;");
scroll->setWidget(mMemoryView);
scroll->setVisible(true);
tabMemory->layout()->addWidget(scroll);

mMemoryComparisonScrollArea = new QScrollArea(tabMemory);
mMemoryComparisonView = new WidgetMemoryView(mMemoryComparisonScrollArea);
mMemoryComparisonScrollArea->setStyleSheet("background-color: #fff;");
mMemoryComparisonScrollArea->setWidget(mMemoryComparisonView);
mMemoryComparisonScrollArea->setVisible(true);
tabMemory->layout()->addWidget(mMemoryComparisonScrollArea);
mMemoryComparisonScrollArea->setVisible(false);

{
auto scroll = new QScrollArea(tabMemory);
mMemoryView = new WidgetMemoryView(scroll);
scroll->setStyleSheet("background-color: #fff;");
scroll->setWidget(mMemoryView);
tabMemory->layout()->addWidget(scroll);

mMemoryComparisonScrollArea = new QScrollArea(tabMemory);
mMemoryComparisonView = new WidgetMemoryView(mMemoryComparisonScrollArea);
mMemoryComparisonScrollArea->setStyleSheet("background-color: #fff;");
mMemoryComparisonScrollArea->setWidget(mMemoryComparisonView);
tabMemory->layout()->addWidget(mMemoryComparisonScrollArea);
mMemoryComparisonScrollArea->setVisible(false);
}
// TAB LEVEL
scroll = new QScrollArea(tabLevel);
mSpelunkyLevel = new WidgetSpelunkyLevel(mEntityPtr, scroll);
scroll->setStyleSheet("background-color: #fff;");
scroll->setWidget(mSpelunkyLevel);
scroll->setVisible(true);
tabLevel->layout()->addWidget(scroll);

{
mSpelunkyLevel = new WidgetSpelunkyLevel(mEntityPtr, tabLevel);
mSpelunkyLevel->paintFloor(QColor(160, 160, 160));
mSpelunkyLevel->paintEntity(mEntityPtr, QColor(222, 52, 235));
tabLevel->setStyleSheet("background-color: #fff;");
tabLevel->setWidget(mSpelunkyLevel);
}
// TAB CPP
mCPPTextEdit = new QTextEdit(this);
mCPPTextEdit->setReadOnly(true);
auto font = QFont("Courier", 10);
font.setFixedPitch(true);
font.setStyleHint(QFont::Monospace);
auto fontMetrics = QFontMetrics(font);
mCPPTextEdit->setFont(font);
mCPPTextEdit->setTabStopWidth(4 * fontMetrics.width(' '));
mCPPTextEdit->setLineWrapMode(QTextEdit::LineWrapMode::NoWrap);
QPalette palette = mCPPTextEdit->palette();
palette.setColor(QPalette::Base, QColor("#1E1E1E"));
palette.setColor(QPalette::Text, QColor("#D4D4D4"));
mCPPTextEdit->setPalette(palette);
mCPPTextEdit->document()->setDocumentMargin(10);
mCPPSyntaxHighlighter = new CPPSyntaxHighlighter(mCPPTextEdit->document());

tabCPP->layout()->addWidget(mCPPTextEdit);
{
mCPPTextEdit->setReadOnly(true);
auto font = QFont("Courier", 10);
font.setFixedPitch(true);
font.setStyleHint(QFont::Monospace);
auto fontMetrics = QFontMetrics(font);
mCPPTextEdit->setFont(font);
mCPPTextEdit->setTabStopWidth(4 * fontMetrics.width(' '));
mCPPTextEdit->setLineWrapMode(QTextEdit::LineWrapMode::NoWrap);
QPalette palette = mCPPTextEdit->palette();
palette.setColor(QPalette::Base, QColor("#1E1E1E"));
palette.setColor(QPalette::Text, QColor("#D4D4D4"));
mCPPTextEdit->setPalette(palette);
mCPPTextEdit->document()->setDocumentMargin(10);
mCPPSyntaxHighlighter = new CPPSyntaxHighlighter(mCPPTextEdit->document());
}
mainLayout->setMargin(5);
autoRefresh->toggleAutoRefresh(true);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Views/ViewJournalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ S2Plugin::ViewJournalPage::ViewJournalPage(uintptr_t address, QWidget* parent) :
setWindowTitle("JournalPage");

auto mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);
auto refreshLayout = new QHBoxLayout();
mainLayout->addLayout(refreshLayout);

Expand Down Expand Up @@ -63,9 +64,7 @@ S2Plugin::ViewJournalPage::ViewJournalPage(uintptr_t address, QWidget* parent) :
mMainTreeView->setColumnWidth(gsColMemoryAddressDelta, 75);
mMainTreeView->setColumnWidth(gsColType, 100);
mMainTreeView->updateTableHeader();

mainLayout->setMargin(5);
mMainTreeView->setVisible(true);
mMainTreeView->updateTree(0, 0, true);
autoRefresh->toggleAutoRefresh(true);
}

Expand Down
27 changes: 8 additions & 19 deletions src/Views/ViewLevelGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ S2Plugin::ViewLevelGen::ViewLevelGen(uintptr_t address, QWidget* parent) : QWidg
setWindowTitle("LevelGen");

auto mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);
auto refreshLayout = new QHBoxLayout();
mainLayout->addLayout(refreshLayout);

Expand All @@ -37,22 +38,15 @@ S2Plugin::ViewLevelGen::ViewLevelGen(uintptr_t address, QWidget* parent) : QWidg
mainLayout->addWidget(mMainTabWidget);

// TABS
auto tabData = new QWidget();
auto tabRooms = new QWidget();
tabData->setLayout(new QVBoxLayout());
tabData->layout()->setMargin(0);
tabData->setObjectName("datawidget");
tabRooms->setLayout(new QVBoxLayout());
tabRooms->layout()->setMargin(0);

mMainTabWidget->addTab(tabData, "Data");
mMainTreeView = new TreeViewMemoryFields(this);
auto tabRooms = new QScrollArea(this);

mMainTabWidget->addTab(mMainTreeView, "Data");
mMainTabWidget->addTab(tabRooms, "Rooms");

// TAB DATA
{
mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->addMemoryFields(Configuration::get()->typeFields(MemoryFieldType::LevelGen), "LevelGen", mLevelGenPtr);
tabData->layout()->addWidget(mMainTreeView);

mMainTreeView->setColumnWidth(gsColValue, 250);
mMainTreeView->setColumnWidth(gsColField, 125);
Expand All @@ -67,10 +61,9 @@ S2Plugin::ViewLevelGen::ViewLevelGen(uintptr_t address, QWidget* parent) : QWidg

// TAB ROOMS
{
auto scroll = new QScrollArea(this);
scroll->setWidgetResizable(true);
tabRooms->setWidgetResizable(true);
auto containerWidget = new QWidget(this);
scroll->setWidget(containerWidget);
tabRooms->setWidget(containerWidget);
auto containerLayout = new QVBoxLayout(containerWidget);

for (const auto& field : Configuration::get()->typeFields(MemoryFieldType::LevelGen))
Expand All @@ -86,13 +79,9 @@ S2Plugin::ViewLevelGen::ViewLevelGen(uintptr_t address, QWidget* parent) : QWidg
containerLayout->addWidget(roomWidget);
}
}
dynamic_cast<QVBoxLayout*>(tabRooms->layout())->addWidget(scroll);
}

mainLayout->setMargin(5);
mMainTreeView->setVisible(true);
autoRefresh->toggleAutoRefresh(true);
mMainTreeView->updateTree(0, 0, true); // just initial refresh so we don't the all fields marked as just changed (red)
mMainTreeView->updateTree(0, 0, true);
}

void S2Plugin::ViewLevelGen::refreshLevelGen()
Expand Down
2 changes: 1 addition & 1 deletion src/Views/ViewParticleDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ S2Plugin::ViewParticleDB::ViewParticleDB(QWidget* parent) : WidgetDatabaseView(M
particleNameCompleter->setFilterMode(Qt::MatchContains);
QObject::connect(particleNameCompleter, static_cast<void (QCompleter::*)(const QString&)>(&QCompleter::activated), this, &ViewParticleDB::searchFieldCompleterActivated);
mSearchLineEdit->setCompleter(particleNameCompleter);
mCompareTableWidget->setRowCount(particleEmitters.count());
mCompareTableWidget->setRowCount(static_cast<int>(particleEmitters.count()));
showID(1);
}

Expand Down
10 changes: 4 additions & 6 deletions src/Views/ViewStdMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ S2Plugin::ViewStdMap::ViewStdMap(const std::string& keytypeName, const std::stri
setWindowTitle(QString("std::map<%1, %2>").arg(QString::fromStdString(keytypeName), QString::fromStdString(valuetypeName)));

auto mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(5);
auto refreshLayout = new QHBoxLayout();
mainLayout->addLayout(refreshLayout);

Expand All @@ -43,9 +44,7 @@ S2Plugin::ViewStdMap::ViewStdMap(const std::string& keytypeName, const std::stri
mMainTreeView = new TreeViewMemoryFields(this);
mMainTreeView->setEnableChangeHighlighting(false);
mMainTreeView->activeColumns.disable(gsColComparisonValue).disable(gsColComparisonValueHex).disable(gsColMemoryAddressDelta).disable(gsColComment);
mMainTreeView->setVisible(true);
mainLayout->addWidget(mMainTreeView);
mainLayout->setMargin(5);
autoRefresh->toggleAutoRefresh(true);
refreshMapContents();
}
Expand Down Expand Up @@ -122,21 +121,20 @@ void S2Plugin::ViewStdMap::refreshMapContents()
parent_field.name = "obj_" + std::to_string(x);
parent = mMainTreeView->addMemoryField(parent_field, parent_field.name, 0, 0);

mMainTreeView->addMemoryField(key_field, key_field.name, _cur.key_ptr(), 0, parent);
mMainTreeView->addMemoryField(key_field, key_field.name, _cur.key_ptr(), 0, 0, parent);

if (mMapValueTypeSize == 0) // StdSet
continue;

mMainTreeView->addMemoryField(value_field, value_field.name, _cur.value_ptr(), 0, parent);
mMainTreeView->addMemoryField(value_field, value_field.name, _cur.value_ptr(), 0, 0, parent);
}
refreshData();

mMainTreeView->updateTableHeader();
mMainTreeView->setColumnWidth(gsColField, 145);
mMainTreeView->setColumnWidth(gsColValueHex, 125);
mMainTreeView->setColumnWidth(gsColMemoryAddress, 125);
mMainTreeView->setColumnWidth(gsColType, 100);
mMainTreeView->setColumnWidth(gsColValue, 300);
mMainTreeView->updateTree(0, 0, true);
}

void S2Plugin::ViewStdMap::refreshData()
Expand Down
Loading

0 comments on commit ad4cae6

Please sign in to comment.