Skip to content

Commit

Permalink
Preview is pretty much working. A few things are hardcoded right now,…
Browse files Browse the repository at this point in the history
… this could be solved in a more general way.
  • Loading branch information
codereader committed Nov 19, 2017
1 parent 9cf0c12 commit c5d3c7a
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
54 changes: 37 additions & 17 deletions plugins/dm.editing/MissionInfoEditDialog.cpp
Expand Up @@ -26,7 +26,8 @@ namespace

MissionInfoEditDialog::MissionInfoEditDialog(wxWindow* parent) :
DialogBase(_(WINDOW_TITLE), parent),
_missionTitleStore(new wxutil::TreeModel(_missionTitleColumns, true))
_missionTitleStore(new wxutil::TreeModel(_missionTitleColumns, true)),
_updateInProgress(false)
{
populateWindow();

Expand All @@ -45,24 +46,21 @@ MissionInfoEditDialog::MissionInfoEditDialog(wxWindow* parent) :
_darkmodTxt = std::make_shared<map::DarkmodTxt>();
}

_guiView->setGui(GlobalGuiManager().getGui("guis/mainmenu.gui"));
_guiView->setMissionInfoFile(_darkmodTxt);

updateValuesFromDarkmodTxt();
}

void MissionInfoEditDialog::updateValuesFromDarkmodTxt()
{
_missionTitleStore->Clear();

if (!_darkmodTxt)
{
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogTitleEntry")->SetValue("");
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogAuthorEntry")->SetValue("");
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogDescriptionEntry")->SetValue("");
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogVersionEntry")->SetValue("");
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogReqTdmVersionEntry")->SetValue("");
findNamedObject<wxStaticText>(this, "MissionInfoEditDialogOutputPath")->SetLabelText("-");

return;
}
assert(_darkmodTxt); // this should be non-NULL at all times

if (!_darkmodTxt) return;

_updateInProgress = true;

findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogTitleEntry")->SetValue(_darkmodTxt->getTitle());
findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogAuthorEntry")->SetValue(_darkmodTxt->getAuthor());
Expand All @@ -85,6 +83,10 @@ void MissionInfoEditDialog::updateValuesFromDarkmodTxt()

row.SendItemAdded();
}

_guiView->update();

_updateInProgress = false;
}

void MissionInfoEditDialog::populateWindow()
Expand Down Expand Up @@ -122,8 +124,6 @@ void MissionInfoEditDialog::populateWindow()
_guiView = new MissionInfoGuiView(previewPanel);
previewPanel->GetSizer()->Add(_guiView, 1, wxEXPAND);

_guiView->setGui(GlobalGuiManager().getGui("guis/mainmenu.gui"));

makeLabelBold(this, "MissionInfoLabel");

wxButton* saveButton = findNamedObject<wxButton>(this, "MissionInfoEditDialogSaveButton");
Expand All @@ -146,24 +146,44 @@ void MissionInfoEditDialog::populateWindow()
std::bind(&MissionInfoEditDialog::testDeleteTitle, this)
);

// Wire up the text entry boxes to update the preview
setupNamedEntryBox("MissionInfoEditDialogTitleEntry");
setupNamedEntryBox("MissionInfoEditDialogAuthorEntry");
setupNamedEntryBox("MissionInfoEditDialogDescriptionEntry");
setupNamedEntryBox("MissionInfoEditDialogVersionEntry");

Layout();
Fit();
CenterOnScreen();
}

