metaforce/Editor/Space.cpp

273 lines
9.7 KiB
C++
Raw Normal View History

#include "Space.hpp"
#include "ViewManager.hpp"
2016-01-07 00:40:27 +00:00
#include "ResourceBrowser.hpp"
2016-02-02 04:29:58 +00:00
#include "ParticleEditor.hpp"
2016-02-02 08:31:05 +00:00
#include "ModelViewer.hpp"
#include "InformationCenter.hpp"
2016-01-18 23:33:23 +00:00
#include "icons/icons.hpp"
2016-03-05 00:03:41 +00:00
namespace urde
{
2016-03-04 23:04:53 +00:00
static logvisor::Module Log("URDE::Space");
2016-01-17 04:14:13 +00:00
Space::Space(ViewManager& vm, Class cls, Space* parent)
: m_spaceMenuNode(*this), m_spaceSelectBind(*this),
m_vm(vm), m_class(cls), m_parent(parent) {}
2016-03-04 23:04:53 +00:00
specter::View* Space::buildSpaceView(specter::ViewResources& res)
{
2016-01-05 00:01:02 +00:00
if (usesToolbar())
2016-01-07 00:40:27 +00:00
{
2016-03-04 23:04:53 +00:00
m_spaceView.reset(new specter::Space(res, *m_parent->basisView(), *this, specter::Toolbar::Position::Bottom, toolbarUnits()));
specter::View* sview = buildContentView(res);
2016-01-11 02:17:08 +00:00
m_spaceView->setContentView(sview);
2016-03-04 23:04:53 +00:00
specter::Toolbar& tb = *m_spaceView->toolbar();
2016-02-01 20:04:55 +00:00
const std::string* classStr = SpaceMenuNode::LookupClassString(m_class);
2016-03-04 23:04:53 +00:00
specter::Icon* classIcon = SpaceMenuNode::LookupClassIcon(m_class);
const zeus::CColor* classColor = SpaceMenuNode::LookupClassColor(m_class);
m_spaceSelectButton.reset(new specter::Button(res, tb, &m_spaceSelectBind, "", classIcon,
specter::Button::Style::Block,
classColor?*classColor:zeus::CColor::skWhite));
tb.push_back(m_spaceSelectButton.get(), 0);
2016-01-17 04:14:13 +00:00
buildToolbarView(res, tb);
2016-01-11 02:17:08 +00:00
return m_spaceView.get();
2016-01-07 00:40:27 +00:00
}
else
{
2016-03-04 23:04:53 +00:00
m_spaceView.reset(new specter::Space(res, *m_parent->basisView(), *this, specter::Toolbar::Position::None, 0));
specter::View* sview = buildContentView(res);
2016-01-11 02:17:08 +00:00
m_spaceView->setContentView(sview);
return m_spaceView.get();
2016-01-07 00:40:27 +00:00
}
}
2016-01-17 04:14:13 +00:00
std::vector<Space::SpaceMenuNode::SubNodeData> Space::SpaceMenuNode::s_subNodeDats =
{
2016-02-17 03:42:27 +00:00
{Class::ResourceBrowser, "resource_browser", "Resource Browser", GetIcon(SpaceIcon::ResourceBrowser), {0.0f, 1.0f, 0.0f, 1.0f}},
{Class::EffectEditor, "effect_editor", "Effect Editor", GetIcon(SpaceIcon::ParticleEditor), {1.0f, 0.5f, 0.0f, 1.0f}},
{Class::ModelViewer, "model_viewer", "Model Viewer", GetIcon(SpaceIcon::ModelViewer), {0.95f, 0.95f, 0.95f, 1.0f}},
{Class::InformationCenter, "information_center", "Information Center", GetIcon(SpaceIcon::InformationCenter), {0.0f, 1.0f, 1.0f, 1.0f}}
2016-01-17 04:14:13 +00:00
};
std::string Space::SpaceMenuNode::s_text = "Space Types";
2016-02-01 20:04:55 +00:00
void Space::SpaceMenuNode::InitializeStrings(ViewManager& vm)
2016-01-17 04:14:13 +00:00
{
s_text = vm.translateOr("space_types", s_text.c_str());
for (SubNodeData& sn : s_subNodeDats)
sn.m_text = vm.translateOr(sn.m_key, sn.m_text.c_str());
}
2016-03-04 23:04:53 +00:00
std::unique_ptr<specter::View> Space::SpaceSelectBind::buildMenu(const specter::Button* button)
2016-01-17 04:14:13 +00:00
{
2016-03-04 23:04:53 +00:00
return std::unique_ptr<specter::View>(new specter::Menu(m_space.m_vm.rootView().viewRes(),
2016-01-17 04:14:13 +00:00
*m_space.m_spaceView, &m_space.m_spaceMenuNode));
}
2016-03-04 23:04:53 +00:00
specter::View* RootSpace::buildSpaceView(specter::ViewResources& res)
2016-01-11 02:17:08 +00:00
{
2016-03-04 23:04:53 +00:00
specter::View* newRoot = buildContentView(res);
2016-01-11 02:17:08 +00:00
m_vm.RootSpaceViewBuilt(newRoot);
return newRoot;
}
2016-03-04 23:04:53 +00:00
specter::View* RootSpace::basisView() {return &m_vm.rootView();}
2016-02-01 01:13:45 +00:00
2016-03-04 23:04:53 +00:00
specter::View* SplitSpace::buildContentView(specter::ViewResources& res)
{
2016-01-12 00:46:27 +00:00
int clearance = res.pixelFactor() * SPECTER_TOOLBAR_GAUGE;
2016-03-04 23:04:53 +00:00
m_splitView.reset(new specter::SplitView(res, *m_parent->basisView(), this, m_state.axis,
2016-01-12 00:46:27 +00:00
m_state.split, clearance, clearance));
2016-01-05 00:01:02 +00:00
if (m_slots[0])
m_splitView->setContentView(0, m_slots[0]->buildSpaceView(res));
if (m_slots[1])
m_splitView->setContentView(1, m_slots[1]->buildSpaceView(res));
return m_splitView.get();
}
void SplitSpace::setChildSlot(unsigned slot, std::unique_ptr<Space>&& space)
2016-01-04 05:31:02 +00:00
{
2016-01-05 00:01:02 +00:00
if (slot > 1)
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "invalid slot %u for SplitView", slot);
2016-01-05 00:01:02 +00:00
m_slots[slot] = std::move(space);
m_slots[slot]->m_parent = this;
}
2016-03-04 23:04:53 +00:00
void SplitSpace::joinViews(specter::SplitView* thisSplit, int thisSlot, specter::SplitView* otherSplit, int otherSlot)
2016-02-01 01:13:45 +00:00
{
if (thisSplit == otherSplit)
{
SplitSpace* thisSS = dynamic_cast<SplitSpace*>(m_slots[thisSlot].get());
if (thisSS)
{
2016-03-04 23:04:53 +00:00
int ax = thisSS->m_state.axis == specter::SplitView::Axis::Horizontal ? 1 : 0;
2016-02-01 01:13:45 +00:00
const boo::SWindowRect& thisRect = m_splitView->subRect();
const boo::SWindowRect& subRect = thisSS->m_splitView->subRect();
int splitPx = subRect.location[ax] + subRect.size[ax] * thisSS->m_state.split -
thisRect.location[ax];
thisSS->m_state.split = splitPx / float(thisRect.size[ax]);
}
m_parent->exchangeSpaceSplitJoin(this, std::move(m_slots[thisSlot]));
m_vm.BuildSpaceViews();
}
else
{
for (int i=0 ; i<2 ; ++i)
{
SplitSpace* otherSS = dynamic_cast<SplitSpace*>(m_slots[i].get());
if (otherSS && otherSS->m_splitView.get() == otherSplit)
{
2016-03-04 23:04:53 +00:00
int ax = m_state.axis == specter::SplitView::Axis::Horizontal ? 1 : 0;
2016-02-01 01:13:45 +00:00
const boo::SWindowRect& thisRect = m_splitView->subRect();
const boo::SWindowRect& subRect = otherSS->m_splitView->subRect();
int splitPx = subRect.location[ax] + subRect.size[ax] * otherSS->m_state.split -
thisRect.location[ax];
m_state.split = splitPx / float(thisRect.size[ax]);
exchangeSpaceSplitJoin(otherSS, std::move(otherSS->m_slots[otherSlot ^ 1]));
m_vm.BuildSpaceViews();
break;
}
}
}
}
2016-03-04 23:04:53 +00:00
specter::ISplitSpaceController* Space::spaceSplit(specter::SplitView::Axis axis, int thisSlot)
{
if (m_parent)
{
2016-02-01 01:13:45 +00:00
/* Reject split operations with insufficient clearance */
int clearance = m_vm.m_viewResources.pixelFactor() * SPECTER_TOOLBAR_GAUGE;
2016-03-04 23:04:53 +00:00
if (axis == specter::SplitView::Axis::Horizontal)
2016-02-01 01:13:45 +00:00
{
if (m_spaceView->subRect().size[1] <= clearance)
return nullptr;
}
else
{
if (m_spaceView->subRect().size[0] <= clearance)
return nullptr;
}
2016-01-11 02:17:08 +00:00
SplitSpace* ss = new SplitSpace(m_vm, m_parent, axis);
ss->setChildSlot(thisSlot, m_parent->exchangeSpaceSplitJoin(this, std::unique_ptr<Space>(ss)));
ss->setChildSlot(thisSlot ^ 1, std::unique_ptr<Space>(copy(ss)));
2016-01-11 02:17:08 +00:00
m_vm.BuildSpaceViews();
return ss;
}
return nullptr;
}
std::unique_ptr<Space> RootSpace::exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{
std::unique_ptr<Space> ret = std::move(keepSpace);
2016-01-11 02:17:08 +00:00
if (removeSpace == m_spaceTree.get())
{
2016-01-11 02:17:08 +00:00
m_spaceTree.swap(ret);
m_spaceTree->m_parent = this;
}
else
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "RootSpace::exchangeSpaceSplitJoin() failure");
return ret;
}
std::unique_ptr<Space> SplitSpace::exchangeSpaceSplitJoin(Space* removeSpace, std::unique_ptr<Space>&& keepSpace)
{
std::unique_ptr<Space> ret = std::move(keepSpace);
if (removeSpace == m_slots[0].get())
{
m_slots[0].swap(ret);
m_slots[0]->m_parent = this;
}
else if (removeSpace == m_slots[1].get())
{
m_slots[1].swap(ret);
m_slots[1]->m_parent = this;
}
else
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "SplitSpace::exchangeSpaceSplitJoin() failure");
return ret;
2016-01-05 00:01:02 +00:00
}
template <class Reader>
static Space* BuildNewSpace(ViewManager& vm, Space::Class cls, Space* parent, Reader& r)
2016-01-05 00:01:02 +00:00
{
using Class = Space::Class;
switch (cls)
2016-01-04 05:31:02 +00:00
{
case Class::SplitSpace:
return new SplitSpace(vm, parent, r);
2016-01-07 00:40:27 +00:00
case Class::ResourceBrowser:
return new ResourceBrowser(vm, parent, r);
2016-02-01 20:04:55 +00:00
case Class::EffectEditor:
return new EffectEditor(vm, parent, r);
2016-02-02 08:31:05 +00:00
case Class::ModelViewer:
return new ModelViewer(vm, parent, r);
case Class::InformationCenter:
return new InformationCenter(vm, parent, r);
2016-01-04 05:31:02 +00:00
default: break;
}
return nullptr;
}
2016-03-04 23:04:53 +00:00
void Space::saveState(athena::io::IStreamWriter& w) const
2016-01-07 00:40:27 +00:00
{
w.writeUint32Big(atUint32(m_class));
spaceState().write(w);
}
2016-03-04 23:04:53 +00:00
void Space::saveState(athena::io::YAMLDocWriter& w) const
2016-01-07 00:40:27 +00:00
{
w.writeUint32("class", atUint32(m_class));
spaceState().write(w);
}
Space* Space::NewSpaceFromConfigStream(ViewManager& vm, Space* parent, ConfigReader& r)
2016-01-05 00:01:02 +00:00
{
Class cls = Class(r.readUint32("class"));
return BuildNewSpace(vm, cls, parent, r);
}
RootSpace* Space::NewRootSpaceFromConfigStream(ViewManager& vm, ConfigReader& r)
{
Class cls = Class(r.readUint32("class"));
if (cls != Class::RootSpace)
return nullptr;
return new RootSpace(vm, r);
2016-01-05 00:01:02 +00:00
}
2016-07-09 01:23:34 +00:00
void Space::SpaceMenuNode::SubNode::activated(const boo::SWindowCoord &coord)
{
std::unique_ptr<Space> newSpace;
switch(m_data.m_cls)
{
case Class::InformationCenter:
if (typeid(InformationCenter) != typeid(m_space))
newSpace.reset(new InformationCenter(m_space.m_parent->m_vm, m_space.m_parent));
break;
case Class::EffectEditor:
if (typeid(EffectEditor) != typeid(m_space))
newSpace.reset(new EffectEditor(m_space.m_parent->m_vm, m_space.m_parent));
break;
case Class::ResourceBrowser:
if (typeid(ResourceBrowser) != typeid(m_space))
newSpace.reset(new ResourceBrowser(m_space.m_parent->m_vm, m_space.m_parent));
break;
case Class::ModelViewer:
if (typeid(ModelViewer) != typeid(m_space))
newSpace.reset(new ModelViewer(m_space.m_parent->m_vm, m_space.m_parent));
break;
2016-07-09 01:23:34 +00:00
default: break;
}
if (newSpace)
{
Space* parent = m_space.m_parent;
m_space.m_parent->exchangeSpaceSplitJoin(&m_space, std::move(newSpace));
parent->m_vm.BuildSpaceViews();
}
}
}