Fixed bug where window/fullscreen button only displayed "windowed"

Fixed bug where failing to confirm a change to fullscreen did not return you to window mode
Fixed bug where selecting blacklisted resolutions was possible
Resolutions removed from the blacklist are now available immediately
Blacklisted resolutions are now displayed but are not selectable
Resolutions can now be removed from the blacklist individually
Crash detection improved: Crashes / kills are now detected until either the race mode GUI is opened or STK is quit


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1412 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
scifly 2008-01-21 22:06:57 +00:00
parent ad86255e48
commit 25db1ea889
8 changed files with 228 additions and 87 deletions

View File

@ -59,6 +59,26 @@ enum WidgetTokens
ConfigDisplay::ConfigDisplay()
{
// The following code comes before the widget code because it may change
// the fullscreen status, which is used in displaying the WTOK_FULLSCREEN
// text.
// if prev resolution different to current res then a resolution change
// has been rejected
if (user_config->m_width != user_config->m_prev_width
&& user_config->m_height != user_config->m_prev_height)
{
changeResolution(user_config->m_prev_width,
user_config->m_prev_height,true);
}
// if m_prev_windowed is true and m_fullscreen is true then a change to
// fullscreen has been rejected
if (user_config->m_prev_windowed && user_config->m_fullscreen)
{
drv_toggleFullscreen();
user_config->m_prev_windowed = false; //reset flag
}
const bool SHOW_RECT = true;
const bool SHOW_TEXT = true;
widget_manager->setInitialRectState(SHOW_RECT, WGT_AREA_ALL, WGT_TRANS_BLACK);
@ -102,16 +122,17 @@ ConfigDisplay::ConfigDisplay()
widget_manager->addWgt( WTOK_APPLY_RES, 40, 7);
widget_manager->setWgtText( WTOK_APPLY_RES, _("Apply "));
if (!user_config->m_blacklist_res.empty())
{
widget_manager->addWgt( WTOK_EMPTY3, 40, 2);
widget_manager->deactivateWgt( WTOK_EMPTY3 );
widget_manager->hideWgtRect( WTOK_EMPTY3 );
widget_manager->hideWgtText( WTOK_EMPTY3 );
widget_manager->addWgt( WTOK_EMPTY3, 40, 2);
widget_manager->deactivateWgt( WTOK_EMPTY3 );
widget_manager->hideWgtRect( WTOK_EMPTY3 );
widget_manager->hideWgtText( WTOK_EMPTY3 );
widget_manager->addWgt( WTOK_CLEAR_BLACKLIST, 40, 7);
widget_manager->setWgtText( WTOK_CLEAR_BLACKLIST, _("Clear from Blacklist"));
widget_manager->deactivateWgt( WTOK_CLEAR_BLACKLIST);
widget_manager->hideWgtRect( WTOK_CLEAR_BLACKLIST);
widget_manager->hideWgtText( WTOK_CLEAR_BLACKLIST);
widget_manager->addWgt( WTOK_CLEAR_BLACKLIST, 55, 7);
widget_manager->setWgtText( WTOK_CLEAR_BLACKLIST, _("Clear Resolution Blacklist"));
}
widget_manager->addWgt( WTOK_EMPTY1, 40, 7);
widget_manager->deactivateWgt( WTOK_EMPTY1 );
@ -121,14 +142,6 @@ ConfigDisplay::ConfigDisplay()
widget_manager->addWgt( WTOK_QUIT, 40, 7);
widget_manager->setWgtText( WTOK_QUIT, _("Press <ESC> to go back"));
widget_manager->setWgtTextSize( WTOK_QUIT, WGT_FNT_SML );
//if prev resolution different to current res then a resolution change has been rejected
if (user_config->m_width != user_config->m_prev_width
&& user_config->m_height != user_config->m_prev_height)
{
changeResolution(user_config->m_prev_width,
user_config->m_prev_height,true);
}
widget_manager->layout( WGT_AREA_ALL );
@ -147,9 +160,23 @@ ConfigDisplay::ConfigDisplay()
widget_manager->setWgtText(WTOK_CURRENT_RES, m_resolution);
}
// Set crashed flag to false (needed after confirming change to fullscreen)
user_config->m_crashed = false; //if got here,then fullscreen change didn't crash STK
user_config->saveConfig();
m_blacklist_res_size = 0;
if (!user_config->m_blacklist_res.empty())
{
m_blacklist_res_size = (int)user_config->m_blacklist_res.size();
if (onBlacklist(m_curr_width,m_curr_height) >= 0) // check current res against blacklist
{
// if in windowed mode make fullscreen unavailable
if (!user_config->m_fullscreen)
{
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
widget_manager->deactivateWgt(WTOK_FULLSCREEN);
}
else
showBlacklistButtons(); // change widgets to blacklisted mode
}
}
}
//-----------------------------------------------------------------------------
@ -164,19 +191,45 @@ void ConfigDisplay::select()
switch ( widget_manager->getSelectedWgt())
{
case WTOK_FULLSCREEN:
drv_toggleFullscreen();
drv_toggleFullscreen();
if (user_config->m_fullscreen)
menu_manager->pushMenu(MENUID_DISPLAY_RES_CONFIRM);
break;
{
user_config->m_prev_windowed = true;
menu_manager->pushMenu(MENUID_DISPLAY_RES_CONFIRM);
}
else
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
changeApplyButton();
break;
case WTOK_INCR_RES:
m_sizes_index = std::min(m_sizes_size-1,m_sizes_index+1);
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("Apply %dx%d"),m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
//if there is a blacklist and we are fullscreen, inform user about blacklisted res
if (!user_config->m_blacklist_res.empty() && user_config->m_fullscreen)
{
if (onBlacklist() >= 0) // check new res against blacklist
{
showBlacklistButtons(); // change widgets to blacklisted mode
}
else
changeApplyButton();
}
else
changeApplyButton(); // change text on Apply button
break;
case WTOK_DECR_RES:
m_sizes_index = std::max(0,m_sizes_index-1);
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("Apply %dx%d"),m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
//if there is a blacklist and we are fullscreen, inform user about blacklisted res
if (!user_config->m_blacklist_res.empty() && user_config->m_fullscreen)
{
if (onBlacklist() >= 0) // check new res against blacklist
{
showBlacklistButtons(); // change widgets to blacklisted mode
}
else
changeApplyButton();
}
else
changeApplyButton(); // change text on Apply button
break;
case WTOK_APPLY_RES:
if (m_curr_width != m_sizes[m_sizes_index].first
@ -184,13 +237,27 @@ void ConfigDisplay::select()
{
changeResolution(m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
if (user_config->m_fullscreen)
if (user_config->m_fullscreen) // if in fullscreen seek confirmation
menu_manager->pushMenu(MENUID_DISPLAY_RES_CONFIRM);
else
{
snprintf (m_resolution, MAX_MESSAGE_LENGTH, "Current: %dx%d",
user_config->m_width, user_config->m_height);
widget_manager->setWgtText(WTOK_CURRENT_RES, m_resolution);
// Check new res against blacklist to determine if fullscreen is an option
if (!user_config->m_blacklist_res.empty())
{
if (onBlacklist(user_config->m_width, user_config->m_height) >= 0)
{
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen Unavailable"));
widget_manager->deactivateWgt(WTOK_FULLSCREEN);
}
else
{
widget_manager->setWgtText(WTOK_FULLSCREEN, _("Fullscreen mode"));
widget_manager->activateWgt(WTOK_FULLSCREEN);
}
}
widget_manager->layout();
// set prev_width and height values to current
user_config->m_prev_width = m_curr_width = user_config->m_width;
@ -200,9 +267,15 @@ void ConfigDisplay::select()
}
break;
case WTOK_CLEAR_BLACKLIST:
user_config->m_blacklist_res.clear();
widget_manager->hideWgtRect( WTOK_CLEAR_BLACKLIST );
widget_manager->hideWgtText( WTOK_CLEAR_BLACKLIST );
user_config->m_blacklist_res.erase(user_config->m_blacklist_res.begin()
+ onBlacklist());
if (!user_config->m_blacklist_res.empty())
m_blacklist_res_size = (int)user_config->m_blacklist_res.size();
else
m_blacklist_res_size = 0;
changeApplyButton();
widget_manager->layout();
break;
case WTOK_QUIT:
@ -247,66 +320,43 @@ void ConfigDisplay::changeResolution(int width, int height, bool reverse)
//populates a vector with them.
void ConfigDisplay::getScreenModes()
{
if (m_sizes.empty()) //has this data been collected before
{
SDL_Rect **modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE );
SDL_Rect **modes = SDL_ListModes(NULL, SDL_OPENGL | SDL_FULLSCREEN | SDL_HWSURFACE );
//Check if any modes are available
if (!modes)
//Check if any modes are available
if (!modes)
{
std::cerr << "No Screen Modes available" <<std::endl;
}
else if (modes == (SDL_Rect **)-1)
{
//This means all modes are available..Shouldn't happen.
std::cerr << "All modes available" << std::endl;
}
else
{
for (int i = 0; modes[i]; ++i)
m_sizes.push_back (std::pair <int, int> (modes[i]->w, modes[i]->h));
//Sort the entries
sort (m_sizes.begin(), m_sizes.end());
//Prevent use of very small resolutions
const int minRes = 640;
m_sizes_size = (int)m_sizes.size();
for (int i = m_sizes_size-1; i >= 0; --i)
{
std::cerr << "No Screen Modes available" <<std::endl;
}
else if (modes == (SDL_Rect **)-1)
{
//This means all modes are available..Shouldn't happen.
std::cerr << "All modes available" << std::endl;
}
else
{
for (int i = 0; modes[i]; ++i)
m_sizes.push_back (std::pair <int, int> (modes[i]->w, modes[i]->h));
//Sort the entries
sort (m_sizes.begin(), m_sizes.end());
//Prevent use of very small resolutions
const int minRes = 640;
m_sizes_size = (int)m_sizes.size();
for (int i = m_sizes_size-1; i >= 0; --i)
if (m_sizes[i].first < minRes) //find largest width less than minRes
{
if (m_sizes[i].first < minRes) //find largest width less than minRes
{
m_sizes.erase(m_sizes.begin(),m_sizes.begin()+i+1); //remove all resolutions prior
break;
}
m_sizes.erase(m_sizes.begin(),m_sizes.begin()+i+1); //remove all resolutions prior
break;
}
}
}// m_sizes.empty()
}
}
//reassess m_sizes_size
m_sizes_size = (int)m_sizes.size();
//Remove blacklisted resolutions from the list
if (!user_config->m_blacklist_res.empty())
{
int blacklist_res_size = (int)user_config->m_blacklist_res.size();
int black_width, black_height = 0;
for (int i = 0; i < blacklist_res_size; i++)
{
sscanf(user_config->m_blacklist_res[i].c_str(),
"%dx%d",& black_width, & black_height);
for (int i = m_sizes_size-1; i >=0; i--)
{
if (m_sizes[i].first == black_width
&& m_sizes[i].second == black_height)
{
m_sizes.erase(m_sizes.begin()+i);
}
}
}
}
// search m_sizes for the current resolution
m_sizes_index = -1;
@ -323,3 +373,66 @@ void ConfigDisplay::getScreenModes()
}
//-----------------------------------------------------------------------------
void ConfigDisplay::changeApplyButton()
{
// change Apply button text
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("Apply %dx%d"),
m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
widget_manager->activateWgt(WTOK_APPLY_RES);
// hide Remove from blacklist button
widget_manager->hideWgtRect(WTOK_CLEAR_BLACKLIST);
widget_manager->hideWgtText(WTOK_CLEAR_BLACKLIST);
widget_manager->deactivateWgt(WTOK_CLEAR_BLACKLIST);
}
//-----------------------------------------------------------------------------
int ConfigDisplay::onBlacklist()
{
int black_width, black_height = 0;
for (int i = 0; i < m_blacklist_res_size; i++)
{
sscanf(user_config->m_blacklist_res[i].c_str(),
"%dx%d",& black_width, & black_height);
if (m_sizes[m_sizes_index].first == black_width
&& m_sizes[m_sizes_index].second == black_height)
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
int ConfigDisplay::onBlacklist(int width, int height)
{
int black_width, black_height = 0;
for (int i = 0; i < m_blacklist_res_size; i++)
{
sscanf(user_config->m_blacklist_res[i].c_str(),
"%dx%d",& black_width, & black_height);
if (width == black_width && height == black_height)
return i;
}
return -1;
}
//-----------------------------------------------------------------------------
void ConfigDisplay::showBlacklistButtons()
{
//change Apply button to Blacklisted button
snprintf(m_resolution, MAX_MESSAGE_LENGTH, _("%dx%d Blacklisted"),
m_sizes[m_sizes_index].first,m_sizes[m_sizes_index].second);
widget_manager->setWgtText(WTOK_APPLY_RES, m_resolution);
widget_manager->deactivateWgt(WTOK_APPLY_RES);
//show Remove from blacklist button
widget_manager->showWgtRect( WTOK_CLEAR_BLACKLIST);
widget_manager->showWgtText( WTOK_CLEAR_BLACKLIST);
widget_manager->activateWgt( WTOK_CLEAR_BLACKLIST);
}

View File

@ -41,10 +41,17 @@ private:
char m_resolution[MAX_MESSAGE_LENGTH];
int m_curr_width;
int m_curr_height;
int m_blacklist_res_size;
// changeResolution reverse param is set true when changing to a previous resolution
void changeResolution(int width, int height, bool reverse=false);
void getScreenModes();
void changeApplyButton();
// onBlacklist returns the index of the resolution in the blacklist
// or -1 if not in the blacklist
int onBlacklist();
int onBlacklist(int width, int height);
void showBlacklistButtons();
};
#endif

View File

@ -80,6 +80,8 @@ DisplayResConfirm::DisplayResConfirm()
widget_manager->layout( WGT_AREA_ALL );
m_timer = SDL_AddTimer(1000,timeout,NULL);
if (m_timer == NULL)
std::cerr << "Warning: Timer could not be initialised!" << std::endl;
}
@ -98,6 +100,12 @@ void DisplayResConfirm::select()
//set prev resolution to current values to confirm change
user_config->m_prev_width = user_config->m_width;
user_config->m_prev_height = user_config->m_height;
// if changing to fullscreen then it has now been confirmed
// so we need to change m_prev_windowed to confirm the change
if (user_config->m_fullscreen && user_config->m_prev_windowed)
user_config->m_prev_windowed = false;
SDL_RemoveTimer(m_timer);
menu_manager->popMenu();
break;
@ -131,7 +139,6 @@ void DisplayResConfirm::countdown()
}
}
//=============================================================================
Uint32 timeout(Uint32 interval, void *param)
{
@ -150,3 +157,4 @@ Uint32 timeout(Uint32 interval, void *param)
return (interval);
}