void MissionInfoEditDialog::onSave(wxCommandEvent& ev)
void MissionInfoEditDialog::setupNamedEntryBox(const std::string& ctrlName)
{
try
wxTextCtrl* ctrl = findNamedObject<wxTextCtrl>(this, ctrlName);

assert(ctrl != nullptr);
if (ctrl == nullptr) return;

ctrl->Bind(wxEVT_TEXT, [this](wxCommandEvent& ev)
{
if (_updateInProgress) return;

// Load the values from the UI to the DarkmodTxt instance
_darkmodTxt->setTitle(findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogTitleEntry")->GetValue().ToStdString());
_darkmodTxt->setAuthor(findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogAuthorEntry")->GetValue().ToStdString());
_darkmodTxt->setDescription(findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogDescriptionEntry")->GetValue().ToStdString());
_darkmodTxt->setVersion(findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogVersionEntry")->GetValue().ToStdString());
_darkmodTxt->setReqTdmVersion(findNamedObject<wxTextCtrl>(this, "MissionInfoEditDialogReqTdmVersionEntry")->GetValue().ToStdString());

// Mission list is kept in sync all the time, no need to load them into the instance here
_guiView->update();
});
}

void MissionInfoEditDialog::onSave(wxCommandEvent& ev)
{
try
{
// DarkmodTxt is kept in sync all the time, no need to load anything, just save to disk
_darkmodTxt->saveToCurrentMod();

// Close the dialog
Expand Down
6 changes: 5 additions & 1 deletion plugins/dm.editing/MissionInfoEditDialog.h
Expand Up @@ -8,6 +8,7 @@
#include "wxutil/menu/PopupMenu.h"

#include "DarkmodTxt.h"
#include "MissionInfoGuiView.h"

namespace wxutil { class GuiView; }

Expand Down Expand Up @@ -41,7 +42,9 @@ class MissionInfoEditDialog :
// Context menu
wxutil::PopupMenuPtr _missionTitlesContextMenu;

wxutil::GuiView* _guiView;
MissionInfoGuiView* _guiView;

bool _updateInProgress;

public:
// Constructor
Expand All @@ -52,6 +55,7 @@ class MissionInfoEditDialog :
private:
void populateWindow();
void updateValuesFromDarkmodTxt();
void setupNamedEntryBox(const std::string& ctrlName);

void onSave(wxCommandEvent& ev);
void onCancel(wxCommandEvent& ev);
Expand Down
34 changes: 34 additions & 0 deletions plugins/dm.editing/MissionInfoGuiView.cpp
Expand Up @@ -58,4 +58,38 @@ void MissionInfoGuiView::setGui(const gui::IGuiPtr& gui)
setWindowDefFilter("ModToInstallParent");
}

void MissionInfoGuiView::setMissionInfoFile(const map::DarkmodTxtPtr& file)
{
_file = file;
}

void MissionInfoGuiView::update()
{
const gui::IGuiPtr& gui = getGui();

if (!_file || !gui) return;

gui->findWindowDef("modTitle")->setText(_file->getTitle());
gui->findWindowDef("modDescription")->setText(_file->getDescription());
gui->findWindowDef("modAuthor")->setText(_file->getAuthor());

// These are internationalised strings in the GUI code, let's hardcode some for the preview
gui->findWindowDef("modLastPlayedTitle")->setText("Last played:");
gui->findWindowDef("modCompletedTitle")->setText("Completed:");
gui->findWindowDef("modLastPlayedValue")->setText("2017-11-19");
gui->findWindowDef("modCompletedValue")->setText("2017-11-26");
gui->findWindowDef("modSizeTitle")->setText("Space used:");
gui->findWindowDef("modSizeValue")->setText("123 MB");
gui->findWindowDef("modSizeEraseFromDiskAction")->setText("[Erase from disk]");

gui->findWindowDef("modLoadN")->setText("Install Mission");
gui->findWindowDef("modLoadH")->setText("Install Mission");
gui->findWindowDef("modLoad")->setText("Install Mission");
gui->findWindowDef("moreInfoH")->setText("Notes");
gui->findWindowDef("moreInfoN")->setText("Notes");
gui->findWindowDef("moreInfo")->setText("Notes");

redraw();
}

} // namespace
9 changes: 9 additions & 0 deletions plugins/dm.editing/MissionInfoGuiView.h
Expand Up @@ -2,6 +2,7 @@

#include "igui.h"
#include "wxutil/preview/GuiView.h"
#include "DarkmodTxt.h"

namespace ui
{
Expand All @@ -18,11 +19,19 @@ class MissionInfoGuiView :

std::vector<std::string> backgroundDefList;

// The file containing the mission info this view is previewing
map::DarkmodTxtPtr _file;

public:
MissionInfoGuiView(wxWindow* parent);

virtual void setGui(const gui::IGuiPtr& gui) override;

void setMissionInfoFile(const map::DarkmodTxtPtr& file);

// Loads the values from the attached DarkmodTxt file into the GUI
void update();

protected:
virtual void setGLViewPort();
};
Expand Down
5 changes: 2 additions & 3 deletions plugins/dm.gui/gui/RenderableText.cpp
Expand Up @@ -28,7 +28,7 @@ RenderableText::RenderableText(const IGuiWindowDef& owner) :

void RenderableText::printMissingGlyphSetError() const
{
rConsoleError() << "[dm.gui] Font '" << _font->getName() << "'"
rWarning() << "[dm.gui] Font '" << _font->getName() << "'"
<< " does not have glyph set for resolution "
<< _resolution << std::endl;
}
Expand All @@ -46,8 +46,6 @@ void RenderableText::realiseFontShaders()
}
else
{
printMissingGlyphSetError();

switch (_resolution)
{
case fonts::Resolution12:
Expand All @@ -60,6 +58,7 @@ void RenderableText::realiseFontShaders()
break;
case fonts::Resolution48:
rWarning() << "No resolutions to fall back." << std::endl;
printMissingGlyphSetError();
return;
}
}
Expand Down

0 comments on commit c5d3c7a

Please sign in to comment.