mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 20:22:31 +01:00
a bit more load menu progress ( does not load yet )
This commit is contained in:
parent
01f8f518b3
commit
bbef21da6b
@ -763,6 +763,18 @@ int GraphicScrollBar::getThickness() const {
|
||||
return horizontal?getH():getW();
|
||||
}
|
||||
|
||||
void GraphicScrollBar::arrangeComponents(vector<GraphicComponent *> &gcs) {
|
||||
if(getElementCount()!=0 ) {
|
||||
for(int i = getVisibleStart(); i <= getVisibleEnd(); ++i) {
|
||||
if(horizontal){
|
||||
gcs[i]->setX(getX()+getLength()-gcs[i]->getW()-gcs[i]->getW()*(i-getVisibleStart()));
|
||||
}
|
||||
else {
|
||||
gcs[i]->setY(getY()+getLength()-gcs[i]->getH()-gcs[i]->getH()*(i-getVisibleStart()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ===========================================================
|
||||
// class PopupMenu
|
||||
// ===========================================================
|
||||
|
@ -355,6 +355,7 @@ public:
|
||||
|
||||
int getVisibleCompPosStart() const {return visibleCompPosStart;}
|
||||
int getVisibleCompPosEnd() const {return visibleCompPosEnd;}
|
||||
void arrangeComponents(vector<GraphicComponent *> &gcs);
|
||||
};
|
||||
|
||||
// ===========================================================
|
||||
|
@ -38,11 +38,21 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||
int yPos=30;
|
||||
int xPos=20;
|
||||
int xSpacing=20;
|
||||
int slotsLineHeight=20;
|
||||
int slotsLineHeight=30;
|
||||
int slotLinesYBase=650;
|
||||
int slotsToRender=30;
|
||||
int slotsToRender=20;
|
||||
int slotWidth=200;
|
||||
|
||||
selectedButton=NULL;
|
||||
|
||||
string userData = Config::getInstance().getString("UserData_Root","");
|
||||
if(userData != "") {
|
||||
endPathWithSlash(userData);
|
||||
}
|
||||
saveGameDir = userData +"saved";
|
||||
endPathWithSlash(saveGameDir);
|
||||
|
||||
|
||||
lines[0].init(0,slotLinesYBase+slotsLineHeight);
|
||||
lines[1].init(0, slotLinesYBase-(slotsToRender-1)*slotsLineHeight-5);
|
||||
//lines[1].setHorizontal(false);
|
||||
@ -60,13 +70,13 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||
noSavedGamesLabel.setText(lang.get("NoSavedGames"));
|
||||
|
||||
savedGamesLabel.registerGraphicComponent(containerName,"savedGamesLabel");
|
||||
savedGamesLabel.init(120, slotLinesYBase+30);
|
||||
savedGamesLabel.init(120, slotLinesYBase+slotsLineHeight+10);
|
||||
savedGamesLabel.setFont(CoreData::getInstance().getMenuFontBig());
|
||||
savedGamesLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
||||
savedGamesLabel.setText(lang.get("SavedGames"));
|
||||
|
||||
infoHeaderLabel.registerGraphicComponent(containerName,"infoHeaderLabel");
|
||||
infoHeaderLabel.init(650, slotLinesYBase+30);
|
||||
infoHeaderLabel.init(650, slotLinesYBase+slotsLineHeight+10);
|
||||
infoHeaderLabel.setFont(CoreData::getInstance().getMenuFontBig());
|
||||
infoHeaderLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D());
|
||||
infoHeaderLabel.setText(lang.get("SavegameInfo"));
|
||||
@ -95,6 +105,9 @@ MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu):
|
||||
slotsScrollBar.setVisibleSize(slotsToRender);
|
||||
slotsScrollBar.setVisibleStart(0);
|
||||
|
||||
listFiles(20,slotLinesYBase,460,slotsLineHeight);
|
||||
slotsScrollBar.setElementCount(filenames.size());
|
||||
|
||||
|
||||
GraphicComponent::applyAllCustomProperties(containerName);
|
||||
}
|
||||
@ -109,6 +122,25 @@ void MenuStateLoadGame::clearSlots() {
|
||||
while(!slots.empty()) {
|
||||
delete slots.back();
|
||||
slots.pop_back();
|
||||
slotsGB.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuStateLoadGame::listFiles(int keyButtonsXBase, int keyButtonsYBase, int keyButtonsWidth, int keyButtonsHeight) {
|
||||
// Save the file now
|
||||
vector<string> paths;
|
||||
paths.push_back(saveGameDir);
|
||||
filenames.clear();
|
||||
findAll(paths, "*.xml", filenames, true, false, true);
|
||||
for(int i = 0; i < filenames.size(); ++i) {
|
||||
GraphicButton *button=new GraphicButton();
|
||||
button->init( keyButtonsXBase, keyButtonsYBase, keyButtonsWidth,keyButtonsHeight);
|
||||
button->setText(filenames[i]);
|
||||
// button->setCustomTexture(CoreData::getInstance().getCustomTexture());
|
||||
// button->setUseCustomTexture(true);
|
||||
|
||||
slots.push_back(button);
|
||||
slotsGB.push_back(button);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,11 +166,31 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
}
|
||||
else if(deleteButton.mouseClick(x, y)){
|
||||
soundRenderer.playFx(coreData.getClickSoundB());
|
||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||
if(selectedButton==NULL)
|
||||
{
|
||||
Lang &lang= Lang::getInstance();
|
||||
console.addStdMessage(lang.get("NothingSelected"));
|
||||
}
|
||||
else
|
||||
{
|
||||
string filename=saveGameDir+selectedButton->getText()+".xml";
|
||||
console.addStdMessage("Trying to delete file: '"+filename+"'");
|
||||
}
|
||||
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||
}
|
||||
else if(loadButton.mouseClick(x, y)){
|
||||
soundRenderer.playFx(coreData.getClickSoundB());
|
||||
mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||
if(selectedButton==NULL)
|
||||
{
|
||||
Lang &lang= Lang::getInstance();
|
||||
console.addStdMessage(lang.get("NothingSelected"));
|
||||
}
|
||||
else
|
||||
{
|
||||
string filename=saveGameDir+selectedButton->getText()+".xml";
|
||||
console.addStdMessage("Trying to load file: '"+filename+"'");
|
||||
}
|
||||
//mainMenu->setState(new MenuStateRoot(program, mainMenu));
|
||||
}
|
||||
else if(slotsScrollBar.mouseClick(x, y)){
|
||||
soundRenderer.playFx(coreData.getClickSoundB());
|
||||
@ -147,6 +199,7 @@ void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){
|
||||
if(slotsScrollBar.getElementCount()!=0){
|
||||
for(int i = slotsScrollBar.getVisibleStart(); i <= slotsScrollBar.getVisibleEnd(); ++i) {
|
||||
if(slots[i]->mouseClick(x, y)) {
|
||||
selectedButton=slots[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -161,9 +214,7 @@ void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms){
|
||||
loadButton.mouseMove(x, y);
|
||||
if(slotsScrollBar.getElementCount()!=0){
|
||||
for(int i = slotsScrollBar.getVisibleStart(); i <= slotsScrollBar.getVisibleEnd(); ++i) {
|
||||
if(slots[i]->mouseMove(x, y)) {
|
||||
break;
|
||||
}
|
||||
slots[i]->mouseMove(x, y);
|
||||
}
|
||||
}
|
||||
slotsScrollBar.mouseMove(x,y);
|
||||
@ -191,9 +242,15 @@ void MenuStateLoadGame::render(){
|
||||
}
|
||||
else{
|
||||
for(int i = slotsScrollBar.getVisibleStart(); i <= slotsScrollBar.getVisibleEnd(); ++i) {
|
||||
if(slots[i]==selectedButton){
|
||||
bool lightedOverride = true;
|
||||
renderer.renderButton(slots[i],&YELLOW,&lightedOverride);
|
||||
}
|
||||
else{
|
||||
renderer.renderButton(slots[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
renderer.renderScrollBar(&slotsScrollBar);
|
||||
|
||||
renderer.renderConsole(&console,false,true);
|
||||
@ -204,6 +261,7 @@ void MenuStateLoadGame::update(){
|
||||
if(Config::getInstance().getBool("AutoTest")){
|
||||
AutoTest::getInstance().updateNewGame(program, mainMenu);
|
||||
}
|
||||
slotsScrollBar.arrangeComponents(slotsGB);
|
||||
console.update();
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,17 @@ namespace Glest{ namespace Game{
|
||||
// ===============================
|
||||
// class MenuStateLoadGame
|
||||
// ===============================
|
||||
typedef vector<GraphicButton*> SaveSlotButtons;
|
||||
//typedef vector<GraphicButton*> SaveSlotButtons;
|
||||
class MenuStateLoadGame: public MenuState{
|
||||
private:
|
||||
GraphicButton loadButton;
|
||||
GraphicButton deleteButton;
|
||||
GraphicButton abortButton;
|
||||
SaveSlotButtons slots;
|
||||
vector<GraphicButton*> slots;
|
||||
vector<GraphicComponent*> slotsGB;
|
||||
vector<string> filenames;
|
||||
GraphicScrollBar slotsScrollBar;
|
||||
GraphicButton* selectedButton;
|
||||
|
||||
GraphicLabel headerLabel;
|
||||
GraphicLabel noSavedGamesLabel;
|
||||
@ -37,6 +40,8 @@ private:
|
||||
|
||||
GraphicLine lines[2];
|
||||
|
||||
string saveGameDir;
|
||||
|
||||
public:
|
||||
MenuStateLoadGame(Program *program, MainMenu *mainMenu);
|
||||
~MenuStateLoadGame();
|
||||
@ -50,6 +55,7 @@ public:
|
||||
void reloadUI();
|
||||
private:
|
||||
void clearSlots();
|
||||
void listFiles(int keyButtonsXBase, int keyButtonsYBase, int keyButtonsWidth, int keyButtonsHeight);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user