Selaa lähdekoodia

* added a number of key shortcuts
* stack queue will be shown when 'q' is pressed

Michał W. Urbańczyk 17 vuotta sitten
vanhempi
sitoutus
c431577a5e
10 muutettua tiedostoa jossa 123 lisäystä ja 196 poistoa
  1. 18 13
      AdventureMapButton.cpp
  2. 6 6
      AdventureMapButton.h
  3. 34 13
      CAdvmapInterface.cpp
  4. 3 4
      CAdvmapInterface.h
  5. 19 13
      CBattleInterface.cpp
  6. 2 1
      CBattleInterface.h
  7. 9 9
      CCastleInterface.cpp
  8. 8 10
      CHeroWindow.cpp
  9. 23 126
      CPlayerInterface.cpp
  10. 1 1
      CPlayerInterface.h

+ 18 - 13
AdventureMapButton.cpp

@@ -20,16 +20,16 @@ AdventureMapButton::AdventureMapButton ()
 //{
 //	init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, activ);
 //}
-AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, bool activ,  std::vector<std::string> * add, bool playerColoredButton )
+AdventureMapButton::AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y,  const std::string &defName,int key, std::vector<std::string> * add, bool playerColoredButton )
 {
 	std::map<int,std::string> pom;
 	pom[0] = Name;
-	init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, activ);
+	init(Callback, pom, HelpBox, playerColoredButton, defName, add, x, y, key);
 }
 
-AdventureMapButton::AdventureMapButton( const std::map<int,std::string> &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, bool activ/*=false*/, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
+AdventureMapButton::AdventureMapButton( const std::map<int,std::string> &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key, std::vector<std::string> * add /*= NULL*/, bool playerColoredButton /*= false */ )
 {
-	init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, activ);
+	init(Callback, Name, HelpBox, playerColoredButton, defName, add, x, y, key);
 }
 
 void AdventureMapButton::clickLeft (tribool down)
@@ -90,9 +90,15 @@ void AdventureMapButton::activate()
 	KeyInterested::activate();
 }
 
-void AdventureMapButton::keyPressed (const SDL_KeyboardEvent & key)
+void AdventureMapButton::keyPressed(const SDL_KeyboardEvent & key)
 {
-	//TODO: check if it's shortcut
+	if(key.keysym.sym == ourKey)
+	{
+		if(key.state == SDL_PRESSED)
+			clickLeft(true);
+		else
+			clickLeft(false);
+	}
 }
 
 void AdventureMapButton::deactivate()
@@ -105,7 +111,7 @@ void AdventureMapButton::deactivate()
 	KeyInterested::deactivate();
 }
 
-void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ )
+void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key)
 {
 	callback = Callback;
 	blocked = actOnDown = false;
@@ -113,6 +119,7 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
 	abs=true;
 	active=false;
 	ourObj=NULL;
+	ourKey = key;
 	state=0;
 	hoverTexts = Name;
 	helpBox=HelpBox;
@@ -148,8 +155,6 @@ void AdventureMapButton::init(const CFunctionList<void()> &Callback, const std::
 	pos.y=y;
 	pos.w = imgs[curimg][0]->w;
 	pos.h = imgs[curimg][0]->h  -1;
-	if (activ)
-		activate();
 }
 
 void AdventureMapButton::block( bool on )
@@ -195,10 +200,10 @@ void CHighlightableButton::clickLeft( tribool down )
 	}
 } 
 
-CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ )
+CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key )
 {
 	onlyOn = false;
-	init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,activ);
+	init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,key);
 	callback2 = onDeselect;
 }
 void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt)
@@ -206,9 +211,9 @@ void CHighlightableButtonsGroup::addButton(CHighlightableButton* bt)
 	bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
 	buttons.push_back(bt);
 }
-void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect)
+void CHighlightableButtonsGroup::addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect, int key)
 {
-	CHighlightableButton *bt = new CHighlightableButton(OnSelect,0,tooltip,HelpBox,false,defName,0,x,y,0);
+	CHighlightableButton *bt = new CHighlightableButton(OnSelect,0,tooltip,HelpBox,false,defName,0,x,y,key);
 	bt->ID = uid;
 	bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID);
 	bt->onlyOn = true;

