options menu
ingame resolution change ( game restart needed )
everything not really poolished yet!
This commit is contained in:
Titus Tscharntke 2010-04-01 00:13:28 +00:00
parent 2eae390d34
commit 5ecc84099a
7 changed files with 393 additions and 96 deletions

View File

@ -29,7 +29,10 @@ FogOfWarSmoothing=true
FogOfWarSmoothingFrameSkip=3
FontConsole=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
FontDisplay=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
FontMenu=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
FontMenuBig=-*-*-bold-*-*-*-16-*-*-*-*-*-*-*
FontMenuNormal=-*-*-*-*-*-*-12-*-*-*-*-*-*-*
FontMenuSmall=-*-*-*-*-*-*-10-*-*-*-*-*-*-*
FontMenuVeryBig=-*-*-bold-*-*-*-20-*-*-*-*-*-*-*
Lang=english
MaxLights=3
NetPlayerName=SoftCoder

View File

@ -0,0 +1,147 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "core_data.h"
#include "logger.h"
#include "renderer.h"
#include "graphics_interface.h"
#include "config.h"
#include "util.h"
#include "leak_dumper.h"
using namespace Shared::Sound;
using namespace Shared::Graphics;
using namespace Shared::Util;
namespace Glest{ namespace Game{
// =====================================================
// class CoreData
// =====================================================
// ===================== PUBLIC ========================
CoreData &CoreData::getInstance(){
static CoreData coreData;
return coreData;
}
CoreData::~CoreData(){
deleteValues(waterSounds.getSounds().begin(), waterSounds.getSounds().end());
}
void CoreData::load(){
const string dir="data/core";
Logger::getInstance().add("Core data");
Renderer &renderer= Renderer::getInstance();
//textures
backgroundTexture= renderer.newTexture2D(rsGlobal);
backgroundTexture->setMipmap(false);
backgroundTexture->getPixmap()->load(dir+"/menu/textures/back.tga");
fireTexture= renderer.newTexture2D(rsGlobal);
fireTexture->setFormat(Texture::fAlpha);
fireTexture->getPixmap()->init(1);
fireTexture->getPixmap()->load(dir+"/misc_textures/fire_particle.tga");
snowTexture= renderer.newTexture2D(rsGlobal);
snowTexture->setMipmap(false);
snowTexture->setFormat(Texture::fAlpha);
snowTexture->getPixmap()->init(1);
snowTexture->getPixmap()->load(dir+"/misc_textures/snow_particle.tga");
customTexture= renderer.newTexture2D(rsGlobal);
customTexture->getPixmap()->load("data/core/menu/textures/custom_texture.tga");
logoTexture= renderer.newTexture2D(rsGlobal);
logoTexture->setMipmap(false);
logoTexture->getPixmap()->load(dir+"/menu/textures/logo.tga");
waterSplashTexture= renderer.newTexture2D(rsGlobal);
waterSplashTexture->setFormat(Texture::fAlpha);
waterSplashTexture->getPixmap()->init(1);
waterSplashTexture->getPixmap()->load(dir+"/misc_textures/water_splash.tga");
buttonSmallTexture= renderer.newTexture2D(rsGlobal);
buttonSmallTexture->getPixmap()->load(dir+"/menu/textures/button_small.tga");
buttonBigTexture= renderer.newTexture2D(rsGlobal);
buttonBigTexture->getPixmap()->load(dir+"/menu/textures/button_big.tga");
//display font
Config &config= Config::getInstance();
string displayFontName= config.getString("FontDisplay");
displayFont= renderer.newFont(rsGlobal);
displayFont->setType(displayFontName);
displayFont->setSize(computeFontSize(15));
//menu fonts
string menuFontNameSmall= config.getString("FontMenuSmall");
menuFontSmall= renderer.newFont(rsGlobal);
menuFontSmall->setType(menuFontNameSmall);
menuFontSmall->setSize(computeFontSize(10));
string menuFontNameNormal= config.getString("FontMenuNormal");
menuFontNormal= renderer.newFont(rsGlobal);
menuFontNormal->setType(menuFontNameNormal);
menuFontNormal->setSize(computeFontSize(12));
menuFontNormal->setWidth(Font::wBold);
string menuFontNameBig= config.getString("FontMenuBig");
menuFontBig= renderer.newFont(rsGlobal);
menuFontBig->setType(menuFontNameBig);
menuFontBig->setSize(computeFontSize(16));
string menuFontNameVeryBig= config.getString("FontMenuVeryBig");
menuFontVeryBig= renderer.newFont(rsGlobal);
menuFontVeryBig->setType(menuFontNameVeryBig);
menuFontVeryBig->setSize(computeFontSize(20));
//console font
string consoleFontName= Config::getInstance().getString("FontConsole");
consoleFont= renderer.newFont(rsGlobal);
consoleFont->setType(consoleFontName);
consoleFont->setSize(computeFontSize(16));
//sounds
clickSoundA.load(dir+"/menu/sound/click_a.wav");
clickSoundB.load(dir+"/menu/sound/click_b.wav");
clickSoundC.load(dir+"/menu/sound/click_c.wav");
introMusic.open(dir+"/menu/music/intro_music.ogg");
introMusic.setNext(&menuMusic);
menuMusic.open(dir+"/menu/music/menu_music.ogg");
menuMusic.setNext(&menuMusic);
waterSounds.resize(6);
for(int i=0; i<6; ++i){
waterSounds[i]= new StaticSound();
waterSounds[i]->load(dir+"/water_sounds/water"+intToStr(i)+".wav");
}
}
int CoreData::computeFontSize(int size){
int screenH= Config::getInstance().getInt("ScreenHeight");
int rs= size*screenH/750;
if(rs<12){
rs= 12;
}
return rs;
}
// ================== PRIVATE ========================
}}//end namespace

