[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] rev 2344 - in trunk/src: . gui input/buttons
From: |
Ingo Ruhnke |
Subject: |
[Pingus-CVS] rev 2344 - in trunk/src: . gui input/buttons |
Date: |
Thu, 24 Jun 2004 21:01:02 +0200 |
Author: grumbel
Date: 2004-06-24 21:01:01 +0200 (Thu, 24 Jun 2004)
New Revision: 2344
Modified:
trunk/src/gui/surface_button.hxx
trunk/src/input/buttons/key_button.cxx
trunk/src/input/buttons/multiple_button.cxx
trunk/src/input/buttons/multiple_button.hxx
trunk/src/menu_button.cxx
trunk/src/menu_button.hxx
trunk/src/pingus_menu.cxx
trunk/src/pingus_menu.hxx
Log:
- some simplifications of the menu code
Modified: trunk/src/gui/surface_button.hxx
===================================================================
--- trunk/src/gui/surface_button.hxx 2004-06-24 16:41:28 UTC (rev 2343)
+++ trunk/src/gui/surface_button.hxx 2004-06-24 19:01:01 UTC (rev 2344)
@@ -59,7 +59,7 @@
virtual void on_pointer_enter ();
virtual void on_pointer_leave ();
- virtual void on_click() =0;
+ virtual void on_click() {}
private:
SurfaceButton (const SurfaceButton&);
SurfaceButton& operator= (const SurfaceButton&);
Modified: trunk/src/input/buttons/key_button.cxx
===================================================================
--- trunk/src/input/buttons/key_button.cxx 2004-06-24 16:41:28 UTC (rev
2343)
+++ trunk/src/input/buttons/key_button.cxx 2004-06-24 19:01:01 UTC (rev
2344)
@@ -50,14 +50,20 @@
KeyButton::key_press_handler (const CL_InputEvent& event)
{
if (event.id == button)
- pressed = true;
+ {
+ pressed = true;
+ button_down();
+ }
}
void
KeyButton::key_release_handler (const CL_InputEvent& event)
{
if (event.id == button)
- pressed = false;
+ {
+ pressed = false;
+ button_up();
+ }
}
} // namespace Buttons
Modified: trunk/src/input/buttons/multiple_button.cxx
===================================================================
--- trunk/src/input/buttons/multiple_button.cxx 2004-06-24 16:41:28 UTC (rev
2343)
+++ trunk/src/input/buttons/multiple_button.cxx 2004-06-24 19:01:01 UTC (rev
2344)
@@ -17,6 +17,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#include <iostream>
#include "multiple_button.hxx"
namespace Pingus {
@@ -25,6 +26,13 @@
MultipleButton::MultipleButton (const std::vector<Button*>& buttons_) :
buttons(buttons_)
{
+ down_count = 0;
+
+ for (std::vector<Button*>::iterator it = buttons.begin(); it !=
buttons.end(); it++)
+ {
+ slots.push_back((*it)->sig_button_up() .connect(this,
&MultipleButton::on_button_up));
+ slots.push_back((*it)->sig_button_down().connect(this,
&MultipleButton::on_button_down));
+ }
}
MultipleButton::~MultipleButton ()
@@ -50,6 +58,26 @@
return false;
}
+void
+MultipleButton::on_button_up()
+{
+ down_count -= 1;
+ if (down_count < 0)
+ down_count = 0;
+
+ if (down_count == 0)
+ button_up();
+}
+
+void
+MultipleButton::on_button_down()
+{
+ if (down_count == 0)
+ button_down();
+
+ down_count += 1;
+}
+
} // namespace Buttons
} // namespace Input
} // namespace Pingus
Modified: trunk/src/input/buttons/multiple_button.hxx
===================================================================
--- trunk/src/input/buttons/multiple_button.hxx 2004-06-24 16:41:28 UTC (rev
2343)
+++ trunk/src/input/buttons/multiple_button.hxx 2004-06-24 19:01:01 UTC (rev
2344)
@@ -38,9 +38,9 @@
private:
std::vector<Button*> buttons;
-
+ std::vector<CL_Slot> slots;
+ int down_count;
public:
-
MultipleButton (const std::vector<Button*>& buttons_);
~MultipleButton ();
@@ -48,6 +48,9 @@
virtual void update (float delta);
private:
+ void on_button_up();
+ void on_button_down();
+
MultipleButton (const MultipleButton&);
MultipleButton& operator= (const MultipleButton&);
};
Modified: trunk/src/menu_button.cxx
===================================================================
--- trunk/src/menu_button.cxx 2004-06-24 16:41:28 UTC (rev 2343)
+++ trunk/src/menu_button.cxx 2004-06-24 19:01:01 UTC (rev 2344)
@@ -39,6 +39,24 @@
using EditorNS::Editor;
+SurfaceButton::SurfaceButton(const CL_Point& pos_, const CL_Sprite& sprite_,
+ const std::string& text_, const std::string&
desc_)
+{
+ text = text_;
+ desc = desc_;
+
+ x_pos = pos_.x;
+ y_pos = pos_.y;
+
+ surface_p = sprite_;
+
+ font = Fonts::pingus_small;
+ font_large = Fonts::pingus_large;
+
+ mouse_over = false;
+ pressed = false;
+}
+
SurfaceButton::SurfaceButton ()
{
font = Fonts::pingus_small;
@@ -59,6 +77,12 @@
}
void
+SurfaceButton::on_click ()
+{
+ click();
+}
+
+void
SurfaceButton::draw (GraphicContext& gc)
{
if (mouse_over && !pressed)
@@ -70,19 +94,9 @@
gc.draw(surface_p, Vector(x_pos - surface_p.get_width()/2,
y_pos - surface_p.get_height()/2));
- if (line2.empty())
- {
- gc.print_center(font_large, x_pos + 32,
- y_pos - 32 - font_large.get_height()/2,
- line1.c_str());
- }
- else
- {
- gc.print_center(font_large, x_pos + 32, y_pos - 32 -
(font_large.get_height() - 5),
- line1.c_str());
- gc.print_center(font_large, x_pos + 32, y_pos - 32,
- line2.c_str());
- }
+ gc.print_center(font_large, x_pos + 32,
+ y_pos - 32 - font_large.get_height()/2,
+ text);
}
else if (mouse_over && pressed)
{
@@ -95,25 +109,12 @@
gc.draw(surface_p,
Vector(x_pos - surface_p.get_width()/2 * shrink,
y_pos - surface_p.get_height()/2 * shrink));
-#ifdef CLANLIB_0_6
- shrink, shrink, 0);
-#endif
-
- if (line2.empty())
- {
- gc.print_center(font_large,
- x_pos + 32,
- y_pos - 32 - font_large.get_height()/2,
- line1.c_str());
- }
- else
- {
- gc.print_center(font_large,
- x_pos + 32, y_pos - 32 - font_large.get_height(),
- line1.c_str());
- gc.print_center(font_large, x_pos + 32, y_pos - 32,
- line2.c_str());
- }
+ //#ifdef CLANLIB_0_6
+ // shrink, shrink, 0);
+ gc.print_center(font_large,
+ x_pos + 32,
+ y_pos - 32 - font_large.get_height()/2,
+ text);
}
else
{
@@ -166,254 +167,6 @@
&& y < y_pos + int(surface_p.get_height()) / 2);
}
-///////////////////////////////////////////////
-
-CreditButton::CreditButton (PingusMenu* menu_)
- : menu(menu_)
-{
- // x_pos = CL_Display::get_width() * 500 / 640;
- // y_pos = CL_Display::get_height() * 420 / 480;
-
- x_pos = CL_Display::get_width() * 126 / 640;
- y_pos = CL_Display::get_height() * 369 / 480;
-
- // desc["en"] = "..:: Starts the level you played at last ::..";
- desc = _("..:: The people who brought this game to you ::..");
- //desc["de"] = "..:: Wer hat den dieses Spiel verbrochen...? ::..";
-
- line1 = _("Credits");
- //line1["de"] = "Credits";
-
- surface_p = Resource::load_sprite("menu/credits_on", "core");
- // surface = Resource::load_sprite("NewButtons/credits_off", "menu");
-
- //surface = Resource::load_sprite("Buttons/play", "menu");
- //surface_p = Resource::load_sprite("Buttons/play_p", "menu");
-}
-
-CreditButton::~CreditButton ()
-{
-}
-
-void
-CreditButton::on_click ()
-{
- std::cout << "Pushing credits screen" << std::endl;
- ScreenManager::instance()->push_screen (Credits::instance(), false);
-}
-
-///////////////////////////////////////////////
-
-OptionsButton::OptionsButton (PingusMenu* menu_)
- : menu(menu_)
-{
- // x_pos = CL_Display::get_width() * 150 / 640; //150;
- // y_pos = CL_Display::get_height() * 330 / 480; //330;
-
- x_pos = CL_Display::get_width() * 516 / 640; //150;
- y_pos = CL_Display::get_height() * 113 / 480; //330;
-
- desc = _("..:: Takes you to the options menu ::..");
- // desc["de"] = "..:: Einstellungen und Mogeleien ::..";
-
- line1 = _("Options");
- //line1["de"] = "Einstellungen";
-
- // surface = Resource::load_sprite("NewButtons/options_off", "menu");
- surface_p = Resource::load_sprite("menu/options_on", "core");
-
- // surface = Resource::load_sprite("Buttons/options", "menu");
- // surface_p = Resource::load_sprite("Buttons/options_p", "menu");
-}
-
-OptionsButton::~OptionsButton ()
-{
-}
-
-void
-OptionsButton::on_click()
-{
- //option_menu.display();
- //menu->get_manager ()->set_menu (&menu->get_manager ()->optionmenu);
- perr (PINGUS_DEBUG_GUI) << "Option menu currently disabled" << std::endl;
-}
-
-///////////////////////////////////////////////
-
-QuitButton::QuitButton(PingusMenu* m)
- : menu (m)
-{
- // x_pos = CL_Display::get_width() * 500 / 640;
- // y_pos = CL_Display::get_height() * 320 / 480;
-
- x_pos = CL_Display::get_width() * 650 / 800;
- y_pos = CL_Display::get_height() * 370 / 600;
-
- desc = _("..:: Bye, bye ::..");
- //desc["de"] = "..:: Auf Wiedersehen ::..";
-
- line1 = _("Exit");
- //line1["de"] = "Ausgang";
-
- // surface = Resource::load_sprite("Buttons/quit", "menu");
- // surface_p = Resource::load_sprite("Buttons/quit_p", "menu");
-
- // surface = Resource::load_sprite("NewButtons/exit_off", "menu");
- surface_p = Resource::load_sprite("menu/exit_on", "core");
-}
-
-QuitButton::~QuitButton()
-{
-}
-
-void
-QuitButton::on_click()
-{
- menu->get_manager ()->show_exit_menu ();
-}
-
-///////////////////////////////////////////////
-
-LoadButton::LoadButton()
-{
- x_pos = CL_Display::get_width() * 400 / 800;
- y_pos = CL_Display::get_height() * 500 / 600;
-
- //surface = Resource::load_sprite("menu/load", "core");
- surface_p = Resource::load_sprite("menu/load_p", "core");
-}
-
-LoadButton::~LoadButton()
-{
-}
-
-void LoadButton::on_click()
-{
- /* std::string levelfile;
- levelfile = file.select(pXXXus_datadir, "*.pingus");
- if (!levelfile.empty()) {
- PingusGame game;
- game.start(levelfile);
- }*/
-}
-
-EditorButton::EditorButton (PingusMenu* menu_)
- : menu(menu_)
-{
- x_pos = CL_Display::get_width() * 150 / 800;
- y_pos = CL_Display::get_height() * 370 / 600;
-
- desc = _("..:: Launch the level editor ::..");
- //desc["de"] = "..:: Den Level Editor starten ::..";
-
- line1 = _("Create a");
- line2 = _("Level");
-
- //line1["de"] = "Level";
- //line2["de"] = "Editor";
-
- // surface = Resource::load_sprite("Buttons/editor", "menu");
- // surface_p = Resource::load_sprite("Buttons/editor_p", "menu");
-
- surface_p = Resource::load_sprite("menu/create_on", "core");
-}
-
-EditorButton::~EditorButton ()
-{
-
-}
-
-void
-EditorButton::load_level (const std::string& str)
-{
- Editor::instance ()->load_level (str);
-}
-
-void
-EditorButton::on_click()
-{
- ScreenManager::instance()->push_screen (Editor::instance(), false);
-}
-
-StoryButton::StoryButton (PingusMenu* menu_)
- : menu(menu_)
-{
- x_pos = CL_Display::get_width() * 400 / 800;
- y_pos = CL_Display::get_height() * 370 / 600;
-
- desc = _("..:: Start the game ::..");
- line1 = _("Start");
- surface_p = Resource::load_sprite("menu/play_on", "core");
-}
-
-StoryButton::~StoryButton () {}
-
-void
-StoryButton::on_click ()
-{
- Sound::PingusSound::play_sound ("letsgo");
-
- bool story_seen = false;
- StatManager::instance()->get_bool("story-seen", story_seen);
-
- if (!story_seen)
- {
- ScreenManager::instance()->push_screen(new StoryScreen(Story::intro),
true);
- }
- else
- {
-
ScreenManager::instance()->push_screen(WorldMapNS::WorldMapManager::instance
());
- }
-}
-
-ThemeButton::ThemeButton (PingusMenu* menu_)
- : menu(menu_)
-{
- x_pos = CL_Display::get_width() * 321 / 640;
- y_pos = CL_Display::get_height() * 100 / 480;
-
- desc = _("..:: Start a contrib level ::..");
-
- line1 = _("Contrib");
- surface_p = Resource::load_sprite("menu/play_on", "core");
-}
-
-void
-ThemeButton::on_click ()
-{
- Sound::PingusSound::play_sound ("letsgo");
-
-#ifdef CLANLIB_0_6
- ThemeSelector theme_selector;
- theme_selector.display();
-#endif
-}
-
-#if 0
-MultiplayerButton::MultiplayerButton (PingusMenu* menu_)
- : menu(menu_)
-{
- x_pos = CL_Display::get_width() * 320 / 640;
- y_pos = CL_Display::get_height() * 369 / 480;
-
- desc = _("..:: Multiplayer Modes... experimental stuff ::..");
-
- line1 = _("Multi");
-
- surface_p = Resource::load_sprite("menu/multi_on", "core");
-}
-
-MultiplayerButton::~MultiplayerButton ()
-{
-}
-
-void
-MultiplayerButton::on_click ()
-{
- multiplayer_config.display ();
-}
-#endif
-
} // namespace Pingus
/* EOF */
Modified: trunk/src/menu_button.hxx
===================================================================
--- trunk/src/menu_button.hxx 2004-06-24 16:41:28 UTC (rev 2343)
+++ trunk/src/menu_button.hxx 2004-06-24 19:01:01 UTC (rev 2344)
@@ -41,13 +41,16 @@
int y_pos;
std::string desc;
- std::string line1;
- std::string line2;
+ std::string text;
bool mouse_over;
bool pressed;
+ CL_Signal_v0 click;
+
public:
+ SurfaceButton(const CL_Point& pos, const CL_Sprite& sprite,
+ const std::string& text, const std::string& desc);
SurfaceButton();
virtual ~SurfaceButton();
@@ -63,128 +66,13 @@
void on_primary_button_click (int x, int y) { on_click (); UNUSED_ARG(x);
UNUSED_ARG(y); }
- virtual void on_click () =0;
-
+ virtual void on_click ();
+ CL_Signal_v0& sig_click() { return click; }
private:
SurfaceButton (const SurfaceButton&);
SurfaceButton& operator= (const SurfaceButton&);
};
-class CreditButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-public:
- CreditButton(PingusMenu* menu);
- virtual ~CreditButton();
- void on_click();
-
-private:
- CreditButton (const CreditButton&);
- CreditButton& operator= (const CreditButton&);
-};
-
-class OptionsButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-public:
- OptionsButton(PingusMenu* menu);
- virtual ~OptionsButton();
- void on_click();
-
-private:
- OptionsButton (const OptionsButton&);
- OptionsButton& operator= (const OptionsButton&);
-};
-
-class QuitButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-public:
- QuitButton(PingusMenu*);
- virtual ~QuitButton();
- void on_click();
-
-private:
- QuitButton (const QuitButton&);
- QuitButton& operator= (const QuitButton&);
-};
-
-class LoadButton : public SurfaceButton
-{
-public:
- LoadButton();
- virtual ~LoadButton();
- void on_click();
-
-private:
- LoadButton (const LoadButton&);
- LoadButton& operator= (const LoadButton&);
-};
-
-class EditorButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-
-public:
- EditorButton( PingusMenu* menu);
- virtual ~EditorButton();
-
- void on_click();
- void load_level(const std::string& str);
-
-private:
- EditorButton (const EditorButton&);
- EditorButton& operator= (const EditorButton&);
-};
-
-class StoryButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-public:
- StoryButton(PingusMenu* menu);
- ~StoryButton();
- void on_click();
-
-private:
- StoryButton (const StoryButton&);
- StoryButton& operator= (const StoryButton&);
-};
-
-class ThemeButton : public SurfaceButton
-{
-private:
- PingusMenu* menu;
-public:
- ThemeButton(PingusMenu* menu);
- void on_click();
-
-private:
- ThemeButton (const ThemeButton&);
- ThemeButton& operator= (const ThemeButton&);
-};
-
-#if 0
-class MultiplayerButton : public SurfaceButton
-{
-private:
- MultiplayerConfig multiplayer_config;
- PingusMenu* menu;
-public:
- MultiplayerButton(PingusMenu* menu);
- virtual ~MultiplayerButton();
- void on_click();
-
-private:
- MultiplayerButton (const MultiplayerButton&);
- MultiplayerButton& operator= (const MultiplayerButton&);
-};
-#endif
-
} // namespace Pingus
#endif
Modified: trunk/src/pingus_menu.cxx
===================================================================
--- trunk/src/pingus_menu.cxx 2004-06-24 16:41:28 UTC (rev 2343)
+++ trunk/src/pingus_menu.cxx 2004-06-24 19:01:01 UTC (rev 2344)
@@ -19,14 +19,24 @@
#include <ClanLib/Display/display.h>
#include <config.h>
+#include "gettext.h"
#include "menu_button.hxx"
#include "resource.hxx"
#include "debug.hxx"
+#include "sound/sound.hxx"
+#include "stat_manager.hxx"
+#include "story_screen.hxx"
+#include "story.hxx"
+#include "editor/editor.hxx"
+#include "worldmap/manager.hxx"
+#include "gui/screen_manager.hxx"
#include "pingus_menu_manager.hxx"
#include "gui/gui_manager.hxx"
namespace Pingus {
+using EditorNS::Editor;
+
PingusMenu::PingusMenu (PingusMenuManager* m)
: PingusSubMenu (m)
{
@@ -38,21 +48,35 @@
{
if (!is_init)
{
- //pout << "PingusMenu::init ()" << std::endl;
- //event_enabled = true;
is_init = true;
background = Resource::load_sprite("misc/logo", "core");
- //gui_manager->add(new OptionsButton(this));
- /*if (game_finished)
- gui_manager->add(new CreditButton(this));*/
- //gui_manager->add(new MultiplayerButton(this));
- //gui_manager->add(new ThemeButton(this));
+ SurfaceButton* editor_button = new
SurfaceButton(CL_Point(CL_Display::get_width() * 150 / 800,
+
CL_Display::get_height() * 370 / 600),
+
Resource::load_sprite("menu/create_on", "core"),
+ _("Create a\nLevel"),
+ _("..:: Launch the
level editor ::.."));
- gui_manager->add(new QuitButton(this));
- gui_manager->add(new StoryButton(this));
- gui_manager->add(new EditorButton (this));
+ SurfaceButton* start_button = new
SurfaceButton(CL_Point(CL_Display::get_width() * 400 / 800,
+
CL_Display::get_height() * 370 / 600),
+
Resource::load_sprite("menu/play_on", "core"),
+ _("Start"),
+ _("..:: Start the game
::.."));
+
+ SurfaceButton* quit_button = new
SurfaceButton(CL_Point(CL_Display::get_width() * 650 / 800,
+
CL_Display::get_height() * 370 / 600),
+
Resource::load_sprite("menu/exit_on", "core"),
+ _("Exit"),
+ _("..:: Bye, bye ::.."));
+
+ slots.push_back(editor_button->sig_click().connect(this,
&PingusMenu::do_editor));
+ slots.push_back(start_button->sig_click().connect(this,
&PingusMenu::do_start));
+ slots.push_back(quit_button->sig_click().connect(this,
&PingusMenu::do_quit));
+
+ gui_manager->add(quit_button);
+ gui_manager->add(start_button);
+ gui_manager->add(editor_button);
}
}
@@ -61,6 +85,36 @@
}
void
+PingusMenu::do_quit()
+{
+ get_manager ()->show_exit_menu ();
+}
+
+void
+PingusMenu::do_start()
+{ // Start the story mode
+ Sound::PingusSound::play_sound ("letsgo");
+
+ bool story_seen = false;
+ StatManager::instance()->get_bool("story-seen", story_seen);
+
+ if (!story_seen)
+ {
+ ScreenManager::instance()->push_screen(new StoryScreen(Story::intro),
true);
+ }
+ else
+ {
+
ScreenManager::instance()->push_screen(WorldMapNS::WorldMapManager::instance
());
+ }
+}
+
+void
+PingusMenu::do_editor()
+{
+ ScreenManager::instance()->push_screen (Editor::instance(), false);
+}
+
+void
PingusMenu::on_resize(int w, int h)
{
pout << "Width: " << w << " Height: " << h << std::endl;
Modified: trunk/src/pingus_menu.hxx
===================================================================
--- trunk/src/pingus_menu.hxx 2004-06-24 16:41:28 UTC (rev 2343)
+++ trunk/src/pingus_menu.hxx 2004-06-24 19:01:01 UTC (rev 2344)
@@ -45,15 +45,18 @@
public:
bool is_init;
private:
+ std::vector<CL_Slot> slots;
Input::Controller* controller;
- SurfaceButton * temp_button;
- SurfaceButton * current_button;
CL_Sprite background;
LayerManager layer_manager;
CL_Surface cursor_sur;
void on_resize (int w, int h);
+
+ void do_quit();
+ void do_start();
+ void do_editor();
public:
PingusMenu (PingusMenuManager* m);
~PingusMenu();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] rev 2344 - in trunk/src: . gui input/buttons,
Ingo Ruhnke <=