+ 6 - 6
AdventureMapButton.h

@@ -8,7 +8,7 @@ class AdventureMapButton
 public:
 	std::map<int,std::string> hoverTexts; //state -> text for statusbar
 	std::string helpBox; //for right-click help
-	char key; //key shortcut
+	int ourKey; //key shortcut
 	CFunctionList<void()> callback;
 	bool colorChange, blocked,
 		actOnDown; //runs when mouse is pressed down over it, not when up
@@ -22,18 +22,18 @@ public:
 	void deactivate(); // makes button inactive (but doesn't delete)
 
 	AdventureMapButton(); //c-tor
-	AdventureMapButton( const std::map<int,std::string> &, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
-	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+	AdventureMapButton( const std::map<int,std::string> &, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
+	AdventureMapButton( const std::string &Name, const std::string &HelpBox, const CFunctionList<void()> &Callback, int x, int y, const std::string &defName, int key=0, std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
 	//AdventureMapButton( std::string Name, std::string HelpBox, boost::function<void()> Callback, int x, int y, std::string defName, bool activ=false,  std::vector<std::string> * add = NULL, bool playerColoredButton = false );//c-tor
 
-	void init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ );
+	void init(const CFunctionList<void()> &Callback, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key );
 };
 
 class CHighlightableButton 
 	: public AdventureMapButton
 {
 public:
-	CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ );
+	CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, int key=0 );
 	bool selected, onlyOn;
 	CFunctionList<void()> callback2; //when disselecting
 	void select(bool on);
@@ -48,7 +48,7 @@ public:
 
 	//void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid);
 	void addButton(CHighlightableButton* bt);//add existing button, it'll be deleted by CHighlightableButtonsGroup destructor
-	void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0); //creates new button
+	void addButton(const std::map<int,std::string> &tooltip, const std::string &HelpBox, const std::string &defName, int x, int y, int uid, const CFunctionList<void()> &OnSelect=0, int key=0); //creates new button
 	CHighlightableButtonsGroup(const CFunctionList2<void(int)> &OnChange);
 	~CHighlightableButtonsGroup();
 	void activate();

+ 34 - 13
CAdvmapInterface.cpp

@@ -308,7 +308,6 @@ void CTerrainRect::activate()
 	ClickableL::activate();
 	ClickableR::activate();
 	Hoverable::activate();
-	KeyInterested::activate();
 	MotionInterested::activate();
 };
 void CTerrainRect::deactivate()
@@ -316,7 +315,6 @@ void CTerrainRect::deactivate()
 	ClickableL::deactivate();
 	ClickableR::deactivate();
 	Hoverable::deactivate();
-	KeyInterested::deactivate();
 	MotionInterested::deactivate();
 };
 void CTerrainRect::clickLeft(tribool down)
@@ -467,7 +465,6 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
 	}
 	CGI->curh->changeGraphic(0,0);
 }