View File

@ -1,7 +1,7 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Marti<EFBFBD>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
@ -58,7 +58,7 @@ void BattleEnd::render(){
renderer.reset2d();
renderer.renderBackground(CoreData::getInstance().getBackgroundTexture());
textRenderer->begin(CoreData::getInstance().getMenuFontBig());
textRenderer->begin(CoreData::getInstance().getMenuFontNormal());
int lm= 20;
int bm= 100;

View File

@ -33,101 +33,43 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
{
Lang &lang= Lang::getInstance();
Config &config= Config::getInstance();
//modeinfos=list<ModeInfo> ();
Shared::Platform::getFullscreenVideoModes(&modeInfos);
activeInputLabel=NULL;
//create
buttonOk.init(200, 150, 100);
buttonAbort.init(310, 150, 100);
buttonAutoConfig.init(450, 150, 125);
//labels
labelVolumeFx.init(200, 530);
labelVolumeAmbient.init(200, 500);
labelVolumeMusic.init(200, 470);
labelLang.init(200, 400);
labelPlayerNameLabel.init(200,370);
labelPlayerName.init(350,370);
labelFilter.init(200, 340);
labelShadows.init(200, 310);
labelTextures3D.init(200, 280);
labelLights.init(200, 250);
labelUnitParticles.init(200,220);
//list boxes
listBoxVolumeFx.init(350, 530, 80);
listBoxVolumeAmbient.init(350, 500, 80);
listBoxVolumeMusic.init(350, 470, 80);
listBoxMusicSelect.init(350, 440, 150);
listBoxLang.init(350, 400, 170);
listBoxFilter.init(350, 340, 170);
listBoxShadows.init(350, 310, 170);
listBoxTextures3D.init(350, 280, 80);
listBoxLights.init(350, 250, 80);
listBoxUnitParticles.init(350,220,80);
//set text
buttonOk.setText(lang.get("Ok"));
buttonAbort.setText(lang.get("Abort"));
buttonAutoConfig.setText(lang.get("AutoConfig"));
labelLang.setText(lang.get("Language"));
labelPlayerNameLabel.setText(lang.get("Playername"));
labelShadows.setText(lang.get("Shadows"));
labelFilter.setText(lang.get("Filter"));
labelTextures3D.setText(lang.get("Textures3D"));
labelLights.setText(lang.get("MaxLights"));
labelUnitParticles.setText(lang.get("ShowUnitParticles"));
int leftline=640;
int rightline=640;
int leftLabelStart=50;
int leftColumnStart=leftLabelStart+150;
int rightLabelStart=500;
int rightColumnStart=rightLabelStart+150;
int buttonRowPos=20;
int captionOffset=75;
leftline-=30;
labelAudioSection.init(leftLabelStart+captionOffset, leftline);
labelAudioSection.setFont(CoreData::getInstance().getMenuFontVeryBig());
labelAudioSection.setText(lang.get("Audio"));
leftline-=30;
//soundboxes
labelVolumeFx.init(leftLabelStart, leftline);
labelVolumeFx.setText(lang.get("FxVolume"));
listBoxVolumeFx.init(leftColumnStart, leftline, 80);
leftline-=30;
labelVolumeAmbient.init(leftLabelStart, leftline);
listBoxVolumeAmbient.init(leftColumnStart, leftline, 80);
labelVolumeAmbient.setText(lang.get("AmbientVolume"));
leftline-=30;
labelVolumeMusic.init(leftLabelStart, leftline);
listBoxVolumeMusic.init(leftColumnStart, leftline, 80);
labelVolumeMusic.setText(lang.get("MusicVolume"));
//sound
//lang
vector<string> langResults;
findAll("data/lang/*.lng", langResults, true);
if(langResults.empty()){
throw runtime_error("There is no lang file");
}
listBoxLang.setItems(langResults);
listBoxLang.setSelectedItem(config.getString("Lang"));
//playerName
labelPlayerName.setText(config.getString("NetPlayerName",Socket::getHostName().c_str()));
//shadows
for(int i= 0; i<Renderer::sCount; ++i){
listBoxShadows.pushBackItem(lang.get(Renderer::shadowsToStr(static_cast<Renderer::Shadows>(i))));
}
string str= config.getString("Shadows");
listBoxShadows.setSelectedItemIndex(clamp(Renderer::strToShadows(str), 0, Renderer::sCount-1));
//filter
listBoxFilter.pushBackItem("Bilinear");
listBoxFilter.pushBackItem("Trilinear");
listBoxFilter.setSelectedItem(config.getString("Filter"));
//textures 3d
listBoxTextures3D.pushBackItem(lang.get("No"));
listBoxTextures3D.pushBackItem(lang.get("Yes"));
listBoxTextures3D.setSelectedItemIndex(clamp(config.getBool("Textures3D"), false, true));
//textures 3d
listBoxUnitParticles.pushBackItem(lang.get("No"));
listBoxUnitParticles.pushBackItem(lang.get("Yes"));
listBoxUnitParticles.setSelectedItemIndex(clamp(config.getBool("UnitParticles"), 0, 1));
//lights
for(int i= 1; i<=8; ++i){
listBoxLights.pushBackItem(intToStr(i));
}
listBoxLights.setSelectedItemIndex(clamp(config.getInt("MaxLights")-1, 0, 7));
//sound
leftline-=30;
for(int i=0; i<=100; i+=5){
listBoxVolumeFx.pushBackItem(intToStr(i));
listBoxVolumeAmbient.pushBackItem(intToStr(i));
@ -136,6 +78,106 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu):
listBoxVolumeFx.setSelectedItem(intToStr(config.getInt("SoundVolumeFx")/5*5));
listBoxVolumeAmbient.setSelectedItem(intToStr(config.getInt("SoundVolumeAmbient")/5*5));
listBoxVolumeMusic.setSelectedItem(intToStr(config.getInt("SoundVolumeMusic")/5*5));
leftline-=30;
labelMiscSection.init(leftLabelStart+captionOffset, leftline);
labelMiscSection.setFont(CoreData::getInstance().getMenuFontVeryBig());
labelMiscSection.setText(lang.get("Misc"));
leftline-=30;
//lang
labelLang.init(leftLabelStart, leftline);
labelLang.setText(lang.get("Language"));
listBoxLang.init(leftColumnStart, leftline, 170);
vector<string> langResults;
findAll("data/lang/*.lng", langResults, true);
if(langResults.empty()){
throw runtime_error("There is no lang file");
}
listBoxLang.setItems(langResults);
listBoxLang.setSelectedItem(config.getString("Lang"));
leftline-=30;
//playerName
labelPlayerNameLabel.init(leftLabelStart,leftline);
labelPlayerNameLabel.setText(lang.get("Playername"));
labelPlayerName.init(leftColumnStart,leftline);
labelPlayerName.setText(config.getString("NetPlayerName",Socket::getHostName().c_str()));
leftline-=30;
leftline-=30;
labelVideoSection.init(leftLabelStart+captionOffset, leftline);
labelVideoSection.setFont(CoreData::getInstance().getMenuFontVeryBig());
labelVideoSection.setText(lang.get("Video"));
leftline-=30;
//resolution
labelScreenModes.init(leftLabelStart, leftline);
labelScreenModes.setText(lang.get("Resolution"));
listBoxScreenModes.init(leftColumnStart, leftline, 170);
for(list<ModeInfo>::const_iterator it= modeInfos.begin(); it!=modeInfos.end(); ++it){
listBoxScreenModes.pushBackItem((*it).getString());
}
listBoxScreenModes.setSelectedItem(config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight"));
leftline-=30;
//filter
labelFilter.init(leftLabelStart, leftline);
labelFilter.setText(lang.get("Filter"));
listBoxFilter.init(leftColumnStart, leftline, 170);
listBoxFilter.pushBackItem("Bilinear");
listBoxFilter.pushBackItem("Trilinear");
listBoxFilter.setSelectedItem(config.getString("Filter"));
leftline-=30;
//shadows
labelShadows.init(leftLabelStart, leftline);
labelShadows.setText(lang.get("Shadows"));
listBoxShadows.init(leftColumnStart, leftline, 170);
for(int i= 0; i<Renderer::sCount; ++i){
listBoxShadows.pushBackItem(lang.get(Renderer::shadowsToStr(static_cast<Renderer::Shadows>(i))));
}
string str= config.getString("Shadows");
listBoxShadows.setSelectedItemIndex(clamp(Renderer::strToShadows(str), 0, Renderer::sCount-1));
leftline-=30;
//textures 3d
labelTextures3D.init(leftLabelStart, leftline);
listBoxTextures3D.init(leftColumnStart, leftline, 80);
labelTextures3D.setText(lang.get("Textures3D"));
listBoxTextures3D.pushBackItem(lang.get("No"));
listBoxTextures3D.pushBackItem(lang.get("Yes"));
listBoxTextures3D.setSelectedItemIndex(clamp(config.getBool("Textures3D"), false, true));
leftline-=30;
//lights
labelLights.init(leftLabelStart, leftline);
labelLights.setText(lang.get("MaxLights"));
listBoxLights.init(leftColumnStart, leftline, 80);
for(int i= 1; i<=8; ++i){
listBoxLights.pushBackItem(intToStr(i));
}
listBoxLights.setSelectedItemIndex(clamp(config.getInt("MaxLights")-1, 0, 7));
leftline-=30;
//unit particles
labelUnitParticles.init(leftLabelStart,leftline);
labelUnitParticles.setText(lang.get("ShowUnitParticles"));
listBoxUnitParticles.init(leftColumnStart,leftline,80);
listBoxUnitParticles.pushBackItem(lang.get("No"));
listBoxUnitParticles.pushBackItem(lang.get("Yes"));
listBoxUnitParticles.setSelectedItemIndex(clamp(config.getBool("UnitParticles"), 0, 1));
leftline-=30;
// buttons
buttonOk.init(200, buttonRowPos, 100);
buttonOk.setText(lang.get("Ok"));
buttonAbort.setText(lang.get("Abort"));
buttonAbort.init(310, buttonRowPos, 100);
buttonAutoConfig.setText(lang.get("AutoConfig"));
buttonAutoConfig.init(450, buttonRowPos, 125);
}
@ -174,6 +216,7 @@ void MenuStateOptions::mouseClick(int x, int y, MouseButton mouseButton){
listBoxVolumeFx.mouseClick(x, y);
listBoxVolumeAmbient.mouseClick(x, y);
listBoxVolumeMusic.mouseClick(x, y);
listBoxScreenModes.mouseClick(x, y);
}
}
@ -191,6 +234,7 @@ void MenuStateOptions::mouseMove(int x, int y, const MouseState *ms){
listBoxTextures3D.mouseMove(x, y);
listBoxUnitParticles.mouseMove(x, y);
listBoxLights.mouseMove(x, y);
listBoxScreenModes.mouseMove(x, y);
}
void MenuStateOptions::keyDown(char key){
@ -249,6 +293,11 @@ void MenuStateOptions::render(){
renderer.renderLabel(&labelVolumeFx);
renderer.renderLabel(&labelVolumeAmbient);
renderer.renderLabel(&labelVolumeMusic);
renderer.renderLabel(&labelVideoSection);
renderer.renderLabel(&labelAudioSection);
renderer.renderLabel(&labelMiscSection);
renderer.renderLabel(&labelScreenModes);
renderer.renderListBox(&listBoxScreenModes);
}
void MenuStateOptions::saveConfig(){
@ -275,7 +324,20 @@ void MenuStateOptions::saveConfig(){
config.setString("SoundVolumeAmbient", listBoxVolumeAmbient.getSelectedItem());
CoreData::getInstance().getMenuMusic()->setVolume(strToInt(listBoxVolumeMusic.getSelectedItem())/100.f);
config.setString("SoundVolumeMusic", listBoxVolumeMusic.getSelectedItem());
//just for the moment ....
string currentResolution=config.getString("ScreenWidth")+"x"+config.getString("ScreenHeight");
string selectedResolution=listBoxScreenModes.getSelectedItem();
if(currentResolution!=selectedResolution){
for(list<ModeInfo>::const_iterator it= modeInfos.begin(); it!=modeInfos.end(); ++it){
if((*it).getString()==selectedResolution)
{
config.setInt("ScreenWidth",(*it).width);
config.setInt("ScreenHeight",(*it).height);
}
}
}
config.save();
Renderer::getInstance().loadConfig();
SoundRenderer::getInstance().loadConfig();

View File

@ -44,11 +44,18 @@ private:
GraphicListBox listBoxVolumeFx;
GraphicListBox listBoxVolumeAmbient;
GraphicListBox listBoxVolumeMusic;
GraphicListBox listBoxMusicSelect;
GraphicLabel labelPlayerName;
GraphicLabel labelPlayerNameLabel;
GraphicLabel *activeInputLabel;
GraphicLabel labelScreenModes;
GraphicListBox listBoxScreenModes;
list<ModeInfo> modeInfos;
GraphicLabel labelVideoSection;
GraphicLabel labelAudioSection;
GraphicLabel labelMiscSection;
public:
MenuStateOptions(Program *program, MainMenu *mainMenu);

View File

@ -14,6 +14,8 @@
#include <string>
#include <vector>
#include <stdexcept>
#include <list>
#include <SDL.h>
@ -23,6 +25,7 @@
using std::string;
using std::vector;
using std::list;
using std::exception;
using Shared::Platform::int64;
@ -76,6 +79,20 @@ private:
int64 queryCounter(int multiplier) const;
};
// =====================================================
// class ModeInfo
// =====================================================
class ModeInfo {
public:
int width;
int height;
int depth;
ModeInfo(int width, int height, int depth);
string getString() const;
};
// =====================================================
// class PlatformExceptionHandler
// =====================================================
@ -101,6 +118,7 @@ void createDirectoryPaths(string Path);
string extractDirectoryPathFromFile(string filename);
string extractExtension(const string& filename);
void getFullscreenVideoModes(list<ModeInfo> *modeinfos);
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight);
bool changeVideoMode(int resH, int resW, int colorBits, int refreshFrequency);
void restoreVideoMode(bool exitingApp=false);

View File

@ -509,6 +509,51 @@ void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight) {
}
}
void getFullscreenVideoModes(list<ModeInfo> *modeinfos) {
// Get the current video hardware information
//const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
//colorBits = vidInfo->vfmt->BitsPerPixel;
//screenWidth = vidInfo->current_w;
//screenHeight = vidInfo->current_h;
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
/* Get available fullscreen/hardware modes */
SDL_Rect**modes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE);
/* Check if there are any modes available */
if (modes == (SDL_Rect**)0) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] no hardware modes available.\n",__FILE__,__FUNCTION__,__LINE__);
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h);
}
/* Check if our resolution is restricted */
else if (modes == (SDL_Rect**)-1) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] all resolutions available.\n",__FILE__,__FUNCTION__,__LINE__);
const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo();
modeinfos->push_back(ModeInfo(vidInfo->current_w,vidInfo->current_h,vidInfo->vfmt->BitsPerPixel));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding only current resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,vidInfo->current_w,vidInfo->current_h);
}
else{
/* Print valid modes */
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] available Modes are:\n",__FILE__,__FUNCTION__,__LINE__);
int bestW = -1;
int bestH = -1;
for(int i=0; modes[i]; ++i) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"%d x %d\n",modes[i]->w, modes[i]->h,modes[i]->x);
modeinfos->push_back(ModeInfo(modes[i]->w,modes[i]->h,modes[i]->x));
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] adding resolution: %d x %d.\n",__FILE__,__FUNCTION__,__LINE__,modes[i]->w,modes[i]->h);
}
}
}
bool changeVideoMode(int resW, int resH, int colorBits, int ) {
Private::shouldBeFullscreen = true;
return true;
@ -592,4 +637,19 @@ bool isKeyDown(int virtualKey) {
return false;
}
// =====================================
// ModeInfo
// =====================================
ModeInfo::ModeInfo(int w, int h, int d) {
width=w;
height=h;
depth=d;
}
string ModeInfo::getString() const{
return intToStr(width)+"x"+intToStr(height);
}
}}//end namespace