1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

Częściowo zrobione okno wyboru scenariusza.

Uwaga - wersja wczesna, z błędami. Niektórych nawet jestem świadomy.

Poza tym zmiany, które za ten cały czas mi się powprowadzały, a które zostaną bezlitośnie wypunktowane przez Traca.
This commit is contained in:
Michał W. Urbańczyk
2007-06-28 10:47:28 +00:00
parent 0428ea1f86
commit d5b8919bb3
10 changed files with 710 additions and 57 deletions

11
CMT.cpp
View File

@@ -46,7 +46,7 @@ const char * NAME = "VCMI 0.2";
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
SDL_Surface * ekran;
TTF_Font * TNRB16, *TNR, *GEOR13;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX;
int def(FILE *source, FILE *dest, int level, int winBits=15, int memLevel =8)
{
int ret, flush;
@@ -215,6 +215,7 @@ int _tmain(int argc, _TCHAR* argv[])
float i;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0)
{
CPG=NULL;
TTF_Init();
atexit(TTF_Quit);
atexit(SDL_Quit);
@@ -222,6 +223,7 @@ int _tmain(int argc, _TCHAR* argv[])
TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16);
//TNR = TTF_OpenFont("Fonts\\tnr.ttf",10);
GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
//initializing audio
CMusicHandler * mush = new CMusicHandler;
@@ -283,7 +285,10 @@ int _tmain(int argc, _TCHAR* argv[])
CObjectHandler * objh = new CObjectHandler;
objh->loadObjects();
cgi->objh = objh;
CAmbarCendamo * ac = new CAmbarCendamo("9gryf"); //4gryf
std::string mapname;
if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
else mapname = "4gryf";
CAmbarCendamo * ac = new CAmbarCendamo(mapname.c_str()); //4gryf
CMapHeader * mmhh = new CMapHeader(ac->bufor); //czytanie nag��wka
cgi->ac = ac;
THC std::cout<<"Wczytywanie pliku: "<<tmh.getDif()<<std::endl;
@@ -425,7 +430,7 @@ int _tmain(int argc, _TCHAR* argv[])
if(updateScreen)
{
SDL_FillRect(ekran, NULL, SDL_MapRGB(ekran->format, 0, 0, 0));
SDL_Surface * help = mh->terrainRect(xx,yy,25,18,zz);
SDL_Surface * help = mh->terrainRect(xx,yy,25,19,zz);
SDL_BlitSurface(help,NULL,ekran,NULL);
SDL_FreeSurface(help);
SDL_UpdateRect(ekran, 0, 0, ekran->w, ekran->h);

View File

@@ -68,13 +68,13 @@ SDL_Surface * CMessage::drawBox1(int w, int h)
return ret;
}
std::vector<std::string> * CMessage::breakText(std::string text)
std::vector<std::string> * CMessage::breakText(std::string text, int line)
{
std::vector<std::string> * ret = new std::vector<std::string>();
while (text.length()>30)
while (text.length()>line)
{
int whereCut = -1;
for (int i=30; i>0; i--)
for (int i=line; i>0; i--)
{
if (text[i]==' ')
{

View File

@@ -5,28 +5,63 @@
#include "CSemiDefHandler.h"
enum EWindowType {infoOnly, infoOK, yesOrNO};
class CPreGame;
class MapSel;
typedef void(CPreGame::*ttt)();
template <class T=ttt> class CGroup;
template <class T=ttt> class CPoinGroup ;
template <class T=ttt> struct Button
{
struct OverButton
{
int ID;
int type;
SDL_Rect pos;
T fun;
CSemiDefHandler* imgs;
int state;
virtual void show() ;
virtual void press(bool down=true);
};
template <class T=ttt> struct Button: public OverButton
{
T fun;
CGroup<T> * ourGroup;
Button( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CGroup<T>* gr=NULL, int id=-1)
:state(0),selectable(Sel),selected(false),imgs(Imgs),pos(Pos),fun(Fun),ourGroup(gr), type(0), ID(id){};
:fun(Fun),ourGroup(gr){type=0;imgs=Imgs;selectable=Sel;selected=false;state=0;pos=Pos;ID=id;};
Button(){};
bool selectable, selected;
bool highlightable, highlighted;
int state;
int ID;
virtual void hover(bool on=true);
virtual void press(bool down=true);
virtual void select(bool on=true);
CGroup<T> * ourGroup;
};
template<class T=CPreGame> class Slider
{ //
public:
SDL_Rect pos;
Button<void(Slider::*)()> up, down, slider;
int positionsAmnt, capacity;
int whereAreWe;
bool moving;
void(T::*fun)(int);
void clickDown(int x, int y, bool bzgl=true);
void clickUp(int x, int y, bool bzgl=true);
void mMove(int x, int y, bool bzgl=true);
void moveUp();
void moveDown();
void activate(MapSel * ms);
Slider(int x, int y, int h, int amnt, int cap);
void updateSlid();
void handleIt(SDL_Event sev);
};
//template<class T=void(CPreGame::*)(int)>
template<class T=ttt> struct IntBut: public Button<T>
{
public:
int key;
int * what;
IntBut(){type=2;fun=NULL;};
IntBut( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel, int Key, int * What)
: Button(Pos,Fun,Imgs,Sel,gr),key(My),key(Key),what(What){ourGroup=gr;type=2;fun=NULL;};
void set(){*what=key;};
};
template<class T=ttt> struct IntSelBut: public Button<T>
{
public:
@@ -34,7 +69,7 @@ public:
int key;
IntSelBut(){};
IntSelBut( SDL_Rect Pos, T Fun,CSemiDefHandler* Imgs, bool Sel=false, CPoinGroup<T>* gr=NULL, int My=-1)
: Button(Pos,Fun,Imgs,Sel,gr),key(My){ourGroup=gr;};
: Button(Pos,Fun,Imgs,Sel,gr),key(My){ourGroup=gr;type=1;};
void select(bool on=true) {(*this).Button::select(on);ourGroup->setYour(this);}
};
template <class T=ttt> class CPoinGroup :public CGroup<T>
@@ -53,7 +88,7 @@ public:
class CMessage
{
public:
std::vector<std::string> * breakText(std::string text);
static std::vector<std::string> * breakText(std::string text, int line=30);
CSemiDefHandler * piecesOfBox;
SDL_Surface * background;
SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,

View File

@@ -1,9 +1,14 @@
#include "stdafx.h"
#include "CPreGame.h"
#include "SDL.h"
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
#include "boost/algorithm/string.hpp"
//#include "boost/foreach.hpp"
#include "zlib.h"
#include <sstream>
extern SDL_Surface * ekran;
extern SDL_Color tytulowy, tlo, zwykly ;
extern TTF_Font * TNRB16, *TNR, *GEOR13;
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX;
SDL_Rect genRect(int hh, int ww, int xx, int yy);
SDL_Color genRGB(int r, int g, int b, int a=0);
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
@@ -11,8 +16,13 @@ void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=ty
CPreGame * CPG;
void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran);
bool isItIn(const SDL_Rect * rect, int x, int y);
template <class T> void Button<T>::press(bool down)
namespace fs = boost::filesystem;
void OverButton::show()
{
blitAt(imgs->ourImages[0].bitmap,pos.x,pos.y);
updateRect(&pos);
}
void OverButton::press(bool down)
{
int i;
if (down) state=i=1;
@@ -43,9 +53,510 @@ template <class T> void Button<T>::select(bool on)
ourGroup->selected =this;
}
}
//void Slider::clickDown(int x, int y, bool bzgl=true);
//void Slider::clickUp(int x, int y, bool bzgl=true);
//void Slider::mMove(int x, int y, bool bzgl=true);
void Slider<>::updateSlid()
{
float perc = ((float)whereAreWe)/((float)positionsAmnt-capacity);
float myh=perc*((float)pos.h-48)+pos.y+16;
SDL_FillRect(ekran,&genRect(pos.h-32,pos.w,pos.x,pos.y+16),0);
blitAt(slider.imgs->ourImages[0].bitmap,pos.x,(int)myh);
slider.pos.y=(int)myh;
updateRect(&pos);
}
void Slider<>::moveDown()
{
if (whereAreWe<positionsAmnt-capacity)
(CPG->*fun)(++whereAreWe);
updateSlid();
}
void Slider<>::moveUp()
{
if (whereAreWe>0)
(CPG->*fun)(--whereAreWe);
updateSlid();
}
//void Slider::moveByOne(bool up);
Slider<>::Slider(int x, int y, int h, int amnt, int cap)
{
positionsAmnt = amnt;
capacity = cap;
pos = genRect(h,16,x,y);
down = Button<void(Slider::*)()>(genRect(16,16,x,y+h-16),&Slider::moveDown,CPG->slh->giveDef("SCNRBDN.DEF"),false);
up = Button<void(Slider::*)()>(genRect(16,16,x,y),&Slider::moveUp,CPG->slh->giveDef("SCNRBUP.DEF"),false);
slider = Button<void(Slider::*)()>(genRect(16,16,x,y+16),NULL,CPG->slh->giveDef("SCNRBSL.DEF"),false);
moving = false;
whereAreWe=0;
pos = genRect(h,16,x,y);
}
void Slider<>::activate(MapSel * ms)
{
SDL_FillRect(ekran,&pos,0);
up.show();
down.show();
slider.show();
SDL_Flip(ekran);
CPG->interested.push_back(this);
}
void Slider<>::handleIt(SDL_Event sEvent)
{
if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
{
down.press();
}
else if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
{
up.press();
}
else if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
{
//slider.press();
moving=true;
}
else if (isItIn(&pos,sEvent.motion.x,sEvent.motion.y))
{
float dy = sEvent.motion.y-pos.y-16;
float pe = dy/((float)(pos.h-32));
if (pe>1) pe=1;
if (pe<0) pe=0;
whereAreWe = pe*(positionsAmnt-capacity);
if (whereAreWe<0)whereAreWe=0;
updateSlid();
(CPG->*fun)(whereAreWe);
}
}
else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
if ((down.state==1) && isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
{
(this->*down.fun)();
}
if ((up.state==1) && isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
{
(this->*up.fun)();
}
if (down.state==1) down.press(false);
if (up.state==1) up.press(false);
if (moving)
{
//slider.press();
moving=false;
}
}
//else if (sEvent.type==SDL_KEYDOWN)
//{
// switch (sEvent.key.keysym.sym)
// {
// case (SDLK_UP):
// moveUp();
// break;
// case (SDLK_DOWN):
// moveDown();
// break;
// }
//}
else if (moving && sEvent.type==SDL_MOUSEMOTION)
{
if (isItIn(&genRect(pos.h,pos.w+64,pos.x-32,pos.y),sEvent.motion.x,sEvent.motion.y))
{
int my = sEvent.motion.y-(pos.y+16);
int all =pos.h-48;
float ile = (float)my / (float)all;
if (ile>1) ile=1;
if (ile<0) ile=0;
int ktory = ile*(positionsAmnt-capacity);
if (ktory!=whereAreWe)
{
whereAreWe=ktory;
updateSlid();
}
(CPG->*fun)(whereAreWe);
}
}
/*else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
if (ourScenSel->pressed)
{
ourScenSel->pressed->press(false);
ourScenSel->pressed=NULL;
}
for (int i=0;i<btns.size(); i++)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
if (btns[i]->selectable)
btns[i]->select(true);
if (btns[i]->fun)
(this->*(btns[i]->fun))();
return;
}
}
if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
{
(this->*down.fun)();
}
if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
{
(this->*up.fun)();
}
if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
{
(this->*slider.fun)();
}
}*/
}
MapSel::~MapSel()
{
SDL_FreeSurface(bg);
for (int i=0;i<scenImgs.size();i++)
SDL_FreeSurface(scenImgs[i]);
for (int i=0;i<scenList.size();i++)
delete scenList[i];
}
int MapSel::countWL()
{
int ret=0;
for (int i=0;i<ourMaps.size();i++)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
continue;
else ret++;
}
return ret;
}
void MapSel::printMaps(int from, int to, int at, bool abs)
{
if (true)//
{
int help=-1;
for (int i=0;i<ourMaps.size();i++)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
continue;
else help++;
if (help==from)
{
from=i;
break;
}
}
}
SDL_Color nasz;
for (int i=at;i<to;i++)
{
if (sizeFilter && ((ourMaps[(i-at)+from].width) != sizeFilter))
{
to++;
at++;
from++;
if (((i-at)+from)>ourMaps.size()-1) break;
else continue;
}
if ((i-at+from) == selected)
nasz=tytulowy;
else nasz=zwykly;
//SDL_Rect pier = genRect(25,351,24,126+(i*25));
SDL_Surface * scenin = SDL_CreateRGBSurface(ekran->flags,351,25,ekran->format->BitsPerPixel,ekran->format->Rmask,ekran->format->Gmask,ekran->format->Bmask,ekran->format->Amask);
SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
int temp=-1;
std::ostringstream ostr(std::ostringstream::out); ostr << ourMaps[(i-at)+from].playerAmnt << "/" << ourMaps[(i-at)+from].humenPlayers;
printAt(ostr.str(),6,4,GEOR13,nasz,scenin);
std::string temp2;
switch (ourMaps[(i-at)+from].width)
{
case 36:
temp2="S";
break;
case 72:
temp2="M";
break;
case 108:
temp2="L";
break;
case 144:
temp2="XL";
break;
default:
temp2="C";
break;
}
printAt(temp2,43,5,GEOR13,nasz,scenin);
switch (ourMaps[(i-at)+from].version)
{
case Eformat::SoD:
temp=2;
break;
case Eformat::WoG:
temp=3;
break;
}
blitAt(Dtypes->ourImages[temp].bitmap,67,2,scenin);
if (!(ourMaps[(i-at)+from].name.length()))
ourMaps[(i-at)+from].name = "Unnamed";
printAt(ourMaps[(i-at)+from].name,105,6,GEOR13,nasz,scenin);
if (ourMaps[(i-at)+from].victoryCondition==EvictoryConditions::winStandard)
temp=11;
else temp=ourMaps[(i-at)+from].victoryCondition;
blitAt(Dvic->ourImages[temp].bitmap,285,2,scenin);
if (ourMaps[(i-at)+from].lossCondition.typeOfLossCon == ElossCon::lossStandard)
temp=3;
else temp=ourMaps[(i-at)+from].lossCondition.typeOfLossCon;
blitAt(Dloss->ourImages[temp].bitmap,318,2,scenin);
blitAt(scenin,24,121+(i-at)*25);
SDL_Flip(ekran);
SDL_FreeSurface(scenin);
}
}
int MapSel::whichWL(int nr)
{
int help=-1;
for (int i=0;i<ourMaps.size();i++)
{
if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
continue;
else help++;
if (help==nr)
{
help=i;
break;
}
}
return help;
}
void MapSel::draw()
{
//blit bg
blitAt(bg,2,6);
printAt("Map Sizes",55,60,GEOR13);
printAt("Select a Scenario to Play",110,25,TNRB16);
//size buttons
small.show();
medium.show();
large.show();
xlarge.show();
all.show();
CPG->btns.push_back(&small);
CPG->btns.push_back(&medium);
CPG->btns.push_back(&large);
CPG->btns.push_back(&xlarge);
CPG->btns.push_back(&all);
//print scenario list
printMaps(0,18);
slid->activate(this);
SDL_Flip(ekran);
}
void MapSel::init()
{
bg = SDL_LoadBMP("h3bitmap.lod\\SCSELBCK.bmp");
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
small.imgs = CPG->slh->giveDef("SCSMBUT.DEF");
small.fun = NULL;
small.pos = genRect(small.imgs->ourImages[0].bitmap->h,small.imgs->ourImages[0].bitmap->w,161,52);
small.ourGroup=NULL;
medium.imgs = CPG->slh->giveDef("SCMDBUT.DEF");
medium.fun = NULL;
medium.pos = genRect(medium.imgs->ourImages[0].bitmap->h,medium.imgs->ourImages[0].bitmap->w,208,52);
medium.ourGroup=NULL;
large.imgs = CPG->slh->giveDef("SCLGBUT.DEF");
large.fun = NULL;
large.pos = genRect(large.imgs->ourImages[0].bitmap->h,large.imgs->ourImages[0].bitmap->w,255,52);
large.ourGroup=NULL;
xlarge.imgs = CPG->slh->giveDef("SCXLBUT.DEF");
xlarge.fun = NULL;
xlarge.pos = genRect(xlarge.imgs->ourImages[0].bitmap->h,xlarge.imgs->ourImages[0].bitmap->w,302,52);
xlarge.ourGroup=NULL;
all.imgs = CPG->slh->giveDef("SCALBUT.DEF");
all.fun = NULL;
all.pos = genRect(all.imgs->ourImages[0].bitmap->h,all.imgs->ourImages[0].bitmap->w,349,52);
all.ourGroup=NULL;
all.selectable=xlarge.selectable=large.selectable=medium.selectable=small.selectable=false;
small.what=medium.what=large.what=xlarge.what=all.what=&sizeFilter;
small.key=36;medium.key=72;large.key=108;xlarge.key=144;all.key=0;
Dtypes = CPG->slh->giveDef("SCSELC.DEF");
Dvic = CPG->slh->giveDef("SCNRVICT.DEF");
Dloss = CPG->slh->giveDef("SCNRLOSS.DEF");
Dsizes = CPG->slh->giveDef("SCNRMPSZ.DEF");
//get map files names
std::vector<std::string> pliczkiTemp;
boost::filesystem::path tie( (fs::initial_path<fs::path>())/"\maps" );
fs::directory_iterator end_iter;
for ( boost::filesystem::directory_iterator dir (tie); dir!=end_iter; ++dir )
{
if (boost::filesystem::is_regular(dir->status()));
{
if (boost::ends_with(dir->path().leaf(),std::string(".h3m")))
pliczkiTemp.push_back("Maps/"+(dir->path().leaf()));
}
}
for (int i=0; i<pliczkiTemp.size();i++)
{
gzFile tempf = gzopen(pliczkiTemp[i].c_str(),"rb");
std::string sss;
int iii=0;
while(++iii)
{
if (iii>3300) break;
int z = gzgetc (tempf);
if (z>=0)
{
sss+=unsigned char(z);
}
else break;
}
gzclose(tempf);
if (sss[0]<28) continue; //zly format
if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna
unsigned char* file2 = new unsigned char[sss.length()];
for (int j=0;j<sss.length();j++)
file2[j]=sss[j];
ourMaps.push_back(CMapInfo(pliczkiTemp[i],file2));
}
std::sort(ourMaps.begin(),ourMaps.end(),mapSorter(ESortBy::name));
slid = new Slider<>(375,92,480,ourMaps.size(),18);
slid->fun = &CPreGame::printMapsFrom;
}
void MapSel::select(int which)
{
//selected = which;
//if ((slid->whereAreWe > which) || (slid->whereAreWe+18 < which))
// selected = which;
//else
{
selected = which;
printMaps(slid->whereAreWe,18,0,true);
}
printSelectedInfo();
}
MapSel::MapSel():selected(0),sizeFilter(0)
{
}
void MapSel::printSelectedInfo()
{
SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(399,337,17,23),ekran,&genRect(399,337,412,29));
SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(50,91,18,447),ekran,&genRect(50,91,413,453));
SDL_BlitSurface(CPG->ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bScens.pos);
SDL_BlitSurface(CPG->ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bOptions.pos);
SDL_BlitSurface(CPG->ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,ekran,&CPG->ourScenSel->bRandom.pos);
//blit texts
printAt(CPG->preth->singleScenarioName,420,25,GEOR13);
printAt("Scenario Description:",420,135,GEOR13);
printAt("Victory Condition:",420,285,GEOR13);
printAt("Loss Condition:",420,340,GEOR13);
printAt("Allies:",420,406,GEOR13,zwykly);
printAt("Enemies:",585,406,GEOR13,zwykly);
int temp = ourMaps[selected].victoryCondition+1;
if (temp>20) temp=0;
std::string sss = CPG->preth->victoryConditions[temp];
if (temp && ourMaps[selected].vicConDetails->allowNormalVictory) sss+= "/" + CPG->preth->victoryConditions[0];
printAt(sss,452,310,GEOR13,zwykly);
temp = ourMaps[selected].lossCondition.typeOfLossCon+1;
if (temp>20) temp=0;
sss = CPG->preth->lossCondtions[temp];
printAt(sss,452,370,GEOR13,zwykly);
//blit descrption
std::vector<std::string> desc = *CMessage::breakText(ourMaps[selected].description,50);
for (int i=0;i<desc.size();i++)
printAt(desc[i],417,152+i*13,GEOR13,zwykly);
if ((selected < 0) || (selected >= ourMaps.size()))
return;
if (ourMaps[selected].name.length())
printAt(ourMaps[selected].name,420,41,GEORXX);
else printAt("Unnamed",420,41,GEORXX);
std::string diff;
switch (ourMaps[selected].difficulty)
{
case 0:
diff=gdiff(CPG->preth->singleEasy);
break;
case 1:
diff=gdiff(CPG->preth->singleNormal);
break;
case 2:
diff=gdiff(CPG->preth->singleHard);
break;
case 3:
diff=gdiff(CPG->preth->singleExpert);
break;
case 4:
diff=gdiff(CPG->preth->singleImpossible);
break;
}
temp=-1;
switch (ourMaps[selected].width)
{
case 36:
temp=0;
break;
case 72:
temp=1;
break;
case 108:
temp=2;
break;
case 144:
temp=3;
break;
default:
temp=4;
break;
}
blitAt(Dsizes->ourImages[temp].bitmap,714,28);
temp=ourMaps[selected].victoryCondition;
if (temp>12) temp=11;
blitAt(Dvic->ourImages[temp].bitmap,420,308); //v
temp=ourMaps[selected].lossCondition.typeOfLossCon;
if (temp>12) temp=3;
blitAt(Dloss->ourImages[temp].bitmap,420,366); //l
printAt(diff,435,470,GEOR13,zwykly);
SDL_Flip(ekran);
}
std::string MapSel::gdiff(std::string ss)
{
std::string ret;
for (int i=2;i<ss.length();i++)
{
if (ss[i]==' ')
break;
ret+=ss[i];
}
return ret;
}
void CPreGame::printMapsFrom(int from)
{
ourScenSel->mapsel.printMaps(from);
}
void CPreGame::showScenList()
{
ourScenSel->listShowed=true;
ourScenSel->mapsel.draw();
}
CPreGame::CPreGame()
{
tytulowy.r=229;tytulowy.g=215;tytulowy.b=123;tytulowy.unused=0;
zwykly.r=255;zwykly.g=255;zwykly.b=255;zwykly.unused=0; //gbr
tlo.r=66;tlo.g=44;tlo.b=24;tlo.unused=0;
@@ -62,17 +573,17 @@ CPreGame::CPreGame()
void CPreGame::initScenSel()
{
ourScenSel = new ScenSel();
ourScenSel->listShowed=false;
if (rand()%2) ourScenSel->background=SDL_LoadBMP("h3bitmap.lod\\ZPIC1000.bmp");
else ourScenSel->background=SDL_LoadBMP("h3bitmap.lod\\ZPIC1001.bmp");
ourScenSel->pressed=NULL;
ourScenSel->scenInf=SDL_LoadBMP("h3bitmap.lod\\GSELPOP1.bmp");
ourScenSel->scenList=SDL_LoadBMP("h3bitmap.lod\\SCSELBCK.bmp");
ourScenSel->randMap=SDL_LoadBMP("h3bitmap.lod\\RANMAPBK.bmp");
ourScenSel->options=SDL_LoadBMP("h3bitmap.lod\\ADVOPTBK.bmp");
SDL_SetColorKey(ourScenSel->scenInf,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenInf->format,0,255,255));
SDL_SetColorKey(ourScenSel->scenList,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenList->format,0,255,255));
//SDL_SetColorKey(ourScenSel->scenList,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenList->format,0,255,255));
SDL_SetColorKey(ourScenSel->randMap,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->randMap->format,0,255,255));
SDL_SetColorKey(ourScenSel->options,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->options->format,0,255,255));
@@ -87,7 +598,7 @@ void CPreGame::initScenSel()
ourScenSel->bImpossible = IntSelBut<>(genRect(0,0,634,456),NULL,slh->giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,5);
ourScenSel->bBack = Button<>(genRect(0,0,584,535),&CPreGame::showNewMenu,slh->giveDef("SCNRBACK.DEF"));
ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::showScenList,slh->giveDef("SCNRBEG.DEF"));
ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::showNewMenu,slh->giveDef("SCNRBEG.DEF"));
ourScenSel->bScens = Button<>(genRect(0,0,414,81),&CPreGame::showScenList,slh->giveDef("GSPBUTT.DEF"));
for (int i=0; i<ourScenSel->bScens.imgs->ourImages.size(); i++)
@@ -99,7 +610,8 @@ void CPreGame::initScenSel()
for (int i=0; i<ourScenSel->bOptions.imgs->ourImages.size(); i++)
printAt("Show Advanced Options",25+i,2+i,GEOR13,zwykly,ourScenSel->bOptions.imgs->ourImages[i].bitmap);
CPG=this;
ourScenSel->mapsel.init();
}
void CPreGame::showScenSel()
@@ -107,13 +619,6 @@ void CPreGame::showScenSel()
state=EState::ScenarioList;
SDL_BlitSurface(ourScenSel->background,NULL,ekran,NULL);
SDL_BlitSurface(ourScenSel->scenInf,NULL,ekran,&genRect(ourScenSel->scenInf->h,ourScenSel->scenInf->w,395,6));
//blit texts
printAt(preth->singleScenarioName,420,25,GEOR13);
printAt("Scenario Description:",420,135,GEOR13);
printAt("Victory Condition:",420,285,GEOR13);
printAt("Loss Condition:",420,340,GEOR13);
printAt("Allies:",420,406,GEOR13,zwykly);
printAt("Enemies:",585,406,GEOR13,zwykly);
printAt("Map Diff:",427,438,GEOR13);
printAt("Player Difficulty:",527,438,GEOR13);
printAt("Rating:",685,438,GEOR13);
@@ -123,11 +628,8 @@ void CPreGame::showScenSel()
SDL_BlitSurface(ourScenSel->bHard.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bHard.pos);
SDL_BlitSurface(ourScenSel->bExpert.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bExpert.pos);
SDL_BlitSurface(ourScenSel->bImpossible.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bImpossible.pos);
SDL_BlitSurface(ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bScens.pos);
SDL_BlitSurface(ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bOptions.pos);
SDL_BlitSurface(ourScenSel->bBegin.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBegin.pos);
SDL_BlitSurface(ourScenSel->bBack.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bBack.pos);
SDL_BlitSurface(ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,ekran,&ourScenSel->bRandom.pos);
//blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y);
//blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105);
//blitAt(ourScenSel->bOptions.imgs->ourImages[0].bitmap,414,509);
@@ -153,19 +655,20 @@ void CPreGame::showScenSel()
btns[i]->pos.w=btns[i]->imgs->ourImages[0].bitmap->w;
btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h;
}
handleOther = &CPreGame::scenHandleEv;
ourScenSel->mapsel.printSelectedInfo();
SDL_Flip(ekran);
}
void CPreGame::showScenList()
{}
void CPreGame::showOptions()
{}
void CPreGame::initNewMenu()
{
ourNewMenu = new menuItems();
ourNewMenu->bgAd = SDL_LoadBMP("h3bitmap.lod\\ZNEWGAM.bmp");
ourNewMenu->background = SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp");
blitAt(ourNewMenu->bgAd,114,312,ourNewMenu->background);
slh = new CSemiLodHandler();
slh->openLod("H3sprite.lod");
//loading menu buttons
@@ -209,6 +712,7 @@ void CPreGame::initNewMenu()
void CPreGame::showNewMenu()
{
btns.clear();
handleOther=NULL;
state = EState::newGame;
SDL_BlitSurface(ourNewMenu->background,NULL,ekran,NULL);
SDL_BlitSurface(ourNewMenu->newGame->ourImages[0].bitmap,NULL,ekran,&ourNewMenu->lNewGame);
@@ -390,20 +894,20 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
mush->playClick();
btns[i]->press(true);
ourScenSel->pressed=btns[i];
}
}
if (ourScenSel->listShowed && (sEvent.button.y>121) &&(sEvent.button.y<570)
&& (sEvent.button.x>55) && (sEvent.button.x<372))
{
int py = ((sEvent.button.y-121)/25)+ourScenSel->mapsel.slid->whereAreWe;
ourScenSel->mapsel.select(ourScenSel->mapsel.whichWL(py));
}
}
else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
if (ourScenSel->pressed)
{
ourScenSel->pressed->press(false);
ourScenSel->pressed=NULL;
}
for (int i=0;i<btns.size(); i++)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
@@ -412,9 +916,24 @@ void CPreGame::scenHandleEv(SDL_Event& sEvent)
btns[i]->select(true);
if (btns[i]->fun)
(this->*(btns[i]->fun))();
return;
int zz = btns.size();
if (i>=zz)
break;
if (btns[i]->state && btns[i]->type==2)
{
((IntBut<> *)(btns[i]))->set();
ourScenSel->mapsel.slid->whereAreWe=0;
ourScenSel->mapsel.slid->updateSlid();
ourScenSel->mapsel.slid->positionsAmnt=ourScenSel->mapsel.countWL();
ourScenSel->mapsel.printMaps(0);
}
}
}
if (ourScenSel->pressed && ourScenSel->pressed->state==1)
{
ourScenSel->pressed->press(false);
ourScenSel->pressed=NULL;
}
}
}
void CPreGame::runLoop()
@@ -429,6 +948,8 @@ void CPreGame::runLoop()
menuItems * current = currentItems();
if(sEvent.type==SDL_QUIT)
return ;
for (int i=0;i<interested.size();i++)
interested[i]->handleIt(sEvent);
if (!current)
{
(this->*handleOther)(sEvent);
@@ -562,12 +1083,12 @@ void CPreGame::runLoop()
}
else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
{
mush->playClick();
for (int i=0;i<btns.size(); i++)
{
if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
{
btns[i]->press(true);
mush->playClick();
//SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,ekran,&btns[i].pos);
//updateRect(&btns[i].pos);
}
@@ -577,31 +1098,26 @@ void CPreGame::runLoop()
{
highlightButton(1,1);
current->highlighted=1;
mush->playClick();
}
else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
{
highlightButton(2,1);
current->highlighted=2;
mush->playClick();
}
else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
{
highlightButton(3,1);
current->highlighted=3;
mush->playClick();
}
else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
{
highlightButton(4,1);
current->highlighted=4;
mush->playClick();
}
else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
{
highlightButton(5,1);
current->highlighted=5;
mush->playClick();
}
}
else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))