-void CTerrainRect::keyPressed (const SDL_KeyboardEvent & key){}
 void CTerrainRect::hover(bool on)
 {
 	if (!on)
@@ -978,34 +975,34 @@ CAdvMapInt::CAdvMapInt(int Player)
 :player(Player),
 statusbar(7,556),
 kingOverview(CGI->preth->zelp[293].first,CGI->preth->zelp[293].second,
-			 boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", false,NULL,true),
+			 boost::bind(&CAdvMapInt::fshowOverview,this), 679, 196, "IAM002.DEF", SDLK_k, NULL,true),
 
 underground(CGI->preth->zelp[294].first,CGI->preth->zelp[294].second,
-			boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
+			boost::bind(&CAdvMapInt::fswitchLevel,this), 711, 196, "IAM010.DEF", SDLK_u, new std::vector<std::string>(1,std::string("IAM003.DEF")),true),
 
 questlog(CGI->preth->zelp[295].first,CGI->preth->zelp[295].second,
-		 boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", false,NULL,true),
+		 boost::bind(&CAdvMapInt::fshowQuestlog,this), 679, 228, "IAM004.DEF", SDLK_q, NULL,true),
 
 sleepWake(CGI->preth->zelp[296].first,CGI->preth->zelp[296].second,
-		  boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fsleepWake,this), 711, 228, "IAM005.DEF", SDLK_w, NULL,true),
 
 moveHero(CGI->preth->zelp[297].first,CGI->preth->zelp[297].second,
-		  boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fmoveHero,this), 679, 260, "IAM006.DEF", SDLK_m, NULL,true),
 
 spellbook(CGI->preth->zelp[298].first,CGI->preth->zelp[298].second,
-		  boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fshowSpellbok,this), 711, 260, "IAM007.DEF", SDLK_c, NULL,true),
 
 advOptions(CGI->preth->zelp[299].first,CGI->preth->zelp[299].second,
-		  boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fadventureOPtions,this), 679, 292, "IAM008.DEF", SDLK_a, NULL,true),
 
 sysOptions(CGI->preth->zelp[300].first,CGI->preth->zelp[300].second,
-		  boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fsystemOptions,this), 711, 292, "IAM009.DEF", SDLK_o, NULL,true),
 
 nextHero(CGI->preth->zelp[301].first,CGI->preth->zelp[301].second,
-		  boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fnextHero,this), 679, 324, "IAM000.DEF", SDLK_h, NULL,true),
 
 endTurn(CGI->preth->zelp[302].first,CGI->preth->zelp[302].second,
-		  boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", false,NULL,true),
+		  boost::bind(&CAdvMapInt::fendTurn,this), 679, 356, "IAM001.DEF", SDLK_e, NULL,true),
 
 townList(5,&genRect(192,48,747,196),747,196,747,372)
 {
@@ -1130,10 +1127,12 @@ void CAdvMapInt::activate()
 	heroList.activate();
 	townList.activate();
 	terrain.activate();
+	KeyInterested::activate();
 	show();
 }
 void CAdvMapInt::deactivate()
 {
+	KeyInterested::deactivate();
 	if(subInt == heroWindow)
 	{
 		heroWindow->deactivate();
@@ -1282,6 +1281,28 @@ void CAdvMapInt::centerOn(int3 on)
 	LOCPLINT->adventureInt->updateScreen=true;
 	updateMinimap=true;
 }
+void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
+{
+	bool CAdvMapInt::* scrollDir;
+	switch(key.keysym.sym)
+	{
+	case SDLK_UP: 
+		scrollDir = &CAdvMapInt::scrollingUp; 
+		break;
+	case SDLK_LEFT: 
+		scrollDir = &CAdvMapInt::scrollingLeft; 
+		break;
+	case SDLK_RIGHT: 
+		scrollDir = &CAdvMapInt::scrollingRight; 
+		break;
+	case SDLK_DOWN: 
+		scrollDir = &CAdvMapInt::scrollingDown; 
+		break;
+	default: 
+		return;
+	}
+	this->*scrollDir = key.state==SDL_PRESSED;
+}
 void CAdvMapInt::handleRightClick(std::string text, tribool down, CIntObject * client)
 {
 	if (down)

+ 3 - 4
CAdvmapInterface.h

@@ -41,8 +41,7 @@ public:
 	void showTile(const int3 &pos); //removes FoW
 };
 class CTerrainRect
-	:  public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject, public KeyInterested,
-	public MotionInterested
+	:  public ClickableL, public ClickableR, public Hoverable, public MotionInterested
 {
 public:
 	int tilesw, tilesh; //width and height of terrain to blit in tiles
@@ -58,7 +57,6 @@ public:
 	void clickRight(tribool down);
 	void hover(bool on);
 	void mouseMoved (const SDL_MouseMotionEvent & sEvent);
-	void keyPressed (const SDL_KeyboardEvent & key);
 	void show();
 	void showPath();
 	int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position
@@ -99,7 +97,7 @@ public:
 	CDefHandler * getAnim(int mode);
 };
 /*****************************/
-class CAdvMapInt : public CMainInterface //adventure map interface
+class CAdvMapInt : public CMainInterface, public KeyInterested //adventure map interface
 {
 public:
 	CAdvMapInt(int Player);
@@ -171,6 +169,7 @@ public:
 	void centerOn(int3 on);
 	int3 verifyPos(int3 ver);
 	void handleRightClick(std::string text, tribool down, CIntObject * client);
+	void keyPressed(const SDL_KeyboardEvent & key);
 
 
 };

+ 19 - 13
CBattleInterface.cpp

@@ -85,15 +85,15 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	CSDL_Ext::update();
 
 	//preparing buttons and console
-	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", false, NULL, false);
-	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", false, NULL, false);
-	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", false, NULL, false);
-	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", false, NULL, false);
-	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", false, NULL, false);
-	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", false, NULL, false);
-	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", false, NULL, false);
-	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", false, NULL, false);
-	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", false, NULL, false);
+	bOptions = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bOptionsf,this), 3, 561, "icm003.def", SDLK_o);
+	bSurrender = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSurrenderf,this), 54, 561, "icm001.def", SDLK_s);
+	bFlee = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bFleef,this), 105, 561, "icm002.def", SDLK_r);
+	bAutofight  = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bAutofightf,this), 157, 561, "icm004.def", SDLK_a);
+	bSpell = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bSpellf,this), 645, 561, "icm005.def", SDLK_c);
+	bWait = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bWaitf,this), 696, 561, "icm006.def", SDLK_w);
+	bDefence = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bDefencef,this), 747, 561, "icm007.def", SDLK_d);
+	bConsoleUp = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleUpf,this), 624, 561, "ComSlide.def", SDLK_UP);
+	bConsoleDown = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleInterface::bConsoleDownf,this), 624, 580, "ComSlide.def", SDLK_DOWN);
 	bConsoleDown->bitmapOffset = 2;
 	console = new CBattleConsole();
 	console->pos.x = 211;
