2
0
Эх сурвалжийг харах

Castle interface: improved town scrolling.
Minor changes for future loading-without-restarting.

Michał W. Urbańczyk 16 жил өмнө
parent
commit
ec3b254c83

+ 41 - 4
client/CCastleInterface.cpp

@@ -390,7 +390,7 @@ public:
 	}
 } srthlp ;
 
-CCastleInterface::CCastleInterface(const CGTownInstance * Town)
+CCastleInterface::CCastleInterface(const CGTownInstance * Town, int listPos)
 :hslotup(241,387,0,Town->garrisonHero,this),hslotdown(241,483,1,Town->visitingHero,this)
 {
 	bars = CDefHandler::giveDefEss("TPTHBAR.DEF");
@@ -418,6 +418,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town)
 	townlist = new CTownList(3,pos.x+744,pos.y+414,"IAM014.DEF","IAM015.DEF");//744,526);
 	exit = new AdventureMapButton
 		(CGI->generaltexth->tcommands[8],"",boost::bind(&CCastleInterface::close,this),pos.x+744,pos.y+544,"TSBTNS.DEF",SDLK_RETURN);
+	exit->assignedKeys.insert(SDLK_ESCAPE);
 	split = new AdventureMapButton
 		(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+744,pos.y+382,"TSBTNS.DEF");
 	statusbar = new CStatusBar(pos.x+7,pos.y+555,"TSTATBAR.bmp",732);
@@ -427,8 +428,10 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town)
 	townlist->fun = boost::bind(&CCastleInterface::townChange,this);
 	townlist->genList();
 	townlist->selected = vstd::findPos(townlist->items,Town);
-	if((townlist->selected+1) > townlist->SIZE)
-		townlist->from = townlist->selected -  townlist->SIZE + 2;
+
+	townlist->from = townlist->selected - listPos;
+	amax(townlist->from, 0);
+	amin(townlist->from, townlist->items.size() - townlist->SIZE);
 
 	graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID);
 	exit->bitmapOffset = 4;
@@ -734,8 +737,9 @@ void CCastleInterface::showAll( SDL_Surface * to/*=NULL*/)
 void CCastleInterface::townChange()
 {
 	const CGTownInstance * nt = townlist->items[townlist->selected];
+	int tpos = townlist->selected - townlist->from;
 	LOCPLINT->popIntTotally(this);
-	LOCPLINT->pushInt(new CCastleInterface(nt));
+	LOCPLINT->pushInt(new CCastleInterface(nt, tpos));
 }
 
 void CCastleInterface::show(SDL_Surface * to)
@@ -781,6 +785,7 @@ void CCastleInterface::activate()
 	}
 	hslotdown.activate();
 	hslotup.activate();
+	KeyInterested::activate();
 }
 
 void CCastleInterface::deactivate()
@@ -796,6 +801,7 @@ void CCastleInterface::deactivate()
 	}
 	hslotdown.deactivate();
 	hslotup.deactivate();
+	KeyInterested::deactivate();
 }
 
 void CCastleInterface::addBuilding(int bid)
@@ -963,6 +969,37 @@ void CCastleInterface::enterTavern()
 	LOCPLINT->pushInt(tv);
 }
 
+void CCastleInterface::keyPressed( const SDL_KeyboardEvent & key )
+{
+	if(key.state != SDL_RELEASED) return;
+
+	switch(key.keysym.sym)
+	{
+	case SDLK_UP:
+		if(townlist->selected)
+		{
+			townlist->selected--;
+			townlist->from--;
+			townChange();
+		}
+		break;
+	case SDLK_DOWN:
+		if(townlist->selected < townlist->items.size() - 1)
+		{
+			townlist->selected++;
+			townlist->from++;
+			townChange();
+		}
+		break;
+	case SDLK_SPACE:
+		if(town->visitingHero && town->garrisonHero)
+		{
+			LOCPLINT->cb->swapGarrisonHero(town);
+		}
+		break;
+	}
+}
+
 void CHallInterface::CBuildingBox::hover(bool on)
 {
 	Hoverable::hover(on);

+ 4 - 2
client/CCastleInterface.h

@@ -68,7 +68,7 @@ public:
 	~CHeroGSlot(); //d-tor
 };
 
-class CCastleInterface : public CWindowWithGarrison
+class CCastleInterface : public CWindowWithGarrison, public KeyInterested
 {
 public:
 	SDL_Rect pos; //why not inherit this member from CIntObject ?
@@ -95,9 +95,11 @@ public:
 
 	std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
 
-	CCastleInterface(const CGTownInstance * Town); //c-tor
+	CCastleInterface(const CGTownInstance * Town, int listPos = 1); //c-tor
 	~CCastleInterface(); //d-tor
+
 	void townChange();
+	void keyPressed(const SDL_KeyboardEvent & key);
 	void show(SDL_Surface * to);
 	void showAll(SDL_Surface * to);
 	void buildingClicked(int building);

+ 13 - 0
client/CMT.cpp

@@ -321,12 +321,25 @@ void processCommand(const std::string &message, CClient *&client)
 		readed >> fname;
 		client->save(fname);
 	}
+	else if(cn=="list")
+	{
+		if(CPG)
+			for(int i = 0; i < CPG->ourScenSel->mapsel.ourGames.size(); i++)
+				tlog0 << i << ".\t" << CPG->ourScenSel->mapsel.ourGames[i]->filename << std::endl;
+	}
 	else if(cn=="load")
 	{
 		std::string fname;
 		readed >> fname;
 		client->load(fname);
 	}
+	else if(cn=="ln")
+	{
+		int num;
+		readed >> num;
+		std::string &name = CPG->ourScenSel->mapsel.ourGames[num]->filename;
+		client->load(name.substr(0, name.size()-6));
+	}
 	else if(cn=="resolution")
 	{
 		std::map<std::pair<int,int>, config::GUIOptions >::iterator j;

+ 1 - 1
client/Client.cpp

@@ -190,9 +190,9 @@ void CClient::load( const std::string & fname )
 	close(); //kill server
 	tlog0 <<"Sent kill signal to the server: "<<tmh.getDif()<<std::endl;
 
-	VLC->clear(); //delete old handlers
 	delete CGI->mh;
 	delete CGI->state;
+	VLC->clear(); //delete old handlers
 
 
 	for(std::map<ui8,CGameInterface *>::iterator i = playerint.begin(); i!=playerint.end(); i++)

+ 4 - 0
lib/map.cpp

@@ -598,6 +598,10 @@ Mapa::Mapa()
 }
 Mapa::~Mapa()
 {
+	//for(int i=0; i < defy.size(); i++)
+	//	if(defy[i]->serial < 0) //def not present in the main vector in defobjinfo
+	//		delete defy[i];
+
 	if(terrain)
 	{
 		for (int ii=0;ii<width;ii++)

+ 0 - 3
mapHandler.cpp

@@ -1509,9 +1509,6 @@ CMapHandler::~CMapHandler()
 	delete fullHide;
 	delete partialHide;
 
-	for(int i=0; i < map->defy.size(); i++)
-		delete map->defy[i];
-
 	for(int i=0; i < roadDefs.size(); i++)
 		delete roadDefs[i];