View File

@@ -10,22 +10,61 @@
#include "CMusicHandler.h"
class CPreGame;
extern CPreGame * CPG;
struct RanSel
{
Button<> horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random
size[4], twoLevel, showRand;
CGroup<> *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize;
};
class MapSel
{
public:
bool showed;
SDL_Surface * bg;
int selected;
CSemiDefHandler * Dtypes, * Dvic, * Dloss, *Dsizes;
std::vector<Mapa*> scenList;
std::vector<SDL_Surface*> scenImgs;
int current;
std::vector<CMapInfo> ourMaps;
IntBut<> small, medium, large, xlarge, all;
Button<> nrplayer, mapsize, type, name, viccon, loscon;
Slider<> *slid, *descslid;
int sizeFilter;
int whichWL(int nr);
int countWL();
void draw();
void init();
std::string gdiff(std::string ss);
void printMaps(int from,int to=18, int at=0, bool abs=false);
void select(int which);
void printSelectedInfo();
MapSel();
~MapSel();
};
class ScenSel
{
public:
bool listShowed;
RanSel ransel;
MapSel mapsel;
SDL_Surface * background, *scenInf, *scenList, *randMap, *options ;
Button<> bScens, bOptions, bRandom, bBegin, bBack;
IntSelBut<> bEasy, bNormal, bHard, bExpert, bImpossible;
Button<> * pressed;
CPoinGroup<> * difficulty;
std::vector<Mapa> maps;
void genScenList();
int selectedDiff;
void initRanSel();
void showRanSel();
void hideRanSel();
void genScenList();
~ScenSel(){delete difficulty;};
} ;
class CPreGame
{
public:
std::vector<Slider<> *> interested;
CMusicHandler * mush;
CSemiLodHandler * slh ;
std::vector<Button<> *> btns;
@@ -37,7 +76,7 @@ public:
mainMenu, newGame, loadGame, ScenarioList
} state;
struct menuItems {
SDL_Surface * background;
SDL_Surface * background, *bgAd;
CSemiDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit;
@@ -66,6 +105,7 @@ public:
void showCenBox (std::string data);
void showAskBox (std::string data, void(*f1)(),void(*f2)());
void hideBox ();
void printMapsFrom(int from);
};
#endif //CPREGAME_H
#endif //CPREGAME_H

