|
@@ -9,6 +9,7 @@
|
|
|
#include <boost/function.hpp>
|
|
|
#include <boost/bind.hpp>
|
|
|
#include <cstdlib>
|
|
|
+#include "GUIBase.h"
|
|
|
|
|
|
/*
|
|
|
* CPreGame.h, part of VCMI engine
|
|
@@ -21,288 +22,171 @@
|
|
|
*/
|
|
|
|
|
|
struct CMusicHandler;
|
|
|
-class CPreGame;
|
|
|
-class CDefHandler;
|
|
|
-extern CPreGame * CPG;
|
|
|
+using boost::bind;
|
|
|
+using boost::ref;
|
|
|
|
|
|
-typedef void(CPreGame::*ttt)();
|
|
|
-class CGroup;
|
|
|
-class CPoinGroup ;
|
|
|
-class IntSelBut;
|
|
|
-
|
|
|
-struct HighButton
|
|
|
-{
|
|
|
- int ID;
|
|
|
- int type;
|
|
|
- SDL_Rect pos;
|
|
|
- CDefHandler* imgs;
|
|
|
- int state;
|
|
|
- bool freeimgs;
|
|
|
- HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1);
|
|
|
- HighButton();
|
|
|
- virtual ~HighButton();
|
|
|
- bool selectable, selected;
|
|
|
- bool highlightable, highlighted;
|
|
|
- virtual void show();
|
|
|
- virtual void press(bool down=true);
|
|
|
- virtual void hover(bool on=true)=0;
|
|
|
- virtual void select(bool on=true)=0;
|
|
|
-};
|
|
|
-struct Button: public HighButton
|
|
|
-{
|
|
|
- CGroup *ourGroup;
|
|
|
- Button( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1);
|
|
|
- Button();
|
|
|
- boost::function<void()> fun;
|
|
|
- virtual void hover(bool on=true);
|
|
|
- virtual void select(bool on=true);
|
|
|
-};
|
|
|
-struct SetrButton: public Button
|
|
|
-{
|
|
|
- int key, * poin;
|
|
|
- virtual void press(bool down=true);
|
|
|
- SetrButton();
|
|
|
+enum EState { //where are we?
|
|
|
+ mainMenu, newGame, loadGame, ScenarioList, saveGame
|
|
|
};
|
|
|
|
|
|
-class Slider
|
|
|
-{
|
|
|
-public:
|
|
|
- bool vertical; // false means horizontal
|
|
|
- SDL_Rect pos; // position
|
|
|
- Button *up, *down, //or left/right
|
|
|
- *slider;
|
|
|
- int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
|
|
|
- int whereAreWe; // first displayed thing
|
|
|
- bool moving;
|
|
|
- boost::function<void(int)> fun;
|
|
|
- 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 deactivate();
|
|
|
- void activate();
|
|
|
- Slider(int x, int y, int h, int amnt, int cap, bool ver);
|
|
|
- ~Slider();
|
|
|
- void updateSlid();
|
|
|
- void handleIt(SDL_Event sev);
|
|
|
-};
|
|
|
|
|
|
-struct IntBut: public Button
|
|
|
+class CMenuScreen : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- int key;
|
|
|
- int * what;
|
|
|
- IntBut();
|
|
|
- void set();
|
|
|
+ CPicture *bgAd;
|
|
|
+ AdventureMapButton *buttons[5];
|
|
|
+
|
|
|
+ CMenuScreen(EState which);
|
|
|
+ ~CMenuScreen();
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
+ void show(SDL_Surface * to);
|
|
|
+ void moveTo(CMenuScreen *next);
|
|
|
};
|
|
|
-class CGroup
|
|
|
+
|
|
|
+
|
|
|
+struct FileInfo
|
|
|
{
|
|
|
-public:
|
|
|
- Button * selected;
|
|
|
- int type; // 1=sinsel
|
|
|
- CGroup():selected(NULL),type(0){};
|
|
|
+ std::string name;
|
|
|
+ std::time_t date;
|
|
|
};
|
|
|
|
|
|
-class CPoinGroup :public CGroup
|
|
|
+class InfoCard : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/)
|
|
|
- void setYour(IntSelBut * your);
|
|
|
+ CPicture *bg;
|
|
|
+ EState type;
|
|
|
+
|
|
|
+ CHighlightableButtonsGroup *difficulty;
|
|
|
+ CDefHandler *sizes, *sFlags;;
|
|
|
+
|
|
|
+ void changeSelection(const CMapInfo *to);
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
+ InfoCard(EState Type);
|
|
|
+ ~InfoCard();
|
|
|
};
|
|
|
-struct IntSelBut: public Button
|
|
|
+
|
|
|
+class SelectionTab : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- CPoinGroup * ourPoinGroup;
|
|
|
- int key;
|
|
|
- IntSelBut(){};
|
|
|
- IntSelBut( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1);
|
|
|
- void select(bool on=true);
|
|
|
+ int positions; //how many entries (games/maps) can be shown
|
|
|
+ CPicture *bg; //general bg image
|
|
|
+ CSlider *slider;
|
|
|
+ std::vector<CMapInfo> allItems;
|
|
|
+ std::vector<CMapInfo*> curItems;
|
|
|
+ size_t selectionPos;
|
|
|
+ boost::function<void(CMapInfo *)> onSelect;
|
|
|
+
|
|
|
+ ESortBy sortingBy;
|
|
|
+ bool ascending;
|
|
|
+
|
|
|
+ CDefHandler *format;
|
|
|
+
|
|
|
+ void getFiles(std::vector<FileInfo> &out, const std::string &dirname, const std::string &ext);
|
|
|
+ void parseMaps(std::vector<FileInfo> &files, int start = 0, int threads = 1);
|
|
|
+ void parseGames(std::vector<FileInfo> &files);
|
|
|
+ void filter(int size); //0 - all
|
|
|
+ void select(int position); //position: <0 - positions> position on the screen
|
|
|
+ int getPosition(int x, int y); //convert mouse coords to entry position; -1 means none
|
|
|
+ void sliderMove(int slidPos);
|
|
|
+ void sortBy(int criteria);
|
|
|
+ void sort();
|
|
|
+ void printMaps(SDL_Surface *to);
|
|
|
+
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
+ void clickLeft(tribool down, bool previousState);
|
|
|
+ SelectionTab(EState Type, const boost::function<void(CMapInfo *)> &OnSelect);
|
|
|
+ ~SelectionTab();
|
|
|
};
|
|
|
-class PreGameTab
|
|
|
+
|
|
|
+class OptionsTab : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- bool showed;
|
|
|
- virtual void init()=0;
|
|
|
- virtual void show()=0;
|
|
|
- virtual void hide()=0;
|
|
|
- PreGameTab();
|
|
|
-};
|
|
|
-class RanSel : public PreGameTab
|
|
|
-{
|
|
|
- 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 Options : public PreGameTab
|
|
|
-{
|
|
|
- bool inited;
|
|
|
- struct OptionSwitch:public HighButton
|
|
|
+ enum SelType {TOWN, HERO, BONUS};
|
|
|
+ struct SelectedBox : public CIntObject //img with current town/hero/bonus
|
|
|
{
|
|
|
- void hover(bool on=true){};
|
|
|
- void select(bool on=true){};
|
|
|
- OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which)
|
|
|
- :HighButton(Pos,Imgs,false,7),left(Left),which(Which)
|
|
|
- {selectable=false;highlightable=false;}
|
|
|
- void press(bool down=true);
|
|
|
- bool left;
|
|
|
- int playerID;
|
|
|
- int serialID;
|
|
|
- int which; //-1=castle;0=hero;1=bonus
|
|
|
+ SelType which;
|
|
|
+ ui8 player; //serial nr
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
+ SelectedBox(SelType Which, ui8 Player);
|
|
|
};
|
|
|
- struct PlayerFlag:public HighButton
|
|
|
- {
|
|
|
- int color;
|
|
|
- PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color)
|
|
|
- :HighButton(Pos,Imgs,false,7),color(Color)
|
|
|
- {selectable=false;highlightable=true;}
|
|
|
- void hover(bool on=true);
|
|
|
- void press(bool down=true);
|
|
|
- void select(bool on=true){};
|
|
|
- };
|
|
|
- struct PlayerOptions
|
|
|
+
|
|
|
+ struct PlayerOptionsEntry : public CIntObject
|
|
|
{
|
|
|
- PlayerOptions(int serial, int player);
|
|
|
- Ecolor color;
|
|
|
- PlayerFlag flag;
|
|
|
- //SDL_Surface * bg;
|
|
|
- OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright;
|
|
|
- int nr;
|
|
|
+ PlayerSettings &s;
|
|
|
+ CPicture *bg;
|
|
|
+ AdventureMapButton *btns[6]; //left and right for town, hero, bonus
|
|
|
+ AdventureMapButton *flag;
|
|
|
+ SelectedBox *town;
|
|
|
+ SelectedBox *hero;
|
|
|
+ SelectedBox *bonus;
|
|
|
+
|
|
|
+ PlayerOptionsEntry(OptionsTab *owner, PlayerSettings &S);
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
};
|
|
|
-public:
|
|
|
+ CPicture *bg;
|
|
|
+ CSlider *turnDuration;
|
|
|
+
|
|
|
std::set<int> usedHeroes;
|
|
|
- Slider * turnLength;
|
|
|
- SDL_Surface * bg,
|
|
|
- * rHero, * rCastle, * nHero, * nCastle;
|
|
|
- std::vector<SDL_Surface*> bgs;
|
|
|
- std::vector<CDefHandler*> flags;
|
|
|
- CDefHandler //* castles, * heroes, * bonus,
|
|
|
- * left, * right,
|
|
|
- * bonuses;
|
|
|
- std::vector<PlayerOptions*> poptions;
|
|
|
- void show();
|
|
|
- void hide();
|
|
|
- void init();
|
|
|
- void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
|
|
|
- bool canUseThisHero(int ID);
|
|
|
- int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
|
|
|
- Options(){inited=showed=false;};
|
|
|
- ~Options();
|
|
|
+
|
|
|
+ std::vector<PlayerOptionsEntry *> entries;
|
|
|
+
|
|
|
+ void nextCastle(int player, int dir); //dir == -1 or +1
|
|
|
+ void nextHero(int player, int dir); //dir == -1 or +1
|
|
|
+ void nextBonus(int player, int dir); //dir == -1 or +1
|
|
|
+ void setTurnLength(int npos);
|
|
|
+ void flagPressed(int player);
|
|
|
+
|
|
|
+ void changeSelection(const CMapInfo *to);
|
|
|
+ OptionsTab(EState Type/*, StartInfo &Opts*/);
|
|
|
+ ~OptionsTab();
|
|
|
+ void showAll(SDL_Surface * to);
|
|
|
+
|
|
|
+ int nextAllowedHero( int min, int max, int incl, int dir );
|
|
|
+
|
|
|
+ bool canUseThisHero( int ID );
|
|
|
};
|
|
|
-class MapSel : public PreGameTab
|
|
|
+
|
|
|
+class CSelectionScreen : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- ESortBy sortBy;
|
|
|
- SDL_Surface * bg;
|
|
|
- CDefHandler * Dtypes, * Dvic;
|
|
|
- CDefHandler *Dsizes, * Dloss,
|
|
|
- * sFlags;
|
|
|
- std::vector<SDL_Surface*> scenImgs;
|
|
|
-
|
|
|
- std::vector<CMapInfo*> ourMaps; // Maps
|
|
|
- std::vector<CMapInfo*> ourGames; // Saved games
|
|
|
- std::vector<CMapInfo*> selMaps; // (sub)set of either ourMaps or ourGames
|
|
|
- int selected; // selected map, relative to selMaps
|
|
|
-
|
|
|
- IntBut small, medium, large, xlarge, all;
|
|
|
- SetrButton nrplayer, mapsize, type, name, viccon, loscon;
|
|
|
- Slider *slid, *descslid;
|
|
|
- int sizeFilter;
|
|
|
- void show();
|
|
|
- void hide();
|
|
|
- void init();
|
|
|
- std::string gdiff(std::string ss);
|
|
|
- void printMaps(int from=0);
|
|
|
- void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false);
|
|
|
- void moveByX(int nlines);
|
|
|
- void printSelectedInfo();
|
|
|
- void printFlags();
|
|
|
- void processMaps(const std::vector<std::string> &pliczkiTemp, int start, int threads);
|
|
|
- void processGames(const std::vector<std::string> &pliczkiTemp);
|
|
|
- void updateSelection();
|
|
|
- MapSel();
|
|
|
- ~MapSel();
|
|
|
+ CPicture *bg; //general bg image
|
|
|
+ AdventureMapButton *start, *back;
|
|
|
+ InfoCard *card;
|
|
|
+ SelectionTab *sel;
|
|
|
+ OptionsTab *opt;
|
|
|
+
|
|
|
+ EState type; //new/save/load#Game
|
|
|
+ const CMapInfo *current;
|
|
|
+ StartInfo sInfo;
|
|
|
+ CIntObject *curTab;
|
|
|
+
|
|
|
+ CSelectionScreen(EState Type);
|
|
|
+ ~CSelectionScreen();
|
|
|
+ void toggleTab(CIntObject *tab);
|
|
|
+ void changeSelection(const CMapInfo *to);
|
|
|
+ void updateStartInfo(const CMapInfo * to);
|
|
|
+ void startGame();
|
|
|
+ void difficultyChange(int to);
|
|
|
};
|
|
|
-class ScenSel
|
|
|
-{
|
|
|
-public:
|
|
|
- CPoinGroup * difficulty;
|
|
|
- bool listShowed;
|
|
|
- //RanSel ransel;
|
|
|
- MapSel mapsel;
|
|
|
- SDL_Surface * background, *savenameStrip, *scenInf, *scenList, *randMap, *options ;
|
|
|
- Button bScens, bOptions, bRandom, bBegin, bLoad, bBack;
|
|
|
- IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible;
|
|
|
- Button * pressed;
|
|
|
- std::vector<Mapa> maps;
|
|
|
- int selectedDiff;
|
|
|
- void initRanSel();
|
|
|
- void showRanSel();
|
|
|
- void hideRanSel();
|
|
|
- void genScenList();
|
|
|
- ScenSel();
|
|
|
- ~ScenSel();
|
|
|
-} ;
|
|
|
-class CPreGame
|
|
|
+
|
|
|
+class CGPreGame : public CIntObject
|
|
|
{
|
|
|
public:
|
|
|
- std::string playerName;
|
|
|
- int playerColor;
|
|
|
- HighButton * highlighted;
|
|
|
- PreGameTab* currentTab;
|
|
|
- StartInfo ret;
|
|
|
- bool run;
|
|
|
- bool first; //hasn't we showed the scensel
|
|
|
- std::vector<Slider *> interested;
|
|
|
- std::vector<HighButton *> btns;
|
|
|
- SDL_Rect * currentMessage;
|
|
|
- SDL_Surface * behindCurMes;
|
|
|
- CDefHandler *ok, *cancel;
|
|
|
- enum EState { //where are we?
|
|
|
- mainMenu, newGame, loadGame, ScenarioList, saveGame
|
|
|
- } state, fromMenu;
|
|
|
- struct menuItems {
|
|
|
- menuItems();
|
|
|
- ~menuItems();
|
|
|
- SDL_Surface * background, *bgAd;
|
|
|
- CDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
|
|
|
- SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
|
|
|
- ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit;
|
|
|
- int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
|
|
|
- } * ourMainMenu, * ourNewMenu, * ourLoadMenu;
|
|
|
- ScenSel *ourScenSel;
|
|
|
- Options * ourOptions;
|
|
|
- std::string map; //selected map
|
|
|
- CPreGame(); //c-tor
|
|
|
- ~CPreGame();//d-tor
|
|
|
- std::string buttonText(int which);
|
|
|
- menuItems * currentItems();
|
|
|
- void(CPreGame::*handleOther)(SDL_Event&);
|
|
|
- void scenHandleEv(SDL_Event& sEvent);
|
|
|
- void begin();
|
|
|
- void quitAskBox();
|
|
|
- void quit(){exit(EXIT_SUCCESS);};
|
|
|
- void initScenSel();
|
|
|
- void showScenSel();
|
|
|
- void showScenList();
|
|
|
- void initOptions();
|
|
|
- void showOptions();
|
|
|
- void initNewMenu();
|
|
|
- void initLoadMenu();
|
|
|
- void showNewMenu();
|
|
|
- void showLoadMenu();
|
|
|
- void showMainMenu();
|
|
|
- StartInfo runLoop(); // runs mainloop of PreGame
|
|
|
- void initMainMenu(); //loads components for main menu
|
|
|
- void highlightButton(int which, int on); //highlights one from 5 main menu buttons
|
|
|
- void showCenBox (std::string data); //
|
|
|
- void showAskBox (std::string data, void(*f1)(),void(*f2)());
|
|
|
- void hideBox ();
|
|
|
- void printRating();
|
|
|
- void printMapsFrom(int from);
|
|
|
- void setTurnLength(int on);
|
|
|
- void sortMaps();
|
|
|
+ SDL_Surface *mainbg;
|
|
|
+ CMenuScreen *scrs[3];
|
|
|
+
|
|
|
+ SDL_Surface *nHero, *rHero, *nTown, *rTown; // none/random hero/town imgs
|
|
|
+ CDefHandler *bonuses;
|
|
|
+ CDefHandler *victory, *loss;
|
|
|
+
|
|
|
+ CGPreGame();
|
|
|
+ ~CGPreGame();
|
|
|
+ void run();
|
|
|
+ void openSel(EState type);
|
|
|
+ void loadGraphics();
|
|
|
+ void disposeGraphics();
|
|
|
};
|
|
|
|
|
|
+extern CGPreGame *CGP;
|
|
|
|
|
|
#endif // __CPREGAME_H__
|