View File

@ -21,7 +21,6 @@
#define HEADER_DISPLAY_RES_CONFIRM_H
#include "base_gui.hpp"
//#include "translation.hpp"
#include <SDL/SDL.h>
@ -35,9 +34,10 @@ public:
void countdown();
private:
SDL_TimerID m_timer;
char m_count[60];
int m_counter;
SDL_TimerID m_timer;
};
Uint32 timeout(Uint32 interval, void *param);

View File

@ -22,6 +22,7 @@
#include "race_manager.hpp"
#include "menu_manager.hpp"
#include "translation.hpp"
#include "user_config.hpp"
enum WidgetTokens
{
@ -69,6 +70,11 @@ GameMode::GameMode()
widget_manager->setWgtTextSize( WTOK_BACK, WGT_FNT_SML );
widget_manager->layout(WGT_AREA_ALL);
// Set crashed flag to false, as if made it here after chaging res
// then can't have crashed or been killed
user_config->m_crashed = false;
user_config->saveConfig();
}
//-----------------------------------------------------------------------------

View File

@ -478,6 +478,9 @@ int main(int argc, char *argv[] )
}
/* Program closing...*/
// Set crashed flag to false
user_config->m_crashed = false;
user_config->saveConfig();
drv_deinit();

View File

@ -133,6 +133,7 @@ void UserConfig::setDefaults()
m_height = 600;
m_prev_width = m_width;
m_prev_height = m_height;
m_prev_windowed = false;
m_crashed = false;
m_blacklist_res.clear();
m_karts = 4;
@ -442,6 +443,7 @@ void UserConfig::loadConfig(const std::string& filename)
lisp->get("height", m_height);
lisp->get("prev_width", m_prev_width);
lisp->get("prev_height", m_prev_height);
lisp->get("prev_windowed", m_prev_windowed);
//detect if resolution change previously crashed STK
lisp->get("crash_detected", m_crashed);
// blacklisted resolutions
@ -638,6 +640,7 @@ void UserConfig::saveConfig(const std::string& filename)
writer->write("height\t", m_height);
writer->write("prev_width\t", m_prev_width);
writer->write("prev_height\t", m_prev_height);
writer->write("prev_windowed\t", m_prev_windowed);
writer->write("crash_detected\t", m_crashed);
writer->write("blacklisted_resolutions\t", m_blacklist_res);
writer->write("fullscreen\t", m_fullscreen);

View File

@ -156,6 +156,7 @@ public:
int m_height;
int m_prev_width;
int m_prev_height;
bool m_prev_windowed;
bool m_crashed;
std::vector<std::string> m_blacklist_res;
int m_karts;