@@ -249,6 +249,7 @@ void CBattleInterface::setPrintMouseShadow(bool set)
 
 void CBattleInterface::activate()
 {
+	KeyInterested::activate();
 	MotionInterested::activate();
 	subInt = NULL;
 	bOptions->activate();
@@ -272,6 +273,7 @@ void CBattleInterface::activate()
 
 void CBattleInterface::deactivate()
 {
+	KeyInterested::deactivate();
 	MotionInterested::deactivate();
 	bOptions->deactivate();
 	bSurrender->deactivate();
@@ -463,7 +465,11 @@ void CBattleInterface::show(SDL_Surface * to)
 		resWindow->show(to);
 	}
 }
-
+void CBattleInterface::keyPressed(const SDL_KeyboardEvent & key)
+{
+	if(key.keysym.sym == SDLK_q)
+		showStackQueue = key.state==SDL_PRESSED;
+}
 void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
 {
 	if(activeStack>=0 && !spellDestSelectMode)
@@ -1864,7 +1870,7 @@ CBattleReslutWindow::CBattleReslutWindow(const BattleResult &br, const SDL_Rect
 	SDL_Surface * pom = SDL_ConvertSurface(background, screen->format, screen->flags);
 	SDL_FreeSurface(background);
 	background = pom;
-	exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", false, NULL, false);
+	exit = new AdventureMapButton (std::string(), std::string(), boost::bind(&CBattleReslutWindow::bExitf,this), 549, 524, "iok6432.def", SDLK_RETURN);
 
 	if(br.winner==0) //attacker won
 	{
@@ -2041,9 +2047,9 @@ CBattleOptionsWindow::CBattleOptionsWindow(const SDL_Rect & position, CBattleInt
 	animSpeeds->select(owner->getAnimSpeed(), 1);
 	animSpeeds->onChange = boost::bind(&CBattleInterface::setAnimSpeed, owner, _1);
 
-	setToDefault = new AdventureMapButton (CGI->preth->zelp[392].first, CGI->preth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def", false, NULL, false);
+	setToDefault = new AdventureMapButton (CGI->preth->zelp[392].first, CGI->preth->zelp[392].second, boost::bind(&CBattleOptionsWindow::bDefaultf,this), 405, 443, "codefaul.def");
 	std::swap(setToDefault->imgs[0][0], setToDefault->imgs[0][1]);
-	exit = new AdventureMapButton (CGI->preth->zelp[393].first, CGI->preth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def", false, NULL, false);
+	exit = new AdventureMapButton (CGI->preth->zelp[393].first, CGI->preth->zelp[393].second, boost::bind(&CBattleOptionsWindow::bExitf,this), 516, 443, "soretrn.def",SDLK_RETURN);
 	std::swap(exit->imgs[0][0], exit->imgs[0][1]);
 
 	//printing texts to background

+ 2 - 1
CBattleInterface.h

@@ -114,7 +114,7 @@ public:
 	void show(SDL_Surface * to = 0);
 };
 
-class CBattleInterface : public CMainInterface, public MotionInterested
+class CBattleInterface : public CMainInterface, public MotionInterested, public KeyInterested
 {
 private:
 	SDL_Surface * background, * menu, * amountBasic, * amountNormal, * cellBorders, * backgroundWithHexes;
@@ -204,6 +204,7 @@ public:
 	void activate();
 	void deactivate();
 	void show(SDL_Surface * to = NULL);
+	void keyPressed(const SDL_KeyboardEvent & key);
 	void mouseMoved(const SDL_MouseMotionEvent &sEvent);
 	bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
 

+ 9 - 9
CCastleInterface.cpp

@@ -357,9 +357,9 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
 
 	townlist = new CTownList(3,&genRect(128,48,744,414),744,414,744,526);
 	exit = new AdventureMapButton
-		(CGI->townh->tcommands[8],"",boost::bind(&CCastleInterface::close,this),744,544,"TSBTNS.DEF",false,NULL,false);
+		(CGI->townh->tcommands[8],"",boost::bind(&CCastleInterface::close,this),744,544,"TSBTNS.DEF",SDLK_RETURN);
 	split = new AdventureMapButton
-		(CGI->townh->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),744,382,"TSBTNS.DEF",false,NULL,false);
+		(CGI->townh->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),744,382,"TSBTNS.DEF");
 	statusbar = new CStatusBar(8,555,"TSTATBAR.bmp",732);
 
 	townlist->fun = boost::bind(&CCastleInterface::townChange,this);
@@ -975,7 +975,7 @@ CHallInterface::CHallInterface(CCastleInterface * owner)
 	bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
 	status = CDefHandler::giveDefEss("TPTHCHK.DEF");
 	exit = new AdventureMapButton
-		(CGI->townh->tcommands[8],"",boost::bind(&CHallInterface::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
+		(CGI->townh->tcommands[8],"",boost::bind(&CHallInterface::close,this),748,556,"TPMAGE1.DEF",SDLK_RETURN);
 
 	//preparing boxes with buildings//
 	boxes.resize(5);
@@ -1243,9 +1243,9 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod
 	if(!mode)
 	{
 		buy = new AdventureMapButton
-			("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",false,NULL,false);
+			("","",boost::bind(&CBuildWindow::Buy,this),pos.x+45,pos.y+446,"IBUY30.DEF",SDLK_RETURN);
 		cancel = new AdventureMapButton
-			("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",false,NULL,false);
+			("","",boost::bind(&CBuildWindow::close,this),pos.x+290,pos.y+445,"ICANCEL.DEF",SDLK_ESCAPE);
 		if(state!=7)
 			buy->state=2;
 	}
@@ -1320,7 +1320,7 @@ CFortScreen::CFortScreen( CCastleInterface * owner )
 {
 	LOCPLINT->curint->subInt = this;
 	bg = NULL;
-	exit = new AdventureMapButton(CGI->townh->tcommands[8],"",boost::bind(&CFortScreen::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
+	exit = new AdventureMapButton(CGI->townh->tcommands[8],"",boost::bind(&CFortScreen::close,this),748,556,"TPMAGE1.DEF",SDLK_RETURN);
 	positions += genRect(126,386,10,22),genRect(126,386,404,22),
 		genRect(126,386,10,155),genRect(126,386,404,155),
 		genRect(126,386,10,288),genRect(126,386,404,288),
@@ -1423,7 +1423,7 @@ void CFortScreen::RecArea::deactivate()
 CMageGuildScreen::CMageGuildScreen(CCastleInterface * owner)
 {
 	bg = BitmapHandler::loadBitmap("TPMAGE.bmp");
-	exit = new AdventureMapButton(CGI->townh->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),748,556,"TPMAGE1.DEF",false,NULL,false);
+	exit = new AdventureMapButton(CGI->townh->tcommands[8],"",boost::bind(&CMageGuildScreen::close,this),748,556,"TPMAGE1.DEF",SDLK_RETURN);
 	scrolls = CDefHandler::giveDefEss("SPELLSCR.DEF");
 	scrolls2 = CDefHandler::giveDefEss("TPMAGES.DEF");
 	SDL_Surface *view = BitmapHandler::loadBitmap(graphics->guildBgs[owner->town->subID]);
@@ -1561,8 +1561,8 @@ CBlacksmithDialog::CBlacksmithDialog(bool possible, int creMachineID, int aid, i
 	pos.h = bmp->h;
 	pos.x = screen->w/2 - pos.w/2;
 	pos.y = screen->h/2 - pos.h/2;
-	buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF");
-	cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF");
+	buy = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 42,pos.y + 312,"IBUY30.DEF",SDLK_RETURN);
+	cancel = new AdventureMapButton("","",boost::bind(&CBlacksmithDialog::close,this),pos.x + 224,pos.y + 312,"ICANCEL.DEF",SDLK_ESCAPE);
 	if(possible)
 		buy->callback += boost::bind(&CCallback::buyArtifact,LOCPLINT->cb,LOCPLINT->cb->getHeroInfo(hid,2),aid);
 	else

+ 8 - 10
CHeroWindow.cpp

@@ -44,22 +44,20 @@ CHeroWindow::CHeroWindow(int playerColor):
 	garInt = NULL;
 	ourBar = new CStatusBar(72, 567, "ADROLLVR.bmp", 660);
 
-	quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(), boost::function<void()>(), 674, 524, "hsbtns.def", false, NULL, false);
-	dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", false, NULL, false);
-	questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", false, NULL, false);
+	quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(), boost::function<void()>(), 674, 524, "hsbtns.def", SDLK_RETURN);
+	dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", SDLK_d);
+	questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", SDLK_q);
 
 	formations = new CHighlightableButtonsGroup(0);
-	formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[23]),CGI->generaltexth->heroscrn[29], "hsbtns6.def",546, 491, 0);
-	formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[24]),CGI->generaltexth->heroscrn[30], "hsbtns7.def",546, 527, 1);
-	//gar1button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[23]), CGI->generaltexth->heroscrn[29], false, "hsbtns6.def" , NULL,546, 491, false);
-	//gar3button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[24]), CGI->generaltexth->heroscrn[30], false,  "hsbtns7.def", NULL, 546, 527, false);
+	formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[23]),CGI->generaltexth->heroscrn[29], "hsbtns6.def",546, 491, 0, 0, SDLK_t);
+	formations->addButton(map_list_of(0,CGI->generaltexth->heroscrn[24]),CGI->generaltexth->heroscrn[30], "hsbtns7.def",546, 527, 1, 0, SDLK_l);
 
 
-	gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, false);
+	gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, SDLK_b);
 	gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
 	boost::algorithm::replace_first(gar4button->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
-	leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false);
-	rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false);
+	leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", SDLK_LEFT);
+	rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", SDLK_RIGHT);
 
 	for(int g=0; g<8; ++g)
 	{

+ 23 - 126
CPlayerInterface.cpp

@@ -496,7 +496,10 @@ CInfoWindow::CInfoWindow(std::string text, int player, int charperline, const st
 	{
 		buttons.push_back(new AdventureMapButton("","",Buttons[i].second,0,0,Buttons[i].first));
 		if(!Buttons[i].second) //if no function, then by default we'll set it to close
+		{
+			buttons[i]->ourKey = SDLK_RETURN;
 			buttons[i]->callback += boost::bind(&CInfoWindow::close,this);
+		}
 	}
 	for(int i=0;i<comps.size();i++)
 	{
@@ -504,7 +507,7 @@ CInfoWindow::CInfoWindow(std::string text, int player, int charperline, const st
 	}
 	CMessage::drawIWindow(this,text,player,charperline);
 }
-CInfoWindow::CInfoWindow()
+CInfoWindow::CInfoWindow() 
 {
 }
 void CInfoWindow::close()
@@ -1712,128 +1715,22 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
 		LOCPLINT->adventureInt->scrollingDown = false;
 	}
 }