View File

@@ -76,6 +76,11 @@ void CSemiDefHandler::openDef(std::string name, std::string lodName, int dist)
loadImages(lodName);
}
CSemiDefHandler::~CSemiDefHandler()
{
for (int i=0;i<ourImages.size();i++)
SDL_FreeSurface(ourImages[i].bitmap);
}
void CSemiDefHandler::readFileList(int dist)
{
howManyImgs = buforD[788];
@@ -95,6 +100,7 @@ void CSemiDefHandler::readFileList(int dist)
}
else pom--;
}
delete buforD;
}
void CSemiDefHandler::loadImages(std::string path)
{
@@ -137,4 +143,4 @@ void CSemiDefHandler::openImg(const char *name)
SDL_SetColorKey(vinya.bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(vinya.bitmap->format,0,255,255));
vinya.imName = name;
ourImages.push_back(vinya);
}
}

View File

@@ -25,5 +25,6 @@ public:
void openDef(std::string name, std::string lodName, int dist=1);
void readFileList(int dist = 1);
void loadImages(std::string path);
~CSemiDefHandler();
};
#endif // SEMIDEF_H

View File

@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "map.h"
int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)

52
map.h
View File

@@ -6,6 +6,7 @@
#include "global.h"
#include "CSemiDefHandler.h"
enum ESortBy{name,playerAm,size,format, viccon,loscon};
struct Sresource
{
std::string resName; //name of this resource
@@ -185,7 +186,6 @@ struct Mapa
int howManyTeams;
std::vector<CMapEvent> events;
};
class CMapHeader
{
public:
@@ -205,6 +205,54 @@ public:
int howManyTeams;
CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
};
class CMapInfo : public CMapHeader
{
public:
std::string filename;
int playerAmnt, humenPlayers;
CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
{
playerAmnt=humenPlayers=0;
for (int i=0;i<8;i++)
{
if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
else if (players[i].canComputerPlay) {playerAmnt++;}
}
};
};
#endif //MAPD_H
class mapSorter
{
public:
ESortBy sortBy;
bool operator()(CMapHeader & a, CMapHeader& b)
{
switch (sortBy)
{
case ESortBy::format:
return (a.version<b.version);
break;
case ESortBy::loscon:
return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
break;
case ESortBy::playerAm:
//TODO
break;
case ESortBy::size:
return (a.width<b.width);
break;
case ESortBy::viccon:
return (a.victoryCondition<b.victoryCondition);
break;
case ESortBy::name:
return (a.name<b.name);
break;
default:
return (a.name<b.name);
break;
}
};
mapSorter(ESortBy es):sortBy(es){};
};
#endif //MAPD_H

View File

@@ -11,5 +11,6 @@
#include <tchar.h>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
// TODO: reference additional headers your program requires here