Skip to content

Commit

Permalink
Removed highlight of virtual properties.
Browse files Browse the repository at this point in the history
Fixed bug with post-mapping of properties after script changed.
Added auto-select in select script tool.
Fixed empty properties in produced opCodes in scripts (initial instructions, now they are inited from start by zero/default values)
DronCode committed May 2, 2024
1 parent 741a3d9 commit 690ac53
Showing 5 changed files with 66 additions and 48 deletions.
16 changes: 0 additions & 16 deletions BMEdit/Editor/Include/Models/SceneObjectControllerModel.h
Original file line number Diff line number Diff line change
@@ -13,19 +13,6 @@ namespace models
{
Q_OBJECT

private:
struct SpecialRow
{
int startRow { 0 };
int endRow { 0 };
QColor backgroundColor {};

bool includes(int row) const
{
return row >= startRow && row <= endRow;
}
};

public:
SceneObjectControllerModel(QObject *parent = nullptr);

@@ -34,8 +21,6 @@ namespace models
void setControllerIndex(int controllerIndex);
void resetController();

QVariant data(const QModelIndex &index, int role) const override;

private:
void addSugarViews(const gamelib::Type* pControllerType, gamelib::Value& v, const std::string& scriptName);
void removeSugarViews(const gamelib::Type* pControllerType, gamelib::Value& v);
@@ -48,6 +33,5 @@ namespace models

gamelib::scene::SceneObject *m_geom { nullptr };
int m_currentControllerIndex = kUnset;
std::vector<SpecialRow> m_specialRows {};
};
}
36 changes: 5 additions & 31 deletions BMEdit/Editor/Source/Models/SceneObjectControllerModel.cpp
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ void SceneObjectControllerModel::setGeom(gamelib::scene::SceneObject *geom)
const bool isNewGeom = m_geom != geom;
beginResetModel();

m_specialRows.clear();
m_geom = geom;
m_currentControllerIndex = kUnset;
endResetModel();
@@ -37,7 +36,6 @@ void SceneObjectControllerModel::resetGeom()
beginResetModel();

// and after that we've ready to do smth else
m_specialRows.clear();
m_geom = nullptr;
m_currentControllerIndex = kUnset;
endResetModel();
@@ -56,9 +54,6 @@ void SceneObjectControllerModel::setControllerIndex(int controllerIndex)

beginResetModel();

// reset special rows info
m_specialRows.clear();

// reset controller index
m_currentControllerIndex = controllerIndex;
endResetModel();
@@ -90,23 +85,6 @@ void SceneObjectControllerModel::resetController()
resetValue();
}

QVariant SceneObjectControllerModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::BackgroundRole)
{
for (const auto& specialRow : m_specialRows)
{
if (specialRow.includes(index.row()))
{
return specialRow.backgroundColor;
}
}
}

// other requests redirect to root logic
return ValueModelBase::data(index, role);
}

void SceneObjectControllerModel::addSugarViews(const gamelib::Type* pControllerType, gamelib::Value &v, const std::string &scriptName)
{
// Ok, it must be pretty easy. First of all we need to find a script description in TypeRegistry
@@ -115,10 +93,6 @@ void SceneObjectControllerModel::addSugarViews(const gamelib::Type* pControllerT
const int baseViewsNr = asDefault.getEntries().size();
const int baseSize = asDefault.getInstructions().size();

SpecialRow row {};
row.endRow = row.startRow = baseSize;
row.backgroundColor = QColor(26, 188, 156);

if (auto scriptInfo = gamelib::TypeRegistry::getInstance().getScriptInfo(scriptName); scriptInfo.has_value())
{
// Ok, let's insert that data
@@ -128,11 +102,7 @@ void SceneObjectControllerModel::addSugarViews(const gamelib::Type* pControllerT
gamelib::ValueEntry temp = ent;
temp.instructions.iOffset += baseSize;
v += temp;
++row.endRow; // I'm not sure that +1 is enough here, but += temp.instructions.iSize is not valid too!
}

// save new row
m_specialRows.emplace_back(row);
}
}

@@ -190,7 +160,11 @@ void SceneObjectControllerModel::onValueChanged()

// And add extra stubs
for (const auto& ent : scriptInfo->entries)
newProperties += ent;
{
auto newEnt = ent;
newEnt.instructions.iOffset += 1; // Add +1 because instruction #0 - our root instruction
newProperties += newEnt;
}

// Done
setValue(newProperties);
3 changes: 3 additions & 0 deletions BMEdit/Editor/UI/Include/SelectScriptTool.h
Original file line number Diff line number Diff line change
@@ -45,13 +45,16 @@ class SelectScriptTool : public widgets::TypePropertyWidget

static Frontend_SelectScriptTool* Create(QWidget* parent);

void setValue(const types::QGlacierValue &value) override;

protected:
// buildLayout and updateLayout not implemented because no dynamic layout here. I'm just handling setValue
void closeEvent(QCloseEvent* pEvent) override;

private:
void disableAcceptButton();
void enableAcceptButton();
void selectByPath(const QString& path);

private slots:
void onAccepted();
56 changes: 56 additions & 0 deletions BMEdit/Editor/UI/Source/SelectScriptTool.cpp
Original file line number Diff line number Diff line change
@@ -127,6 +127,50 @@ void SelectScriptTool::enableAcceptButton()
}
}

void SelectScriptTool::selectByPath(const QString &path)
{
QSignalBlocker blocker { m_ui->gameScripts->selectionModel() };

QStringList pathParts = path.split('\\');
if (pathParts.empty()) return;

auto* model = qobject_cast<models::GameScriptsTreeModel*>(m_ui->gameScripts->model());
if (!model)
{
return;
}

QModelIndex currentIndex = QModelIndex();

foreach (const QString& part, pathParts)
{
bool found = false;
int rows = model->rowCount(currentIndex);

for (int i = 0; i < rows; ++i)
{
QModelIndex childIndex = model->index(i, 0, currentIndex);
QString entryName = model->data(childIndex, Qt::DisplayRole).toString();

if (entryName == part)
{
currentIndex = childIndex;
found = true;
m_ui->gameScripts->expand(currentIndex);
m_ui->gameScripts->scrollTo(currentIndex);
break;
}
}

if (!found)
{
return;
}
}

m_ui->gameScripts->selectionModel()->select(currentIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows);
}

void SelectScriptTool::onAccepted()
{
// need to set value
@@ -188,6 +232,18 @@ void SelectScriptTool::onScriptSelected(const QItemSelection &selected, const QI
}
}

void SelectScriptTool::setValue(const types::QGlacierValue &value)
{
// call for base
widgets::TypePropertyWidget::setValue(value);

if (value.instructions.size() == 1 && value.instructions[0].isString())
{
// Need to parse path
selectByPath(QString::fromStdString(value.instructions[0].getOperand().str));
}
}

Frontend_SelectScriptTool *SelectScriptTool::Create(QWidget *parent)
{
auto* pEditor = new SelectScriptTool(nullptr);
3 changes: 2 additions & 1 deletion BMEdit/GameLib/Source/GameLib/TypeRegistry.cpp
Original file line number Diff line number Diff line change
@@ -62,7 +62,8 @@ namespace gamelib

void produceOpCode(ScriptInfo& si, prp::PRPOpCode opCode)
{
prp::PRPInstruction instruction { opCode }; // idk is it ok or not
const gamelib::prp::PRPOperandVal kNullOperand(0); // initialized with zero but it's not typed holder
prp::PRPInstruction instruction { opCode, kNullOperand };
si.initialInstructions.emplace_back(instruction);
}

0 comments on commit 690ac53

Please sign in to comment.