-void CPlayerInterface::handleKeyUp(SDL_Event *sEvent)
-{
-	switch (sEvent->key.keysym.sym)
-	{
-	case SDLK_LEFT:
-		{
-			LOCPLINT->adventureInt->scrollingLeft = false;
-			break;
-		}
-	case (SDLK_RIGHT):
-		{
-			LOCPLINT->adventureInt->scrollingRight = false;
-			break;
-		}
-	case (SDLK_UP):
-		{
-			LOCPLINT->adventureInt->scrollingUp = false;
-			break;
-		}
-	case (SDLK_DOWN):
-		{
-			LOCPLINT->adventureInt->scrollingDown = false;
-			break;
-		}
-	case (SDLK_u):
-		{
-			adventureInt->underground.clickLeft(false);
-			break;
-		}
-	case (SDLK_m):
-		{
-			adventureInt->moveHero.clickLeft(false);
-			break;
-		}
-	case (SDLK_e):
-		{
-			adventureInt->endTurn.clickLeft(false);
-			break;
-		}
-	case (SDLK_c):
-		{
-			if( dynamic_cast<CBattleInterface*> (curint) )
-			{
-				dynamic_cast<CBattleInterface*> (curint)->showStackQueue = false;
-			}
-			break;
-		}
-	}
-}
-void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
-{
-	switch (sEvent->key.keysym.sym)
-	{
-	case SDLK_LEFT:
-		{
-			LOCPLINT->adventureInt->scrollingLeft = true;
-			break;
-		}
-	case (SDLK_RIGHT):
-		{
-			LOCPLINT->adventureInt->scrollingRight = true;
-			break;
-		}
-	case (SDLK_UP):
-		{
-			LOCPLINT->adventureInt->scrollingUp = true;
-			break;
-		}
-	case (SDLK_DOWN):
-		{
-			LOCPLINT->adventureInt->scrollingDown = true;
-			break;
-		}
-	case (SDLK_u):
-		{
-			adventureInt->underground.clickLeft(true);
-			break;
-		}
-	case (SDLK_m):
-		{
-			adventureInt->moveHero.clickLeft(true);
-			break;
-		}
-	case (SDLK_e):
-		{
-			adventureInt->endTurn.clickLeft(true);
-			break;
-		}
-	case (SDLK_c):
-		{
-			if( dynamic_cast<CBattleInterface*> (curint) )
-			{
-				dynamic_cast<CBattleInterface*> (curint)->showStackQueue = true;
-			}
-			break;
-		}
-	}
-}
 void CPlayerInterface::handleEvent(SDL_Event *sEvent)
 {
 	current = sEvent;
 
-	if(sEvent->type == SDL_MOUSEMOTION)
+	if (sEvent->type==SDL_KEYDOWN || sEvent->type==SDL_KEYUP)
 	{
-		CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
+		std::list<KeyInterested*> miCopy = keyinterested;
+		for(std::list<KeyInterested*>::iterator i=miCopy.begin(); i != miCopy.end();i++)
+			if(vstd::contains(keyinterested,*i))
+				(**i).keyPressed(sEvent->key);
 	}
-
-	if(sEvent->type==SDL_QUIT)
-		exit(0);
-	else if (sEvent->type==SDL_KEYDOWN)
-	{
-		handleKeyDown(sEvent);
-	} //keydown end
-	else if(sEvent->type==SDL_KEYUP)
-	{
-		handleKeyUp(sEvent);
-	}//keyup end
 	else if(sEvent->type==SDL_MOUSEMOTION)
 	{
+		CGI->curh->cursorMove(sEvent->motion.x, sEvent->motion.y);
 		handleMouseMotion(sEvent);
-	} //mousemotion end
-
+	}
 	else if ((sEvent->type==SDL_MOUSEBUTTONDOWN) && (sEvent->button.button == SDL_BUTTON_LEFT))
 	{
 		std::list<ClickableL*> hlp = lclickable;
@@ -3071,9 +2968,9 @@ CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &C
 		curx += 120;
 	}
 
