2018-12-28 06:56:43 +00:00
|
|
|
#include "CTweakEditor.h"
|
|
|
|
#include "ui_CTweakEditor.h"
|
2018-12-30 10:55:50 +00:00
|
|
|
#include "Editor/Undo/IUndoCommand.h"
|
2018-12-28 06:56:43 +00:00
|
|
|
|
2019-01-02 19:26:06 +00:00
|
|
|
/** Internal undo command for changing tabs */
|
|
|
|
class CSetTweakIndexCommand : public IUndoCommand
|
|
|
|
{
|
|
|
|
CTweakEditor* mpEditor;
|
|
|
|
int mOldIndex, mNewIndex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CSetTweakIndexCommand(CTweakEditor* pEditor, int OldIndex, int NewIndex)
|
|
|
|
: IUndoCommand("Change Tab")
|
|
|
|
, mpEditor(pEditor)
|
|
|
|
, mOldIndex(OldIndex)
|
|
|
|
, mNewIndex(NewIndex)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void undo() override { mpEditor->SetActiveTweakIndex(mOldIndex); }
|
|
|
|
virtual void redo() override { mpEditor->SetActiveTweakIndex(mNewIndex); }
|
2019-05-27 01:18:31 +00:00
|
|
|
virtual bool AffectsCleanState() const override { return false; }
|
2019-01-02 19:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** CTweakEditor functions */
|
2018-12-28 06:56:43 +00:00
|
|
|
CTweakEditor::CTweakEditor(QWidget* pParent)
|
|
|
|
: IEditor(pParent)
|
|
|
|
, mpUI(new Ui::CTweakEditor)
|
|
|
|
, mCurrentTweakIndex(-1)
|
|
|
|
, mHasBeenShown(false)
|
|
|
|
{
|
|
|
|
mpUI->setupUi(this);
|
|
|
|
mpUI->TweakTabs->setExpanding(false);
|
2018-12-30 10:55:50 +00:00
|
|
|
mpUI->ToolBar->addSeparator();
|
|
|
|
AddUndoActions(mpUI->ToolBar);
|
|
|
|
SET_WINDOWTITLE_APPVARS("%APP_FULL_NAME% - Tweak Editor[*]");
|
2018-12-28 06:56:43 +00:00
|
|
|
|
2018-12-30 10:55:50 +00:00
|
|
|
connect(mpUI->TweakTabs, SIGNAL(currentChanged(int)), this, SLOT(OnTweakTabClicked(int)));
|
2018-12-30 23:41:43 +00:00
|
|
|
connect(mpUI->ActionSave, SIGNAL(triggered(bool)), this, SLOT(Save()));
|
|
|
|
connect(mpUI->ActionSaveAndRepack, SIGNAL(triggered(bool)), this, SLOT(SaveAndRepack()));
|
2018-12-28 06:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CTweakEditor::~CTweakEditor()
|
|
|
|
{
|
|
|
|
delete mpUI;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CTweakEditor::HasTweaks()
|
|
|
|
{
|
|
|
|
return !mTweakAssets.isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-12-30 23:41:43 +00:00
|
|
|
bool CTweakEditor::Save()
|
|
|
|
{
|
2019-01-28 10:55:15 +00:00
|
|
|
if (!gpEdApp->ActiveProject()->TweakManager()->SaveTweaks())
|
2018-12-30 23:41:43 +00:00
|
|
|
{
|
|
|
|
UICommon::ErrorMsg(this, "Tweaks failed to save!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UndoStack().setClean();
|
|
|
|
setWindowModified(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 06:56:43 +00:00
|
|
|
void CTweakEditor::SetActiveTweakData(CTweakData* pTweakData)
|
|
|
|
{
|
|
|
|
for( int TweakIdx = 0; TweakIdx < mTweakAssets.size(); TweakIdx++ )
|
|
|
|
{
|
|
|
|
if (mTweakAssets[TweakIdx] == pTweakData)
|
|
|
|
{
|
2019-01-02 19:26:06 +00:00
|
|
|
CSetTweakIndexCommand* pCommand = new CSetTweakIndexCommand(this, mCurrentTweakIndex, TweakIdx);
|
|
|
|
UndoStack().push(pCommand);
|
2018-12-28 06:56:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTweakEditor::SetActiveTweakIndex(int Index)
|
|
|
|
{
|
|
|
|
if( mCurrentTweakIndex != Index )
|
|
|
|
{
|
|
|
|
mCurrentTweakIndex = Index;
|
|
|
|
|
|
|
|
CTweakData* pTweakData = mTweakAssets[Index];
|
|
|
|
mpUI->PropertyView->SetIntrinsicProperties(pTweakData->TweakData());
|
|
|
|
|
|
|
|
mpUI->TweakTabs->blockSignals(true);
|
|
|
|
mpUI->TweakTabs->setCurrentIndex(Index);
|
|
|
|
mpUI->TweakTabs->blockSignals(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 10:55:50 +00:00
|
|
|
void CTweakEditor::OnTweakTabClicked(int Index)
|
|
|
|
{
|
|
|
|
if (Index != mCurrentTweakIndex)
|
|
|
|
{
|
|
|
|
CSetTweakIndexCommand* pCommand = new CSetTweakIndexCommand(this, mCurrentTweakIndex, Index);
|
|
|
|
UndoStack().push(pCommand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 06:56:43 +00:00
|
|
|
void CTweakEditor::OnProjectChanged(CGameProject* pNewProject)
|
|
|
|
{
|
|
|
|
// Close and clear tabs
|
|
|
|
mCurrentTweakIndex = -1;
|
|
|
|
mpUI->PropertyView->ClearProperties();
|
|
|
|
close();
|
|
|
|
|
|
|
|
mpUI->TweakTabs->blockSignals(true);
|
|
|
|
|
|
|
|
while (mpUI->TweakTabs->count() > 0)
|
|
|
|
{
|
|
|
|
mpUI->TweakTabs->removeTab(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mTweakAssets.clear();
|
2018-12-30 10:55:50 +00:00
|
|
|
UndoStack().clear();
|
2018-12-28 06:56:43 +00:00
|
|
|
|
|
|
|
// Create tweak list
|
|
|
|
if (pNewProject != nullptr)
|
|
|
|
{
|
2019-01-25 21:06:13 +00:00
|
|
|
for (CTweakData* pTweakData : pNewProject->TweakManager()->TweakObjects())
|
2018-12-28 06:56:43 +00:00
|
|
|
{
|
2019-01-25 21:06:13 +00:00
|
|
|
mTweakAssets << pTweakData;
|
2018-12-28 06:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort in alphabetical order and create tabs
|
|
|
|
if (!mTweakAssets.isEmpty())
|
|
|
|
{
|
2019-11-07 02:52:45 +00:00
|
|
|
std::sort(mTweakAssets.begin(), mTweakAssets.end(), [](CTweakData* pLeft, CTweakData* pRight) -> bool {
|
2019-01-25 21:06:13 +00:00
|
|
|
return pLeft->TweakName().ToUpper() < pRight->TweakName().ToUpper();
|
2018-12-28 06:56:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
foreach (CTweakData* pTweakData, mTweakAssets)
|
|
|
|
{
|
2019-01-25 21:06:13 +00:00
|
|
|
QString TweakName = TO_QSTRING( pTweakData->TweakName() );
|
2018-12-28 06:56:43 +00:00
|
|
|
mpUI->TweakTabs->addTab(TweakName);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetActiveTweakIndex(0);
|
|
|
|
}
|
2018-12-30 10:55:50 +00:00
|
|
|
|
|
|
|
mpUI->TweakTabs->blockSignals(false);
|
2019-01-28 10:55:15 +00:00
|
|
|
|
|
|
|
// Hide "save and repack" button for MP2+ as it doesn't do anything different from the regular Save button
|
|
|
|
mpUI->ActionSaveAndRepack->setVisible( !pNewProject || pNewProject->Game() <= EGame::Prime );
|
2018-12-28 06:56:43 +00:00
|
|
|
}
|