Commits

Anonymous committed bc348d0

* Ajout affichage des FPS
* Modifications en cours de la GUI ( menu configuration des touches un peu cassé mais utilisable )

Comments (0)

Files changed (9)

 		<Unit filename="src/editoractions.d" />
 		<Unit filename="src/editordialogs.d" />
 		<Unit filename="src/editortools.d" />
+		<Unit filename="src/fps.d" />
 		<Unit filename="src/game.d" />
 		<Unit filename="src/gameconstants.d" />
 		<Unit filename="src/gamemanager.d" />
 
    VOLUME_UP {
       METHOD = key
-      KEYCODE = 43
+      KEYCODE = 280
    }
  ; page up
 
    VOLUME_DOWN {
       METHOD = key
-      KEYCODE = 45
+      KEYCODE = 281
    }
  ; page down
 

src/editortools.d

 	}
 
 	void initTiles() {
+		mTiles ~= Tile( "Environment :", '\0');
 		mTiles ~= Tile( "wall1.png", '#' );
 		mTiles ~= Tile( "wall2.png", '=' );
 		mTiles ~= Tile( "bigwall1_1.png", '1' );
 		mTiles ~= Tile( "brick.png", '*' );
 		mTiles ~= Tile( "fluid_top_full_000001.png", ',' );
 		mTiles ~= Tile( "fluid_000001.png", '~' );
-		mTiles ~= Tile( "", '\0');
+		mTiles ~= Tile( "Doors & keys :", '\0');
 		mTiles ~= Tile( "bluedoor.png", 'b' );
 		mTiles ~= Tile( "greendoor.png", 'g' );
 		mTiles ~= Tile( "reddoor.png", 'r' );
 		mTiles ~= Tile( "bluekey.png", 'B' );
 		mTiles ~= Tile( "greenkey.png", 'G' );
 		mTiles ~= Tile( "redkey.png", 'R' );
-		mTiles ~= Tile( "", '\0');
+		mTiles ~= Tile( "Entities :", '\0');
 		mTiles ~= Tile( "hero_right_000002.png", '@' );
 		mTiles ~= Tile( "princess_000001.png", 'X' );
 		mTiles ~= Tile( "editor_ennemi_h_left.png", '<' );
 		mTiles ~= Tile( "ennemy_c_000001.png", 'u' );
 		mTiles ~= Tile( "boss_icon.png", '&' );
 		mTiles ~= Tile( "save_0.png", 'c' );
-		mTiles ~= Tile( "", '\0');
+		mTiles ~= Tile( "Powerups :", '\0');
 		mTiles ~= Tile( "jump.png", 'j' );
 		mTiles ~= Tile( "doublejump.png", 'J' );
 		mTiles ~= Tile( "shot.png", 's' );
 		mTiles ~= Tile( "powerup_missile.png", 'm' );
 		mTiles ~= Tile( "horizontal_speed.png", 'H' );
 		mTiles ~= Tile( "vertical_speed.png", 'V' );
-		mTiles ~= Tile( "", '\0');
-		mTiles ~= Tile( "delete.png", '\0' );
+		mTiles ~= Tile( "Delete :", '\0');
+		mTiles ~= Tile( "delete.png", '\1' );
 
 		mTilesPanel = GUI.instance.addPanel( 300, 0 );
 		mTilesPanel.setAlign( GUI.Panel.ALIGN.MAX, GUI.Panel.ALIGN.CENTERED );
 		foreach( inout tile; mTiles ) {
-			if( tile.bitmap == "" ) {
+
+			if( tile.mapCode == 0 ) {
+				mTilesPanel.nl();
+				mTilesPanel.addLabel( tile.bitmap );
 				mTilesPanel.nl();
 			}
 			else {
 				mSelectedBitmap = tile.bitmap;
 				mSelectedCode = tile.mapCode;
 
-				if( tile.mapCode != '\0' )
+				if( tile.mapCode != '\1' )
 					mSelectedAction = ActionType.ADD_TILE;
 				else
 					mSelectedAction = ActionType.DELETE_TILE;
+
+module fps;
+
+import textsurface;
+import screen;
+
+class Fps {
+
+	TextSurface mFps;
+
+	this() {
+		mFps = new TextSurface("00");
+	}
+
+	~this() {
+		delete( mFps );
+	}
+
+	void draw() {
+		mFps.setText( std.string.toString(gScreen.getFPS()) );
+		mFps.draw( gScreen.WIDTH - mFps.w, 0 );
+	}
+}

src/gamemanager.d

 import gameconstants;
 import screen;
 import editor;
+import fps;
 
 /// technically : the GamePartManager
 class GameManager {
 
 	GamePart mGamePart;
+	Fps mFps;
 
 	this() {
 		mGamePart = new MainMenu();
+		mFps = new Fps;
 	}
 
 	~this() {
+		delete(mFps);
 	}
 
 	bool update() {
 			default:
 			break;
 		}
+		mFps.draw();
 		gScreen.vsync();
 		return( true );
 	}
 			return( b );
 		}
 
+		TextButton addTextButton( uint width, string caption, ButtonListener listener=null ) {
+
+			TextButton b = addTextButton( caption, "", listener );
+			b.changeWidth( width );
+
+			return( b );
+		}
+
+
 		IconButton addIconButton( string iconFileName, ButtonListener listener=null  ) {
 			IconButton b = new IconButton(this, mXInsert, mYInsert, iconFileName, listener );
 			mButtons ~= b;
 			return( p );
 		}
 
-		Menu addMenu( string[] items ) {
-			Menu m = new Menu( this, mXInsert, mYInsert, items );
+		Menu addMenu( string[] items, uint width=0 ) {
+			Menu m = new Menu( this, mXInsert, mYInsert, items, width );
 			mPanels ~= m;
 			resize( m.width, m.height );
 			return( m );
 
 		private void resize( int w, int h ) {
 
+			int prevW = mW;
+			int prevH = mH;
+
 			bool updateBg = false;
 			if( mXInsert+w > mW-mMargin ) { mW = mXInsert + w + mMargin; updateBg = true; }
 			if( mYInsert+h > mH-mMargin ) { mH = mYInsert + h + mMargin; updateBg = true; }
 			}
 
 			// special case for Panels : make the parent grow accordingly
-			//if( (cast(Panel)this) && (mParent !is null) ) (cast(Panel)mParent).resize( mW, mH );
+			//if( (cast(Panel)this) && (mParent !is null) )
+			//	(cast(Panel)mParent).resize( mW-prevW, mH-prevH );
 
 			move( mX, mY ); // move depending on auto-alignment
 
 		}
 
 		void checkButtons( int x, int y, bool clicked ) {
+
+			// sub-panels
 			foreach( p; mPanels ) {
 				p.checkButtons( x, y , clicked );
 			}
 
-			foreach( b; mButtons ) {
-				if( b.isIn( x, y ) ) {
-					if( !b.highlighted())  {
-						b.highlight(true);
-						if( mHighlighted ) mHighlighted.highlight(false);
-						mHighlighted = b;
+			// buttons and text inputs fields
+			if( clicked ) {
+
+				foreach( b; mButtons ) {
+					if( b.isIn( x, y ) ) {
+						b.notifyListener();
 					}
-					if( clicked ) b.notifyListener();
 				}
-			}
 
-			if( clicked ) {
 				foreach( i, ti; mTextInputs ) {
 					if( ti.isIn(x,y) ) {
 						mTextInputs[mSelectedTextInput].selected = false;
 					}
 				}
 			}
+			else {
+				foreach( b; mButtons ) {
+					if( b.isIn( x, y ) ) {
+						if( !b.highlighted())  {
+							b.highlight(true);
+							if( mHighlighted ) mHighlighted.highlight(false);
+							mHighlighted = b;
+						}
+					}
+				}
+			}
 		}
 
 		void injectKey( ubyte key ) {
 
-			if( key == 9 ) {
+			if( key == 9 && mTextInputs.length > 0) { // TAB
 				mTextInputs[mSelectedTextInput].selected = false;
 				mSelectedTextInput = (mSelectedTextInput+1) % mTextInputs.length;
 				mTextInputs[mSelectedTextInput].selected = true;
 	class Menu: public Panel, ButtonListener {
 
 		TextButton[] mItems;
-		uint mSelectedItem;
+		int mSelectedItem;
 		MenuListener mListener;
+		uint mItemWidth;
 
 		this( Widget parent, int x=0, int y=0 ) {
 			super( parent, x, y );
 		}
 
-		this( Widget parent, int x, int y, string[] items ) {
+		this( Widget parent, int x, int y, string[] items, uint width=0 ) {
 			super( parent, x, y);
+			mItemWidth = width;
 			addItems( items );
 		}
 
 		void addItems( string[] labels ... ) {
 			foreach( label; labels ) {
-				TextButton tb = this.addTextButton( label, "", this );
+				TextButton tb;
+				if( mItemWidth > 0 )
+					tb = this.addTextButton( mItemWidth, label, this );
+				else
+					tb = this.addTextButton( label, "", this );
 				mItems ~= tb;
 				this.nl();
 			}
 		void checkButtons( int x, int y, bool clicked ) {
 			super.checkButtons(x,y,clicked);
 
+			// update the selected item ( potentially changed via mouse input )
+			foreach( i, b; mButtons ) {
+				if( b.highlighted ) mSelectedItem = i;
+			}
+
 			if( gInputManager.isReleased( IMA_UP )) move( -1 );
 
 			if( gInputManager.isReleased( IMA_DOWN )) move( +1 );
 		}
 
 		void move( int dir ) {
-			mSelectedItem = ( mSelectedItem + dir )%(mItems.length);
+			mSelectedItem += dir;
+			if( mSelectedItem < 0) mSelectedItem = mItems.length-1;
+			if( mSelectedItem > mItems.length-1 ) mSelectedItem = 0;
+			//mSelectedItem = ( mSelectedItem + dir )%(mItems.length);
+
 			if( mHighlighted ) mHighlighted.highlight(false);
 			mItems[mSelectedItem].highlight(true);
 			mHighlighted = mItems[mSelectedItem];
 
 		foreach( p; mPanels ) {
 			if( !p.hidden ) {
-				p.checkButtons( mPx, mPy, click );
-				p.injectKey( gInputManager.getKeyDown() );
+				if( (relx || rely) || click )
+					p.checkButtons( mPx, mPy, click );
+				else
+					p.checkButtons( -1, -1, click );
+				p.injectKey( gInputManager.getKeyDown() ); // for text inputs
 				p.render();
 			}
 		}

src/inputconfigurationdialog.d

 import inputactions;
 debug import std.stdio;
 
-class InputConfigurationDialog: GUI.ButtonListener {
+class InputConfigurationDialog: GUI.ButtonListener, GUI.MenuListener {
 
 	GUI.Panel mPanel;
 	GUI.Button mApplyButton;
 	GUI.Button mCancelButton;
 	GUI.Button[] mActionButtons;
 
+	GUI.Menu mActionsMenu;
+	GUI.Panel mDefinitionsPanel;
+
 	InputConfiguration mInputConfig;
 
 	InputDetectDialog mDetect;
 		mPanel = GUI.instance.addPanel(0,0);
 		mPanel.setAlign( GUI.Panel.ALIGN.CENTERED, GUI.Panel.ALIGN.CENTERED );
 
+		string items[];
+		foreach( ia; mInputConfig.mInputActions ) {	items ~= ia.name; }
+		mActionsMenu = mPanel.addMenu( items, 200 );
+		mActionsMenu.setListener(this);
+
+		mDefinitionsPanel = mPanel.addPanel();
+
+		foreach( ia; mInputConfig.mInputActions ) {
+			//mActionButtons ~= b;
+			switch( ia.method ) {
+				case IAM_KEY:
+					mDefinitionsPanel.addLabel( "key: " ~ gInputManager.getKeyName( ia.keycode ) );
+				break;
+				case IAM_BUTTON:
+					mDefinitionsPanel.addLabel( "joy#" ~ std.string.toString(ia.joynum) ~ " button#" ~ std.string.toString(ia.button) );
+				break;
+				case IAM_AXIS:
+					string dir = std.string.toString( ia.dir );
+					mDefinitionsPanel.addLabel( "joy#" ~ std.string.toString(ia.joynum) ~ " axis#" ~ std.string.toString(ia.axis) ~ " dir:" ~ dir );
+				break;
+				default:
+				break;
+			}
+			//mPanel.tab(250);
+			mDefinitionsPanel.nl();
+		}
+
+/*
 		foreach( ia; mInputConfig.mInputActions ) {
 			GUI.TextButton b = mPanel.addTextButton( ia.name, "", this );
 			b.changeWidth(180);
 			}
 			mPanel.nl();
 		}
-
+*/
 		mPanel.nl();
 
 		mApplyButton = mPanel.addTextButton( "Apply", "", this );
 			mDone = true;
 			return;
 		}
-
+		/*
 		foreach( n, button; mActionButtons ) {
 			if( b == button ) {
 				mPanel.hide;
 				mDetect = new InputDetectDialog( mInputConfig.mInputActions[n] );
 			}
 		}
+		*/
+	}
+
+	void onSelectedItem( int item ) {
+		if( item >= 0 ) {
+			mConfiguredAction = item;
+			mDetect = new InputDetectDialog( mInputConfig.mInputActions[item] );
+		}
 	}
 
 }
     int mDelay;
     uint mMilliseconds;
     bool mFullscreen;
+
+	uint mFPS;
+	uint mFPSTime;
+	uint mNbFrames;
 
     this() {
         gScreen = this;
 		}
 	}
 
-	void vsync() {
-
-		SDL_Flip(gScreen.mSurface); //Refresh the screen
-
-		// vsync
-		mDelay = 16 - ( SDL_GetTicks() - mMilliseconds );
-		if( mDelay > 0 ) SDL_Delay( mDelay );
-		mMilliseconds = SDL_GetTicks();
-
+	void vsync() {
+		//SDL_UpdateRect( mSurface, 0, 0, WIDTH, HEIGHT );
+		//SDL_Delay( 1 );
+		SDL_Flip(gScreen.mSurface);
+
+		mDelay = 16 - ( SDL_GetTicks() - mMilliseconds );
+		if( mDelay > 0 ) SDL_Delay( mDelay );
+		mMilliseconds = SDL_GetTicks();
+
+		// FPS management
+		mNbFrames++;
+		uint time = SDL_GetTicks() - mFPSTime;
+		if( time > 1000 ) {
+			mFPS = mNbFrames*1000/time;
+			mNbFrames = 0;
+			mFPSTime = SDL_GetTicks();
+		}
 	}
+
+	uint getFPS() {
+		return( mFPS );
+	}
 
 }
 		foreach( o ; list ) {
 			lists[o.mDrawPriority] ~= o;
 		}
-
+
+		SDL_Rect dest;
 		foreach( l ; lists ) {
 			foreach( o ; l ) {
-				SDL_Rect dest;
 				with( dest ) {
 					x = cast(short)(o.mX - mX);
 					y = cast(short)(o.mY - mY);