[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3075 - trunk/pingus/src/editor
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3075 - trunk/pingus/src/editor |
Date: |
Tue, 4 Sep 2007 01:27:38 +0200 |
Author: grumbel
Date: 2007-09-04 01:27:36 +0200 (Tue, 04 Sep 2007)
New Revision: 3075
Modified:
trunk/pingus/src/editor/context_menu.cpp
trunk/pingus/src/editor/context_menu.hpp
trunk/pingus/src/editor/editor_level.cpp
trunk/pingus/src/editor/editor_level.hpp
trunk/pingus/src/editor/editor_panel.cpp
trunk/pingus/src/editor/editor_panel.hpp
trunk/pingus/src/editor/editor_screen.cpp
trunk/pingus/src/editor/editor_screen.hpp
trunk/pingus/src/editor/editor_viewport.cpp
trunk/pingus/src/editor/editor_viewport.hpp
trunk/pingus/src/editor/level_head.cpp
trunk/pingus/src/editor/level_head.hpp
trunk/pingus/src/editor/level_impl.hpp
trunk/pingus/src/editor/level_objs.cpp
trunk/pingus/src/editor/level_objs.hpp
trunk/pingus/src/editor/panel_buttons.cpp
trunk/pingus/src/editor/panel_buttons.hpp
Log:
- fixed copyright headers and indention
Modified: trunk/pingus/src/editor/context_menu.cpp
===================================================================
--- trunk/pingus/src/editor/context_menu.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/context_menu.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -27,216 +28,216 @@
namespace Editor {
- // Determine which actions are available for these objects
- ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector3f p,
EditorViewport* vp, bool base_menu)
- : objs(o),
- viewport(vp),
- pos(p),
- selected_action_offset(0),
- displayed_child(0),
- item_height(Fonts::pingus_small.get_height())
- {
- if (base_menu)
- {
- // Create all available child menus
- width = 110;
- show = true;
- create_child_menus();
- }
- else
- {
- width = 200;
- show = false;
- }
+// Determine which actions are available for these objects
+ContextMenu::ContextMenu(std::vector<LevelObj*> o, Vector3f p, EditorViewport*
vp, bool base_menu)
+ : objs(o),
+ viewport(vp),
+ pos(p),
+ selected_action_offset(0),
+ displayed_child(0),
+ item_height(Fonts::pingus_small.get_height())
+{
+ if (base_menu)
+ {
+ // Create all available child menus
+ width = 110;
+ show = true;
+ create_child_menus();
+ }
+ else
+ {
+ width = 200;
+ show = false;
+ }
- total_height = item_height * actions.size();
- }
+ total_height = item_height * actions.size();
+}
- ContextMenu::~ContextMenu()
- {
- }
+ContextMenu::~ContextMenu()
+{
+}
- // Keep track of where the mouse is for highlighting
- void
- ContextMenu::on_pointer_move(int x, int y)
- {
- mouse_at.x = (float)x;
- mouse_at.y = (float)y;
+// Keep track of where the mouse is for highlighting
+void
+ContextMenu::on_pointer_move(int x, int y)
+{
+ mouse_at.x = (float)x;
+ mouse_at.y = (float)y;
- selected_action_offset = (unsigned)((mouse_at.y - pos.y) /
item_height);
- }
+ selected_action_offset = (unsigned)((mouse_at.y - pos.y) / item_height);
+}
- void
- ContextMenu::draw(DrawingContext &gc)
- {
- if (show)
- {
- // Draw the box
- gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y +
total_height,
- Color(211,211,211,100));
- // Draw the border
- gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y +
total_height,
- Color(0,0,0));
- // Draw the highlighted action if the mouse is in the
box
- if (hover)
- {
- gc.draw_fillrect(pos.x, pos.y +
selected_action_offset *
- item_height, pos.x + width, pos.y +
(selected_action_offset + 1) * item_height,
- Color(128,128,128,150));
- }
+void
+ContextMenu::draw(DrawingContext &gc)
+{
+ if (show)
+ {
+ // Draw the box
+ gc.draw_fillrect(pos.x, pos.y, pos.x + width, pos.y + total_height,
+ Color(211,211,211,100));
+ // Draw the border
+ gc.draw_rect(pos.x, pos.y, pos.x + width, pos.y + total_height,
+ Color(0,0,0));
+ // Draw the highlighted action if the mouse is in the box
+ if (hover)
+ {
+ gc.draw_fillrect(pos.x, pos.y + selected_action_offset *
+ item_height, pos.x + width, pos.y +
(selected_action_offset + 1) * item_height,
+ Color(128,128,128,150));
+ }
- // Draw the action names
- for (unsigned i = 0; i < actions.size(); i++)
- gc.print_left(Fonts::pingus_small, pos.x, pos.y
+
- (i * item_height),
actions[i].friendly_name);
- }
- }
+ // Draw the action names
+ for (unsigned i = 0; i < actions.size(); i++)
+ gc.print_left(Fonts::pingus_small, pos.x, pos.y +
+ (i * item_height), actions[i].friendly_name);
+ }
+}
- bool
- ContextMenu::is_at(int x, int y)
- {
- if (show)
- return (x > pos.x && x < pos.x + width &&
- y > pos.y && y < pos.y + total_height);
- else
- return false;
- }
+bool
+ContextMenu::is_at(int x, int y)
+{
+ if (show)
+ return (x > pos.x && x < pos.x + width &&
+ y > pos.y && y < pos.y + total_height);
+ else
+ return false;
+}
- void
- ContextMenu::on_primary_button_click(int x, int y)
- {
- if (!actions[selected_action_offset].child)
- {
- for (unsigned i = 0; i < objs.size(); i++)
- {
- switch
(actions[selected_action_offset].modifier)
- {
- case (REMOVE) :
- objs[i]->remove();
- break;
- case (ROTATE) :
-
objs[i]->set_modifier(actions[selected_action_offset].parameter);
- break;
- case (SET_OWNER) :
-
objs[i]->set_owner(StringUtil::to<int>(actions[selected_action_offset].parameter));
- break;
- case (SET_DIRECTION) :
-
objs[i]->set_direction(actions[selected_action_offset].parameter);
- break;
- case (SET_Z_POS) :
-
objs[i]->set_pos(Vector3f(objs[i]->get_pos().x, objs[i]->get_pos().y,
-
(float)StringUtil::to<int>(actions[selected_action_offset].parameter)));
-
objs[i]->set_orig_pos(objs[i]->get_pos());
- break;
- default :
- break;
- }
- }
- viewport->remove_context_menu();
- }
- }
+void
+ContextMenu::on_primary_button_click(int x, int y)
+{
+ if (!actions[selected_action_offset].child)
+ {
+ for (unsigned i = 0; i < objs.size(); i++)
+ {
+ switch (actions[selected_action_offset].modifier)
+ {
+ case (REMOVE) :
+ objs[i]->remove();
+ break;
+ case (ROTATE) :
+
objs[i]->set_modifier(actions[selected_action_offset].parameter);
+ break;
+ case (SET_OWNER) :
+
objs[i]->set_owner(StringUtil::to<int>(actions[selected_action_offset].parameter));
+ break;
+ case (SET_DIRECTION) :
+
objs[i]->set_direction(actions[selected_action_offset].parameter);
+ break;
+ case (SET_Z_POS) :
+ objs[i]->set_pos(Vector3f(objs[i]->get_pos().x,
objs[i]->get_pos().y,
+
(float)StringUtil::to<int>(actions[selected_action_offset].parameter)));
+ objs[i]->set_orig_pos(objs[i]->get_pos());
+ break;
+ default :
+ break;
+ }
+ }
+ viewport->remove_context_menu();
+ }
+}
- void
- ContextMenu::on_secondary_button_click(int x, int y)
- {
- // Does the same as the primary button
- on_primary_button_click(x, y);
- }
+void
+ContextMenu::on_secondary_button_click(int x, int y)
+{
+ // Does the same as the primary button
+ on_primary_button_click(x, y);
+}
- void
- ContextMenu::create_child_menus()
- {
- // Create Remove button - available to all objects
- actions.push_back(ContextItem("Remove", "", REMOVE, 0));
+void
+ContextMenu::create_child_menus()
+{
+ // Create Remove button - available to all objects
+ actions.push_back(ContextItem("Remove", "", REMOVE, 0));
- // Determine which actions are available to the selected objects
- unsigned available_attribs = 0xffff;
- for (unsigned i = 0; i < (unsigned)objs.size(); i++)
- available_attribs = available_attribs &
objs[i]->get_attribs();
+ // Determine which actions are available to the selected objects
+ unsigned available_attribs = 0xffff;
+ for (unsigned i = 0; i < (unsigned)objs.size(); i++)
+ available_attribs = available_attribs & objs[i]->get_attribs();
- ContextMenu* menu;
- if (available_attribs & CAN_ROTATE)
- {
- menu = new ContextMenu(objs, Vector3f(pos.x + width,
pos.y), viewport, false);
- viewport->get_screen()->get_gui_manager()->add(menu,
true);
- menu->add_action(ContextItem("0 degrees", "ROT0",
ROTATE, 0));
- menu->add_action(ContextItem("90 Degrees", "ROT90",
ROTATE, 0));
- menu->add_action(ContextItem("180 Degrees", "ROT180",
ROTATE, 0));
- menu->add_action(ContextItem("270 Degrees", "ROT270",
ROTATE, 0));
- menu->add_action(ContextItem("0 Degrees + Flip",
"ROT0FLIP", ROTATE, 0));
- menu->add_action(ContextItem("90 Degrees + Flip",
"ROT90FLIP", ROTATE, 0));
- menu->add_action(ContextItem("180 Degrees + Flip",
"ROT180FLIP", ROTATE, 0));
- menu->add_action(ContextItem("270 Degrees + Flip",
"ROT270FLIP", ROTATE, 0));
- add_action(ContextItem("Rotate >", "", ROTATE, menu));
- }
- if (available_attribs & HAS_OWNER)
- {
- menu = new ContextMenu(objs, Vector3f(pos.x + width,
pos.y), viewport, false);
- viewport->get_screen()->get_gui_manager()->add(menu,
true);
- menu->add_action(ContextItem("0", "0", SET_OWNER, 0));
- menu->add_action(ContextItem("1", "1", SET_OWNER, 0));
- menu->add_action(ContextItem("2", "2", SET_OWNER, 0));
- menu->add_action(ContextItem("3", "3", SET_OWNER, 0));
- add_action(ContextItem("Set Owner >", "", SET_OWNER,
menu));
- }
- if (available_attribs & HAS_DIRECTION)
- {
- menu = new ContextMenu(objs, Vector3f(pos.x + width,
pos.y), viewport, false);
- viewport->get_screen()->get_gui_manager()->add(menu,
true);
- menu->add_action(ContextItem("Left", "left",
SET_DIRECTION, 0));
- menu->add_action(ContextItem("Right", "right",
SET_DIRECTION, 0));
- menu->add_action(ContextItem("Misc.", "misc",
SET_DIRECTION, 0));
- add_action(ContextItem("Direction >", "",
SET_DIRECTION, menu));
- }
- menu = new ContextMenu(objs, Vector3f(pos.x + width, pos.y),
viewport, false);
- viewport->get_screen()->get_gui_manager()->add(menu, true);
- menu->add_action(ContextItem("-50", "-50", SET_Z_POS, 0));
- menu->add_action(ContextItem("-25", "-25", SET_Z_POS, 0));
- menu->add_action(ContextItem("0", "0", SET_Z_POS, 0));
- menu->add_action(ContextItem("25", "25", SET_Z_POS, 0));
- menu->add_action(ContextItem("50", "50", SET_Z_POS, 0));
- add_action(ContextItem("Set Z Pos. >", "", SET_Z_POS, menu));
+ ContextMenu* menu;
+ if (available_attribs & CAN_ROTATE)
+ {
+ menu = new ContextMenu(objs, Vector3f(pos.x + width, pos.y), viewport,
false);
+ viewport->get_screen()->get_gui_manager()->add(menu, true);
+ menu->add_action(ContextItem("0 degrees", "ROT0", ROTATE, 0));
+ menu->add_action(ContextItem("90 Degrees", "ROT90", ROTATE, 0));
+ menu->add_action(ContextItem("180 Degrees", "ROT180", ROTATE, 0));
+ menu->add_action(ContextItem("270 Degrees", "ROT270", ROTATE, 0));
+ menu->add_action(ContextItem("0 Degrees + Flip", "ROT0FLIP", ROTATE, 0));
+ menu->add_action(ContextItem("90 Degrees + Flip", "ROT90FLIP", ROTATE,
0));
+ menu->add_action(ContextItem("180 Degrees + Flip", "ROT180FLIP", ROTATE,
0));
+ menu->add_action(ContextItem("270 Degrees + Flip", "ROT270FLIP", ROTATE,
0));
+ add_action(ContextItem("Rotate >", "", ROTATE, menu));
+ }
+ if (available_attribs & HAS_OWNER)
+ {
+ menu = new ContextMenu(objs, Vector3f(pos.x + width, pos.y), viewport,
false);
+ viewport->get_screen()->get_gui_manager()->add(menu, true);
+ menu->add_action(ContextItem("0", "0", SET_OWNER, 0));
+ menu->add_action(ContextItem("1", "1", SET_OWNER, 0));
+ menu->add_action(ContextItem("2", "2", SET_OWNER, 0));
+ menu->add_action(ContextItem("3", "3", SET_OWNER, 0));
+ add_action(ContextItem("Set Owner >", "", SET_OWNER, menu));
+ }
+ if (available_attribs & HAS_DIRECTION)
+ {
+ menu = new ContextMenu(objs, Vector3f(pos.x + width, pos.y), viewport,
false);
+ viewport->get_screen()->get_gui_manager()->add(menu, true);
+ menu->add_action(ContextItem("Left", "left", SET_DIRECTION, 0));
+ menu->add_action(ContextItem("Right", "right", SET_DIRECTION, 0));
+ menu->add_action(ContextItem("Misc.", "misc", SET_DIRECTION, 0));
+ add_action(ContextItem("Direction >", "", SET_DIRECTION, menu));
+ }
+ menu = new ContextMenu(objs, Vector3f(pos.x + width, pos.y), viewport,
false);
+ viewport->get_screen()->get_gui_manager()->add(menu, true);
+ menu->add_action(ContextItem("-50", "-50", SET_Z_POS, 0));
+ menu->add_action(ContextItem("-25", "-25", SET_Z_POS, 0));
+ menu->add_action(ContextItem("0", "0", SET_Z_POS, 0));
+ menu->add_action(ContextItem("25", "25", SET_Z_POS, 0));
+ menu->add_action(ContextItem("50", "50", SET_Z_POS, 0));
+ add_action(ContextItem("Set Z Pos. >", "", SET_Z_POS, menu));
- // TODO - Add more menu options here
- }
+ // TODO - Add more menu options here
+}
- void
- ContextMenu::add_action(ContextItem item)
- {
- actions.push_back(item);
- total_height += item_height;
- }
+void
+ContextMenu::add_action(ContextItem item)
+{
+ actions.push_back(item);
+ total_height += item_height;
+}
- void
- ContextMenu::display(bool should_display)
- {
- show = should_display;
- if (!show && displayed_child)
- displayed_child->display(false);
- }
+void
+ContextMenu::display(bool should_display)
+{
+ show = should_display;
+ if (!show && displayed_child)
+ displayed_child->display(false);
+}
- void
- ContextMenu::update(float delta)
- {
- UNUSED_ARG(delta);
+void
+ContextMenu::update(float delta)
+{
+ UNUSED_ARG(delta);
- if (displayed_child != actions[selected_action_offset].child)
- {
- if (displayed_child)
- {
- displayed_child->display(false);
- displayed_child = 0;
- }
- if (actions[selected_action_offset].child)
- {
- displayed_child =
actions[selected_action_offset].child;
- displayed_child->display(true);
- }
- }
- }
+ if (displayed_child != actions[selected_action_offset].child)
+ {
+ if (displayed_child)
+ {
+ displayed_child->display(false);
+ displayed_child = 0;
+ }
+ if (actions[selected_action_offset].child)
+ {
+ displayed_child = actions[selected_action_offset].child;
+ displayed_child->display(true);
+ }
+ }
+}
-} // Editor namespace
+} // Editor namespace
/* EOF */
Modified: trunk/pingus/src/editor/context_menu.hpp
===================================================================
--- trunk/pingus/src/editor/context_menu.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/context_menu.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -27,99 +28,97 @@
namespace Editor {
- class LevelObj;
- class EditorViewport;
- class ContextMenu;
+class LevelObj;
+class EditorViewport;
+class ContextMenu;
- typedef enum ItemModifier { REMOVE, ROTATE, SET_OWNER, SET_DIRECTION,
- STRETCH, SET_Z_POS };
+typedef enum ItemModifier { REMOVE, ROTATE, SET_OWNER, SET_DIRECTION,
+ STRETCH, SET_Z_POS };
- class ContextItem {
- public:
- std::string friendly_name;
- std::string parameter;
- ItemModifier modifier;
- ContextMenu* child;
+class ContextItem {
+public:
+ std::string friendly_name;
+ std::string parameter;
+ ItemModifier modifier;
+ ContextMenu* child;
- public:
- ContextItem(std::string friendly_name_, std::string parameter_,
ItemModifier mod,
- ContextMenu* child_menu)
- : friendly_name(friendly_name_),
- parameter(parameter_),
- modifier(mod),
- child(child_menu)
- { }
- };
+public:
+ ContextItem(std::string friendly_name_, std::string parameter_, ItemModifier
mod,
+ ContextMenu* child_menu)
+ : friendly_name(friendly_name_),
+ parameter(parameter_),
+ modifier(mod),
+ child(child_menu)
+ { }
+};
- class ContextMenu : public GUI::Component {
- private:
- /** Creates the child menu structure and detemines which
actions are available */
- void create_child_menus();
+class ContextMenu : public GUI::Component {
+private:
+ /** Creates the child menu structure and detemines which actions are
available */
+ void create_child_menus();
- /** Level objects to be affected by this menu */
- std::vector<LevelObj*> objs;
+ /** Level objects to be affected by this menu */
+ std::vector<LevelObj*> objs;
- /** Viewport to which this menu belongs */
- EditorViewport* viewport;
+ /** Viewport to which this menu belongs */
+ EditorViewport* viewport;
- /** List of actions available in this menu */
- std::vector<ContextItem> actions;
+ /** List of actions available in this menu */
+ std::vector<ContextItem> actions;
- /** Where the mouse is located */
- Vector3f mouse_at;
+ /** Where the mouse is located */
+ Vector3f mouse_at;
- /** Location of context menu */
- Vector3f pos;
+ /** Location of context menu */
+ Vector3f pos;
- /** Is the mouse over the menu? */
- bool hover;
+ /** Is the mouse over the menu? */
+ bool hover;
- /** Should this be showing? */
- bool show;
+ /** Should this be showing? */
+ bool show;
- /** The offset into actions vector of the currently highlighted
action */
- unsigned selected_action_offset;
+ /** The offset into actions vector of the currently highlighted action */
+ unsigned selected_action_offset;
- /** Currently displayed child menu (if any) */
- ContextMenu* displayed_child;
+ /** Currently displayed child menu (if any) */
+ ContextMenu* displayed_child;
- /** Height of a single action */
- unsigned item_height;
+ /** Height of a single action */
+ unsigned item_height;
- unsigned total_height;
- unsigned width;
+ unsigned total_height;
+ unsigned width;
- public:
- // Constructor
- ContextMenu (std::vector<LevelObj*>, Vector3f p,
EditorViewport* v, bool base_menu = true);
+public:
+ // Constructor
+ ContextMenu (std::vector<LevelObj*>, Vector3f p, EditorViewport* v, bool
base_menu = true);
- // Desctructor
- ~ContextMenu ();
+ // Desctructor
+ ~ContextMenu ();
- /** Add an action to the list */
- void add_action(ContextItem item);
+ /** Add an action to the list */
+ void add_action(ContextItem item);
- void display (bool should_display);
+ void display (bool should_display);
- /// GUI Component Functions
- bool is_at(int x, int y);
- void draw (DrawingContext& gc);
- void update (float delta);
- void on_pointer_move (int x, int y);
- void on_primary_button_click(int x, int y);
- void on_secondary_button_click(int x, int y);
- void on_pointer_enter () { hover = true; }
- void on_pointer_leave () { hover = false; }
+ /// GUI Component Functions
+ bool is_at(int x, int y);
+ void draw (DrawingContext& gc);
+ void update (float delta);
+ void on_pointer_move (int x, int y);
+ void on_primary_button_click(int x, int y);
+ void on_secondary_button_click(int x, int y);
+ void on_pointer_enter () { hover = true; }
+ void on_pointer_leave () { hover = false; }
+private:
+ ContextMenu ();
+ ContextMenu (const ContextMenu&);
+ ContextMenu& operator= (const ContextMenu&);
+}; // ContextMenu class
- private:
- ContextMenu ();
- ContextMenu (const ContextMenu&);
- ContextMenu& operator= (const ContextMenu&);
-
- }; // ContextMenu class
-
} // Editor namespace
#endif
Modified: trunk/pingus/src/editor/editor_level.cpp
===================================================================
--- trunk/pingus/src/editor/editor_level.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_level.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -26,12 +27,11 @@
#include "../pingus_level.hpp"
#include "../sexpr_file_writer.hpp"
-
namespace Editor {
// Default constructor
EditorLevel::EditorLevel() :
- impl(new LevelImpl())
+ impl(new LevelImpl())
{
}
@@ -39,211 +39,211 @@
// Default Destructor
EditorLevel::~EditorLevel()
{
- if (impl)
- delete impl;
+ if (impl)
+ delete impl;
}
/** Verify that level is valid:
- Level should contain the following attributes in order to be "valid":
- -----------
- LevelObj's:
- - At least 1 entrance
- - At least 1 exit
- - At least 1 surface-background
- - Each object should be within valid ranges (pos Vector3f should be inside
the world)
- -----------
- Head section:
- - Everything should be filled in and within valid ranges
- */
+ Level should contain the following attributes in order to be "valid":
+ -----------
+ LevelObj's:
+ - At least 1 entrance
+ - At least 1 exit
+ - At least 1 surface-background
+ - Each object should be within valid ranges (pos Vector3f should be inside
the world)
+ -----------
+ Head section:
+ - Everything should be filled in and within valid ranges
+*/
bool EditorLevel::is_valid()
{
- std::cout << "EditorLevel::is_valid() - Not yet implemented" <<
std::endl;
- if (impl)
- return true;
- else
- return false;
+ std::cout << "EditorLevel::is_valid() - Not yet implemented" << std::endl;
+ if (impl)
+ return true;
+ else
+ return false;
}
// Save the level to a file. Returns true if successful
bool EditorLevel::save_level(const std::string& filename)
{
- // Make sure level is valid
- if (!is_valid())
- return false;
+ // Make sure level is valid
+ if (!is_valid())
+ return false;
- // Create new file (overwrite existing file)
- std::ofstream out_file(filename.c_str());
- SExprFileWriter fw(out_file);
+ // Create new file (overwrite existing file)
+ std::ofstream out_file(filename.c_str());
+ SExprFileWriter fw(out_file);
- // Write header
- fw.begin_section("pingus-level");
- fw.write_int("version", 2);
- fw.begin_section("head");
- fw.write_string("levelname", impl->levelname);
- fw.write_string("description", impl->description);
- fw.write_string("author", impl->author);
- fw.write_int("number-of-pingus", impl->number_of_pingus);
- fw.write_int("number-to-save", impl->number_to_save);
- fw.write_int("time", impl->time);
- fw.write_int("difficulty", impl->difficulty);
- // FIXME: Allow user to decide if level is playable or not
- fw.write_int("playable", 1);
- fw.write_string("comment", impl->comment);
- fw.write_string("music", impl->music);
+ // Write header
+ fw.begin_section("pingus-level");
+ fw.write_int("version", 2);
+ fw.begin_section("head");
+ fw.write_string("levelname", impl->levelname);
+ fw.write_string("description", impl->description);
+ fw.write_string("author", impl->author);
+ fw.write_int("number-of-pingus", impl->number_of_pingus);
+ fw.write_int("number-to-save", impl->number_to_save);
+ fw.write_int("time", impl->time);
+ fw.write_int("difficulty", impl->difficulty);
+ // FIXME: Allow user to decide if level is playable or not
+ fw.write_int("playable", 1);
+ fw.write_string("comment", impl->comment);
+ fw.write_string("music", impl->music);
- // Write the list of actions to the file
- fw.begin_section("actions");
- for (std::map<std::string, int>::const_iterator i =
impl->actions.begin();
- i != impl->actions.end(); i++)
- {
- fw.write_int(i->first.c_str(), i->second);
- }
- fw.end_section(); // actions
+ // Write the list of actions to the file
+ fw.begin_section("actions");
+ for (std::map<std::string, int>::const_iterator i = impl->actions.begin();
+ i != impl->actions.end(); i++)
+ {
+ fw.write_int(i->first.c_str(), i->second);
+ }
+ fw.end_section(); // actions
- fw.write_size("levelsize", impl->size);
- fw.end_section(); // head
+ fw.write_size("levelsize", impl->size);
+ fw.end_section(); // head
- // Write the objects
- fw.begin_section("objects");
- for (unsigned i = 0; i < impl->objects.size(); i++)
- impl->objects[i]->write_properties(fw);
- fw.end_section(); // objects
+ // Write the objects
+ fw.begin_section("objects");
+ for (unsigned i = 0; i < impl->objects.size(); i++)
+ impl->objects[i]->write_properties(fw);
+ fw.end_section(); // objects
- fw.end_section(); // pingus-level
+ fw.end_section(); // pingus-level
- // Clean up
- out_file.close();
+ // Clean up
+ out_file.close();
- return true;
+ return true;
}
// Load an existing level from a file
void EditorLevel::load_level(const std::string& filename)
{
- if (impl)
- delete impl;
- impl = new LevelImpl();
+ if (impl)
+ delete impl;
+ impl = new LevelImpl();
- // Load the level from the file - we don't care what it's res_name is.
- PingusLevel existing_level("", filename);
+ // Load the level from the file - we don't care what it's res_name is.
+ PingusLevel existing_level("", filename);
- // Assign all of the level information to our LevelImpl
- impl->levelname = existing_level.get_levelname();
- impl->description = existing_level.get_description();
- impl->ambient_light = existing_level.get_ambient_light();
- impl->size = existing_level.get_size();
- impl->number_of_pingus = existing_level.get_number_of_pingus();
- impl->number_to_save = existing_level.get_number_to_save();
- impl->actions = existing_level.get_actions();
- impl->time = existing_level.get_time();
- impl->difficulty = existing_level.get_difficulty();
- impl->author = existing_level.get_author();
- impl->music = existing_level.get_music();
+ // Assign all of the level information to our LevelImpl
+ impl->levelname = existing_level.get_levelname();
+ impl->description = existing_level.get_description();
+ impl->ambient_light = existing_level.get_ambient_light();
+ impl->size = existing_level.get_size();
+ impl->number_of_pingus = existing_level.get_number_of_pingus();
+ impl->number_to_save = existing_level.get_number_to_save();
+ impl->actions = existing_level.get_actions();
+ impl->time = existing_level.get_time();
+ impl->difficulty = existing_level.get_difficulty();
+ impl->author = existing_level.get_author();
+ impl->music = existing_level.get_music();
- // Temporary objects
- unsigned attribs;
- Vector3f p;
- Color tmp_color;
- ResDescriptor desc;
- std::string tmp_str;
- int tmp_int;
- float tmp_float;
- bool tmp_bool;
+ // Temporary objects
+ unsigned attribs;
+ Vector3f p;
+ Color tmp_color;
+ ResDescriptor desc;
+ std::string tmp_str;
+ int tmp_int;
+ float tmp_float;
+ bool tmp_bool;
- // Get the objects
- std::vector<FileReader> objs = existing_level.get_objects();
- for (std::vector<FileReader>::const_iterator i = objs.begin(); i !=
objs.end(); i++)
- {
- // Create new object
- LevelObj* obj = new LevelObj(i->get_name(), impl);
- attribs = obj->get_attribs();
+ // Get the objects
+ std::vector<FileReader> objs = existing_level.get_objects();
+ for (std::vector<FileReader>::const_iterator i = objs.begin(); i !=
objs.end(); i++)
+ {
+ // Create new object
+ LevelObj* obj = new LevelObj(i->get_name(), impl);
+ attribs = obj->get_attribs();
- // All objects have a position - get that.
- i->read_vector("position", p);
- obj->set_orig_pos(p);
- obj->set_pos(p);
+ // All objects have a position - get that.
+ i->read_vector("position", p);
+ obj->set_orig_pos(p);
+ obj->set_pos(p);
- // Get optional attributes based on the attribs value
- if (attribs & HAS_SURFACE)
- {
- i->read_desc("surface", desc);
- obj->set_res_desc(desc);
- }
- if (attribs & HAS_TYPE)
- {
- i->read_string("type", tmp_str);
- obj->set_type(tmp_str);
- }
- if (attribs & HAS_SPEED)
- {
- i->read_int("speed", tmp_int);
- obj->set_speed(tmp_int);
- }
- if (attribs & HAS_WIDTH)
- {
- i->read_int("width", tmp_int);
- obj->set_width(tmp_int);
- }
- if (attribs & HAS_PARALLAX)
- {
- i->read_float("parallax", tmp_float);
- obj->set_parallax(tmp_float);
- }
- if (attribs & HAS_OWNER)
- {
- i->read_int("owner-id", tmp_int);
- obj->set_owner(tmp_int);
- }
- if (attribs & HAS_DIRECTION)
- {
- i->read_string("direction", tmp_str);
- obj->set_direction(tmp_str);
- }
- if (attribs & HAS_COLOR)
- {
- i->read_color("color", tmp_color);
- obj->set_color(tmp_color);
- }
- if (attribs & HAS_SCROLL)
- {
- i->read_float("scroll-x", tmp_float);
- obj->set_scroll_x(tmp_float);
- i->read_float("scroll-y", tmp_float);
- obj->set_scroll_y(tmp_float);
- }
- if (attribs & HAS_STRETCH)
- {
- i->read_bool("stretch-x", tmp_bool);
- obj->set_stretch_x(tmp_bool);
- i->read_bool("stretch-y", tmp_bool);
- obj->set_stretch_y(tmp_bool);
- i->read_bool("keep-aspect", tmp_bool);
- obj->set_aspect(tmp_bool);
- }
- if (attribs & HAS_PARA)
- {
- i->read_float("para-x", tmp_float);
- obj->set_para_x(tmp_float);
- i->read_float("para-y", tmp_float);
- obj->set_para_y(tmp_float);
- }
- if (attribs & HAS_RELEASE_RATE)
- {
- i->read_int("release-rate", tmp_int);
- obj->set_release_rate(tmp_int);
- }
+ // Get optional attributes based on the attribs value
+ if (attribs & HAS_SURFACE)
+ {
+ i->read_desc("surface", desc);
+ obj->set_res_desc(desc);
+ }
+ if (attribs & HAS_TYPE)
+ {
+ i->read_string("type", tmp_str);
+ obj->set_type(tmp_str);
+ }
+ if (attribs & HAS_SPEED)
+ {
+ i->read_int("speed", tmp_int);
+ obj->set_speed(tmp_int);
+ }
+ if (attribs & HAS_WIDTH)
+ {
+ i->read_int("width", tmp_int);
+ obj->set_width(tmp_int);
+ }
+ if (attribs & HAS_PARALLAX)
+ {
+ i->read_float("parallax", tmp_float);
+ obj->set_parallax(tmp_float);
+ }
+ if (attribs & HAS_OWNER)
+ {
+ i->read_int("owner-id", tmp_int);
+ obj->set_owner(tmp_int);
+ }
+ if (attribs & HAS_DIRECTION)
+ {
+ i->read_string("direction", tmp_str);
+ obj->set_direction(tmp_str);
+ }
+ if (attribs & HAS_COLOR)
+ {
+ i->read_color("color", tmp_color);
+ obj->set_color(tmp_color);
+ }
+ if (attribs & HAS_SCROLL)
+ {
+ i->read_float("scroll-x", tmp_float);
+ obj->set_scroll_x(tmp_float);
+ i->read_float("scroll-y", tmp_float);
+ obj->set_scroll_y(tmp_float);
+ }
+ if (attribs & HAS_STRETCH)
+ {
+ i->read_bool("stretch-x", tmp_bool);
+ obj->set_stretch_x(tmp_bool);
+ i->read_bool("stretch-y", tmp_bool);
+ obj->set_stretch_y(tmp_bool);
+ i->read_bool("keep-aspect", tmp_bool);
+ obj->set_aspect(tmp_bool);
+ }
+ if (attribs & HAS_PARA)
+ {
+ i->read_float("para-x", tmp_float);
+ obj->set_para_x(tmp_float);
+ i->read_float("para-y", tmp_float);
+ obj->set_para_y(tmp_float);
+ }
+ if (attribs & HAS_RELEASE_RATE)
+ {
+ i->read_int("release-rate", tmp_int);
+ obj->set_release_rate(tmp_int);
+ }
- impl->objects.push_back((LevelObj*)obj);
- }
+ impl->objects.push_back((LevelObj*)obj);
+ }
- // Sort by Z coordinate
- impl->sort_objs();
+ // Sort by Z coordinate
+ impl->sort_objs();
}
void
EditorLevel::add_object(LevelObj* obj)
{
- impl->objects.push_back(obj);
+ impl->objects.push_back(obj);
}
} // Editor namespace
Modified: trunk/pingus/src/editor/editor_level.hpp
===================================================================
--- trunk/pingus/src/editor/editor_level.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_level.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -23,45 +24,44 @@
#include <vector>
#include "level_impl.hpp"
-
namespace Editor {
- class LevelObj;
+class LevelObj;
class EditorLevel
{
private:
- LevelImpl* impl;
+ LevelImpl* impl;
public:
- /** Construct new blank level */
- EditorLevel();
+ /** Construct new blank level */
+ EditorLevel();
- /** Destructor */
- ~EditorLevel();
+ /** Destructor */
+ ~EditorLevel();
- /** Verify that level is valid */
- bool is_valid();
+ /** Verify that level is valid */
+ bool is_valid();
- /** Save the level to a file. Returns true if successful */
- bool save_level(const std::string& filename);
+ /** Save the level to a file. Returns true if successful */
+ bool save_level(const std::string& filename);
- /** Load an existing level from a file */
- void load_level(const std::string& filename);
+ /** Load an existing level from a file */
+ void load_level(const std::string& filename);
- /** Return all objects in the level */
- std::vector<LevelObj*> get_objects() const { return impl->objects; }
+ /** Return all objects in the level */
+ std::vector<LevelObj*> get_objects() const { return impl->objects; }
- /** Add an object to the level */
- void add_object(LevelObj* obj);
+ /** Add an object to the level */
+ void add_object(LevelObj* obj);
- /** Return LevelImpl */
- LevelImpl* get_level_impl() { return impl; }
+ /** Return LevelImpl */
+ LevelImpl* get_level_impl() { return impl; }
private:
- EditorLevel (const EditorLevel&);
+ EditorLevel (const EditorLevel&);
EditorLevel& operator= (const EditorLevel&);
}; // EditorLevel class
Modified: trunk/pingus/src/editor/editor_panel.cpp
===================================================================
--- trunk/pingus/src/editor/editor_panel.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_panel.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -32,17 +33,17 @@
#include "panel_buttons.hpp"
- class GUI::Component;
+class GUI::Component;
namespace Editor {
// Constructor
EditorPanel::EditorPanel(EditorScreen* es)
-: editor(es),
- pressed_button(0),
- combobox_1(0),
- combobox_2(0),
- snap_to_checkbox(0)
+ : editor(es),
+ pressed_button(0),
+ combobox_1(0),
+ combobox_2(0),
+ snap_to_checkbox(0)
{
}
@@ -58,115 +59,115 @@
void
EditorPanel::init()
{
- // Create panel buttons
- add((PanelButton*)(new PanelButtonExit(this)));
- add((PanelButton*)(new PanelButtonLoad(this)));
- add((PanelButton*)(new PanelButtonSave(this)));
- add((PanelButton*)(new PanelButtonGroundpiece(this)));
+ // Create panel buttons
+ add((PanelButton*)(new PanelButtonExit(this)));
+ add((PanelButton*)(new PanelButtonLoad(this)));
+ add((PanelButton*)(new PanelButtonSave(this)));
+ add((PanelButton*)(new PanelButtonGroundpiece(this)));
add((PanelButton*)(new PanelButtonHead(this)));
- // Create Checkboxes
- snap_to_checkbox = new GUI::Checkbox(Vector3f(370, 5), "Snap To Grid:
", this);
- get_screen()->get_gui_manager()->add(snap_to_checkbox, true);
+ // Create Checkboxes
+ snap_to_checkbox = new GUI::Checkbox(Vector3f(370, 5), "Snap To Grid: ",
this);
+ get_screen()->get_gui_manager()->add(snap_to_checkbox, true);
- // Create Comboboxes
- combobox_3 = new GUI::Combobox(Vector3f(500, 36), this);
- combobox_2 = new GUI::Combobox(Vector3f(500, 18), this);
- combobox_1 = new GUI::Combobox(Vector3f(500, 0), this);
- get_screen()->get_gui_manager()->add(combobox_3, true);
- get_screen()->get_gui_manager()->add(combobox_2, true);
- get_screen()->get_gui_manager()->add(combobox_1, true);
- combobox_3->set_enabled(false);
- combobox_2->set_enabled(false);
- combobox_1->set_enabled(false);
+ // Create Comboboxes
+ combobox_3 = new GUI::Combobox(Vector3f(500, 36), this);
+ combobox_2 = new GUI::Combobox(Vector3f(500, 18), this);
+ combobox_1 = new GUI::Combobox(Vector3f(500, 0), this);
+ get_screen()->get_gui_manager()->add(combobox_3, true);
+ get_screen()->get_gui_manager()->add(combobox_2, true);
+ get_screen()->get_gui_manager()->add(combobox_1, true);
+ combobox_3->set_enabled(false);
+ combobox_2->set_enabled(false);
+ combobox_1->set_enabled(false);
}
// Draw the panel
void
EditorPanel::draw (DrawingContext& gc)
{
- // Draw the panel
- gc.draw_fillrect(0, 0, (float)Display::get_width(),
- 50.0f, Color(80,80,80), -50);
+ // Draw the panel
+ gc.draw_fillrect(0, 0, (float)Display::get_width(),
+ 50.0f, Color(80,80,80), -50);
}
// Add the button to the vector, set it's position, and add to the gui_manager
void
EditorPanel::add(PanelButton* button)
{
- // Determind where to place this buttons
- Vector3f new_pos;
+ // Determind where to place this buttons
+ Vector3f new_pos;
- if (panel_buttons.empty())
- new_pos = Vector3f(0.0f, 0.0f, 0.0f);
- else
- new_pos = Vector3f(panel_buttons.back()->get_pos() +
- Vector3f((float)(5 +
panel_buttons.back()->get_width()), 0.0f));
- // Add button to collection of buttons
- panel_buttons.push_back(button);
+ if (panel_buttons.empty())
+ new_pos = Vector3f(0.0f, 0.0f, 0.0f);
+ else
+ new_pos = Vector3f(panel_buttons.back()->get_pos() +
+ Vector3f((float)(5 +
panel_buttons.back()->get_width()), 0.0f));
+ // Add button to collection of buttons
+ panel_buttons.push_back(button);
- // Add a 5 pixel spacing between all buttons
- button->set_pos(new_pos);
+ // Add a 5 pixel spacing between all buttons
+ button->set_pos(new_pos);
- // Add the button to the GUI Manager
- get_screen()->get_gui_manager()->add((GUI::Component*)button, true);
+ // Add the button to the GUI Manager
+ get_screen()->get_gui_manager()->add((GUI::Component*)button, true);
}
void
EditorPanel::set_selected_button(PanelButton* pb)
{
- if (pressed_button)
- {
- combobox_1->set_enabled(false);
- combobox_2->set_enabled(false);
- combobox_3->set_enabled(false);
- pressed_button->select(false);
- }
+ if (pressed_button)
+ {
+ combobox_1->set_enabled(false);
+ combobox_2->set_enabled(false);
+ combobox_3->set_enabled(false);
+ pressed_button->select(false);
+ }
- pressed_button = pb;
- if (pressed_button)
- pressed_button->select(true);
+ pressed_button = pb;
+ if (pressed_button)
+ pressed_button->select(true);
}
GUI::Combobox*
EditorPanel::get_combobox(int i)
{
- switch(i)
- {
- case 1 :
- return combobox_1;
- case 2 :
- return combobox_2;
- case 3:
- return combobox_3;
- default :
- return 0;
- }
+ switch(i)
+ {
+ case 1 :
+ return combobox_1;
+ case 2 :
+ return combobox_2;
+ case 3:
+ return combobox_3;
+ default :
+ return 0;
+ }
}
void
EditorPanel::checkbox_changed(bool new_value, GUI::Checkbox* box)
{
- if (box == snap_to_checkbox)
- editor->get_viewport()->set_snap_to(new_value);
+ if (box == snap_to_checkbox)
+ editor->get_viewport()->set_snap_to(new_value);
}
void
EditorPanel::combobox_changed(GUI::Combobox* box)
{
- if (pressed_button)
- {
- int i;
- if (box == combobox_1)
- i = 1;
- else if (box == combobox_2)
- i = 2;
- else
- i = 3;
+ if (pressed_button)
+ {
+ int i;
+ if (box == combobox_1)
+ i = 1;
+ else if (box == combobox_2)
+ i = 2;
+ else
+ i = 3;
- // Send the ID field of the Combobox to whichever button is
currently selected.
- pressed_button->combobox_changed(i,
- get_combobox(i)->get_selected_item()->get_id());
- }
+ // Send the ID field of the Combobox to whichever button is currently
selected.
+ pressed_button->combobox_changed(i,
+
get_combobox(i)->get_selected_item()->get_id());
+ }
}
Modified: trunk/pingus/src/editor/editor_panel.hpp
===================================================================
--- trunk/pingus/src/editor/editor_panel.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_panel.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -27,75 +28,75 @@
#include "../gui/combobox_listener.hpp"
- class DrawingContext;
- class GUI::Checkbox;
- class GUI::Combobox;
+class DrawingContext;
+class GUI::Checkbox;
+class GUI::Combobox;
namespace Editor {
- class PanelButton;
- class EditorScreen;
+class PanelButton;
+class EditorScreen;
/** This class contains all of the buttons, comboboxes, and other components */
class EditorPanel : public GUI::Component,
- public GUI::CheckboxListener, public GUI::ComboboxListener
+ public GUI::CheckboxListener, public GUI::ComboboxListener
{
private:
- /** The EditorScreen to which this panel belongs */
- EditorScreen* editor;
+ /** The EditorScreen to which this panel belongs */
+ EditorScreen* editor;
- /** Collection of buttons on this panel */
- std::vector<PanelButton*> panel_buttons;
+ /** Collection of buttons on this panel */
+ std::vector<PanelButton*> panel_buttons;
- /** Currently selected object on this panel */
- PanelButton* pressed_button;
+ /** Currently selected object on this panel */
+ PanelButton* pressed_button;
- /** Combobox which can change it's item list based on the button
pressed */
- GUI::Combobox* combobox_1;
- GUI::Combobox* combobox_2;
- GUI::Combobox* combobox_3;
+ /** Combobox which can change it's item list based on the button pressed */
+ GUI::Combobox* combobox_1;
+ GUI::Combobox* combobox_2;
+ GUI::Combobox* combobox_3;
- /** Checkbox which controls the snap-to-grid functionality */
- GUI::Checkbox* snap_to_checkbox;
+ /** Checkbox which controls the snap-to-grid functionality */
+ GUI::Checkbox* snap_to_checkbox;
public:
- /** Constructor
- @param es The EditorScreen to which this panel belongs */
- EditorPanel(EditorScreen* es);
+ /** Constructor
+ @param es The EditorScreen to which this panel belongs */
+ EditorPanel(EditorScreen* es);
- /** Destructor - nothing really happens here */
- ~EditorPanel();
+ /** Destructor - nothing really happens here */
+ ~EditorPanel();
- /** Initialize the panel - Adds all of the buttons and text fields
- Wait to run this until after the panel has been added
to the gui_manager */
- void init();
+ /** Initialize the panel - Adds all of the buttons and text fields
+ Wait to run this until after the panel has been added to the gui_manager
*/
+ void init();
- /** Add a button to the panel
- @param button The PanelButton that you'd like to add. The given
object will be
- deleted automaticly at the end. */
- void add(PanelButton* button);
+ /** Add a button to the panel
+ @param button The PanelButton that you'd like to add. The given object
will be
+ deleted automaticly at the end. */
+ void add(PanelButton* button);
- /** Draws the panel */
- void draw(DrawingContext& gc);
+ /** Draws the panel */
+ void draw(DrawingContext& gc);
- /** Return the editor screen */
- EditorScreen* get_screen() { return editor; }
+ /** Return the editor screen */
+ EditorScreen* get_screen() { return editor; }
- /** Return the combobox object */
- GUI::Combobox* get_combobox(int i);
+ /** Return the combobox object */
+ GUI::Combobox* get_combobox(int i);
- /** Changes which button is currently pressed */
- void set_selected_button(PanelButton* pb);
+ /** Changes which button is currently pressed */
+ void set_selected_button(PanelButton* pb);
- /** Event that fires when a checkbox gets changed */
- void checkbox_changed(bool new_value, GUI::Checkbox* box);
+ /** Event that fires when a checkbox gets changed */
+ void checkbox_changed(bool new_value, GUI::Checkbox* box);
- /** Event that fires when a combobox gets changed */
- void combobox_changed(GUI::Combobox* box);
+ /** Event that fires when a combobox gets changed */
+ void combobox_changed(GUI::Combobox* box);
private:
- EditorPanel();
+ EditorPanel();
EditorPanel (const EditorPanel&);
EditorPanel& operator= (const EditorPanel&);
Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_screen.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -40,35 +41,35 @@
// Default constructor
EditorScreen::EditorScreen(EditorLevel* level)
-: plf(level),
- panel(0),
- viewport(0),
- filedialog(0),
- close_dialog(false)
+ : plf(level),
+ panel(0),
+ viewport(0),
+ filedialog(0),
+ close_dialog(false)
{
- if (!plf) plf = new EditorLevel();
+ if (!plf) plf = new EditorLevel();
}
// Destructor
EditorScreen::~EditorScreen()
{
- delete plf;
- if (filedialog)
- delete filedialog;
+ delete plf;
+ if (filedialog)
+ delete filedialog;
}
// Startup code
void
EditorScreen::on_startup()
{
- // Create the viewport for the images and data
- viewport = new EditorViewport(this);
- gui_manager->add(viewport, true);
+ // Create the viewport for the images and data
+ viewport = new EditorViewport(this);
+ gui_manager->add(viewport, true);
- // Create the panel for the buttons
- panel = new EditorPanel(this);
- gui_manager->add(panel, true);
- panel->init();
+ // Create the panel for the buttons
+ panel = new EditorPanel(this);
+ gui_manager->add(panel, true);
+ panel->init();
}
@@ -76,7 +77,7 @@
void
EditorScreen::close_screen()
{
- ScreenManager::instance()->pop_screen();
+ ScreenManager::instance()->pop_screen();
}
// Escape was pressed
@@ -90,38 +91,38 @@
void
EditorScreen::show_file_dialog(bool for_loading)
{
- if (filedialog)
- delete filedialog;
- close_dialog = false;
- filedialog = new FileDialog(this, ".scm",
- path_manager.complete("levels/"), for_loading);
- filedialog->preload();
+ if (filedialog)
+ delete filedialog;
+ close_dialog = false;
+ filedialog = new FileDialog(this, ".scm",
+ path_manager.complete("levels/"), for_loading);
+ filedialog->preload();
}
// Close dialog box
void
EditorScreen::cancel()
{
- close_dialog = true;
+ close_dialog = true;
}
// Save the current level
void
EditorScreen::save(const std::string &file, const std::string &filemask)
{
- close_dialog = true;
- plf->save_level(file);
- panel->set_selected_button(0);
+ close_dialog = true;
+ plf->save_level(file);
+ panel->set_selected_button(0);
}
// Load a new level
void
EditorScreen::load(const std::string &file, const std::string &filemask)
{
- close_dialog = true;
- plf->load_level(file);
- viewport->refresh();
- panel->set_selected_button(0);
+ close_dialog = true;
+ plf->load_level(file);
+ viewport->refresh();
+ panel->set_selected_button(0);
}
// Play the current level (save to a temporary file
@@ -129,61 +130,61 @@
void
EditorScreen::play_level()
{
- // Ask, "Would you like to save first?".
- // if so, save the file normally.
+ // Ask, "Would you like to save first?".
+ // if so, save the file normally.
- // Then save to a temporary file
+ // Then save to a temporary file
- // Load the temporary file
+ // Load the temporary file
}
// Draw the background and components
bool
EditorScreen::draw(DrawingContext &gc)
{
- // Black out screen
- gc.fill_screen(Color(0,0,0));
- gui_manager->draw(gc);
+ // Black out screen
+ gc.fill_screen(Color(0,0,0));
+ gui_manager->draw(gc);
- // FIXME: Remove this warning
- gc.print_center(Fonts::pingus_large, (float)(Display::get_width() / 2),
- (float)(Display::get_height() / 2), "Not yet functional");
+ // FIXME: Remove this warning
+ gc.print_center(Fonts::pingus_large, (float)(Display::get_width() / 2),
+ (float)(Display::get_height() / 2), "Not yet functional");
- if (filedialog)
- filedialog->draw(gc);
+ if (filedialog)
+ filedialog->draw(gc);
- return true;
+ return true;
}
void
EditorScreen::update(const GameDelta &delta)
{
- if (filedialog)
- {
- if (close_dialog)
- {
- delete filedialog;
- filedialog = 0;
- }
- else
- filedialog->update(delta);
- }
- else
- GUIScreen::update(delta);
+ if (filedialog)
+ {
+ if (close_dialog)
+ {
+ delete filedialog;
+ filedialog = 0;
+ }
+ else
+ filedialog->update(delta);
+ }
+ else
+ GUIScreen::update(delta);
}
void
EditorScreen::add_object(LevelObj* obj)
{
- plf->add_object(obj);
- viewport->add_object(obj);
+ plf->add_object(obj);
+ viewport->add_object(obj);
}
void
EditorScreen::add_objects(std::vector<LevelObj*> objs)
{
- for (std::vector<LevelObj*>::const_iterator it = objs.begin(); it !=
objs.end(); it++)
- add_object(*it);
+ for (std::vector<LevelObj*>::const_iterator it = objs.begin(); it !=
objs.end(); it++)
+ add_object(*it);
}
} // Editor namespace
Modified: trunk/pingus/src/editor/editor_screen.hpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_screen.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -36,73 +37,73 @@
class EditorViewport;
/** This class is the screen that contains all of the
- editor objects */
+ editor objects */
class EditorScreen : public GUIScreen, public FileDialogListener
{
private:
- /** The level currently being edited */
- EditorLevel* plf;
+ /** The level currently being edited */
+ EditorLevel* plf;
- /** Panel which contains all of the buttons for each action */
- EditorPanel* panel;
+ /** Panel which contains all of the buttons for each action */
+ EditorPanel* panel;
- /** Viewport which holds all of the level images and data */
- EditorViewport* viewport;
+ /** Viewport which holds all of the level images and data */
+ EditorViewport* viewport;
- /** File Dialog box */
- FileDialog* filedialog;
+ /** File Dialog box */
+ FileDialog* filedialog;
- bool close_dialog;
+ bool close_dialog;
public:
- /** Default constructor */
+ /** Default constructor */
EditorScreen(EditorLevel* level = 0);
- /** Destructor */
- ~EditorScreen();
+ /** Destructor */
+ ~EditorScreen();
- /** Code that runs when the screen first opens */
+ /** Code that runs when the screen first opens */
void on_startup();
- /** Closes the current screen */
+ /** Closes the current screen */
void close_screen();
- /** Code that runs when the Escape button is pressed */
+ /** Code that runs when the Escape button is pressed */
void on_escape_press();
- /** Draw the items in the screen */
- bool draw (DrawingContext& gc);
+ /** Draw the items in the screen */
+ bool draw (DrawingContext& gc);
- /** Update the GUI objects */
- void update (const GameDelta& delta);
+ /** Update the GUI objects */
+ void update (const GameDelta& delta);
- /** Return the gui_manager */
- GUI::GUIManager* get_gui_manager() const { return gui_manager; }
+ /** Return the gui_manager */
+ GUI::GUIManager* get_gui_manager() const { return gui_manager; }
- /** Return the viewport */
- EditorViewport* get_viewport() const { return viewport; }
+ /** Return the viewport */
+ EditorViewport* get_viewport() const { return viewport; }
- /** Return a pointer to the current level */
- EditorLevel* get_level() const { return plf; }
+ /** Return a pointer to the current level */
+ EditorLevel* get_level() const { return plf; }
- /** Add an object to both the EditorLevel and the EditorViewport */
- void add_object(LevelObj* obj);
- void add_objects(std::vector<LevelObj*> objs);
+ /** Add an object to both the EditorLevel and the EditorViewport */
+ void add_object(LevelObj* obj);
+ void add_objects(std::vector<LevelObj*> objs);
- /** Show a file dialog box */
- void show_file_dialog(bool for_loading);
+ /** Show a file dialog box */
+ void show_file_dialog(bool for_loading);
- /** Closes the file dialog box */
- void cancel();
+ /** Closes the file dialog box */
+ void cancel();
- /** Saves the currently loaded level */
- void save(const std::string &file, const std::string &filemask);
+ /** Saves the currently loaded level */
+ void save(const std::string &file, const std::string &filemask);
- /** Load a new level */
- void load(const std::string &file, const std::string &filemask);
+ /** Load a new level */
+ void load(const std::string &file, const std::string &filemask);
- /** Plays the currently loaded level */
- void play_level();
+ /** Plays the currently loaded level */
+ void play_level();
private:
EditorScreen (const EditorScreen&);
Modified: trunk/pingus/src/editor/editor_viewport.cpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_viewport.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -35,156 +36,156 @@
// Constructor
EditorViewport::EditorViewport(EditorScreen* e) :
- state(Display::get_width(), Display::get_height()),
- scene_context(new SceneContext()),
- editor(e),
- autoscroll(true),
- highlighted_area(0,0,0,0),
- context_menu(0),
- snap_to(false),
- current_action(NOTHING)
+ state(Display::get_width(), Display::get_height()),
+ scene_context(new SceneContext()),
+ editor(e),
+ autoscroll(true),
+ highlighted_area(0,0,0,0),
+ context_menu(0),
+ snap_to(false),
+ current_action(NOTHING)
{
- // FIXME: Hardcoded values should be determined by level size
- state.set_limit(Rect(-30, -50, 1600, 1300));
- state.set_pos(Vector2f(0, 0));
+ // FIXME: Hardcoded values should be determined by level size
+ state.set_limit(Rect(-30, -50, 1600, 1300));
+ state.set_pos(Vector2f(0, 0));
}
// Destructor
EditorViewport::~EditorViewport ()
{
- delete scene_context;
+ delete scene_context;
}
// When someone right-clicks inside the viewport
void
EditorViewport::on_secondary_button_click(int x, int y)
{
- remove_context_menu();
+ remove_context_menu();
- Vector3f mouse_pos(x - (state.get_width()/2 - state.get_pos().x),
- y - (state.get_height()/2 - state.get_pos().y));
+ Vector3f mouse_pos(x - (state.get_width()/2 - state.get_pos().x),
+ y - (state.get_height()/2 - state.get_pos().y));
- std::cout << "Right-click at " << mouse_pos.x << ", "
- << mouse_pos.y << std::endl;
+ std::cout << "Right-click at " << mouse_pos.x << ", "
+ << mouse_pos.y << std::endl;
-// LevelObj* obj = object_at((int)mouse_pos.x, (int)mouse_pos.y);
- if (!current_objs.empty())
- {
- // std::vector<LevelObj*> objs;
- // objs.push_back(obj);
- context_menu = new ContextMenu(current_objs, Vector3f((float)x,
(float)y), this);
- editor->get_gui_manager()->add(context_menu, true);
- }
+ // LevelObj* obj = object_at((int)mouse_pos.x, (int)mouse_pos.y);
+ if (!current_objs.empty())
+ {
+ // std::vector<LevelObj*> objs;
+ // objs.push_back(obj);
+ context_menu = new ContextMenu(current_objs, Vector3f((float)x,
(float)y), this);
+ editor->get_gui_manager()->add(context_menu, true);
+ }
}
// Select 1 or more LevelObjs, or drag them.
void
EditorViewport::on_primary_button_press(int x, int y)
{
- remove_context_menu();
+ remove_context_menu();
- if (current_action == NOTHING)
- {
- LevelObj* obj = object_at(x - (state.get_width()/2 -
(int)state.get_pos().x),
- y - (state.get_height()/2 - (int)state.get_pos().y));
+ if (current_action == NOTHING)
+ {
+ LevelObj* obj = object_at(x - (state.get_width()/2 -
(int)state.get_pos().x),
+ y - (state.get_height()/2 -
(int)state.get_pos().y));
- if (obj)
- {
- // If the currently selected object isn't selected,
select it and deselect the rest
- if (!obj->is_selected())
- {
- for (unsigned i = 0; i < current_objs.size();
i++)
- current_objs[i]->unselect();
- current_objs.clear();
- obj->select();
- current_objs.push_back(obj);
- }
- // Allow dragging of the currently selected objects
- current_action = DRAGGING;
- drag_start_pos = mouse_at_world;
- }
- else
- {
- current_objs.clear();
- current_action = HIGHLIGHTING;
- highlighted_area.left = highlighted_area.right = x;
- highlighted_area.top = highlighted_area.bottom = y;
- }
- }
+ if (obj)
+ {
+ // If the currently selected object isn't selected, select it and
deselect the rest
+ if (!obj->is_selected())
+ {
+ for (unsigned i = 0; i < current_objs.size(); i++)
+ current_objs[i]->unselect();
+ current_objs.clear();
+ obj->select();
+ current_objs.push_back(obj);
+ }
+ // Allow dragging of the currently selected objects
+ current_action = DRAGGING;
+ drag_start_pos = mouse_at_world;
+ }
+ else
+ {
+ current_objs.clear();
+ current_action = HIGHLIGHTING;
+ highlighted_area.left = highlighted_area.right = x;
+ highlighted_area.top = highlighted_area.bottom = y;
+ }
+ }
}
void
EditorViewport::on_primary_button_release(int x, int y)
{
- if (current_action == HIGHLIGHTING)
- {
- // Make sure CL_Rect starts at the top left
- if (highlighted_area.right < highlighted_area.left)
- std::swap(highlighted_area.left,
highlighted_area.right);
- if (highlighted_area.bottom < highlighted_area.top)
- std::swap(highlighted_area.top,
highlighted_area.bottom);
+ if (current_action == HIGHLIGHTING)
+ {
+ // Make sure CL_Rect starts at the top left
+ if (highlighted_area.right < highlighted_area.left)
+ std::swap(highlighted_area.left, highlighted_area.right);
+ if (highlighted_area.bottom < highlighted_area.top)
+ std::swap(highlighted_area.top, highlighted_area.bottom);
- for (unsigned i = 0; i < objs.size(); i++)
- {
- // Calculate the object's position
- Vector2i obj_pos((int)objs[i]->get_pos().x +
(state.get_width()/2 -
- (int)state.get_pos().x),
(int)objs[i]->get_pos().y + (state.get_height()/2 -
- (int)state.get_pos().y));
+ for (unsigned i = 0; i < objs.size(); i++)
+ {
+ // Calculate the object's position
+ Vector2i obj_pos((int)objs[i]->get_pos().x + (state.get_width()/2 -
+
(int)state.get_pos().x), (int)objs[i]->get_pos().y + (state.get_height()/2 -
+
(int)state.get_pos().y));
- if (highlighted_area.is_inside(obj_pos))
- {
- current_objs.push_back(objs[i]);
- objs[i]->select();
- }
- else
- objs[i]->unselect();
- }
- }
- else if (current_action == DRAGGING)
- {
- // Set the objects' positions for good
- for (unsigned i = 0; i < objs.size(); i++)
- objs[i]->set_orig_pos(objs[i]->get_pos());
- }
- current_action = NOTHING;
+ if (highlighted_area.is_inside(obj_pos))
+ {
+ current_objs.push_back(objs[i]);
+ objs[i]->select();
+ }
+ else
+ objs[i]->unselect();
+ }
+ }
+ else if (current_action == DRAGGING)
+ {
+ // Set the objects' positions for good
+ for (unsigned i = 0; i < objs.size(); i++)
+ objs[i]->set_orig_pos(objs[i]->get_pos());
+ }
+ current_action = NOTHING;
}
void
EditorViewport::on_pointer_move(int x, int y)
{
- mouse_at = Vector3f(float(x), float(y));
- mouse_at_world = Vector3f(x - (state.get_width()/2 - state.get_pos().x),
- y - (state.get_height()/2 - state.get_pos().y));
+ mouse_at = Vector3f(float(x), float(y));
+ mouse_at_world = Vector3f(x - (state.get_width()/2 - state.get_pos().x),
+ y - (state.get_height()/2 - state.get_pos().y));
- if (current_action == HIGHLIGHTING)
- {
- highlighted_area.right = x;
- highlighted_area.bottom = y;
- }
- else if (current_action == DRAGGING)
- {
- float new_x, new_y;
+ if (current_action == HIGHLIGHTING)
+ {
+ highlighted_area.right = x;
+ highlighted_area.bottom = y;
+ }
+ else if (current_action == DRAGGING)
+ {
+ float new_x, new_y;
- for (unsigned i = 0; i < current_objs.size(); i++)
- {
- Vector3f orig_pos(current_objs[i]->get_orig_pos());
- float x_offset = mouse_at_world.x - drag_start_pos.x;
- float y_offset = mouse_at_world.y - drag_start_pos.y;
- if (snap_to)
- {
- // FIXME: May need to adjust the snap-to offset
here.
- new_x = (float)((int)((x_offset + orig_pos.x) /
10) * 10);
- new_y = (float)((int)((y_offset + orig_pos.y) /
10) * 10);
- }
- else
- {
- new_x = x_offset + orig_pos.x;
- new_y = y_offset + orig_pos.y;
- }
- current_objs[i]->set_pos(Vector3f(new_x, new_y,
orig_pos.z));
- }
- }
+ for (unsigned i = 0; i < current_objs.size(); i++)
+ {
+ Vector3f orig_pos(current_objs[i]->get_orig_pos());
+ float x_offset = mouse_at_world.x - drag_start_pos.x;
+ float y_offset = mouse_at_world.y - drag_start_pos.y;
+ if (snap_to)
+ {
+ // FIXME: May need to adjust the snap-to offset here.
+ new_x = (float)((int)((x_offset + orig_pos.x) / 10) * 10);
+ new_y = (float)((int)((y_offset + orig_pos.y) / 10) * 10);
+ }
+ else
+ {
+ new_x = x_offset + orig_pos.x;
+ new_y = y_offset + orig_pos.y;
+ }
+ current_objs[i]->set_pos(Vector3f(new_x, new_y, orig_pos.z));
+ }
+ }
}
@@ -192,91 +193,91 @@
void
EditorViewport::draw(DrawingContext &gc)
{
- scene_context->clear();
- state.push(*scene_context);
+ scene_context->clear();
+ state.push(*scene_context);
- // Now, draw all of the objects
+ // Now, draw all of the objects
- // Draw the level objects
- for (unsigned i = 0; i < objs.size(); i++)
- objs[i]->draw(scene_context->color());
+ // Draw the level objects
+ for (unsigned i = 0; i < objs.size(); i++)
+ objs[i]->draw(scene_context->color());
- if (current_action == HIGHLIGHTING)
- gc.draw_rect((float)highlighted_area.left,
(float)highlighted_area.top,
- (float)highlighted_area.right,
(float)highlighted_area.bottom,
- Color(255,255,255,150));
+ if (current_action == HIGHLIGHTING)
+ gc.draw_rect((float)highlighted_area.left, (float)highlighted_area.top,
+ (float)highlighted_area.right,
(float)highlighted_area.bottom,
+ Color(255,255,255,150));
- state.pop(*scene_context);
- gc.draw(new SceneContextDrawingRequest(scene_context, Vector3f(0, 0,
-150)));
+ state.pop(*scene_context);
+ gc.draw(new SceneContextDrawingRequest(scene_context, Vector3f(0, 0, -150)));
}
// Returns true if the viewport is at the x,y coordinate
bool
EditorViewport::is_at(int x, int y)
{
- // FIXME: Should return true everywhere except for on the panel
- return true;
+ // FIXME: Should return true everywhere except for on the panel
+ return true;
}
void
EditorViewport::update(float delta)
{
- UNUSED_ARG(delta);
+ UNUSED_ARG(delta);
- // Autoscroll if necessary
- if (autoscroll)
- {
- const int autoscroll_border = 10;
- if (autoscroll)
- {
- if (mouse_at.x < autoscroll_border)
- state.set_pos(state.get_pos() - Vector2f(5, 0));
- else if ((float)Display::get_width() - mouse_at.x <
autoscroll_border)
- state.set_pos(state.get_pos() + Vector2f(5, 0));
- else if (mouse_at.y < autoscroll_border)
- state.set_pos(state.get_pos() - Vector2f(0, 5));
- else if ((float)Display::get_height() - mouse_at.y <
autoscroll_border)
- state.set_pos(state.get_pos() + Vector2f(0, 5));
- }
- }
+ // Autoscroll if necessary
+ if (autoscroll)
+ {
+ const int autoscroll_border = 10;
+ if (autoscroll)
+ {
+ if (mouse_at.x < autoscroll_border)
+ state.set_pos(state.get_pos() - Vector2f(5, 0));
+ else if ((float)Display::get_width() - mouse_at.x <
autoscroll_border)
+ state.set_pos(state.get_pos() + Vector2f(5, 0));
+ else if (mouse_at.y < autoscroll_border)
+ state.set_pos(state.get_pos() - Vector2f(0, 5));
+ else if ((float)Display::get_height() - mouse_at.y <
autoscroll_border)
+ state.set_pos(state.get_pos() + Vector2f(0, 5));
+ }
+ }
}
LevelObj*
EditorViewport::object_at (int x, int y)
{
- // we travel reversly through the object list, so that we get the
- // top-most object
- for (std::vector<LevelObj*>::reverse_iterator i = objs.rbegin ();
- i != objs.rend (); ++i)
- {
- if ((*i)->is_at (x, y))
- return *i;
- }
- return 0;
+ // we travel reversly through the object list, so that we get the
+ // top-most object
+ for (std::vector<LevelObj*>::reverse_iterator i = objs.rbegin ();
+ i != objs.rend (); ++i)
+ {
+ if ((*i)->is_at (x, y))
+ return *i;
+ }
+ return 0;
}
// Delete the context menu if it exists.
void
EditorViewport::remove_context_menu()
{
- if (context_menu)
- {
- editor->get_gui_manager()->remove(context_menu);
- context_menu->display(false);
- context_menu = 0;
- }
+ if (context_menu)
+ {
+ editor->get_gui_manager()->remove(context_menu);
+ context_menu->display(false);
+ context_menu = 0;
+ }
}
void
EditorViewport::refresh()
{
- objs = editor->get_level()->get_objects();
+ objs = editor->get_level()->get_objects();
}
void
EditorViewport::add_object(LevelObj* obj)
{
- objs.push_back(obj);
+ objs.push_back(obj);
}
} // Editor namespace
Modified: trunk/pingus/src/editor/editor_viewport.hpp
===================================================================
--- trunk/pingus/src/editor/editor_viewport.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/editor_viewport.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -26,105 +27,105 @@
#include <string>
- class Vector3f;
- class DrawingContext;
- class SceneContext;
+class Vector3f;
+class DrawingContext;
+class SceneContext;
namespace Editor {
- class LevelObj;
- class EditorScreen;
- class ContextMenu;
+class LevelObj;
+class EditorScreen;
+class ContextMenu;
/** This class is where the actual level graphics will display in the
- level editor. Objects can be added, deleted, moved, modified, etc.
- inside of the EditorViewport */
+ level editor. Objects can be added, deleted, moved, modified, etc.
+ inside of the EditorViewport */
class EditorViewport : public GUI::Component {
public:
- /** Constructor
- @param e The EditorScreen to which this viewport belongs */
- EditorViewport (EditorScreen* e);
+ /** Constructor
+ @param e The EditorScreen to which this viewport belongs */
+ EditorViewport (EditorScreen* e);
- /** Destructor */
- ~EditorViewport ();
+ /** Destructor */
+ ~EditorViewport ();
- /** Draws all of the objects in the viewport */
- void draw(DrawingContext &gc);
+ /** Draws all of the objects in the viewport */
+ void draw(DrawingContext &gc);
- /** Update information about scrolling, etc. */
- void update(float delta);
+ /** Update information about scrolling, etc. */
+ void update(float delta);
- /** Returns whether or not the mouse is inside the viewport */
- bool is_at(int x, int y);
+ /** Returns whether or not the mouse is inside the viewport */
+ bool is_at(int x, int y);
- /** Emitted when the pointer moved, x and y are the new pointer
- coordinates */
+ /** Emitted when the pointer moved, x and y are the new pointer
+ coordinates */
void on_pointer_move (int x, int y);
- /** Get rid of context menu if it exists */
- void remove_context_menu();
+ /** Get rid of context menu if it exists */
+ void remove_context_menu();
- /** Refresh the list of objects (do when loading or creating a new
level) */
- void refresh();
+ /** Refresh the list of objects (do when loading or creating a new level) */
+ void refresh();
- /** Turns the "snap-to-grid" option on or off */
- void set_snap_to(bool s) { snap_to = s; }
+ /** Turns the "snap-to-grid" option on or off */
+ void set_snap_to(bool s) { snap_to = s; }
- /** Add an object to the currently displayed vector of objects */
- void add_object(LevelObj* obj);
+ /** Add an object to the currently displayed vector of objects */
+ void add_object(LevelObj* obj);
- /** Return a pointer to the EditorScreen object */
- EditorScreen* get_screen() { return editor; }
+ /** Return a pointer to the EditorScreen object */
+ EditorScreen* get_screen() { return editor; }
private:
- EditorViewport();
- EditorViewport (const EditorViewport&);
+ EditorViewport();
+ EditorViewport (const EditorViewport&);
EditorViewport& operator= (const EditorViewport&);
- GraphicContextState state;
- SceneContext* scene_context;
+ GraphicContextState state;
+ SceneContext* scene_context;
- /** The EditorScreen to which this viewport belongs */
- EditorScreen* editor;
+ /** The EditorScreen to which this viewport belongs */
+ EditorScreen* editor;
- /** Whether or not Autoscrolling is turned on */
- bool autoscroll;
+ /** Whether or not Autoscrolling is turned on */
+ bool autoscroll;
- /** Where the mouse is right now - used for autoscrolling */
- Vector3f mouse_at;
+ /** Where the mouse is right now - used for autoscrolling */
+ Vector3f mouse_at;
- /** Where the mouse is at in relation to the world/level */
- Vector3f mouse_at_world;
+ /** Where the mouse is at in relation to the world/level */
+ Vector3f mouse_at_world;
- /** Where the mouse started dragging from */
- Vector3f drag_start_pos;
+ /** Where the mouse started dragging from */
+ Vector3f drag_start_pos;
- /** All objects in the level */
- std::vector<LevelObj*> objs;
+ /** All objects in the level */
+ std::vector<LevelObj*> objs;
- /** The currently selected LevelObjs */
- std::vector<LevelObj*> current_objs;
+ /** The currently selected LevelObjs */
+ std::vector<LevelObj*> current_objs;
- /** The region that is currently highlighted */
- Rect highlighted_area;
+ /** The region that is currently highlighted */
+ Rect highlighted_area;
- /** Returns the topmost object at this x, y location */
- LevelObj* object_at(int x, int y);
+ /** Returns the topmost object at this x, y location */
+ LevelObj* object_at(int x, int y);
- /** There should only be 0 or 1 context menus on the screen */
- ContextMenu* context_menu;
+ /** There should only be 0 or 1 context menus on the screen */
+ ContextMenu* context_menu;
- /** Whether or not the "snap-to-grid" functionality is on. */
- bool snap_to;
+ /** Whether or not the "snap-to-grid" functionality is on. */
+ bool snap_to;
- /** What is the currently selected action that the mouse is doing */
- enum ActionType { NOTHING = 0, HIGHLIGHTING = 1, DRAGGING = 2 }
current_action;
+ /** What is the currently selected action that the mouse is doing */
+ enum ActionType { NOTHING = 0, HIGHLIGHTING = 1, DRAGGING = 2 }
current_action;
- /// Mouse actions
- void on_primary_button_press(int x, int y);
- void on_primary_button_release(int x, int y);
- void on_secondary_button_click(int x, int y);
+ /// Mouse actions
+ void on_primary_button_press(int x, int y);
+ void on_primary_button_release(int x, int y);
+ void on_secondary_button_click(int x, int y);
};
} // Editor namespace
Modified: trunk/pingus/src/editor/level_head.cpp
===================================================================
--- trunk/pingus/src/editor/level_head.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/level_head.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -36,47 +37,47 @@
namespace Editor {
- class LevelHeadCloseButton : public GUI::SurfaceButton
- {
- private:
- LevelHead* head;
- std::string label;
+class LevelHeadCloseButton : public GUI::SurfaceButton
+{
+private:
+ LevelHead* head;
+ std::string label;
- public:
- LevelHeadCloseButton(LevelHead* h)
- : GUI::SurfaceButton(Display::get_width() -200,
- Display::get_height() -100,
- ResDescriptor("core/menu/exit_button_normal"),
- ResDescriptor("core/menu/exit_button_pressed"),
- ResDescriptor("core/menu/exit_button_hover")),
+public:
+ LevelHeadCloseButton(LevelHead* h)
+ : GUI::SurfaceButton(Display::get_width() -200,
+ Display::get_height() -100,
+ ResDescriptor("core/menu/exit_button_normal"),
+ ResDescriptor("core/menu/exit_button_pressed"),
+ ResDescriptor("core/menu/exit_button_hover")),
head(h),
label(_("Ok"))
- {
- }
+ {
+ }
- void draw (DrawingContext& gc) {
- SurfaceButton::draw(gc);
- gc.print_right(Fonts::chalk_large, (float)Display::get_width() - 150,
- (float)Display::get_height() - 100, label);
- }
+ void draw (DrawingContext& gc) {
+ SurfaceButton::draw(gc);
+ gc.print_right(Fonts::chalk_large, (float)Display::get_width() - 150,
+ (float)Display::get_height() - 100, label);
+ }
- void on_click()
- {
- head->get_head_button()->remove_head();
- }
+ void on_click()
+ {
+ head->get_head_button()->remove_head();
+ }
- void on_pointer_enter()
- {
- SurfaceButton::on_pointer_enter();
- Sound::PingusSound::play_sound ("tick");
- }
- };
+ void on_pointer_enter()
+ {
+ SurfaceButton::on_pointer_enter();
+ Sound::PingusSound::play_sound ("tick");
+ }
+};
LevelHead::LevelHead(EditorPanel* p, PanelButtonHead* pbh) :
head_button(pbh),
- impl(p->get_screen()->get_level()->get_level_impl()),
+ impl(p->get_screen()->get_level()->get_level_impl()),
gui_manager(p->get_screen()->get_gui_manager()),
- pos(Vector3f(50, 75))
+ pos(Vector3f(50, 75))
{
gui_manager->add((GUI::Component*)this, false);
@@ -119,7 +120,7 @@
LevelHead::is_at(int x, int y)
{
return (x > pos.x && y > pos.y && x < Display::get_width()-50 &&
- y < Display::get_height()-50);
+ y < Display::get_height()-50);
}
void
Modified: trunk/pingus/src/editor/level_head.hpp
===================================================================
--- trunk/pingus/src/editor/level_head.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/level_head.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -23,23 +24,23 @@
#include "../gui/component.hpp"
- class Vector3f;
+class Vector3f;
namespace GUI {
- class GUIManager;
- class InputBox;
+class GUIManager;
+class InputBox;
}
namespace Editor {
- class LevelImpl;
- class PanelButtonHead;
- class EditorPanel;
- class LevelHeadCloseButton;
+class LevelImpl;
+class PanelButtonHead;
+class EditorPanel;
+class LevelHeadCloseButton;
- /** This class draws a box with different input boxes that
- * determine the specific level information which is saved
- * in the <HEAD> section of the XML level file */
+/** This class draws a box with different input boxes that
+ * determine the specific level information which is saved
+ * in the <HEAD> section of the XML level file */
class LevelHead : public GUI::Component
{
private:
@@ -51,7 +52,7 @@
GUI::GUIManager* gui_manager;
/** Where this box is drawn*/
- Vector3f pos;
+ Vector3f pos;
// Input boxes for each item of the level impl
GUI::InputBox* name;
@@ -65,9 +66,9 @@
PanelButtonHead* get_head_button() { return head_button; }
- // GUI Component stuff
- bool is_at(int x, int y);
- void draw(DrawingContext& gc);
+ // GUI Component stuff
+ bool is_at(int x, int y);
+ void draw(DrawingContext& gc);
void update(float delta);
};
Modified: trunk/pingus/src/editor/level_impl.hpp
===================================================================
--- trunk/pingus/src/editor/level_impl.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/level_impl.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -29,10 +30,10 @@
namespace Editor {
- static bool LevelObjSort(LevelObj *a, LevelObj *b)
- {
- return (a->get_pos().z < b->get_pos().z);
- }
+static bool LevelObjSort(LevelObj *a, LevelObj *b)
+{
+ return (a->get_pos().z < b->get_pos().z);
+}
class LevelImpl
{
@@ -45,13 +46,13 @@
// Do nothing
}
- /** Destructor */
- ~LevelImpl()
- {
- for (unsigned i = 0; i < objects.size(); i++)
- delete objects[i];
- objects.clear();
- }
+ /** Destructor */
+ ~LevelImpl()
+ {
+ for (unsigned i = 0; i < objects.size(); i++)
+ delete objects[i];
+ objects.clear();
+ }
std::string resname;
@@ -70,19 +71,19 @@
int difficulty;
std::string author;
- std::string comment;
+ std::string comment;
std::string music;
std::vector<LevelObj*> objects;
- /** Sort the objects by their z position */
- void sort_objs()
- {
- std::stable_sort(objects.begin(), objects.end(), LevelObjSort);
- }
+ /** Sort the objects by their z position */
+ void sort_objs()
+ {
+ std::stable_sort(objects.begin(), objects.end(), LevelObjSort);
+ }
private:
- LevelImpl (const LevelImpl&);
+ LevelImpl (const LevelImpl&);
LevelImpl& operator= (const LevelImpl&);
}; // LevelImpl class
Modified: trunk/pingus/src/editor/level_objs.cpp
===================================================================
--- trunk/pingus/src/editor/level_objs.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/level_objs.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -32,231 +32,231 @@
// Default constructor
LevelObj::LevelObj(std::string obj_name, LevelImpl* level_) :
- level(level_),
- pos(Vector3f(0,0,0)),
- translated_pos(Vector3f(0,0,0)),
- section_name(obj_name),
- speed(0),
- parallax(0.0),
- width(0),
- owner_id(-1),
- release_rate(0),
- scroll_x(0),
- scroll_y(0),
- stretch_x(false),
- stretch_y(false),
- keep_aspect(false),
- para_x(0),
- para_y(0),
- color(0,0,0,0),
- attribs(get_attributes(obj_name)),
- removed(false),
- selected(false)
+ level(level_),
+ pos(Vector3f(0,0,0)),
+ translated_pos(Vector3f(0,0,0)),
+ section_name(obj_name),
+ speed(0),
+ parallax(0.0),
+ width(0),
+ owner_id(-1),
+ release_rate(0),
+ scroll_x(0),
+ scroll_y(0),
+ stretch_x(false),
+ stretch_y(false),
+ keep_aspect(false),
+ para_x(0),
+ para_y(0),
+ color(0,0,0,0),
+ attribs(get_attributes(obj_name)),
+ removed(false),
+ selected(false)
{
- if (attribs & HAS_SURFACE_FAKE)
- load_generic_surface();
+ if (attribs & HAS_SURFACE_FAKE)
+ load_generic_surface();
}
void
LevelObj::set_res_desc(const ResDescriptor d)
{
- desc = d;
- refresh_sprite();
+ desc = d;
+ refresh_sprite();
}
// Draw the sprite
void
LevelObj::draw(DrawingContext &gc)
{
- if (!removed && attribs & (HAS_SURFACE | HAS_SURFACE_FAKE))
- {
- // If selected, draw a highlighted box around it
- if (selected)
- gc.draw_rect(translated_pos.x, translated_pos.y,
translated_pos.x
- + sprite.get_width(), translated_pos.y +
sprite.get_height(),
- Color(255,255,255,150), 5000);
- if (attribs & HAS_WIDTH)
- {
- for(int x = static_cast<int>(pos.x); x < pos.x + width;
x += sprite.get_width())
- gc.draw(sprite, Vector3f(static_cast<float>(x),
pos.y, pos.z));
- }
- else if(attribs & HAS_STRETCH)
- {
- // Surface Background - tile it
- for (int x = 0; x < level->size.width; x +=
sprite.get_width())
- for (int y = 0; y < level->size.height; y +=
sprite.get_height())
- gc.draw(sprite, Vector3f((float)x,
(float)y, pos.z));
- }
- else
- gc.draw(sprite, pos);
- }
+ if (!removed && attribs & (HAS_SURFACE | HAS_SURFACE_FAKE))
+ {
+ // If selected, draw a highlighted box around it
+ if (selected)
+ gc.draw_rect(translated_pos.x, translated_pos.y, translated_pos.x
+ + sprite.get_width(), translated_pos.y +
sprite.get_height(),
+ Color(255,255,255,150), 5000);
+ if (attribs & HAS_WIDTH)
+ {
+ for(int x = static_cast<int>(pos.x); x < pos.x + width; x +=
sprite.get_width())
+ gc.draw(sprite, Vector3f(static_cast<float>(x), pos.y, pos.z));
+ }
+ else if(attribs & HAS_STRETCH)
+ {
+ // Surface Background - tile it
+ for (int x = 0; x < level->size.width; x += sprite.get_width())
+ for (int y = 0; y < level->size.height; y += sprite.get_height())
+ gc.draw(sprite, Vector3f((float)x, (float)y, pos.z));
+ }
+ else
+ gc.draw(sprite, pos);
+ }
}
bool
LevelObj::is_at(int x, int y)
{
- if (!removed && attribs & (HAS_SURFACE | HAS_SURFACE_FAKE))
- {
- return (x > translated_pos.x && x < translated_pos.x +
sprite.get_width()
- && y > translated_pos.y && y < translated_pos.y +
sprite.get_height());
- }
- else
- return false;
+ if (!removed && attribs & (HAS_SURFACE | HAS_SURFACE_FAKE))
+ {
+ return (x > translated_pos.x && x < translated_pos.x + sprite.get_width()
+ && y > translated_pos.y && y < translated_pos.y +
sprite.get_height());
+ }
+ else
+ return false;
}
void
LevelObj::set_stretch_x(const bool s)
{
- stretch_x = s;
+ stretch_x = s;
}
void
LevelObj::set_stretch_y(const bool s)
{
- stretch_y = s;
+ stretch_y = s;
}
void
LevelObj::set_aspect(const bool a)
{
- keep_aspect = a;
+ keep_aspect = a;
}
void
LevelObj::refresh_sprite()
{
- if (attribs & HAS_SURFACE)
- {
- sprite = Resource::load_sprite(desc);
- ////int x, y;
- ////sprite.get_alignment(origin, x, y);
+ if (attribs & HAS_SURFACE)
+ {
+ sprite = Resource::load_sprite(desc);
+ ////int x, y;
+ ////sprite.get_alignment(origin, x, y);
- PixelBuffer pb;
+ PixelBuffer pb;
- // Apply modifier, then change the sprite loaded for this
object in memory.
- if (stretch_x || stretch_y)
- {
- float w = (float)sprite.get_width();
- float h = (float)sprite.get_height();
+ // Apply modifier, then change the sprite loaded for this object in
memory.
+ if (stretch_x || stretch_y)
+ {
+ float w = (float)sprite.get_width();
+ float h = (float)sprite.get_height();
- // Determine the new dimensions for the sprite
- if (stretch_x && !stretch_y)
- {
- if (keep_aspect)
- h = h * Display::get_width() / w;
- w = (float)Display::get_width();
- }
- else if (stretch_y && !stretch_x)
- {
- if (keep_aspect)
- w = w * Display::get_height() / h;
- h = (float)Display::get_height();
- }
- else
- {
- w = (float)Display::get_width();
- h = (float)Display::get_height();
- }
+ // Determine the new dimensions for the sprite
+ if (stretch_x && !stretch_y)
+ {
+ if (keep_aspect)
+ h = h * Display::get_width() / w;
+ w = (float)Display::get_width();
+ }
+ else if (stretch_y && !stretch_x)
+ {
+ if (keep_aspect)
+ w = w * Display::get_height() / h;
+ h = (float)Display::get_height();
+ }
+ else
+ {
+ w = (float)Display::get_width();
+ h = (float)Display::get_height();
+ }
- //FIXME: Sat Jan 13 10:26:15 2007
- assert(0);
- // pb = Blitter::scale_surface_to_canvas(
- // sprite.get_frame_pixeldata(0), (int)w, (int)h);
+ //FIXME: Sat Jan 13 10:26:15 2007
+ assert(0);
+ // pb = Blitter::scale_surface_to_canvas(
+ // sprite.get_frame_pixeldata(0), (int)w, (int)h);
- }
- else // No stretch involved
- pb = Resource::load_pixelbuffer(desc);
+ }
+ else // No stretch involved
+ pb = Resource::load_pixelbuffer(desc);
- ////SpriteDescription sprite_desc;
- ////sprite_desc.add_frame(pb);
- ////sprite = Sprite(sprite_desc);
- sprite = Sprite(pb);
- ////sprite.set_alignment(origin, x, y);
- }
- set_translated_pos();
+ ////SpriteDescription sprite_desc;
+ ////sprite_desc.add_frame(pb);
+ ////sprite = Sprite(sprite_desc);
+ sprite = Sprite(pb);
+ ////sprite.set_alignment(origin, x, y);
+ }
+ set_translated_pos();
}
// Set the modifier and actually modify the sprite loaded in memory
void
LevelObj::set_modifier(const std::string m)
{
- // Set modifier
- if (attribs & CAN_ROTATE)
- desc.modifier = ResourceModifierNS::rs_from_string(m);
- refresh_sprite();
+ // Set modifier
+ if (attribs & CAN_ROTATE)
+ desc.modifier = ResourceModifierNS::rs_from_string(m);
+ refresh_sprite();
}
// Writes the attributes for the file
void
LevelObj::write_properties(FileWriter &fw)
{
- if (!removed)
- {
- fw.begin_section(section_name.c_str());
+ if (!removed)
+ {
+ fw.begin_section(section_name.c_str());
- const unsigned attribs = get_attributes(section_name);
+ const unsigned attribs = get_attributes(section_name);
- // Write information about the main sprite
- if (attribs & HAS_SURFACE)
- {
- fw.begin_section("surface");
- fw.write_string("image", desc.res_name);
- fw.write_string("modifier",
ResourceModifierNS::rs_to_string(desc.modifier));
- fw.end_section(); // surface
- }
- // Write the optional information
- if (attribs & HAS_TYPE)
- fw.write_string("type", object_type);
- if (attribs & HAS_SPEED)
- fw.write_int("speed", speed);
- if (attribs & HAS_PARALLAX)
- fw.write_float("parallax", parallax);
- if (attribs & HAS_WIDTH)
- fw.write_int("width", width);
- if (attribs & HAS_OWNER)
- fw.write_int("owner-id", owner_id);
- if (attribs & HAS_DIRECTION)
- fw.write_string("direction", direction);
- if (attribs & HAS_RELEASE_RATE)
- fw.write_int("release-rate", release_rate);
- if (attribs & HAS_COLOR)
- fw.write_color("color", color);
- if (attribs & HAS_STRETCH)
- {
- fw.write_bool("stretch-x", stretch_x);
- fw.write_bool("stretch-y", stretch_y);
- fw.write_bool("keep-aspect", keep_aspect);
- }
- if (attribs & HAS_SCROLL)
- {
- fw.write_float("scroll-x", scroll_x);
- fw.write_float("scroll-y", scroll_y);
- }
- if (attribs & HAS_PARA)
- {
- fw.write_float("para-x", para_x);
- fw.write_float("para-y", para_y);
- }
+ // Write information about the main sprite
+ if (attribs & HAS_SURFACE)
+ {
+ fw.begin_section("surface");
+ fw.write_string("image", desc.res_name);
+ fw.write_string("modifier",
ResourceModifierNS::rs_to_string(desc.modifier));
+ fw.end_section(); // surface
+ }
+ // Write the optional information
+ if (attribs & HAS_TYPE)
+ fw.write_string("type", object_type);
+ if (attribs & HAS_SPEED)
+ fw.write_int("speed", speed);
+ if (attribs & HAS_PARALLAX)
+ fw.write_float("parallax", parallax);
+ if (attribs & HAS_WIDTH)
+ fw.write_int("width", width);
+ if (attribs & HAS_OWNER)
+ fw.write_int("owner-id", owner_id);
+ if (attribs & HAS_DIRECTION)
+ fw.write_string("direction", direction);
+ if (attribs & HAS_RELEASE_RATE)
+ fw.write_int("release-rate", release_rate);
+ if (attribs & HAS_COLOR)
+ fw.write_color("color", color);
+ if (attribs & HAS_STRETCH)
+ {
+ fw.write_bool("stretch-x", stretch_x);
+ fw.write_bool("stretch-y", stretch_y);
+ fw.write_bool("keep-aspect", keep_aspect);
+ }
+ if (attribs & HAS_SCROLL)
+ {
+ fw.write_float("scroll-x", scroll_x);
+ fw.write_float("scroll-y", scroll_y);
+ }
+ if (attribs & HAS_PARA)
+ {
+ fw.write_float("para-x", para_x);
+ fw.write_float("para-y", para_y);
+ }
- // Writes any extra properties that may be necessary (virtual
function)
- write_extra_properties(fw);
+ // Writes any extra properties that may be necessary (virtual function)
+ write_extra_properties(fw);
- // Write the Vector3f position - all objects have this
- fw.write_vector("position", pos);
+ // Write the Vector3f position - all objects have this
+ fw.write_vector("position", pos);
- fw.end_section(); // object's section_name
- }
+ fw.end_section(); // object's section_name
+ }
}
void
LevelObj::load_generic_surface()
{
- if (section_name == "entrance")
- {
- desc.res_name = "entrances/generic";
- desc.modifier = ResourceModifierNS::ROT0;
- sprite = Resource::load_sprite(desc);
- }
+ if (section_name == "entrance")
+ {
+ desc.res_name = "entrances/generic";
+ desc.modifier = ResourceModifierNS::ROT0;
+ sprite = Resource::load_sprite(desc);
+ }
}
// The translated pos is where the object appears to be "at" instead
@@ -264,56 +264,56 @@
void
LevelObj::set_translated_pos()
{
- if (!sprite)
- return;
+ if (!sprite)
+ return;
- translated_pos = pos;
+ translated_pos = pos;
- Origin orig = origin_top_left;
- ////int x, y;
- float w = (float)sprite.get_width();
- float h = (float)sprite.get_height();
+ Origin orig = origin_top_left;
+ ////int x, y;
+ float w = (float)sprite.get_width();
+ float h = (float)sprite.get_height();
- ////sprite.get_alignment(orig, x, y);
- switch (orig)
- {
- case origin_top_left :
- break;
- case origin_top_center :
- translated_pos.x -= w / 2;
- break;
- case origin_top_right :
- translated_pos.x -= w;
- break;
- case origin_center_left :
- translated_pos.y -= w / 2;
- break;
- case origin_center :
- translated_pos.x -= w / 2;
- translated_pos.y -= h / 2;
- break;
- case origin_center_right :
- translated_pos.x -= w;
- translated_pos.y -= h / 2;
- break;
- case origin_bottom_left :
- translated_pos.y -= h;
- break;
- case origin_bottom_center :
- translated_pos.x -= w / 2;
- translated_pos.y -= h;
- break;
- case origin_bottom_right :
- translated_pos.x -= w;
- translated_pos.y -= h;
- }
+ ////sprite.get_alignment(orig, x, y);
+ switch (orig)
+ {
+ case origin_top_left :
+ break;
+ case origin_top_center :
+ translated_pos.x -= w / 2;
+ break;
+ case origin_top_right :
+ translated_pos.x -= w;
+ break;
+ case origin_center_left :
+ translated_pos.y -= w / 2;
+ break;
+ case origin_center :
+ translated_pos.x -= w / 2;
+ translated_pos.y -= h / 2;
+ break;
+ case origin_center_right :
+ translated_pos.x -= w;
+ translated_pos.y -= h / 2;
+ break;
+ case origin_bottom_left :
+ translated_pos.y -= h;
+ break;
+ case origin_bottom_center :
+ translated_pos.x -= w / 2;
+ translated_pos.y -= h;
+ break;
+ case origin_bottom_right :
+ translated_pos.x -= w;
+ translated_pos.y -= h;
+ }
}
void
LevelObj::set_pos(Vector3f p)
{
- pos = p;
- set_translated_pos();
+ pos = p;
+ set_translated_pos();
}
} // Editor namespace
Modified: trunk/pingus/src/editor/level_objs.hpp
===================================================================
--- trunk/pingus/src/editor/level_objs.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/level_objs.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -29,303 +29,303 @@
#include <string>
- class DrawingContext;
+class DrawingContext;
namespace Editor {
- const unsigned HAS_TYPE = 1 << 0;
- const unsigned HAS_SPEED = 1 << 1;
- const unsigned HAS_PARALLAX = 1 << 2;
- const unsigned HAS_WIDTH = 1 << 3;
- const unsigned HAS_OWNER = 1 << 4;
- const unsigned HAS_COLOR = 1 << 5;
- const unsigned HAS_SCROLL = 1 << 6;
- const unsigned HAS_PARA = 1 << 7;
- const unsigned HAS_STRETCH = 1 << 8;
- const unsigned HAS_DIRECTION = 1 << 9;
- const unsigned HAS_RELEASE_RATE = 1 << 10;
- const unsigned HAS_SURFACE = 1 << 11;
- // HAS_SURFACE_FAKE means it has a generic image in the editor, but
isn't saved.
- const unsigned HAS_SURFACE_FAKE = 1 << 12;
- const unsigned CAN_ROTATE = 1 << 13;
+const unsigned HAS_TYPE = 1 << 0;
+const unsigned HAS_SPEED = 1 << 1;
+const unsigned HAS_PARALLAX = 1 << 2;
+const unsigned HAS_WIDTH = 1 << 3;
+const unsigned HAS_OWNER = 1 << 4;
+const unsigned HAS_COLOR = 1 << 5;
+const unsigned HAS_SCROLL = 1 << 6;
+const unsigned HAS_PARA = 1 << 7;
+const unsigned HAS_STRETCH = 1 << 8;
+const unsigned HAS_DIRECTION = 1 << 9;
+const unsigned HAS_RELEASE_RATE = 1 << 10;
+const unsigned HAS_SURFACE = 1 << 11;
+// HAS_SURFACE_FAKE means it has a generic image in the editor, but isn't
saved.
+const unsigned HAS_SURFACE_FAKE = 1 << 12;
+const unsigned CAN_ROTATE = 1 << 13;
- /** Returns a number representing which attributes this object
possesses */
- inline unsigned int get_attributes(std::string obj_type)
- {
- unsigned val;
- if (obj_type == "groundpiece")
- val = HAS_TYPE | HAS_SURFACE | CAN_ROTATE;
- else if (obj_type == "hotspot")
- val = HAS_SPEED | HAS_PARALLAX | HAS_SURFACE |
CAN_ROTATE;
- else if (obj_type == "liquid")
- val = HAS_SPEED | HAS_WIDTH | HAS_SURFACE;
- else if (obj_type == "surface-background")
- val = HAS_COLOR | HAS_STRETCH | HAS_PARA | HAS_SCROLL |
HAS_SURFACE;
- else if (obj_type == "entrance" || obj_type == "woodthing")
- val = HAS_TYPE | HAS_DIRECTION | HAS_RELEASE_RATE |
HAS_OWNER | HAS_SURFACE_FAKE;
- else if (obj_type == "exit")
- val = HAS_OWNER | HAS_SURFACE;
- else
- val = 0;
+/** Returns a number representing which attributes this object possesses */
+inline unsigned int get_attributes(std::string obj_type)
+{
+ unsigned val;
+ if (obj_type == "groundpiece")
+ val = HAS_TYPE | HAS_SURFACE | CAN_ROTATE;
+ else if (obj_type == "hotspot")
+ val = HAS_SPEED | HAS_PARALLAX | HAS_SURFACE | CAN_ROTATE;
+ else if (obj_type == "liquid")
+ val = HAS_SPEED | HAS_WIDTH | HAS_SURFACE;
+ else if (obj_type == "surface-background")
+ val = HAS_COLOR | HAS_STRETCH | HAS_PARA | HAS_SCROLL | HAS_SURFACE;
+ else if (obj_type == "entrance" || obj_type == "woodthing")
+ val = HAS_TYPE | HAS_DIRECTION | HAS_RELEASE_RATE | HAS_OWNER |
HAS_SURFACE_FAKE;
+ else if (obj_type == "exit")
+ val = HAS_OWNER | HAS_SURFACE;
+ else
+ val = 0;
- return val;
- }
+ return val;
+}
- class LevelImpl;
+class LevelImpl;
/** Generic Level Object (groundpiece, sign, etc.) Only special objects will
have
- to inherit from this class - most objects will be able to use
this class alone */
- class LevelObj
+ to inherit from this class - most objects will be able to use this class
alone */
+class LevelObj
{
protected:
- /** Sprite used to draw this object */
- Sprite sprite;
+ /** Sprite used to draw this object */
+ Sprite sprite;
- /** Level to which this object belongs */
- LevelImpl* level;
+ /** Level to which this object belongs */
+ LevelImpl* level;
- /** Resource Desciptor of this object */
- ResDescriptor desc;
+ /** Resource Desciptor of this object */
+ ResDescriptor desc;
- /** Location of this object in the World */
- Vector3f pos;
+ /** Location of this object in the World */
+ Vector3f pos;
- /** Only used for display functions - this is the pos Vector3f adjusted
- by the translation origin of the sprite */
- Vector3f translated_pos;
+ /** Only used for display functions - this is the pos Vector3f adjusted
+ by the translation origin of the sprite */
+ Vector3f translated_pos;
- /** Location of this object before moving it around */
- Vector3f orig_pos;
+ /** Location of this object before moving it around */
+ Vector3f orig_pos;
- /** Name of the section header for this object (hotspot, groundpiece,
etc.) */
- std::string section_name;
+ /** Name of the section header for this object (hotspot, groundpiece, etc.)
*/
+ std::string section_name;
- /** Optional type field for certain objects */
- std::string object_type;
+ /** Optional type field for certain objects */
+ std::string object_type;
- /** Optional speed field for certain objects */
- int speed;
+ /** Optional speed field for certain objects */
+ int speed;
- /** Optional parallax field for certain objects */
- float parallax;
+ /** Optional parallax field for certain objects */
+ float parallax;
- /** Optional width field for certain objects */
- int width;
+ /** Optional width field for certain objects */
+ int width;
- /** Optional owner id field for certain objects */
- int owner_id;
+ /** Optional owner id field for certain objects */
+ int owner_id;
- /** Optional release rate field for certain objects (entrances) */
- int release_rate;
+ /** Optional release rate field for certain objects (entrances) */
+ int release_rate;
- /** Optional direction field for certain objects */
- std::string direction;
+ /** Optional direction field for certain objects */
+ std::string direction;
- /** Optional scroll field in the x direction for certain objects */
- float scroll_x;
+ /** Optional scroll field in the x direction for certain objects */
+ float scroll_x;
- /** Optional scroll field in the y direction for certain objects */
- float scroll_y;
+ /** Optional scroll field in the y direction for certain objects */
+ float scroll_y;
- /** Optional stretch field in the x direction for certain objects */
- bool stretch_x;
+ /** Optional stretch field in the x direction for certain objects */
+ bool stretch_x;
- /** Optional stretch field in the y direction for certain objects */
- bool stretch_y;
+ /** Optional stretch field in the y direction for certain objects */
+ bool stretch_y;
- /** Optional field for keeping the aspect ratio of stretched objects */
- bool keep_aspect;
+ /** Optional field for keeping the aspect ratio of stretched objects */
+ bool keep_aspect;
- /** Optional parallax field in the x direction for certain objects */
- float para_x;
+ /** Optional parallax field in the x direction for certain objects */
+ float para_x;
- /** Optional parallax field in the y direction for certain objects */
- float para_y;
+ /** Optional parallax field in the y direction for certain objects */
+ float para_y;
- /** Optional color field for certain objects */
- Color color;
+ /** Optional color field for certain objects */
+ Color color;
- /** Optional translation origin of the sprite */
- Origin origin;
+ /** Optional translation origin of the sprite */
+ Origin origin;
- /** Number representing which attributes this object possesses */
- unsigned attribs;
+ /** Number representing which attributes this object possesses */
+ unsigned attribs;
- /** Marks if this object has been deleted or not */
- bool removed;
+ /** Marks if this object has been deleted or not */
+ bool removed;
- /** Marks is this object is currently selected */
- bool selected;
+ /** Marks is this object is currently selected */
+ bool selected;
- /** Loads any generic images necessary for objects with
HAS_FAKE_SURFACE */
- void load_generic_surface();
+ /** Loads any generic images necessary for objects with HAS_FAKE_SURFACE */
+ void load_generic_surface();
- /** Write any additional properties to the file for this type */
- virtual void write_extra_properties(FileWriter& fw) { }
+ /** Write any additional properties to the file for this type */
+ virtual void write_extra_properties(FileWriter& fw) { }
- /** Sets a position vector of where the sprite is located based
- on the "translation origin" specified in the sprite file. */
- void set_translated_pos();
+ /** Sets a position vector of where the sprite is located based
+ on the "translation origin" specified in the sprite file. */
+ void set_translated_pos();
-/////////////////////////////////////////////////////////
-/// Retrieve info
+ /////////////////////////////////////////////////////////
+ /// Retrieve info
public:
- /** Retrieve the object's position */
- Vector3f get_pos() const { return pos; }
- Vector3f get_orig_pos() const { return orig_pos; }
+ /** Retrieve the object's position */
+ Vector3f get_pos() const { return pos; }
+ Vector3f get_orig_pos() const { return orig_pos; }
- /** Retrieve this object's attribute number */
- unsigned get_attribs() const { return attribs; }
+ /** Retrieve this object's attribute number */
+ unsigned get_attribs() const { return attribs; }
- /** Retrieve the object's resource name */
- ResDescriptor get_res_desc() const { return desc; }
+ /** Retrieve the object's resource name */
+ ResDescriptor get_res_desc() const { return desc; }
- /** Retrieve the name of the section header for this object */
- std::string get_section_name() const { return section_name; }
+ /** Retrieve the name of the section header for this object */
+ std::string get_section_name() const { return section_name; }
- /** Retrieve the object's type */
- std::string get_type() const { return object_type; }
+ /** Retrieve the object's type */
+ std::string get_type() const { return object_type; }
- /** Retrieve the object's speed */
- int get_speed() const { return speed; }
+ /** Retrieve the object's speed */
+ int get_speed() const { return speed; }
- /** Retrieve the object's release rate (entrances) */
- int get_release_rate() const { return release_rate; }
+ /** Retrieve the object's release rate (entrances) */
+ int get_release_rate() const { return release_rate; }
- /** Retrive the object's parallax (is this even used???) */
- float get_parallax() const { return parallax; }
+ /** Retrive the object's parallax (is this even used???) */
+ float get_parallax() const { return parallax; }
- /** Retrieve the object's owner */
- int get_owner() const { return owner_id; }
+ /** Retrieve the object's owner */
+ int get_owner() const { return owner_id; }
- /** Retrieve the object's width */
- int get_width() const { return width; }
+ /** Retrieve the object's width */
+ int get_width() const { return width; }
- /** Retrieve the object's color */
- Color get_color() const { return color; }
+ /** Retrieve the object's color */
+ Color get_color() const { return color; }
- /** Returns true if the object is stretched in the x direction */
- bool get_stretch_x() const { return stretch_x; }
+ /** Returns true if the object is stretched in the x direction */
+ bool get_stretch_x() const { return stretch_x; }
- /** Returns true if the object is stretched in the y direction */
- bool get_stretch_y() const { return stretch_y; }
+ /** Returns true if the object is stretched in the y direction */
+ bool get_stretch_y() const { return stretch_y; }
- /** Returns true if the object is to maintain it's aspect ratio if
stretched */
- bool get_aspect() const { return keep_aspect; }
+ /** Returns true if the object is to maintain it's aspect ratio if stretched
*/
+ bool get_aspect() const { return keep_aspect; }
- /** Retrive the objects scroll value in the x direction */
- float get_scroll_x() const { return scroll_x; }
+ /** Retrive the objects scroll value in the x direction */
+ float get_scroll_x() const { return scroll_x; }
- /** Retrive the objects scroll value in the y direction */
- float get_scroll_y() const { return scroll_y; }
+ /** Retrive the objects scroll value in the y direction */
+ float get_scroll_y() const { return scroll_y; }
- /** Returns the parallax speed multiplier in the x direction */
- float get_para_x() const { return para_x; }
+ /** Returns the parallax speed multiplier in the x direction */
+ float get_para_x() const { return para_x; }
- /** Returns the parallax speed multiplier in the y direction */
- float get_para_y() const { return para_y; }
+ /** Returns the parallax speed multiplier in the y direction */
+ float get_para_y() const { return para_y; }
- bool is_selected() { return selected; }
+ bool is_selected() { return selected; }
- /** Retrieve the object's direction */
- std::string get_direction() { return direction; }
+ /** Retrieve the object's direction */
+ std::string get_direction() { return direction; }
-/////////////////////////////////////////////////////////
-/// Operations
+ /////////////////////////////////////////////////////////
+ /// Operations
public:
- /** Set the object's position */
- void set_pos(const Vector3f p);
+ /** Set the object's position */
+ void set_pos(const Vector3f p);
- /** Original position of the objects before being dragged around */
- void set_orig_pos(const Vector3f p) { orig_pos = p; }
+ /** Original position of the objects before being dragged around */
+ void set_orig_pos(const Vector3f p) { orig_pos = p; }
- /** Set the object's resource name */
- void set_res_desc(const ResDescriptor d);
+ /** Set the object's resource name */
+ void set_res_desc(const ResDescriptor d);
- /** Set the object's modifier */
- void set_modifier(const std::string m);
+ /** Set the object's modifier */
+ void set_modifier(const std::string m);
- /** Set the object's section header name */
- void set_section_name(const std::string sn) { section_name = sn; }
+ /** Set the object's section header name */
+ void set_section_name(const std::string sn) { section_name = sn; }
- /** Set the object's type */
- void set_type(const std::string t) { object_type = t; }
+ /** Set the object's type */
+ void set_type(const std::string t) { object_type = t; }
- /** Set the object's speed */
- void set_speed(const int s) { speed = s; }
+ /** Set the object's speed */
+ void set_speed(const int s) { speed = s; }
- /** Set the objects release rate */
- void set_release_rate(const int r) { release_rate = r; }
+ /** Set the objects release rate */
+ void set_release_rate(const int r) { release_rate = r; }
- /** Set the object's parallax */
- void set_parallax(const float para) { parallax = para; }
+ /** Set the object's parallax */
+ void set_parallax(const float para) { parallax = para; }
- /** Set the object's width */
- void set_width(const int w) { width = w; }
+ /** Set the object's width */
+ void set_width(const int w) { width = w; }
- /** Set the object's owner_id */
- void set_owner(const int id) { owner_id = id; }
+ /** Set the object's owner_id */
+ void set_owner(const int id) { owner_id = id; }
- /** Set the object's scroll rate in the x direction */
- void set_scroll_x(const float s) { scroll_x = s; }
+ /** Set the object's scroll rate in the x direction */
+ void set_scroll_x(const float s) { scroll_x = s; }
- /** Set the object's scroll rate in the y direction */
- void set_scroll_y(const float s) { scroll_y = s; }
+ /** Set the object's scroll rate in the y direction */
+ void set_scroll_y(const float s) { scroll_y = s; }
- /** Set the objects stretch in the x direction value */
- void set_stretch_x(const bool s);
+ /** Set the objects stretch in the x direction value */
+ void set_stretch_x(const bool s);
- /** Set the objects stretch in the y direction value */
- void set_stretch_y(bool s);
+ /** Set the objects stretch in the y direction value */
+ void set_stretch_y(bool s);
- /** Set whether or not the object should maintain it's aspect ratio
when stretched */
- void set_aspect(const bool a);
+ /** Set whether or not the object should maintain it's aspect ratio when
stretched */
+ void set_aspect(const bool a);
- /** Set the objects color if applicable */
- void set_color(const Color& c)
- { color = c; }
+ /** Set the objects color if applicable */
+ void set_color(const Color& c)
+ { color = c; }
- /** Set the object's parallax scroll multiplier in the x direction */
- void set_para_x(const float p) { para_x = p; }
+ /** Set the object's parallax scroll multiplier in the x direction */
+ void set_para_x(const float p) { para_x = p; }
- /** Set the object's parallax scroll multiplier in the y direction */
- void set_para_y(const float p) { para_y = p; }
+ /** Set the object's parallax scroll multiplier in the y direction */
+ void set_para_y(const float p) { para_y = p; }
- /** Set the object's direction if applicable */
- void set_direction(const std::string d) { direction = d; }
+ /** Set the object's direction if applicable */
+ void set_direction(const std::string d) { direction = d; }
- /** Soft delete of the object (needed for Undo action) */
- void remove() { removed = true; }
+ /** Soft delete of the object (needed for Undo action) */
+ void remove() { removed = true; }
- /** Undelete this object if it's been removed */
- void unremove() { removed = false; }
+ /** Undelete this object if it's been removed */
+ void unremove() { removed = false; }
- /** Select or unselect this object */
- void select() { selected = true; }
- void unselect() { selected = false; }
+ /** Select or unselect this object */
+ void select() { selected = true; }
+ void unselect() { selected = false; }
- /** Write basic properties to the file for this type */
- virtual void write_properties(FileWriter &fw);
+ /** Write basic properties to the file for this type */
+ virtual void write_properties(FileWriter &fw);
- /** Call when the sprite needs to be reloaded */
- void refresh_sprite();
+ /** Call when the sprite needs to be reloaded */
+ void refresh_sprite();
- /** Draws the sprite with the modifier applied */
- virtual void draw(DrawingContext &gc);
+ /** Draws the sprite with the modifier applied */
+ virtual void draw(DrawingContext &gc);
- /** Returns true if the mouse is hovering over this object */
- virtual bool is_at (int x, int y);
+ /** Returns true if the mouse is hovering over this object */
+ virtual bool is_at (int x, int y);
- /** Default Constructor */
- LevelObj(const std::string obj_name, LevelImpl* level_);
+ /** Default Constructor */
+ LevelObj(const std::string obj_name, LevelImpl* level_);
- /** Destructor */
- virtual ~LevelObj() { }
+ /** Destructor */
+ virtual ~LevelObj() { }
private:
- LevelObj (const LevelObj&);
+ LevelObj (const LevelObj&);
LevelObj& operator= (const LevelObj&);
}; // LevelObj class
Modified: trunk/pingus/src/editor/panel_buttons.cpp
===================================================================
--- trunk/pingus/src/editor/panel_buttons.cpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/panel_buttons.cpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -40,7 +41,7 @@
PanelButton::PanelButton(EditorPanel* p) :
hover(false),
panel(p),
- is_selected(false)
+ is_selected(false)
{
button = Resource::load_sprite("core/editor/button");
button_pressed = Resource::load_sprite("core/editor/button_pressed");
@@ -50,25 +51,25 @@
void
PanelButton::draw(DrawingContext &gc)
{
- if (is_selected)
- gc.draw(button_pressed, pos);
- else
- gc.draw(button, pos);
+ if (is_selected)
+ gc.draw(button_pressed, pos);
+ else
+ gc.draw(button, pos);
- // Print the tooltip
- if (hover)
- gc.print_left(Fonts::pingus_small, pos.x, pos.y +
(float)get_width(),
- tooltip, 50);
+ // Print the tooltip
+ if (hover)
+ gc.print_left(Fonts::pingus_small, pos.x, pos.y + (float)get_width(),
+ tooltip, 50);
- // Draw the actual button image
- gc.draw(sur, pos);
+ // Draw the actual button image
+ gc.draw(sur, pos);
}
// Set the position of this panelbutton
void
PanelButton::set_pos(Vector3f p)
{
- pos = p;
+ pos = p;
}
// Is this button at these x,y coordinates?
@@ -80,19 +81,19 @@
}
// Something all buttons should do.
-void
-PanelButton::on_primary_button_click(int x, int y)
+ void
+ PanelButton::on_primary_button_click(int x, int y)
{
- UNUSED_ARG(x);
- UNUSED_ARG(y);
- panel->set_selected_button(this);
+ UNUSED_ARG(x);
+ UNUSED_ARG(y);
+ panel->set_selected_button(this);
}
// Standard exit button
PanelButtonExit::PanelButtonExit(EditorPanel *p) :
- PanelButton(p)
+ PanelButton(p)
{
- tooltip = "Exit the editor";
+ tooltip = "Exit the editor";
sur = Resource::load_sprite("core/editor/exit");
}
@@ -100,15 +101,15 @@
void
PanelButtonExit::on_primary_button_click(int x, int y)
{
- PanelButton::on_primary_button_click(x, y);
- panel->get_screen()->on_escape_press();
+ PanelButton::on_primary_button_click(x, y);
+ panel->get_screen()->on_escape_press();
}
// Standard Load button
PanelButtonLoad::PanelButtonLoad(EditorPanel *p) :
- PanelButton(p)
+ PanelButton(p)
{
- tooltip = "Load existing level";
+ tooltip = "Load existing level";
sur = Resource::load_sprite("core/editor/open");
}
@@ -116,15 +117,15 @@
void
PanelButtonLoad::on_primary_button_click(int x, int y)
{
- PanelButton::on_primary_button_click(x, y);
- panel->get_screen()->show_file_dialog(true);
+ PanelButton::on_primary_button_click(x, y);
+ panel->get_screen()->show_file_dialog(true);
}
// Standard save button
PanelButtonSave::PanelButtonSave(EditorPanel *p) :
- PanelButton(p)
+ PanelButton(p)
{
- tooltip = "Save current level";
+ tooltip = "Save current level";
sur = Resource::load_sprite("core/editor/save");
}
@@ -132,90 +133,90 @@
void
PanelButtonSave::on_primary_button_click(int x, int y)
{
- PanelButton::on_primary_button_click(x, y);
- panel->get_screen()->show_file_dialog(false);
+ PanelButton::on_primary_button_click(x, y);
+ panel->get_screen()->show_file_dialog(false);
}
// Load the groundpieces
PanelButtonGroundpiece::PanelButtonGroundpiece(EditorPanel *p) :
- PanelButton(p)
+ PanelButton(p)
{
- sur = Resource::load_sprite("core/editor/save"); // FIXME: Update this
sprite
- tooltip = "Load a groundpiece";
+ sur = Resource::load_sprite("core/editor/save"); // FIXME: Update this
sprite
+ tooltip = "Load a groundpiece";
}
void
PanelButtonGroundpiece::on_primary_button_click(int x, int y)
{
- PanelButton::on_primary_button_click(x, y);
+ PanelButton::on_primary_button_click(x, y);
- panel->get_combobox(1)->clear();
- panel->get_combobox(1)->set_label("Type");
- panel->get_combobox(2)->set_label("Subtype");
- panel->get_combobox(3)->set_label("Groundpiece");
- std::vector<std::string> groundpieces; //// =
Resource::get_sections("groundpieces");
- for (unsigned i = 0; i < groundpieces.size(); i++)
- {
- // We add each ComboItem to the first box:
- // - The ID field of the ComboItem should be the full resource
name.
- // - The displayed field should only be the section name.
- panel->get_combobox(1)->add(new GUI::ComboItem("groundpieces/"
+ groundpieces[i],
- groundpieces[i]));
- }
- panel->get_combobox(1)->set_enabled(true);
+ panel->get_combobox(1)->clear();
+ panel->get_combobox(1)->set_label("Type");
+ panel->get_combobox(2)->set_label("Subtype");
+ panel->get_combobox(3)->set_label("Groundpiece");
+ std::vector<std::string> groundpieces; //// =
Resource::get_sections("groundpieces");
+ for (unsigned i = 0; i < groundpieces.size(); i++)
+ {
+ // We add each ComboItem to the first box:
+ // - The ID field of the ComboItem should be the full resource name.
+ // - The displayed field should only be the section name.
+ panel->get_combobox(1)->add(new GUI::ComboItem("groundpieces/" +
groundpieces[i],
+ groundpieces[i]));
+ }
+ panel->get_combobox(1)->set_enabled(true);
}
// Populate the other comboboxes with the available resources.
void
PanelButtonGroundpiece::combobox_changed(int i, const std::string &value)
{
- std::string section;
- if (i == 1)
- {
- // Populate the 2nd combobox with the next resource section &
disable box 3.
- panel->get_combobox(2)->clear();
- panel->get_combobox(2)->set_enabled(true);
- panel->get_combobox(3)->set_enabled(false);
+ std::string section;
+ if (i == 1)
+ {
+ // Populate the 2nd combobox with the next resource section & disable
box 3.
+ panel->get_combobox(2)->clear();
+ panel->get_combobox(2)->set_enabled(true);
+ panel->get_combobox(3)->set_enabled(false);
- std::vector<std::string> groundpieces;//// =
Resource::get_sections(
-
////panel->get_combobox(1)->get_selected_item()->get_displayed_string());
- for (std::vector<std::string>::const_iterator it =
groundpieces.begin();
- it != groundpieces.end(); it++)
- panel->get_combobox(2)->add(new GUI::ComboItem(value +
"/" + (*it), (*it)));
- }
- else if (i == 2)
- {
- // Populate the 3rd combobox with the Resource ID's
- panel->get_combobox(3)->clear();
- panel->get_combobox(3)->set_enabled(true);
+ std::vector<std::string> groundpieces;//// = Resource::get_sections(
+ ////panel->get_combobox(1)->get_selected_item()->get_displayed_string());
+ for (std::vector<std::string>::const_iterator it = groundpieces.begin();
+ it != groundpieces.end(); it++)
+ panel->get_combobox(2)->add(new GUI::ComboItem(value + "/" + (*it),
(*it)));
+ }
+ else if (i == 2)
+ {
+ // Populate the 3rd combobox with the Resource ID's
+ panel->get_combobox(3)->clear();
+ panel->get_combobox(3)->set_enabled(true);
- std::vector<std::string> groundpieces;//// =
Resource::get_resources(
- //// "sprite", value);
- for (std::vector<std::string>::const_iterator it =
groundpieces.begin();
- it != groundpieces.end(); it++)
- {
- // new_value is the "displayed_string" for the combobox.
- std::string new_value = (*it).substr(value.length()+1);
- panel->get_combobox(3)->add(new GUI::ComboItem(value +
"/" + new_value,
- new_value));
- }
- }
- else
- {
- // 3rd box was selected - add the resource to the current level.
- LevelObj* obj = new LevelObj("groundpiece",
panel->get_screen()->get_level()->get_level_impl());
- obj->set_res_desc(ResDescriptor(value));
- obj->set_pos(Vector3f(0, 0, 0));
- // 1st combobox displayed the "type" of resource (solid,
transparent, etc.)
-
obj->set_type(panel->get_combobox(1)->get_selected_item()->get_displayed_string());
- panel->get_screen()->add_object(obj);
- }
+ std::vector<std::string> groundpieces;//// = Resource::get_resources(
+ //// "sprite", value);
+ for (std::vector<std::string>::const_iterator it = groundpieces.begin();
+ it != groundpieces.end(); it++)
+ {
+ // new_value is the "displayed_string" for the combobox.
+ std::string new_value = (*it).substr(value.length()+1);
+ panel->get_combobox(3)->add(new GUI::ComboItem(value + "/" +
new_value,
+ new_value));
+ }
+ }
+ else
+ {
+ // 3rd box was selected - add the resource to the current level.
+ LevelObj* obj = new LevelObj("groundpiece",
panel->get_screen()->get_level()->get_level_impl());
+ obj->set_res_desc(ResDescriptor(value));
+ obj->set_pos(Vector3f(0, 0, 0));
+ // 1st combobox displayed the "type" of resource (solid, transparent,
etc.)
+
obj->set_type(panel->get_combobox(1)->get_selected_item()->get_displayed_string());
+ panel->get_screen()->add_object(obj);
+ }
}
PanelButtonHead::PanelButtonHead(EditorPanel *p)
: PanelButton(p),
- head(0)
+ head(0)
{
// FIXME: Update this sprite
sur = Resource::load_sprite("core/editor/save");
@@ -227,13 +228,13 @@
{
PanelButton::on_primary_button_click(x, y);
if (!head)
- {
- head = new LevelHead(panel, this);
- }
+ {
+ head = new LevelHead(panel, this);
+ }
else
- {
- remove_head();
- }
+ {
+ remove_head();
+ }
}
void
Modified: trunk/pingus/src/editor/panel_buttons.hpp
===================================================================
--- trunk/pingus/src/editor/panel_buttons.hpp 2007-09-03 23:01:36 UTC (rev
3074)
+++ trunk/pingus/src/editor/panel_buttons.hpp 2007-09-03 23:27:36 UTC (rev
3075)
@@ -1,7 +1,8 @@
// $Id$
//
// Pingus - A free Lemmings clone
-// Copyright (C) 1999 Ingo Ruhnke <address@hidden>
+// Copyright (C) 2007 Jason Green <address@hidden>,
+// 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
@@ -34,76 +35,76 @@
class PanelButton : public GUI::Component
{
private:
- /** Whether or not the mouse is over the button */
- bool hover;
+ /** Whether or not the mouse is over the button */
+ bool hover;
protected:
- /** The actual button image */
- Sprite sur;
+ /** The actual button image */
+ Sprite sur;
- /** The button background image when not pressed */
- Sprite button;
+ /** The button background image when not pressed */
+ Sprite button;
- /** The button background image while pressed */
- Sprite button_pressed;
+ /** The button background image while pressed */
+ Sprite button_pressed;
- /** The panel to which this button belongs */
- EditorPanel* panel;
+ /** The panel to which this button belongs */
+ EditorPanel* panel;
- /** The string that appears when the mouse is hovering over this button
*/
- std::string tooltip;
+ /** The string that appears when the mouse is hovering over this button */
+ std::string tooltip;
- /** The location of this button on the screen (set by the EditorPanel)
*/
- Vector3f pos;
+ /** The location of this button on the screen (set by the EditorPanel) */
+ Vector3f pos;
- /** Is this button currently selected? */
- bool is_selected;
+ /** Is this button currently selected? */
+ bool is_selected;
public:
- /** Constructor
- @param p The EditorPanel to which this button belongs */
- PanelButton(EditorPanel* p);
+ /** Constructor
+ @param p The EditorPanel to which this button belongs */
+ PanelButton(EditorPanel* p);
- /** Destructor - nothing really happens here */
- virtual ~PanelButton() { }
+ /** Destructor - nothing really happens here */
+ virtual ~PanelButton() { }
- /** Set the position of this button on the screen - used by the
EditorPanel
- @param p the x,y,z Vector3f where this button belongs */
- void set_pos (Vector3f p);
+ /** Set the position of this button on the screen - used by the EditorPanel
+ @param p the x,y,z Vector3f where this button belongs */
+ void set_pos (Vector3f p);
- /** Returns the Vector3f of this button's location */
- Vector3f get_pos () { return pos; }
+ /** Returns the Vector3f of this button's location */
+ Vector3f get_pos () { return pos; }
- /** Returns the width of the sur sprite */
- int get_width() { return sur.get_width(); }
+ /** Returns the width of the sur sprite */
+ int get_width() { return sur.get_width(); }
- /** Returns the height of the sur sprite */
- int get_height() { return sur.get_height(); }
+ /** Returns the height of the sur sprite */
+ int get_height() { return sur.get_height(); }
- /** Draws the button */
- void draw(DrawingContext& gc);
+ /** Draws the button */
+ void draw(DrawingContext& gc);
- /** Return true if the button is located at this x,y coordinate */
- bool is_at(int x, int y);
+ /** Return true if the button is located at this x,y coordinate */
+ bool is_at(int x, int y);
- /** Action taken when the button is clicked */
- virtual void on_primary_button_click(int x, int y);
+ /** Action taken when the button is clicked */
+ virtual void on_primary_button_click(int x, int y);
- /** Action taken when the mouse enters the button area */
- virtual void on_pointer_enter () { hover = true; }
+ /** Action taken when the mouse enters the button area */
+ virtual void on_pointer_enter () { hover = true; }
- /** Action taken when the mouse leaves the button area */
- virtual void on_pointer_leave () { hover = false; }
+ /** Action taken when the mouse leaves the button area */
+ virtual void on_pointer_leave () { hover = false; }
- /** Action taken when the button is selected or not */
- virtual void select(bool s) { is_selected = s; }
+ /** Action taken when the button is selected or not */
+ virtual void select(bool s) { is_selected = s; }
- /** Event that fires when the first combobox has been changed */
- virtual void combobox_changed(int i, const std::string &value) { }
+ /** Event that fires when the first combobox has been changed */
+ virtual void combobox_changed(int i, const std::string &value) { }
private:
- PanelButton (const PanelButton&);
- PanelButton& operator= (const PanelButton&);
+ PanelButton (const PanelButton&);
+ PanelButton& operator= (const PanelButton&);
}; // PanelButton class
@@ -111,15 +112,15 @@
class PanelButtonExit : public PanelButton
{
public:
- /** Constructor
- @param p the EditorPanel to which this button belongs */
- PanelButtonExit (EditorPanel* p);
+ /** Constructor
+ @param p the EditorPanel to which this button belongs */
+ PanelButtonExit (EditorPanel* p);
- /** This function is called by the gui_manager when the button is
clicked */
- void on_primary_button_click (int x, int y);
+ /** This function is called by the gui_manager when the button is clicked */
+ void on_primary_button_click (int x, int y);
private:
- PanelButtonExit ();
+ PanelButtonExit ();
PanelButtonExit (const PanelButtonExit&);
PanelButtonExit& operator= (const PanelButtonExit&);
}; // PanelButtonExit class
@@ -129,15 +130,15 @@
class PanelButtonLoad : public PanelButton
{
public:
- /** Constructor
- @param p the EditorPanel to which this button belongs */
- PanelButtonLoad (EditorPanel* p);
+ /** Constructor
+ @param p the EditorPanel to which this button belongs */
+ PanelButtonLoad (EditorPanel* p);
- /** This function is called by the gui_manager when the button is
clicked */
- void on_primary_button_click (int x, int y);
+ /** This function is called by the gui_manager when the button is clicked */
+ void on_primary_button_click (int x, int y);
private:
- PanelButtonLoad ();
+ PanelButtonLoad ();
PanelButtonLoad (const PanelButtonLoad&);
PanelButtonLoad& operator= (const PanelButtonLoad&);
}; // PanelButtonLoad class
@@ -147,15 +148,15 @@
class PanelButtonSave : public PanelButton
{
public:
- /** Constructor
- @param p the EditorPanel to which this button belongs */
- PanelButtonSave (EditorPanel* p);
+ /** Constructor
+ @param p the EditorPanel to which this button belongs */
+ PanelButtonSave (EditorPanel* p);
- /** This function is called by the gui_manager when the button is
clicked */
- void on_primary_button_click (int x, int y);
+ /** This function is called by the gui_manager when the button is clicked */
+ void on_primary_button_click (int x, int y);
private:
- PanelButtonSave ();
+ PanelButtonSave ();
PanelButtonSave (const PanelButtonSave&);
PanelButtonSave& operator= (const PanelButtonSave&);
}; // PanelButtonSave class
@@ -165,18 +166,18 @@
class PanelButtonGroundpiece : public PanelButton
{
public:
- /** Constructor
- @param p the EditorPanel to which this button belongs */
- PanelButtonGroundpiece (EditorPanel* p);
+ /** Constructor
+ @param p the EditorPanel to which this button belongs */
+ PanelButtonGroundpiece (EditorPanel* p);
- /** This function is called by the gui_manager when the button is
clicked */
- virtual void on_primary_button_click (int x, int y);
+ /** This function is called by the gui_manager when the button is clicked */
+ virtual void on_primary_button_click (int x, int y);
- /** Want to update the other comboboxes with the new groundpieces */
- virtual void combobox_changed(int i, const std::string &value);
+ /** Want to update the other comboboxes with the new groundpieces */
+ virtual void combobox_changed(int i, const std::string &value);
private:
- PanelButtonGroundpiece ();
+ PanelButtonGroundpiece ();
PanelButtonGroundpiece (const PanelButtonGroundpiece&);
PanelButtonGroundpiece& operator= (const PanelButtonGroundpiece&);
}; // PanelButtonGroundpiece class
@@ -185,23 +186,23 @@
/** Display all of the level description <HEAD> information */
class PanelButtonHead : public PanelButton
{
- private:
- LevelHead* head;
+private:
+ LevelHead* head;
- public:
+public:
/** Constructor
- @param p the EditorPanel to which this button belongs */
- PanelButtonHead (EditorPanel* p);
+ @param p the EditorPanel to which this button belongs */
+ PanelButtonHead (EditorPanel* p);
- /** This function is called by the gui_manager when the button is clicked
*/
- virtual void on_primary_button_click (int x, int y);
+ /** This function is called by the gui_manager when the button is clicked */
+ virtual void on_primary_button_click (int x, int y);
- void remove_head();
+ void remove_head();
- private:
- PanelButtonHead ();
- PanelButtonHead (const PanelButtonHead&);
- PanelButtonHead& operator= (const PanelButtonHead&);
+private:
+ PanelButtonHead ();
+ PanelButtonHead (const PanelButtonHead&);
+ PanelButtonHead& operator= (const PanelButtonHead&);
}; // PanelButtonHead class
} // Editor namespace
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3075 - trunk/pingus/src/editor,
grumbel at BerliOS <=