-	max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF");
-	buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF");
-	cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF");
+	max = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF",SDLK_m);
+	buy = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF",SDLK_RETURN);
+	cancel = new AdventureMapButton("","",boost::bind(&CRecrutationWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF",SDLK_ESCAPE);
 	if(!creatures[0].amount)
 	{
 		max->block(true);
@@ -3104,8 +3001,8 @@ CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner)
 	pos.y = screen->h/2 - bitmap->h/2;
 	pos.w = bitmap->w;
 	pos.h = bitmap->h;
-	ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF");
-	cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF");
+	ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF",SDLK_RETURN);
+	cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF",SDLK_ESCAPE);
 	slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,max,0,true);
 	a1 = max;
 	a2 = 0;
@@ -3306,7 +3203,7 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, int creatureCount, StackState
 				CFunctionList<void()> cfl;
 				cfl = boost::bind(&CCreInfoWindow::deactivate,this);
 				cfl += boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[207],boost::ref(upgResCost),fs[0],fs[1],false,false);
-				upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,cfl,pos.x+76,pos.y+237,"IVIEWCR.DEF");
+				upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,cfl,pos.x+76,pos.y+237,"IVIEWCR.DEF",SDLK_u);
 			}
 			else
 			{
@@ -3326,9 +3223,9 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, int creatureCount, StackState
 			CFunctionList<void()> cfl;
 		        cfl = boost::bind(&CCreInfoWindow::deactivate,this);
 			cfl += boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector<SComponent*>(),fs[0],fs[1],false,false);
