Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    570
  • comments
    2427
  • views
    216938

Untitled

Sign in to follow this  
Mushu

120 views

lolz i maek gaem!!1`1

Granted. Its kind of a hack - it injects events directly into the GUI to make the buttons change colors during the 'instructions' phase because I was too lazy to write stuff to do it a more logical way. Granted, you shouldn't be able to see that.

Hur hur hur.
Sign in to follow this  


2 Comments


Recommended Comments

Here's the cleanest code I've ever written*

#include "GUI.h"

#include "SDL_Events.h"
#include "SDL_Window.h"
#include "OGL_Gfx.h"
#include "OGL_Textures.h"
#include "OGL_Font.h"

#include "Log.h"

#include "Button.h"
#include "TextBox.h"
#include "Label.h"

#include <vector>

using namespace pain::sdl;
using namespace pain::ogl;
using namespace pain::gui;
using namespace pain::log;
using namespace pain::core;

struct SimonEvent {};

class ISimonButton :
public IButton,
public HandlerList< SimonEvent >
{
protected:
unsigned long _lightTime;
unsigned long _unlightTime;

public:
USE_HANDLER_LIST( SimonEvent );

void light( DWORD time ) {
// highlight the button
MouseDownEvent mde;
mde.button = BUTTON_LEFT;
mde.x = getX();
mde.y = getY();

IComponent::raiseEvent( mde );

// count down timer
_lightTime = time;
}

void unlight( DWORD time ) {
// do nothing, just set the timer
_unlightTime = time;
}
};

typedef std::vector<ISimonButton*> ComboBreakerType;
ComboBreakerType combolist;
ComboBreakerType::iterator currcombo;
unsigned long combotime = 50000;
unsigned long combountime = 5000;
unsigned long flashtime = 200000;
int startInstructionCount = 3;

template < class GfxAdapter, class Style = Style< GfxAdapter, 0 > >
class SimonButton :
public ISimonButton,
protected Style
{
GfxAdapter* _gfx;

public:
USE_HANDLER_LIST( SimonEvent );
USE_HANDLER_LIST( ButtonEvent );

explicit SimonButton( GfxAdapter* gfx )
: _gfx( gfx )
{}

virtual void render( int rel_x, int rel_y ) {
int x = getX() + rel_x;
int y = getY() + rel_y;
int w = getW();
int h = getH();

_gfx->fillRect( x, y, w, h, _cShadow );
_gfx->fillRect( x+(isPressed() ? _sBorder : 0), y+(isPressed() ? _sBorder : 0), w-_sBorder, h-_sBorder, _cHighlight );
_gfx->fillRect( x+_sBorder, y+_sBorder, w-2*_sBorder, h-2*_sBorder, (isPressed() ? _cHighlight : _cFront ) );
}

virtual void update( unsigned long step ) {
// only operate if we still have lighttime
if ( _lightTime > 0 ) {

// subtract the light time
if ( step >= _lightTime ) {
_lightTime = 0;

// send another event to return the button to normal
MouseUpEvent mue;
mue.button = BUTTON_LEFT;
mue.x = getX();
mue.y = getY();

IComponent::raiseEvent( mue );

// set to the unlight state.
_unlightTime = combountime;
}
else {
_lightTime -= step;

// check to see if the damned thing is still lit.
if ( !isPressed() ) {
// if not, light it

MouseDownEvent mde;
mde.button = BUTTON_LEFT;
mde.x = getX();
mde.y = getY();

IComponent::raiseEvent( mde );

// because of a dirty dirty event code hack (injecting
// events into the GUI results in somewhat undefined
// behavior.
}
}

} else if ( _unlightTime > 0 ) {

// subtract from unlight time
if ( step >= _unlightTime ) {
_unlightTime = 0;

// send a custom event to notify that the animation is done
SimonButton::raiseEvent( SimonEvent() );
}
else {
_unlightTime -= step;
}
}
}
};

static bool running = true;
GfxAdapter gfx;
typedef Style<GfxAdapter, 1> hStyle1;
typedef Style<GfxAdapter, 2> hStyle2;
typedef Style<GfxAdapter, 3> hStyle3;
typedef Style<GfxAdapter, 4> hStyle4;
ISimonButton* buttons[4]; // hack.
SimonButton<GfxAdapter,hStyle1> button1( &gfx

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!