[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Windstille-devel] rev 378 - trunk/src
From: |
Ingo Ruhnke |
Subject: |
[Windstille-devel] rev 378 - trunk/src |
Date: |
Wed, 02 Jun 2004 15:12:45 +0200 |
Author: grumbel
Date: 2004-06-02 15:12:44 +0200 (Wed, 02 Jun 2004)
New Revision: 378
Added:
trunk/src/objmap_object_impl.cxx
trunk/src/objmap_object_impl.hxx
Modified:
trunk/src/SConstruct
trunk/src/flexlay_wrap.i
trunk/src/netpanzer.py
trunk/src/object_add_command.cxx
trunk/src/object_add_command.hxx
trunk/src/object_brush.cxx
trunk/src/object_brush.hxx
trunk/src/object_delete_command.cxx
trunk/src/object_delete_command.hxx
trunk/src/object_layer.cxx
trunk/src/object_layer.hxx
trunk/src/object_move_command.cxx
trunk/src/object_move_command.hxx
trunk/src/object_selector.cxx
trunk/src/object_selector.hxx
trunk/src/objmap_object.cxx
trunk/src/objmap_object.hxx
trunk/src/objmap_select_tool.cxx
trunk/src/objmap_select_tool.hxx
trunk/src/objmap_sprite_object.cxx
trunk/src/objmap_sprite_object.hxx
trunk/src/supertux.py
Log:
- made object_layer objects refcounted
Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/SConstruct 2004-06-02 13:12:44 UTC (rev 378)
@@ -38,6 +38,9 @@
'editor_map.hxx',
'workspace.hxx',
'tileset.hxx',
+ 'objmap_object.hxx',
+ 'objmap_sprite_object.hxx',
+ 'object_layer.hxx',
'layer.hxx',
'editor_map.hxx',
'editor_map_component.hxx',
@@ -89,6 +92,7 @@
'object_selector.cxx',
'object_transform_command.cxx',
'objmap_object.cxx',
+ 'objmap_object_impl.cxx',
'objmap_select_tool.cxx',
'objmap_sprite_object.cxx',
'paint_command.cxx',
Modified: trunk/src/flexlay_wrap.i
===================================================================
--- trunk/src/flexlay_wrap.i 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/flexlay_wrap.i 2004-06-02 13:12:44 UTC (rev 378)
@@ -103,4 +103,5 @@
%include "netpanzer.hxx"
+
/* EOF */
Modified: trunk/src/netpanzer.py
===================================================================
--- trunk/src/netpanzer.py 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/netpanzer.py 2004-06-02 13:12:44 UTC (rev 378)
@@ -72,8 +72,30 @@
# FIXME: Data might not get freed since its 'recursively' refcounted
self.editormap.set_metadata(make_metadata(self))
+ def save_optfile(self, filename):
+ outpots = [] # FIXME
+
+ f = open(filename, "w")
+ f.write("ObjectiveCount: %d\n\n" % len(outposts))
+ for (name, x , y) in outpots:
+ f.write("Name: %s\n" % "Foobar")
+ f.write("Location: %d %d\n\n" % (int(x)/32, int(y)/32))
+
+ def save_spnfile(self, filename):
+ spawnpoints = []
+ f = open(filename, "w")
+
+ f.write("SpawnCount: %d\n\n" % len(spawnpoints))
+ for (x, y) in spawnpoints:
+ f.write("Location: %d %d\n" % (int(x)/32, int(y)/32))
+
def save(self, filename):
- data.save(filename)
+ if filename[-4:] == ".npm":
+ data.save(filename)
+ save_optfile(filename[:-4] + ".opt")
+ save_optfile(filename[:-4] + ".spn")
+ else:
+ raise "Fileextension not valid, must be .npm!"
def activate(self, workspace):
workspace.set_map(self.editormap)
@@ -122,8 +144,20 @@
workspace.set_tool(tilemap_paint_tool.to_tool());
+def on_map_change():
+ if (workspace.get_map().undo_stack_size() > 0):
+ undo_icon.enable()
+ else:
+ undo_icon.disable()
+
+ if (workspace.get_map().redo_stack_size() > 0):
+ redo_icon.enable()
+ else:
+ redo_icon.disable()
+
startlevel = Level(256, 256)
startlevel.activate(workspace)
+connect(startlevel.editormap.sig_change(), on_map_change)
button_panel = Panel(CL_Rect(CL_Point(0, 23), CL_Size(800, 33)),
gui.get_component())
@@ -193,8 +227,8 @@
redo_icon = Icon(CL_Rect(CL_Point(p.inc(32), 2), CL_Size(32, 32)),
make_sprite("../data/images/icons24/stock_redo.png"), "Some
tooltip", button_panel);
-undo_icon.set_callback(editor.undo)
-redo_icon.set_callback(editor.redo)
+undo_icon.set_callback(lambda: workspace.get_map().undo())
+redo_icon.set_callback(lambda: workspace.get_map().redo())
undo_icon.disable()
redo_icon.disable()
@@ -205,17 +239,6 @@
layer_menu = Menu(CL_Point(32*11+2, 54), gui.get_component())
-def on_map_change():
- if (workspace.get_map().undo_stack_size() > 0):
- undo_icon.enable()
- else:
- undo_icon.disable()
-
- if (workspace.get_map().redo_stack_size() > 0):
- redo_icon.enable()
- else:
- redo_icon.disable()
-
def set_tilemap_paint_tool():
workspace.set_tool(tilemap_paint_tool.to_tool())
paint.set_down()
Modified: trunk/src/object_add_command.cxx
===================================================================
--- trunk/src/object_add_command.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_add_command.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -25,7 +25,7 @@
{
public:
ObjectLayer objmap;
- ObjMapObject* obj;
+ std::vector<ObjMapObject> objs;
ObjectAddCommandImpl() {}
virtual ~ObjectAddCommandImpl() {}
@@ -37,33 +37,40 @@
std::string serialize();
};
-ObjectAddCommand::ObjectAddCommand(const ObjectLayer& objmap_, ObjMapObject*
obj_)
+ObjectAddCommand::ObjectAddCommand(const ObjectLayer& objmap_)
: impl(new ObjectAddCommandImpl())
{
impl->objmap = objmap_;
- impl->obj = obj_;
}
ObjectAddCommand::~ObjectAddCommand()
{
}
-int
+/*int
ObjectAddCommand::get_handle() const
{
return impl->obj->get_handle();
+}*/
+
+void
+ObjectAddCommand::add_object(const ObjMapObject& obj)
+{
+ impl->objs.push_back(obj);
}
void
ObjectAddCommandImpl::execute()
{
- objmap.add_object(obj);
+ for(std::vector<ObjMapObject>::iterator i = objs.begin(); i != objs.end();
++i)
+ objmap.add_object(*i);
}
void
ObjectAddCommandImpl::undo()
{
- objmap.delete_object(obj->get_handle());
+ for(std::vector<ObjMapObject>::iterator i = objs.begin(); i != objs.end();
++i)
+ objmap.delete_object(*i);
}
void
Modified: trunk/src/object_add_command.hxx
===================================================================
--- trunk/src/object_add_command.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_add_command.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -20,10 +20,10 @@
#ifndef HEADER_OBJECT_ADD_COMMAND_HXX
#define HEADER_OBJECT_ADD_COMMAND_HXX
+#include "objmap_object.hxx"
#include "command.hxx"
class ObjectLayer;
-class ObjMapObject;
class ObjectAddCommandImpl;
/** ObjectAddCommand adds on object to an ObjectLayer, the user needs
@@ -33,11 +33,13 @@
class ObjectAddCommand
{
public:
- ObjectAddCommand(const ObjectLayer& o, ObjMapObject* ob);
+ ObjectAddCommand(const ObjectLayer& layer);
virtual ~ObjectAddCommand();
- int get_handle() const;
+ void add_object(const ObjMapObject& obj);
+ //int get_handle() const;
+
Command to_command();
private:
Modified: trunk/src/object_brush.cxx
===================================================================
--- trunk/src/object_brush.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_brush.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -17,8 +17,20 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include "objmap_sprite_object.hxx"
+#include "object_add_command.hxx"
+#include "objmap_sprite_object.hxx"
#include "object_brush.hxx"
+#include "editor_map.hxx"
+#include "workspace.hxx"
+class ObjectBrushImpl
+{
+public:
+ CL_Sprite sprite;
+ MetaData data;
+};
+
ObjectBrush::ObjectBrush()
{
@@ -26,8 +38,26 @@
ObjectBrush::ObjectBrush(const CL_Sprite& sprite_,
const MetaData& data_)
- : sprite(sprite_), data(data_)
+ : impl(new ObjectBrushImpl())
{
+ impl->sprite = sprite_;
+ impl->data = data_;
}
+CL_Sprite
+ObjectBrush::get_sprite()
+{
+ return impl->sprite;
+}
+
+ObjMapObject
+ObjectBrush::add_to_layer(ObjectLayer layer, const CL_Point& pos)
+{
+ ObjMapSpriteObject obj(pos, impl->data, impl->sprite);
+ ObjectAddCommand command(layer);
+ command.add_object(obj.to_object());
+ Workspace::current().get_map().execute(command.to_command());
+ return obj.to_object();
+}
+
/* EOF */
Modified: trunk/src/object_brush.hxx
===================================================================
--- trunk/src/object_brush.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_brush.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -21,18 +21,24 @@
#define HEADER_OBJECT_BRUSH_HXX
#include <ClanLib/Display/sprite.h>
+#include "object_layer.hxx"
+#include "objmap_object.hxx"
#include "meta_data.hxx"
+class ObjectBrushImpl;
+
class ObjectBrush
{
public:
- CL_Point pos;
- CL_Sprite sprite;
- MetaData data;
-
ObjectBrush();
ObjectBrush(const CL_Sprite& sprite_,
const MetaData& data_);
+
+ CL_Sprite get_sprite();
+
+ ObjMapObject add_to_layer(ObjectLayer layer, const CL_Point& pos);
+private:
+ SharedPtr<ObjectBrushImpl> impl;
};
#endif
Modified: trunk/src/object_delete_command.cxx
===================================================================
--- trunk/src/object_delete_command.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_delete_command.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -25,7 +25,7 @@
class ObjectDeleteCommandImpl : public CommandImpl
{
public:
- typedef std::vector<ObjMapObject*> Objects;
+ typedef std::vector<ObjMapObject> Objects;
ObjectLayer object_layer;
Objects objects;
@@ -44,9 +44,9 @@
}
void
-ObjectDeleteCommand::add_object(int id)
+ObjectDeleteCommand::add_object(const ObjMapObject& obj)
{
- impl->objects.push_back(impl->object_layer.get_object(id));
+ impl->objects.push_back(obj);
}
void
@@ -54,7 +54,7 @@
{
for(Objects::iterator i = objects.begin(); i != objects.end(); ++i)
{
- object_layer.delete_object((*i)->get_handle());
+ object_layer.delete_object(*i);
}
}
Modified: trunk/src/object_delete_command.hxx
===================================================================
--- trunk/src/object_delete_command.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_delete_command.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -21,6 +21,7 @@
#define HEADER_OBJECT_DELETE_COMMAND_HXX
#include <vector>
+#include "objmap_object.hxx"
#include "command.hxx"
class ObjectDeleteCommandImpl;
@@ -33,7 +34,7 @@
public:
ObjectDeleteCommand(const ObjectLayer& o);
- void add_object(int id);
+ void add_object(const ObjMapObject& obj);
Command to_command();
private:
Modified: trunk/src/object_layer.cxx
===================================================================
--- trunk/src/object_layer.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_layer.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -32,13 +32,12 @@
class ObjectLayerImpl : public LayerImpl
{
public:
- ObjectLayerImpl() {}
- virtual ~ObjectLayerImpl() {}
-
ObjectLayer::Objs objects;
- int handle_count;
CL_SlotContainer slots;
+ ObjectLayerImpl() {}
+ virtual ~ObjectLayerImpl() {}
+
void draw(EditorMapComponent* parent);
bool has_bounding_rect() const { return false; }
};
@@ -46,7 +45,6 @@
ObjectLayer::ObjectLayer()
: impl(new ObjectLayerImpl())
{
- impl->handle_count = 0;
}
ObjectLayer::~ObjectLayer()
@@ -58,69 +56,45 @@
{
for(ObjectLayer::Objs::iterator i = objects.begin(); i != objects.end(); ++i)
{
- (*i)->draw();
+ (*i).draw();
}
}
-int
-ObjectLayer::duplicate_object(int id)
-{
- ObjMapObject* obj = get_object(id);
- ObjMapObject* newobj = obj->duplicate(++impl->handle_count);
- impl->objects.push_back(newobj);
-
- // FIXME: Move to scripting level
- newobj->set_pos(newobj->get_pos() + CL_Point(16, 16));
-
- return newobj->get_handle();
-}
-
-int
-ObjectLayer::add_object(const CL_Sprite& sprite, const CL_Point& pos, const
MetaData& data)
-{
- ObjMapObject* obj = new ObjMapSpriteObject(++impl->handle_count, pos, data,
sprite);
-
- impl->objects.push_back(obj);
-
- return obj->get_handle();
-}
-
-ObjMapObject*
+ObjMapObject
ObjectLayer::find_object(const CL_Point& click_pos)
{
for(Objs::reverse_iterator i = impl->objects.rbegin(); i !=
impl->objects.rend(); ++i)
{
- CL_Rect rect = (*i)->get_bound_rect();
+ CL_Rect rect = (*i).get_bound_rect();
if (rect.is_inside(click_pos))
return *i;
}
- return 0;
+ return ObjMapObject();
}
void
-ObjectLayer::delete_object(int id)
+ObjectLayer::delete_object(const ObjMapObject& obj)
{
for(Objs::iterator i = impl->objects.begin(); i != impl->objects.end(); ++i)
{
- if ((*i)->get_handle() == id)
+ if (obj == (*i))
{
- //delete *i;
impl->objects.erase(i);
break;
}
}
}
-std::vector<ObjectLayer::Obj*>
+ObjectLayer::Objs
ObjectLayer::get_selection(const CL_Rect& rect)
{
- std::vector<ObjectLayer::Obj*> selection;
+ Objs selection;
for(Objs::iterator i = impl->objects.begin(); i != impl->objects.end(); ++i)
{
// FIXME:
- if (rect.is_inside((*i)->get_pos()))
+ if (rect.is_inside((*i).get_pos()))
{
selection.push_back(*i);
}
@@ -129,33 +103,18 @@
return selection;
}
-ObjectLayer::Obj*
-ObjectLayer::get_object(int id)
-{
- for(Objs::iterator i = impl->objects.begin(); i != impl->objects.end(); ++i)
- if ((*i)->get_handle() == id)
- return *i;
- return 0;
-}
-
-ObjectLayer::Objs*
+ObjectLayer::Objs
ObjectLayer::get_objects()
{
- return &impl->objects;
+ return impl->objects;
}
void
-ObjectLayer::add_object(ObjMapObject* obj)
+ObjectLayer::add_object(const ObjMapObject& obj)
{
impl->objects.push_back(obj);
}
-int
-ObjectLayer::get_next_object_handle()
-{
- return ++impl->handle_count;
-}
-
Layer
ObjectLayer::to_layer()
{
Modified: trunk/src/object_layer.hxx
===================================================================
--- trunk/src/object_layer.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_layer.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -26,9 +26,9 @@
#include <ClanLib/Core/Math/point.h>
#include "meta_data.hxx"
#include "layer.hxx"
+#include "objmap_object.hxx"
#include "shared_ptr.hxx"
-class ObjMapObject;
class ObjectLayerImpl;
/** The ObjectLayer provides a simple Layer for holding positioned
@@ -38,7 +38,7 @@
{
public:
typedef ObjMapObject Obj;
- typedef std::vector<ObjMapObject*> Objs;
+ typedef std::vector<ObjMapObject> Objs;
static ObjectLayer current_;
@@ -48,19 +48,13 @@
ObjectLayer();
~ObjectLayer();
- /** Add an object to the map and return a handle to it */
- int add_object(const CL_Sprite& sprite, const CL_Point& pos, const
MetaData& data);
+ void add_object(const ObjMapObject& obj);
+ void delete_object(const ObjMapObject& obj);
- void add_object(ObjMapObject* obj);
- void delete_object(int id);
- int duplicate_object(int id);
+ ObjMapObject find_object(const CL_Point& pos);
+ std::vector<ObjMapObject> get_selection(const CL_Rect& rect);
+ Objs get_objects();
- ObjMapObject* find_object(const CL_Point& pos);
- std::vector<ObjMapObject*> get_selection(const CL_Rect& rect);
- Objs* get_objects();
- ObjectLayer::Obj* get_object(int id);
- int get_next_object_handle();
-
Layer to_layer();
private:
Modified: trunk/src/object_move_command.cxx
===================================================================
--- trunk/src/object_move_command.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_move_command.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -32,7 +32,7 @@
struct Obj {
CL_Point old_pos;
CL_Point new_pos;
- int id;
+ ObjMapObject obj;
};
typedef std::vector<Obj> Objects;
@@ -62,26 +62,17 @@
i != objects.end();
++i)
{
- ObjMapObject* obj = objmap.get_object(i->id);
- if (obj)
- {
- i->new_pos = obj->get_pos();
- }
+ i->new_pos = i->obj.get_pos();
}
}
void
-ObjectMoveCommand::add_obj(int id)
+ObjectMoveCommand::add_obj(const ObjMapObject& obj)
{
- ObjMapObject* obj = impl->objmap.get_object(id);
-
- if (obj)
- {
- ObjectMoveCommandImpl::Obj o;
- o.id = id;
- o.old_pos = obj->get_pos();
- impl->objects.push_back(o);
- }
+ ObjectMoveCommandImpl::Obj o;
+ o.obj = obj;
+ o.old_pos = obj.get_pos();
+ impl->objects.push_back(o);
}
void
@@ -91,11 +82,7 @@
i != objects.end();
++i)
{
- ObjMapObject* obj = objmap.get_object(i->id);
- if (obj)
- {
- obj->set_pos(i->new_pos);
- }
+ i->obj.set_pos(i->new_pos);
}
}
@@ -106,11 +93,7 @@
i != objects.end();
++i)
{
- ObjMapObject* obj = objmap.get_object(i->id);
- if (obj)
- {
- obj->set_pos(i->old_pos);
- }
+ i->obj.set_pos(i->old_pos);
}
}
Modified: trunk/src/object_move_command.hxx
===================================================================
--- trunk/src/object_move_command.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_move_command.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -22,6 +22,7 @@
#include "command.hxx"
+class ObjMapObject;
class ObjectLayer;
class ObjectMoveCommandImpl;
@@ -33,7 +34,7 @@
ObjectMoveCommand(const ObjectLayer& o);
virtual ~ObjectMoveCommand();
- void add_obj(int id);
+ void add_obj(const ObjMapObject& obj);
Command to_command();
private:
Modified: trunk/src/object_selector.cxx
===================================================================
--- trunk/src/object_selector.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_selector.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -24,8 +24,6 @@
#include "editor_map_component.hxx"
#include "object_selector.hxx"
#include "editor.hxx"
-#include "object_add_command.hxx"
-#include "objmap_sprite_object.hxx"
ObjectSelector::ObjectSelector(const CL_Rect& rect,
int obj_w, int obj_h,
@@ -45,6 +43,7 @@
scrolling = false;
offset = 0;
scale = 1.0f;
+ drag_obj = -1;
}
ObjectSelector::~ObjectSelector()
@@ -58,14 +57,12 @@
{
case CL_MOUSE_LEFT:
{
- if (drag_obj.sprite)
+ if (drag_obj != -1)
{
release_mouse();
if (!has_mouse_over())
{
- drag_obj.sprite.set_alpha(1.0f);
-
CL_Point screen(event.mouse_pos.x + get_screen_rect().left,
event.mouse_pos.y + get_screen_rect().top);
@@ -73,16 +70,10 @@
screen.y -
EditorMapComponent::current()->get_screen_rect().top);
ObjectLayer objmap = ObjectLayer::current();
-
- ObjMapObject* obj
- = new ObjMapSpriteObject(objmap.get_next_object_handle(),
-
EditorMapComponent::current()->screen2world(target),
- drag_obj.data,
- drag_obj.sprite);
- ObjectAddCommand command(objmap, obj);
- Workspace::current().get_map().execute(command.to_command());
+ brushes[drag_obj].add_to_layer(objmap,
+
EditorMapComponent::current()->screen2world(target));
}
- drag_obj.sprite = CL_Sprite();
+ drag_obj = -1;
}
}
break;
@@ -106,8 +97,7 @@
{
if (mouse_over_tile != -1)
{
- drag_obj = brushes[mouse_over_tile];
- drag_obj.sprite.set_alpha(0.5);
+ drag_obj = mouse_over_tile;
capture_mouse();
}
}
@@ -169,7 +159,7 @@
CL_Size(static_cast<int>(obj_width),
static_cast<int>(obj_height)));
- CL_Sprite sprite = brushes[i].sprite;
+ CL_Sprite sprite = brushes[i].get_sprite();
sprite.set_alignment(origin_center, 0, 0);
sprite.set_scale(std::min(1.0f,
(float)obj_width/(float)sprite.get_width()),
std::min(1.0f,
(float)obj_height/(float)sprite.get_height()));
@@ -187,12 +177,15 @@
CL_Display::pop_modelview();
// Draw drag sprite
- if (drag_obj.sprite)
+ if (drag_obj != -1)
{
CL_Display::set_cliprect(CL_Rect(CL_Point(0, 0),
CL_Size(CL_Display::get_width(),
CL_Display::get_height())));
- drag_obj.sprite.draw(mouse_pos.x, mouse_pos.y);
+
+ CL_Sprite sprite = brushes[drag_obj].get_sprite();
+ sprite.set_alpha(0.5f);
+ sprite.draw(mouse_pos.x, mouse_pos.y);
}
}
Modified: trunk/src/object_selector.hxx
===================================================================
--- trunk/src/object_selector.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/object_selector.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -47,7 +47,7 @@
float scale;
std::vector<ObjectBrush> brushes;
- ObjectBrush drag_obj;
+ int drag_obj;
public:
ObjectSelector(const CL_Rect& rect, int obj_w, int obj_h, CL_Component*
parent);
Modified: trunk/src/objmap_object.cxx
===================================================================
--- trunk/src/objmap_object.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_object.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -17,17 +17,76 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include "objmap_object_impl.hxx"
#include "objmap_object.hxx"
-ObjMapObject::ObjMapObject(int handle_, const CL_Point& pos_,
+ObjMapObject::ObjMapObject()
+{
+}
+
+ObjMapObject::ObjMapObject(const SharedPtr<ObjMapObjectImpl>& impl_)
+ : impl(impl_)
+{
+}
+
+ObjMapObject::ObjMapObject(const CL_Point& pos_,
const MetaData& data_)
- : handle(handle_), pos(pos_), data(data_)
{
+ impl->pos = pos_;
+ impl->data = data_;
}
-ObjMapObject::ObjMapObject(int handle_, const ObjMapObject& obj)
- : handle(handle_), pos(obj.pos), data(obj.data)
-{
+CL_Point
+ObjMapObject::get_pos() const
+{
+ if (impl.get())
+ return impl->pos;
+ else
+ return CL_Point();
}
+void
+ObjMapObject::set_pos(const CL_Point& p)
+{
+ if (impl.get())
+ impl->pos = p;
+}
+
+MetaData
+ObjMapObject::get_data() const
+{
+ if (impl.get())
+ return impl->data;
+ else
+ return MetaData();
+}
+
+void
+ObjMapObject::draw()
+{
+ if (impl.get())
+ impl->draw();
+}
+
+CL_Rect
+ObjMapObject::get_bound_rect() const
+{
+ if (impl.get())
+ return impl->get_bound_rect();
+ else
+ return CL_Rect();
+}
+
+bool
+ObjMapObject::is_null() const
+{
+ return !impl.get();
+}
+
+bool
+ObjMapObject::operator==(const ObjMapObject& obj) const
+{
+ return impl.get() == obj.impl.get();
+}
+
/* EOF */
Modified: trunk/src/objmap_object.hxx
===================================================================
--- trunk/src/objmap_object.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_object.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -24,31 +24,32 @@
#include <ClanLib/Core/Math/rect.h>
#include "meta_data.hxx"
+class ObjMapObjectImpl;
+
/** */
class ObjMapObject
{
-private:
- int handle;
-
-protected:
- CL_Point pos;
- MetaData data;
-
public:
- ObjMapObject(int handle_, const CL_Point& pos, const MetaData& data);
- ObjMapObject(int handle_, const ObjMapObject& obj);
+ ObjMapObject();
+ ObjMapObject(const SharedPtr<ObjMapObjectImpl>& impl_);
+ ObjMapObject(const CL_Point& pos, const MetaData& data);
virtual ~ObjMapObject() {}
- CL_Point get_pos() const { return pos; }
- void set_pos(const CL_Point& p) { pos = p; }
+ CL_Point get_pos() const;
+ void set_pos(const CL_Point& p);
- MetaData get_data() const { return data; }
+ MetaData get_data() const;
- virtual void draw() =0;
- virtual CL_Rect get_bound_rect() const =0;
- virtual ObjMapObject* duplicate(int handle_) =0;
+ int get_handle() const;
- int get_handle() const { return handle; }
+ void draw();
+ CL_Rect get_bound_rect() const;
+
+ bool is_null() const;
+
+ bool operator==(const ObjMapObject& obj) const;
+private:
+ SharedPtr<ObjMapObjectImpl> impl;
};
#endif
Added: trunk/src/objmap_object_impl.cxx
===================================================================
--- trunk/src/objmap_object_impl.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_object_impl.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -0,0 +1,30 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include "objmap_object_impl.hxx"
+
+ObjMapObjectImpl::ObjMapObjectImpl()
+{
+}
+
+ObjMapObjectImpl::~ObjMapObjectImpl()
+{
+}
+
+/* EOF */
Added: trunk/src/objmap_object_impl.hxx
===================================================================
--- trunk/src/objmap_object_impl.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_object_impl.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -0,0 +1,42 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_OBJMAP_OBJECT_IMPL_HXX
+#define HEADER_OBJMAP_OBJECT_IMPL_HXX
+
+#include <ClanLib/Core/Math/point.h>
+#include <ClanLib/Core/Math/rect.h>
+#include "meta_data.hxx"
+
+class ObjMapObjectImpl
+{
+public:
+ CL_Point pos;
+ MetaData data;
+
+ ObjMapObjectImpl();
+ virtual ~ObjMapObjectImpl();
+
+ virtual void draw() =0;
+ virtual CL_Rect get_bound_rect() const =0;
+};
+
+#endif
+
+/* EOF */
Modified: trunk/src/objmap_select_tool.cxx
===================================================================
--- trunk/src/objmap_select_tool.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_select_tool.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -102,8 +102,8 @@
{
for (ObjMapSelectTool::Selection::iterator i = selection.begin(); i !=
selection.end(); ++i)
{
- (*i)->draw();
- CL_Display::draw_rect((*i)->get_bound_rect(), CL_Color(255, 0, 0));
+ (*i).draw();
+ CL_Display::draw_rect((*i).get_bound_rect(), CL_Color(255, 0, 0));
}
switch(state)
@@ -182,9 +182,9 @@
switch(state)
{
default:
- ObjectLayer::Obj* obj = objmap.find_object(pos);
+ ObjectLayer::Obj obj = objmap.find_object(pos);
- if (obj)
+ if (!obj.is_null())
{
if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT))
{
@@ -199,7 +199,7 @@
{
state = DRAG;
parent->capture_mouse();
- offset = pos - obj->get_pos();
+ offset = pos - obj.get_pos();
drag_start = pos;
if (std::find(selection.begin(), selection.end(), obj) ==
selection.end())
@@ -212,7 +212,7 @@
for (ObjMapSelectTool::Selection::iterator i =
selection.begin();
i != selection.end(); ++i)
{
- move_command->add_obj((*i)->get_handle());
+ move_command->add_obj(*i);
}
}
}
@@ -243,7 +243,7 @@
for (ObjMapSelectTool::Selection::iterator i = selection.begin();
i != selection.end(); ++i)
{
- (*i)->set_pos((*i)->get_pos() + (pos - drag_start));
+ (*i).set_pos((*i).get_pos() + (pos - drag_start));
}
drag_start = pos;
break;
Modified: trunk/src/objmap_select_tool.hxx
===================================================================
--- trunk/src/objmap_select_tool.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_select_tool.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -31,7 +31,7 @@
class ObjMapSelectTool
{
public:
- typedef std::vector<ObjectLayer::Obj*> Selection;
+ typedef std::vector<ObjectLayer::Obj> Selection;
ObjMapSelectTool();
~ObjMapSelectTool();
Modified: trunk/src/objmap_sprite_object.cxx
===================================================================
--- trunk/src/objmap_sprite_object.cxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_sprite_object.cxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -18,30 +18,38 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <ClanLib/Display/display.h>
+#include "objmap_object_impl.hxx"
#include "objmap_sprite_object.hxx"
-ObjMapSpriteObject::ObjMapSpriteObject(int handle_, const CL_Point& pos_,
+class ObjMapSpriteObjectImpl : public ObjMapObjectImpl
+{
+public:
+ CL_Sprite sprite;
+
+ void draw();
+ CL_Rect get_bound_rect() const;
+
+ ObjMapObject* duplicate(int handle_);
+};
+
+ObjMapSpriteObject::ObjMapSpriteObject(const CL_Point& pos_,
const MetaData& data_,
const CL_Sprite& sprite_)
- : ObjMapObject(handle_, pos_,data_),
- sprite(sprite_)
+ : impl(new ObjMapSpriteObjectImpl())
{
-
+ impl->pos = pos_;
+ impl->data = data_;
+ impl->sprite = sprite_;
}
-ObjMapSpriteObject::ObjMapSpriteObject(int handle_, const ObjMapSpriteObject&
obj)
- : ObjMapObject(handle_, obj), sprite(obj.sprite)
-{
-}
-
void
-ObjMapSpriteObject::draw()
+ObjMapSpriteObjectImpl::draw()
{
sprite.draw(pos.x, pos.y);
}
CL_Rect
-ObjMapSpriteObject::get_bound_rect() const
+ObjMapSpriteObjectImpl::get_bound_rect() const
{
CL_Point align = CL_Point(0, 0);
CL_Origin origin_e;
@@ -60,22 +68,23 @@
ObjMapSpriteObject::flip_vertical()
{
float scale_x, scale_y;
- sprite.get_scale(scale_x, scale_y);
- sprite.set_scale(scale_x, -scale_y);
+
+ impl->sprite.get_scale(scale_x, scale_y);
+ impl->sprite.set_scale(scale_x, -scale_y);
}
void
ObjMapSpriteObject::flip_horizontal()
{
float scale_x, scale_y;
- sprite.get_scale(scale_x, scale_y);
- sprite.set_scale(-scale_x, scale_y);
+ impl->sprite.get_scale(scale_x, scale_y);
+ impl->sprite.set_scale(-scale_x, scale_y);
}
-ObjMapObject*
-ObjMapSpriteObject::duplicate(int handle_)
+ObjMapObject
+ObjMapSpriteObject::to_object()
{
- return new ObjMapSpriteObject(handle_, *this);
+ return ObjMapObject(SharedPtr<ObjMapObjectImpl>(impl));
}
/* EOF */
Modified: trunk/src/objmap_sprite_object.hxx
===================================================================
--- trunk/src/objmap_sprite_object.hxx 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/objmap_sprite_object.hxx 2004-06-02 13:12:44 UTC (rev 378)
@@ -21,28 +21,25 @@
#define HEADER_OBJMAP_SPRITE_OBJECT_HXX
#include <ClanLib/Display/sprite.h>
+#include "shared_ptr.hxx"
#include "objmap_object.hxx"
+class ObjMapSpriteObjectImpl;
+
/** */
-class ObjMapSpriteObject : public ObjMapObject
+class ObjMapSpriteObject
{
-private:
- CL_Sprite sprite;
-
public:
- ObjMapSpriteObject(int handle_,
- const CL_Point& pos_,
+ ObjMapSpriteObject(const CL_Point& pos_,
const MetaData& data_,
const CL_Sprite& s);
- ObjMapSpriteObject(int handle_, const ObjMapSpriteObject& obj);
void flip_horizontal();
void flip_vertical();
-
- void draw();
- CL_Rect get_bound_rect() const;
-
- ObjMapObject* duplicate(int handle_);
+
+ ObjMapObject to_object();
+private:
+ SharedPtr<ObjMapSpriteObjectImpl> impl;
};
#endif
Modified: trunk/src/supertux.py
===================================================================
--- trunk/src/supertux.py 2004-05-31 23:46:34 UTC (rev 377)
+++ trunk/src/supertux.py 2004-06-02 13:12:44 UTC (rev 378)
@@ -22,6 +22,18 @@
import ConfigParser
import os
+game_objects = [["money", "images/shared/jumpy-left-middle-0.png"],
+ ["snowball", "images/shared/snowball-left-0.png"],
+ ["mriceblock", "images/shared/mriceblock-left-0.png"],
+ ["mrbomb", "images/shared/mrbomb-left-0.png"],
+ ["flame", "images/shared/flame-0.png"],
+ ["stalactite", "images/shared/stalactite.png"],
+ ["fish", "images/shared/fish-left-0.png"],
+ ["flyingsnowball", "images/shared/flyingsnowball-left-0.png"],
+ ["bouncingsnowball",
"images/shared/bouncingsnowball-left-0.png"],
+ ["spiky", "images/shared/spiky-left-0.png"],
+ ["resetpoint", "images/shared/resetpoint.png"]]
+
class Config:
config = None
datadir = None
@@ -125,8 +137,22 @@
self.background = TilemapLayer(supertux_tileset, self.width,
self.height)
self.background.set_data(get_value_from_tree(["background-tm"],
data, []))
+ def find(lst, obj):
+ for i in lst:
+ if i[0] == obj:
+ return i
+ return None
+
self.objects = ObjectLayer()
-
+ for i in get_value_from_tree(["objects"], data, []):
+ type = i[0]
+ x = get_value_from_tree(["x", "_"], i[1:], [])
+ y = get_value_from_tree(["y", "_"], i[1:], [])
+ print "Got: ", type, x, y
+ object = find(game_objects, type)
+ ObjectBrush(make_sprite(config.datadir + object[1]),
+
make_metadata(object[0])).add_to_layer(self.objects, CL_Point(x, y))
+
else:
raise "Wrong arguments for SuperTux::___init__"
@@ -169,6 +195,13 @@
for i in self.foreground.get_data():
f.write("%d " % i)
f.write(" )\n\n")
+
+ f.write(" (objects\n")
+ for (obj, data) in []:
+ pos = obj.get_pos()
+ f.write(" (%s (x %d) (y %d))" % (data, pos.x, pos.y))
+ f.write(" )\n\n")
+
f.write(" )\n\n;; EOF ;;\n")
# objects = None
@@ -240,16 +273,9 @@
self.objectselector = ObjectSelector(CL_Rect(0, 0, 128, 256), 42, 42,
self.selector_window)
self.objectselector.show(True)
-
self.objectselector.add_brush(ObjectBrush(make_sprite("../data/images/tools/stock-tool-pencil-22.png"),
- make_metadata(None)))
-
self.objectselector.add_brush(ObjectBrush(make_sprite("../data/images/tools/stock-tool-pencil-22.png"),
- make_metadata(None)))
-
self.objectselector.add_brush(ObjectBrush(make_sprite("../data/images/tools/stock-tool-pencil-22.png"),
- make_metadata(None)))
-
self.objectselector.add_brush(ObjectBrush(make_sprite("../data/images/tools/stock-tool-pencil-22.png"),
- make_metadata(None)))
-
self.objectselector.add_brush(ObjectBrush(make_sprite("../data/images/tools/stock-tool-pencil-22.png"),
- make_metadata(None)))
+ for object in game_objects:
+
self.objectselector.add_brush(ObjectBrush(make_sprite(config.datadir +
object[1]),
+
make_metadata(object[0])))
def show_objects(self):
self.tileselector.show(False)
@@ -295,9 +321,21 @@
workspace.set_tool(tilemap_paint_tool.to_tool());
+def on_map_change():
+ if (workspace.get_map().undo_stack_size() > 0):
+ undo_icon.enable()
+ else:
+ undo_icon.disable()
+
+ if (workspace.get_map().redo_stack_size() > 0):
+ redo_icon.enable()
+ else:
+ redo_icon.disable()
+
startlevel = SuperTuxLevel(100, 50)
# startlevel = netpanzer.Level(256, 256)
startlevel.activate(workspace)
+connect(startlevel.editormap.sig_change(), on_map_change)
button_panel = Panel(CL_Rect(CL_Point(0, 23), CL_Size(800, 33)),
gui.get_component())
@@ -360,8 +398,8 @@
redo_icon = Icon(CL_Rect(CL_Point(p.inc(32), 2), CL_Size(32, 32)),
make_sprite("../data/images/icons24/stock_redo.png"), "Some
tooltip", button_panel);
-undo_icon.set_callback(editor.undo)
-redo_icon.set_callback(editor.redo)
+undo_icon.set_callback(lambda: workspace.get_map().undo())
+redo_icon.set_callback(lambda: workspace.get_map().redo())
undo_icon.disable()
redo_icon.disable()
@@ -381,17 +419,6 @@
layer_menu = Menu(CL_Point(32*11+2, 54), gui.get_component())
-def on_map_change():
- if (workspace.get_map().undo_stack_size() > 0):
- undo_icon.enable()
- else:
- undo_icon.disable()
-
- if (workspace.get_map().redo_stack_size() > 0):
- redo_icon.enable()
- else:
- redo_icon.disable()
-
def set_tilemap_paint_tool():
workspace.set_tool(tilemap_paint_tool.to_tool())
paint.set_down()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Windstille-devel] rev 378 - trunk/src,
Ingo Ruhnke <=