-			dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,cfl,pos.x+21,pos.y+237,"IVIEWCR2.DEF");
+			dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,cfl,pos.x+21,pos.y+237,"IVIEWCR2.DEF",SDLK_d);
 		}
-		ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF");
+		ok = new AdventureMapButton("",CGI->preth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF",SDLK_RETURN);
 	}
 	else
 	{
@@ -3446,7 +3343,7 @@ CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<u
 	pos.y = screen->h/2 - bitmap->h/2;
 	pos.w = bitmap->w;
 	pos.h = bitmap->h;
-	ok = new AdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF");
+	ok = new AdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF",SDLK_RETURN);
 
 	//draw window
 	char buf[100], buf2[100];
@@ -3694,7 +3591,7 @@ CMarketplaceWindow::CMarketplaceWindow(int Mode)
 	slider = new CSlider(pos.x+231,pos.y+490,137,boost::bind(&CMarketplaceWindow::sliderMoved,this,_1),0,0);
 	setMode(mode);
 	hLeft = hRight = NULL;
-	ok = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::deactivate,this),pos.x+516,pos.y+520,"IOK6432.DEF");
+	ok = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::deactivate,this),pos.x+516,pos.y+520,"IOK6432.DEF",SDLK_RETURN);
 	ok->callback += boost::bind(&CMarketplaceWindow::clear,this); //clear
 	ok->callback += boost::bind(vstd::delObj<CMarketplaceWindow>,this); //will delete
 	ok->callback += boost::bind(&CMainInterface::activate,LOCPLINT->curint);
