[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3098 - in trunk/pingus/src: . editor
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3098 - in trunk/pingus/src: . editor |
Date: |
Thu, 6 Sep 2007 20:18:20 +0200 |
Author: grumbel
Date: 2007-09-06 20:18:19 +0200 (Thu, 06 Sep 2007)
New Revision: 3098
Modified:
trunk/pingus/src/editor/editor_screen.cpp
trunk/pingus/src/editor/object_selector.cpp
trunk/pingus/src/editor/object_selector.hpp
trunk/pingus/src/resource_manager.cpp
trunk/pingus/src/resource_manager.hpp
trunk/pingus/src/string_util.hpp
Log:
- made ObjectSelector load Sprites (sprite scaling broken, so few sprites show
up)
Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp 2007-09-06 16:49:19 UTC (rev
3097)
+++ trunk/pingus/src/editor/editor_screen.cpp 2007-09-06 18:18:19 UTC (rev
3098)
@@ -198,6 +198,8 @@
}
else
GUIScreen::update(delta);
+
+ SDL_Delay(33); // FIXME: Brute force delay to get CPU usage down
}
void
Modified: trunk/pingus/src/editor/object_selector.cpp
===================================================================
--- trunk/pingus/src/editor/object_selector.cpp 2007-09-06 16:49:19 UTC (rev
3097)
+++ trunk/pingus/src/editor/object_selector.cpp 2007-09-06 18:18:19 UTC (rev
3098)
@@ -110,8 +110,8 @@
void on_primary_button_release (int x, int y)
{
mouse_down = false;
- //if (mouse_over && callback)
- // ((*editor).*callback)();
+ if (mouse_over && callback)
+ ((*object_selector).*callback)();
}
bool is_at(int x, int y)
@@ -132,7 +132,7 @@
ObjectSelector::ObjectSelector(EditorScreen* editor_)
: editor(editor_),
- button_pos(Display::get_width() - 242, 40),
+ button_pos(0,0),
rect(Vector2i(Display::get_width() - 244 + 2, 38 + 3 + 62),
Size(240, 495)),
drawing_context(new DrawingContext(rect)),
@@ -142,20 +142,20 @@
{
editor->get_gui_manager()->add(this, true);
- add_button("core/editor/obj_entrance", "Entrance");
- add_button("core/editor/obj_gp_ground", "Groundpiece (ground)");
- add_button("core/editor/obj_gp_solid", "Groundpiece (solid)");
- add_button("core/editor/obj_gp_bridge", "Groundpiece (bridge)");
- add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)");
- add_button("core/editor/obj_gp_remove", "Groundpiece (remove)");
- add_button("core/editor/obj_hotspot", "Hotspot");
- add_button("core/editor/obj_background", "Background");
+ add_button("core/editor/obj_entrance", "Entrance",
&ObjectSelector::set_entrance);
+ add_button("core/editor/obj_gp_ground", "Groundpiece (ground)",
&ObjectSelector::set_gp_ground);
+ add_button("core/editor/obj_gp_solid", "Groundpiece (solid)",
&ObjectSelector::set_gp_solid);
+ add_button("core/editor/obj_gp_bridge", "Groundpiece (bridge)",
&ObjectSelector::set_gp_bridge);
+ add_button("core/editor/obj_gp_transparent", "Groundpiece (transparent)",
&ObjectSelector::set_gp_transparent);
+ add_button("core/editor/obj_gp_remove", "Groundpiece (remove)",
&ObjectSelector::set_gp_remove);
+ add_button("core/editor/obj_hotspot", "Hotspot",
&ObjectSelector::set_hotspot);
+ add_button("core/editor/obj_background", "Background",
&ObjectSelector::set_background);
// -------------------------------
- add_button("core/editor/obj_exit", "Exit");
- add_button("core/editor/obj_liquid", "Liquid");
- add_button("core/editor/obj_trap", "Trap");
- add_button("core/editor/obj_weather", "Weather");
- add_button("core/editor/obj_worldobj", "Special Object");
+ add_button("core/editor/obj_exit", "Exit", &ObjectSelector::set_exit);
+ add_button("core/editor/obj_liquid", "Liquid", &ObjectSelector::set_liquid);
+ add_button("core/editor/obj_trap", "Trap", &ObjectSelector::set_trap);
+ add_button("core/editor/obj_weather", "Weather",
&ObjectSelector::set_weather);
+ add_button("core/editor/obj_worldobj", "Special Object",
&ObjectSelector::set_worldobj);
}
@@ -186,8 +186,7 @@
gc.push_modelview();
gc.translate(0, offset);
- // black
- //gc.fill_screen(Color(0,0,0));
+ Objects::iterator i = objects.begin();
for(int y = 0; y < 20; ++y)
for(int x = 0; x < 5; ++x)
@@ -195,9 +194,14 @@
gc.draw_fillrect(x * 48, y * 48,
x * 48 + 48, y * 48 + 48,
(((x-(y%2)) % 2) ? Color(0,0,0) :
Color(100,100,100)));
+
+ if (i != objects.end())
+ {
+ gc.draw(i->sprite, x * 48, y * 48);
+ ++i;
+ }
}
- //parent_gc.draw(drawing_context);
gc.pop_modelview();
parent_gc.draw(gc);
@@ -213,14 +217,16 @@
{
editor->get_gui_manager()->add
(new ObjectSelectorButton(this,
- button_pos, image, tooltip,
+ Vector2i(Display::get_width() - 242 +
button_pos.x * 30,
+ 40 + button_pos.y * 30),
+ image, tooltip,
callback), true);
- button_pos.x += 30;
- if (button_pos.x >= Display::get_width())
+ button_pos.x += 1;
+ if (button_pos.x > 7)
{
- button_pos.x = Display::get_width() - 240;
- button_pos.y += 30;
+ button_pos.x = 0;
+ button_pos.y += 1;
}
}
@@ -265,6 +271,101 @@
offset = old_offset + (y - drag_start.y);
}
}
+
+void
+ObjectSelector::set_objects(const std::string& prefix)
+{
+ std::vector<std::string> lst = Resource::resmgr.get_section(prefix);
+ objects.clear();
+ for(std::vector<std::string>::const_iterator i = lst.begin(); i !=
lst.end(); ++i)
+ {
+ std::cout << "Objects: " << *i << std::endl;
+ Sprite sprite = Resource::load_sprite(*i);
+ sprite.scale(48, 48);
+ // need to reset the align to top/left
+ objects.push_back(Object(sprite));
+ }
+}
+
+void
+ObjectSelector::set_gp_ground()
+{
+ set_objects("groundpieces/ground");
+}
+
+void
+ObjectSelector::set_gp_solid()
+{
+ set_objects("groundpieces/solid");
+}
+
+void
+ObjectSelector::set_gp_bridge()
+{
+ set_objects("groundpieces/bridge");
+}
+
+void
+ObjectSelector::set_gp_transparent()
+{
+ set_objects("groundpieces/transparent");
+}
+
+void
+ObjectSelector::set_gp_remove()
+{
+ set_objects("groundpieces/remove");
+}
+
+void
+ObjectSelector::set_hotspot()
+{
+ set_objects("hotspots");
+}
+
+void
+ObjectSelector::set_background()
+{
+ set_objects("textures");
+}
+
+void
+ObjectSelector::set_entrance()
+{
+ set_objects("entrances");
+}
+
+void
+ObjectSelector::set_exit()
+{
+ set_objects("exits");
+}
+
+void
+ObjectSelector::set_liquid()
+{
+ set_objects("liquids");
+}
+
+void
+ObjectSelector::set_trap()
+{
+ set_objects("traps");
+}
+
+void
+ObjectSelector::set_weather()
+{
+ //set_objects("weather");
+ std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" <<
__LINE__ << std::endl;
+}
+
+void
+ObjectSelector::set_worldobj()
+{
+ std::cout << "ObjectSelector: unimplemented: " << __FILE__ << ":" <<
__LINE__ << std::endl;
+}
+
} // namespace Editor
Modified: trunk/pingus/src/editor/object_selector.hpp
===================================================================
--- trunk/pingus/src/editor/object_selector.hpp 2007-09-06 16:49:19 UTC (rev
3097)
+++ trunk/pingus/src/editor/object_selector.hpp 2007-09-06 18:18:19 UTC (rev
3098)
@@ -49,6 +49,18 @@
enum Mode { NOTHING, SCROLLING };
Mode mode;
+ struct Object
+ {
+ Sprite sprite;
+ // add meta-info to track object type
+
+ Object(const Sprite& sprite_)
+ : sprite(sprite_)
+ {}
+ };
+ typedef std::vector<Object> Objects;
+ Objects objects;
+
public:
typedef void (ObjectSelector::*Callback)();
Callback callback;
@@ -71,6 +83,22 @@
void on_pointer_move (int x, int y);
+ void set_objects(const std::string& prefix);
+
+ void set_gp_ground();
+ void set_gp_solid();
+ void set_gp_bridge();
+ void set_gp_transparent();
+ void set_gp_remove();
+ void set_hotspot();
+ void set_background();
+ void set_entrance();
+ void set_exit();
+ void set_liquid();
+ void set_trap();
+ void set_weather();
+ void set_worldobj();
+
private:
ObjectSelector (const ObjectSelector&);
ObjectSelector& operator= (const ObjectSelector&);
Modified: trunk/pingus/src/resource_manager.cpp
===================================================================
--- trunk/pingus/src/resource_manager.cpp 2007-09-06 16:49:19 UTC (rev
3097)
+++ trunk/pingus/src/resource_manager.cpp 2007-09-06 18:18:19 UTC (rev
3098)
@@ -28,6 +28,7 @@
#include "globals.hpp"
#include "lisp/lisp.hpp"
#include "lisp/parser.hpp"
+#include "string_util.hpp"
#include "sprite_description.hpp"
#include "sexpr_file_reader.hpp"
#include "resource_manager.hpp"
@@ -44,6 +45,19 @@
}
}
+std::vector<std::string>
+ResourceManager::get_section(const std::string& name)
+{
+ std::vector<std::string> lst;
+ for (std::map<std::string, SpriteDescription*>::iterator i =
resources.begin();
+ i != resources.end(); ++i)
+ {
+ if (StringUtil::has_prefix(i->first, name))
+ lst.push_back(i->first);
+ }
+ return lst;
+}
+
void
ResourceManager::add_resources(const std::string& filename)
{
Modified: trunk/pingus/src/resource_manager.hpp
===================================================================
--- trunk/pingus/src/resource_manager.hpp 2007-09-06 16:49:19 UTC (rev
3097)
+++ trunk/pingus/src/resource_manager.hpp 2007-09-06 18:18:19 UTC (rev
3098)
@@ -39,6 +39,9 @@
void add_resources(const std::string& filename);
SpriteDescription* get_sprite_description(const std::string& name) const;
+
+ std::vector<std::string> get_section(const std::string& name);
+
private:
void parse(const std::string& section, FileReader&);
void parse_section(const std::string& section, FileReader&);
Modified: trunk/pingus/src/string_util.hpp
===================================================================
--- trunk/pingus/src/string_util.hpp 2007-09-06 16:49:19 UTC (rev 3097)
+++ trunk/pingus/src/string_util.hpp 2007-09-06 18:18:19 UTC (rev 3098)
@@ -73,6 +73,14 @@
return false;
}
+ static bool has_prefix(const std::string& str, const std::string prefix)
+ {
+ if (str.length() < prefix.length())
+ return false;
+ else
+ return str.compare(0, prefix.length(), prefix) == 0;
+ }
+
private:
StringUtil ();
StringUtil (const StringUtil&);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3098 - in trunk/pingus/src: . editor,
grumbel at BerliOS <=