mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
* added fast graphical cursor :)
* building structures should work
This commit is contained in:
parent
e5a064f36b
commit
bfad10a8e4
@ -510,7 +510,9 @@ void CCastleInterface::deactivate()
|
||||
void CCastleInterface::addBuilding(int bid)
|
||||
{
|
||||
//TODO: lepiej by bylo tylko dodawac co trzeba pamietajac o grupach
|
||||
deactivate();
|
||||
recreateBuildings();
|
||||
activate();
|
||||
}
|
||||
|
||||
void CCastleInterface::removeBuilding(int bid)
|
||||
@ -916,12 +918,12 @@ void CHallInterface::CBuildWindow::deactivate()
|
||||
}
|
||||
void CHallInterface::CBuildWindow::Buy()
|
||||
{
|
||||
LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid);
|
||||
deactivate();
|
||||
delete this;
|
||||
delete LOCPLINT->castleInt->hallInt;
|
||||
LOCPLINT->castleInt->hallInt = NULL;
|
||||
LOCPLINT->castleInt->activate();
|
||||
LOCPLINT->cb->buildBuilding(LOCPLINT->castleInt->town,bid);
|
||||
delete this;
|
||||
delete LOCPLINT->castleInt->hallInt;
|
||||
LOCPLINT->castleInt->showAll();
|
||||
}
|
||||
void CHallInterface::CBuildWindow::close()
|
||||
|
@ -1,237 +1,51 @@
|
||||
#include "stdafx.h"
|
||||
#include "CCursorHandler.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "SDL_framerate.h"
|
||||
#include "hch/CLodHandler.h"
|
||||
#include "hch/CDefHandler.h"
|
||||
|
||||
extern SDL_Surface * screen;
|
||||
|
||||
/* Creates a new mouse cursor from an XPM */
|
||||
|
||||
|
||||
/* XPM */
|
||||
static const char *arrow[] = { //no cursor mode
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"X c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
|
||||
/* XPM */
|
||||
static const char *arrow2[] = { //normal cursor
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"X c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static SDL_Cursor *init_system_cursor(const char *image[])
|
||||
{
|
||||
int i, row, col;
|
||||
Uint8 data[4*32];
|
||||
Uint8 mask[4*32];
|
||||
int hot_x, hot_y;
|
||||
|
||||
i = -1;
|
||||
for ( row=0; row<32; ++row ) {
|
||||
for ( col=0; col<32; ++col ) {
|
||||
if ( col % 8 ) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (image[4+row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
//k[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
}
|
||||
|
||||
//int cursorHandlerFunc(void * cursorHandler)
|
||||
//{
|
||||
// FPSmanager * cursorFramerateKeeper = new FPSmanager;
|
||||
// SDL_initFramerate(cursorFramerateKeeper);
|
||||
// SDL_setFramerate(cursorFramerateKeeper, 200);
|
||||
//
|
||||
// CCursorHandler * ch = (CCursorHandler *) cursorHandler;
|
||||
// while(true)
|
||||
// {
|
||||
// if(ch->xbef!=-1 && ch->ybef!=-1) //restore surface under cursor
|
||||
// {
|
||||
// blitAtWR(ch->behindCur, ch->xbef, ch->ybef);
|
||||
// }
|
||||
// ch->xbef = ch->xpos;
|
||||
// ch->ybef = ch->ypos;
|
||||
// //prepare part of surface to restore
|
||||
// SDL_BlitSurface(screen, &genRect(32, 32, ch->xpos, ch->ypos), ch->behindCur, NULL);
|
||||
// CSDL_Ext::update(ch->behindCur);
|
||||
//
|
||||
// //blit cursor
|
||||
// if(ch->curVisible)
|
||||
// {
|
||||
// switch(ch->mode)
|
||||
// {
|
||||
// case 0:
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// case 1:
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// case 2:
|
||||
// {
|
||||
// blitAtWR(ch->deflt->ourImages[ch->number].bitmap, ch->xpos, ch->ypos);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// SDL_framerateDelay(cursorFramerateKeeper);
|
||||
// //SDL_Delay(5); //to avoid great usage of CPU
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
void CCursorHandler::initCursor()
|
||||
{
|
||||
//#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
// int rmask = 0xff000000;
|
||||
// int gmask = 0x00ff0000;
|
||||
// int bmask = 0x0000ff00;
|
||||
// int amask = 0x000000ff;
|
||||
//#else
|
||||
// int rmask = 0x000000ff;
|
||||
// int gmask = 0x0000ff00;
|
||||
// int bmask = 0x00ff0000;
|
||||
// int amask = 0xff000000;
|
||||
//#endif
|
||||
// curVisible = true;
|
||||
// xpos = ypos = 0;
|
||||
// behindCur = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, rmask, gmask, bmask, amask);
|
||||
// xbef = ybef = 0;
|
||||
// adventure = CDefHandler::giveDef("CRADVNTR.DEF");
|
||||
// combat = CDefHandler::giveDef("CRCOMBAT.DEF");
|
||||
// deflt = CDefHandler::giveDef("CRDEFLT.DEF");
|
||||
// spell = CDefHandler::giveDef("CRSPELL.DEF");
|
||||
// //SDL_SetCursor(init_system_cursor(arrow));
|
||||
// //SDL_Thread * myth = SDL_CreateThread(&cursorHandlerFunc, this);
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
int rmask = 0xff000000;
|
||||
int gmask = 0x00ff0000;
|
||||
int bmask = 0x0000ff00;
|
||||
int amask = 0x000000ff;
|
||||
#else
|
||||
int rmask = 0x000000ff;
|
||||
int gmask = 0x0000ff00;
|
||||
int bmask = 0x00ff0000;
|
||||
int amask = 0xff000000;
|
||||
#endif
|
||||
mode = number = xpos = ypos = 0;
|
||||
help = CSDL_Ext::newSurface(32,32);
|
||||
cursors.push_back(CDefHandler::giveDef("CRADVNTR.DEF"));
|
||||
cursors.push_back(CDefHandler::giveDef("CRCOMBAT.DEF"));
|
||||
cursors.push_back(CDefHandler::giveDef("CRDEFLT.DEF"));
|
||||
cursors.push_back(CDefHandler::giveDef("CRSPELL.DEF"));
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
void CCursorHandler::changeGraphic(int type, int no)
|
||||
{
|
||||
//mode = type;
|
||||
//number = no;
|
||||
mode = type;
|
||||
number = no;
|
||||
}
|
||||
|
||||
void CCursorHandler::cursorMove(int x, int y)
|
||||
{
|
||||
//xbef = xpos;
|
||||
//ybef = ypos;
|
||||
//xpos = x;
|
||||
//ypos = y;
|
||||
xpos = x;
|
||||
ypos = y;
|
||||
}
|
||||
|
||||
void CCursorHandler::hardwareCursor()
|
||||
void CCursorHandler::draw1()
|
||||
{
|
||||
//curVisible = false;
|
||||
//SDL_SetCursor(init_system_cursor(arrow2));
|
||||
SDL_BlitSurface(screen,&genRect(32,32,xpos,ypos),help,&genRect(32,32,0,0));
|
||||
blitAt(cursors[mode]->ourImages[number].bitmap,xpos,ypos);
|
||||
}
|
||||
|
||||
void CCursorHandler::hideCursor()
|
||||
void CCursorHandler::draw2()
|
||||
{
|
||||
//curVisible = false;
|
||||
//SDL_SetCursor(init_system_cursor(arrow));
|
||||
}
|
||||
|
||||
void CCursorHandler::showGraphicCursor()
|
||||
{
|
||||
//curVisible = true;
|
||||
//SDL_SetCursor(init_system_cursor(arrow));
|
||||
//changeGraphic(0, 0);
|
||||
blitAt(help,xpos,ypos);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#ifndef CCURSORHANDLER_H
|
||||
#define CCURSORHANDLER_H
|
||||
|
||||
#include "global.h"
|
||||
#include <vector>
|
||||
struct SDL_Thread;
|
||||
class CDefHandler;
|
||||
struct SDL_Surface;
|
||||
@ -8,21 +9,16 @@ struct SDL_Surface;
|
||||
class CCursorHandler //handles cursor
|
||||
{
|
||||
public:
|
||||
SDL_Thread * myThread; //thread that updates cursor
|
||||
bool curVisible; //true if cursor is visible
|
||||
int mode, number;
|
||||
SDL_Surface * behindCur;
|
||||
int xbef, ybef; //position of cursor after last move (to restore background)
|
||||
SDL_Surface * help;
|
||||
|
||||
CDefHandler * adventure, * combat, * deflt, * spell; //read - only
|
||||
int xpos, ypos; //position of cursor - read only
|
||||
std::vector<CDefHandler*> cursors;
|
||||
int xpos, ypos; //position of cursor
|
||||
void initCursor(); //inits cursorHandler
|
||||
void showGraphicCursor(); //shows default graphic cursor
|
||||
void cursorMove(int x, int y); //change cursor's positions to (x, y)
|
||||
void changeGraphic(int type, int no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3)
|
||||
void hideCursor(); //no cursor will be visible
|
||||
void hardwareCursor(); // returns to hardware cursor mode
|
||||
friend int cursorHandlerFunc(void * cursorHandler);
|
||||
void draw1();
|
||||
void draw2();
|
||||
};
|
||||
|
||||
|
||||
|
@ -131,7 +131,7 @@ void CGameState::apply(IPack * pack)
|
||||
case 104:
|
||||
{
|
||||
SetResources *sr = static_cast<SetResources*>(pack);
|
||||
for(int i=0;sr->res.size();i++)
|
||||
for(int i=0;i<sr->res.size();i++)
|
||||
players[sr->player].resources[i] = sr->res[i];
|
||||
break;
|
||||
}
|
||||
|
9
CMT.cpp
9
CMT.cpp
@ -89,8 +89,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//audio initialized
|
||||
cgi->consoleh = new CConsoleHandler;
|
||||
cgi->mush = mush;
|
||||
cgi->curh = new CCursorHandler;
|
||||
THC std::cout<<"\tInitializing sound and cursor: "<<pomtime.getDif()<<std::endl;
|
||||
THC std::cout<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
|
||||
THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
|
||||
CDefHandler::Spriteh = cgi->spriteh = new CLodHandler();
|
||||
cgi->spriteh->init("Data\\H3sprite.lod","Sprites");
|
||||
@ -112,8 +111,10 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
//cgi->curh->initCursor();
|
||||
//cgi->curh->showGraphicCursor();
|
||||
pomtime.getDif();
|
||||
cgi->screenh = new CScreenHandler;
|
||||
cgi->screenh->initScreen();
|
||||
cgi->curh = new CCursorHandler;
|
||||
cgi->curh->initCursor();
|
||||
//cgi->screenh = new CScreenHandler;
|
||||
//cgi->screenh->initScreen();
|
||||
THC std::cout<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
CAbilityHandler * abilh = new CAbilityHandler;
|
||||
|
@ -957,7 +957,7 @@ void CPlayerInterface::yourTurn()
|
||||
//initializing framerate keeper
|
||||
mainFPSmng = new FPSmanager;
|
||||
SDL_initFramerate(mainFPSmng);
|
||||
SDL_setFramerate(mainFPSmng, 24);
|
||||
SDL_setFramerate(mainFPSmng, 48);
|
||||
SDL_Event sEvent;
|
||||
//framerate keeper initialized
|
||||
timeHandler th;
|
||||
@ -993,7 +993,7 @@ void CPlayerInterface::yourTurn()
|
||||
// }
|
||||
//}
|
||||
//water tiles updated
|
||||
CGI->screenh->updateScreen();
|
||||
//CGI->screenh->updateScreen();
|
||||
|
||||
pim->lock();
|
||||
|
||||
@ -1016,7 +1016,7 @@ void CPlayerInterface::yourTurn()
|
||||
if (!castleInt) //stuff for advMapInt
|
||||
{
|
||||
++LOCPLINT->adventureInt->animValHitCount; //for animations
|
||||
if(LOCPLINT->adventureInt->animValHitCount == 4)
|
||||
if(LOCPLINT->adventureInt->animValHitCount == 8)
|
||||
{
|
||||
LOCPLINT->adventureInt->animValHitCount = 0;
|
||||
++animVal;
|
||||
@ -1074,9 +1074,9 @@ void CPlayerInterface::yourTurn()
|
||||
for(int i=0;i<objsToBlit.size();i++)
|
||||
objsToBlit[i]->show();
|
||||
pim->unlock();
|
||||
//SDL_Flip(screen);
|
||||
CGI->curh->draw1();
|
||||
CSDL_Ext::update(screen);
|
||||
SDL_Delay(5); //give time for other apps
|
||||
CGI->curh->draw2();
|
||||
SDL_framerateDelay(mainFPSmng);
|
||||
}
|
||||
adventureInt->hide();
|
||||
@ -1146,7 +1146,6 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
|
||||
//initializing objects and performing first step of move
|
||||
CGHeroInstance * ho = details.ho; //object representing this hero
|
||||
int3 hp = details.src;
|
||||
boost::unique_lock<boost::mutex> un(*pim);
|
||||
if (!details.successful)
|
||||
{
|
||||
ho->moveDir = getDir(details.src,details.dst);
|
||||
@ -1486,7 +1485,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
|
||||
}
|
||||
LOCPLINT->adventureInt->update(); //updating screen
|
||||
CSDL_Ext::update(screen);
|
||||
CGI->screenh->updateScreen();
|
||||
//CGI->screenh->updateScreen();
|
||||
|
||||
++LOCPLINT->adventureInt->animValHitCount; //for animations
|
||||
if(LOCPLINT->adventureInt->animValHitCount == 4)
|
||||
|
BIN
CPreGame.cpp
BIN
CPreGame.cpp
Binary file not shown.
@ -1,45 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "CScreenHandler.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_framerate.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "CCursorHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "hch/CDefHandler.h"
|
||||
|
||||
extern SDL_Surface * screen, * screen2;
|
||||
|
||||
void CScreenHandler::initScreen()
|
||||
{
|
||||
//myth = SDL_CreateThread(&internalScreenFunc, this);
|
||||
}
|
||||
|
||||
void CScreenHandler::updateScreen()
|
||||
{
|
||||
/*blitAt(screen, 0, 0, screen2);
|
||||
switch(CGI->curh->mode)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
blitAt(CGI->curh->adventure->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
blitAt(CGI->curh->combat->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
blitAt(CGI->curh->deflt->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
blitAt(CGI->curh->spell->ourImages[CGI->curh->number].bitmap, CGI->curh->xpos, CGI->curh->ypos, screen2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
CSDL_Ext::update(screen2);*/
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef CSCREENHANDLER_H
|
||||
#define CSCREENHANDLER_H
|
||||
|
||||
struct SDL_Thread;
|
||||
|
||||
class CScreenHandler
|
||||
{
|
||||
private:
|
||||
SDL_Thread * myth;
|
||||
public:
|
||||
void initScreen();
|
||||
void updateScreen();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //CSCREENHANDLER_H
|
@ -357,10 +357,6 @@
|
||||
RelativePath="..\hch\CPreGameTextHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CScreenHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\hch\CSndHandler.cpp"
|
||||
>
|
||||
@ -515,10 +511,6 @@
|
||||
RelativePath="..\hch\CPreGameTextHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\CScreenHandler.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\hch\CSndHandler.h"
|
||||
>
|
||||
|
@ -474,7 +474,7 @@ void CGameHandler::run()
|
||||
newTurn();
|
||||
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
|
||||
{
|
||||
if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0) continue; //players has not towns/castle - loser
|
||||
if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0 || i->first>=PLAYER_LIMIT ) continue; //players has not towns/castle - loser
|
||||
makingTurn = true;
|
||||
gs->currentPlayer = i->first;
|
||||
*connections[i->first] << ui16(100) << i->first;
|
||||
|
Loading…
Reference in New Issue
Block a user