@@ -3858,9 +3755,9 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface
 	CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 283, 217, GEOR16, zwykly, background); //spell book animation
 
 	//setting up buttons
-	quitGame = new AdventureMapButton (CGI->preth->zelp[324].first, CGI->preth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", false, NULL, false);
+	quitGame = new AdventureMapButton (CGI->preth->zelp[324].first, CGI->preth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", SDLK_q);
 	std::swap(quitGame->imgs[0][0], quitGame->imgs[0][1]);
-	backToMap = new AdventureMapButton (CGI->preth->zelp[325].first, CGI->preth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", false, NULL, false);
+	backToMap = new AdventureMapButton (CGI->preth->zelp[325].first, CGI->preth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", SDLK_RETURN);
 	std::swap(backToMap->imgs[0][0], backToMap->imgs[0][1]);
 
 	heroMoveSpeed = new CHighlightableButtonsGroup(0);

+ 1 - 1
CPlayerInterface.h

@@ -136,7 +136,7 @@ class KeyInterested : public virtual CIntObject
 {
 public:
 	virtual ~KeyInterested(){};
-	virtual void keyPressed (const SDL_KeyboardEvent & key)=0;
+	virtual void keyPressed(const SDL_KeyboardEvent & key)=0;
 	virtual void activate()=0;
 	virtual void deactivate()=0;
 };