Skip to content

Commit

Permalink
container gump pythonized
Browse files Browse the repository at this point in the history
  • Loading branch information
spin committed Nov 22, 2012
1 parent 344349b commit 2816a37
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 80 deletions.
8 changes: 8 additions & 0 deletions data/gumps/container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import ui

def create(args):
g = ui.GumpMenu("container", 250, 250)

cont = g.addContainerView((0, 0), args["item"])
cont.background = args["background"]
22 changes: 15 additions & 7 deletions src/fluorescence/ui/components/containerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace fluo {
namespace ui {
namespace components {

ContainerView::ContainerView(CL_GUIComponent* parent, const CL_Rect& bounds) : GumpComponent(parent), sizeAdjusted(false) {
this->set_geometry(bounds);
ContainerView::ContainerView(CL_GUIComponent* parent, const boost::shared_ptr<world::DynamicItem>& cont) : GumpComponent(parent),
backgroundGumpId_(0), sizeAdjusted(false), containerObject_(cont) {
boost::shared_ptr<ContainerRenderQueue> rq(new ContainerRenderQueue());
renderer_.reset(new ContainerRenderer(rq, this));

Expand All @@ -52,6 +52,8 @@ ContainerView::ContainerView(CL_GUIComponent* parent, const CL_Rect& bounds) : G
func_pointer_exit().set(this, &ContainerView::onPointerExit);

set_type_name("containerview");

containerObject_->setContainerView(this);
}

ContainerView::~ContainerView() {
Expand All @@ -70,9 +72,14 @@ unsigned int ContainerView::getHeight() {

void ContainerView::renderOneFrame(CL_GraphicContext& gc, const CL_Rect& clipRect) {
if (!sizeAdjusted && backgroundTexture_ && backgroundTexture_->isReadComplete()) {
CL_Rectf geom = get_geometry();
geom.set_width(backgroundTexture_->getWidth());
geom.set_height(backgroundTexture_->getHeight());
ui::Manager::getSingleton()->queueComponentResize(this, geom);
sizeAdjusted = true;

renderer_->getRenderQueue()->forceRepaint();

return;
}

CL_Draw::texture(gc, renderer_->getTexture(gc), CL_Rectf(0, 0, CL_Sizef(getWidth(), getHeight())));
Expand Down Expand Up @@ -175,17 +182,18 @@ void ContainerView::removeObject(boost::shared_ptr<world::IngameObject> obj) {
}

void ContainerView::setBackgroundGumpId(unsigned int gumpId) {
backgroundGumpId_ = gumpId;
backgroundTexture_ = data::Manager::getTexture(data::TextureSource::GUMPART, gumpId);
sizeAdjusted = false;
request_repaint();
}

boost::shared_ptr<ui::Texture> ContainerView::getBackgroundTexture() {
return backgroundTexture_;
unsigned int ContainerView::getBackgroundGumpId() const {
return backgroundGumpId_;
}

void ContainerView::setContainerObject(boost::shared_ptr<world::DynamicItem> cont) {
containerObject_ = cont;
boost::shared_ptr<ui::Texture> ContainerView::getBackgroundTexture() {
return backgroundTexture_;
}

bool ContainerView::onPointerEnter() {
Expand Down
5 changes: 3 additions & 2 deletions src/fluorescence/ui/components/containerview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace components {

class ContainerView : public GumpComponent {
public:
ContainerView(CL_GUIComponent* parent, const CL_Rect& bounds);
ContainerView(CL_GUIComponent* parent, const boost::shared_ptr<world::DynamicItem>& cont);
~ContainerView();

unsigned int getWidth();
Expand All @@ -54,7 +54,7 @@ class ContainerView : public GumpComponent {
void removeObject(boost::shared_ptr<world::IngameObject> obj);

void setBackgroundGumpId(unsigned int gumpId);
void setContainerObject(boost::shared_ptr<world::DynamicItem> cont);
unsigned int getBackgroundGumpId() const;

boost::shared_ptr<ui::Texture> getBackgroundTexture();

Expand All @@ -70,6 +70,7 @@ class ContainerView : public GumpComponent {
bool onInputReleased(const CL_InputEvent & e);
bool onDoubleClick(const CL_InputEvent& e);

unsigned int backgroundGumpId_;
boost::shared_ptr<ui::Texture> backgroundTexture_;
bool sizeAdjusted;
boost::shared_ptr<world::DynamicItem> containerObject_;
Expand Down
6 changes: 6 additions & 0 deletions src/fluorescence/ui/python/modui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ BOOST_PYTHON_MODULE(ui) {
.def("addPropertyLabel", &PyGumpComponentContainer::addPropertyLabel, bpy::return_value_policy<bpy::reference_existing_object>())
.def("addSysLogLabel", &PyGumpComponentContainer::addSysLogLabel, bpy::return_value_policy<bpy::reference_existing_object>())
.def("addHtmlLabel", &PyGumpComponentContainer::addHtmlLabel, bpy::return_value_policy<bpy::reference_existing_object>())
.def("addContainerView", &PyGumpComponentContainer::addContainerView, bpy::return_value_policy<bpy::reference_existing_object>())
;

// non-instanciable wrapper class for gump menus
Expand Down Expand Up @@ -234,6 +235,11 @@ BOOST_PYTHON_MODULE(ui) {
// sysloglabel component
bpy::class_<components::SysLogLabel, bpy::bases<components::Label>, boost::noncopyable>("SysLogLabel", bpy::no_init)
;

// container view component
bpy::class_<components::ContainerView, bpy::bases<GumpComponent>, boost::noncopyable>("ContainerView", bpy::no_init)
.add_property("background", &components::ContainerView::getBackgroundGumpId, &components::ContainerView::setBackgroundGumpId)
;
}

}
Expand Down
4 changes: 4 additions & 0 deletions src/fluorescence/ui/python/modworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "pyworld.hpp"

#include <world/mobile.hpp>
#include <world/dynamicitem.hpp>

namespace fluo {
namespace ui {
Expand All @@ -48,6 +49,9 @@ BOOST_PYTHON_MODULE(world) {
;

bpy::def("getPlayer", &PyWorld::getPlayer);

bpy::class_<world::DynamicItem, boost::shared_ptr<world::DynamicItem>, bpy::bases<world::ServerObject>, boost::noncopyable>("DynamicItem", bpy::no_init)
;
}

}
Expand Down
17 changes: 13 additions & 4 deletions src/fluorescence/ui/python/pygumpcomponentcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CL_GUIComponent* PyGumpComponentContainer::getParentHelper(CL_GUIComponent* comp
return comp;
}

components::Image* PyGumpComponentContainer::addImage(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex) {
components::Image* PyGumpComponentContainer::addImage(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex) {
components::Image* img = new components::Image(getParentHelper(self));
img->pySetGeometry(geom);
img->setTexture(tex);
Expand Down Expand Up @@ -77,7 +77,7 @@ components::Label* PyGumpComponentContainer::addLabel(CL_GUIComponent* self, boo
return label;
}

components::Button* PyGumpComponentContainer::addPageButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, unsigned int page) {
components::Button* PyGumpComponentContainer::addPageButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, unsigned int page) {
components::Button* but = new components::Button(getParentHelper(self));
but->pySetGeometry(geom);
but->setTexture(tex);
Expand All @@ -88,7 +88,7 @@ components::Button* PyGumpComponentContainer::addPageButton(CL_GUIComponent* sel
return but;
}

components::Button* PyGumpComponentContainer::addServerButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, unsigned int id) {
components::Button* PyGumpComponentContainer::addServerButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, unsigned int id) {
components::Button* but = new components::Button(getParentHelper(self));
but->pySetGeometry(geom);
but->setTexture(tex);
Expand All @@ -99,7 +99,7 @@ components::Button* PyGumpComponentContainer::addServerButton(CL_GUIComponent* s
return but;
}

components::Button* PyGumpComponentContainer::addPythonButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, boost::python::object& func) {
components::Button* PyGumpComponentContainer::addPythonButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, boost::python::object& func) {
components::Button* but = new components::Button(getParentHelper(self));
but->pySetGeometry(geom);
but->setTexture(tex);
Expand Down Expand Up @@ -194,6 +194,15 @@ components::Label* PyGumpComponentContainer::addHtmlLabel(CL_GUIComponent* self,
return label;
}

components::ContainerView* PyGumpComponentContainer::addContainerView(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<world::DynamicItem>& itm) {
components::ContainerView* cont = new components::ContainerView(getParentHelper(self), itm);
cont->pySetGeometry(geom);

static_cast<GumpMenu*>(self->get_top_level_component())->addToCurrentPage(cont);

return cont;
}

}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/fluorescence/ui/python/pygumpcomponentcontainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace fluo {

namespace world {
class Mobile;
class DynamicItem;
}

namespace ui {
Expand All @@ -51,6 +52,7 @@ class WorldView;
class PaperdollView;
class PropertyLabel;
class SysLogLabel;
class ContainerView;
}

namespace python {
Expand All @@ -59,11 +61,11 @@ class PyGumpComponentContainer {
public:
static components::AlphaRegion* addAlphaRegion(CL_GUIComponent* self, boost::python::tuple& geom, float alpha);
static components::Background* addBackground(CL_GUIComponent* self, boost::python::tuple& geom, unsigned int baseId);
static components::Image* addImage(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex);
static components::Image* addImage(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex);
static components::Label* addLabel(CL_GUIComponent* self, boost::python::tuple& geom, const UnicodeString& text);
static components::Button* addPageButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, unsigned int page);
static components::Button* addServerButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, unsigned int id);
static components::Button* addPythonButton(CL_GUIComponent* self, boost::python::tuple& geom, boost::shared_ptr<ui::Texture> tex, boost::python::object& func);
static components::Button* addPageButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, unsigned int page);
static components::Button* addServerButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, unsigned int id);
static components::Button* addPythonButton(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<ui::Texture>& tex, boost::python::object& func);
static components::LineEdit* addLineEdit(CL_GUIComponent* self, boost::python::tuple& geom);
static components::ScrollArea* addScrollArea(CL_GUIComponent* self, boost::python::tuple& geom);
static components::Checkbox* addCheckbox(CL_GUIComponent* self, boost::python::tuple& geom);
Expand All @@ -73,6 +75,7 @@ class PyGumpComponentContainer {
static components::PropertyLabel* addPropertyLabel(CL_GUIComponent* self, boost::python::tuple& geom, const UnicodeString& prop);
static components::SysLogLabel* addSysLogLabel(CL_GUIComponent* self, boost::python::tuple& geom);
static components::Label* addHtmlLabel(CL_GUIComponent* self, boost::python::tuple& geom, const UnicodeString& html);
static components::ContainerView* addContainerView(CL_GUIComponent* self, boost::python::tuple& geom, const boost::shared_ptr<world::DynamicItem>& itm);

private:
// when adding to a scrollarea, the components are not added directly to the area but to a child component
Expand Down
12 changes: 7 additions & 5 deletions src/fluorescence/ui/xmlloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,14 @@ GumpComponent* XmlLoader::parsePaperdoll(pugi::xml_node& node, pugi::xml_node& d
}

GumpComponent* XmlLoader::parseContainer(pugi::xml_node& node, pugi::xml_node& defaultNode, CL_GUIComponent* parent, GumpMenu* top) {
CL_Rect bounds = getBoundsFromNode(node, defaultNode);
ui::components::ContainerView* contView = new ui::components::ContainerView(parent, bounds);
parseId(node, contView);
top->addToCurrentPage(contView);
//CL_Rect bounds = getBoundsFromNode(node, defaultNode);
//ui::components::ContainerView* contView = new ui::components::ContainerView(parent, bounds);
//parseId(node, contView);
//top->addToCurrentPage(contView);

return contView;
//return contView;

return nullptr;
}


Expand Down
91 changes: 48 additions & 43 deletions src/fluorescence/world/dynamicitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace fluo {
namespace world {

DynamicItem::DynamicItem(Serial serial) : ServerObject(serial, IngameObject::TYPE_DYNAMIC_ITEM),
artId_(0), tileDataInfo_(NULL), equipped_(false), containerGump_(NULL), isSpellbook_(false) {
artId_(0), tileDataInfo_(nullptr), equipped_(false), spellbookGump_(nullptr), containerView_(nullptr), isSpellbook_(false) {
}

boost::shared_ptr<ui::Texture> DynamicItem::getIngameTexture() const {
Expand Down Expand Up @@ -374,53 +374,42 @@ void DynamicItem::openContainerGump(unsigned int gumpId) {
if (gumpId == 0xFFFF || isSpellbook()) {
// spellbook
// do nothing, open on spellbook content packet
} else if (containerGump_) {
containerGump_->bring_to_front();
} else if (spellbookGump_) {
spellbookGump_->bring_to_front();
} else if (containerView_) {
containerView_->getGumpMenu()->bring_to_front();
} else {
containerGump_ = ui::Manager::getSingleton()->openXmlGump("container");

ui::components::ContainerView* contView = dynamic_cast<ui::components::ContainerView*>(containerGump_->get_named_item("container"));
if (contView) {
contView->setBackgroundGumpId(gumpId);
boost::shared_ptr<DynamicItem> dynSelf = boost::static_pointer_cast<DynamicItem>(shared_from_this());
contView->setContainerObject(dynSelf);
} else {
LOG_ERROR << "Unable to find container component in container gump" << std::endl;
return;
}

std::list<boost::shared_ptr<IngameObject> >::iterator iter = childObjects_.begin();
std::list<boost::shared_ptr<IngameObject> >::iterator end = childObjects_.end();

for (; iter != end; ++iter) {
contView->addObject(*iter);
boost::python::dict args;
boost::shared_ptr<DynamicItem> sharedThis = boost::dynamic_pointer_cast<DynamicItem>(shared_from_this());
args["item"] = sharedThis;
args["background"] = gumpId;
ui::Manager::getSingleton()->openPythonGump("container", args);

// opening the container gump should set the containerView_ member
if (containerView_) {
std::list<boost::shared_ptr<IngameObject> >::iterator iter = childObjects_.begin();
std::list<boost::shared_ptr<IngameObject> >::iterator end = childObjects_.end();

for (; iter != end; ++iter) {
containerView_->addObject(*iter);
}
}
}
}

void DynamicItem::onContainerGumpClosed() {
containerGump_ = NULL;
containerView_ = nullptr;
}

void DynamicItem::onChildObjectAdded(boost::shared_ptr<IngameObject> obj) {
if (containerGump_) {
ui::components::ContainerView* contView = dynamic_cast<ui::components::ContainerView*>(containerGump_->get_named_item("container"));
if (contView) {
contView->addObject(obj);
} else {
LOG_ERROR << "Unable to find container component in container gump" << std::endl;
}
void DynamicItem::onChildObjectAdded(const boost::shared_ptr<IngameObject>& obj) {
if (containerView_) {
containerView_->addObject(obj);
}
}

void DynamicItem::onBeforeChildObjectRemoved(boost::shared_ptr<IngameObject> obj) {
if (containerGump_) {
ui::components::ContainerView* contView = dynamic_cast<ui::components::ContainerView*>(containerGump_->get_named_item("container"));
if (contView) {
contView->removeObject(obj);
} else {
LOG_ERROR << "Unable to find container component in container gump" << std::endl;
}
void DynamicItem::onBeforeChildObjectRemoved(const boost::shared_ptr<IngameObject>& obj) {
if (containerView_) {
containerView_->removeObject(obj);
}
}

Expand All @@ -435,12 +424,12 @@ void DynamicItem::setSpellbook(unsigned int scrollOffset, const uint8_t* spellBi
}
isSpellbook_ = true;

if (containerGump_) {
containerGump_->bring_to_front();
if (spellbookGump_) {
spellbookGump_->bring_to_front();
} else {
containerGump_ = ui::GumpMenus::openSpellbook(this);
if (containerGump_) {
containerGump_->setCloseCallback(boost::bind(&DynamicItem::spellbookClosedCallback, this));
spellbookGump_ = ui::GumpMenus::openSpellbook(this);
if (spellbookGump_) {
spellbookGump_->setCloseCallback(boost::bind(&DynamicItem::spellbookClosedCallback, this));
}
}
}
Expand All @@ -459,9 +448,25 @@ unsigned int DynamicItem::getSpellbookScrollOffset() const {
}

bool DynamicItem::spellbookClosedCallback() {
containerGump_ = nullptr;
spellbookGump_ = nullptr;
return false;
}

void DynamicItem::setContainerView(ui::components::ContainerView* view) {
containerView_ = view;
}

void DynamicItem::onDelete() {
if (containerView_) {
containerView_->getGumpMenu()->close();
}

if (spellbookGump_) {
spellbookGump_->close();
}

ServerObject::onDelete();
}

}
}
Loading

0 comments on commit 2816a37

Please sign in to comment.