]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Fixed resolution detection and handling
[lugaru.git] / Source / GameTick.cpp
index 122471a4d769c4bdd1766c10889b6f1e9c70b145..bcbce6e9bc9ce576118f70ddb4586c185fa1659c 100644 (file)
@@ -44,6 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Menu.h"
 
 #include <algorithm>
+#include <set>
 
 using namespace std;
 using namespace Game;
@@ -6009,7 +6010,7 @@ void Game::LoadMenu()
     }
 }
 
-extern SDL_Rect **resolutions;
+extern set<pair<int,int>> resolutions;
 
 void MenuTick()
 {
@@ -6033,6 +6034,7 @@ void MenuTick()
     char sbuf[256];
 
     if (Input::MouseClicked() && (selected >= 0)) { // handling of the left mouse clic in menus
+        set<pair<int,int>>::iterator newscreenresolution;
         switch (mainmenu) {
         case 1:
         case 2:
@@ -6081,40 +6083,17 @@ void MenuTick()
             break;
         case 3:
             fireSound();
-            bool isCustomResolution, found;
             switch (selected) {
             case 0:
-                isCustomResolution = true;
-                found = false;
-                for (int i = 0; (!found) && (resolutions[i]); i++) {
-                    if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
-                        isCustomResolution = false;
-
-                    if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
-                        i++;
-                        if (resolutions[i] != NULL) {
-                            newscreenwidth = (int) resolutions[i]->w;
-                            newscreenheight = (int) resolutions[i]->h;
-                        } else if (isCustomResolution) {
-                            if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
-                                newscreenwidth = (int) resolutions[0]->w;
-                                newscreenheight = (int) resolutions[0]->h;
-                            } else {
-                                newscreenwidth = screenwidth;
-                                newscreenheight = screenheight;
-                            }
-                        } else {
-                            newscreenwidth = (int) resolutions[0]->w;
-                            newscreenheight = (int) resolutions[0]->h;
-                        }
-                        found = true;
-                    }
-                }
-
-                if (!found) {
-                    newscreenwidth = (int) resolutions[0]->w;
-                    newscreenheight = (int) resolutions[0]->h;
+                newscreenresolution = resolutions.find(make_pair(newscreenwidth, newscreenheight));
+                /* Next one (end() + 1 is also end() so the ++ is safe even if it was not found) */
+                newscreenresolution++;
+                if (newscreenresolution == resolutions.end()) {
+                    /* It was the last one (or not found), go back to the beginning */
+                    newscreenresolution = resolutions.begin();
                 }
+                newscreenwidth  = newscreenresolution->first;
+                newscreenheight = newscreenresolution->second;
                 break;
             case 1:
                 newdetail++;
@@ -6567,28 +6546,6 @@ void Game::Tick()
             }
         }
 
-        if (Input::isKeyPressed(chatkey) && !console && !chatting && debugmode)
-            chatting = 1;
-
-        if (chatting) {
-            inputText(displaytext[0], &displayselected);
-            if (!waiting) {
-                if (!displaytext[0].empty()) {
-                    displaytext[0].clear();
-                    displayselected = 0;
-                }
-                chatting = 0;
-            }
-
-            displayblinkdelay -= multiplier;
-            if (displayblinkdelay <= 0) {
-                displayblinkdelay = .3;
-                displayblink = 1 - displayblink;
-            }
-        }
-        if (chatting)
-            keyboardfrozen = true;
-
         if (Input::isKeyPressed(consolekey) && debugmode) {
             console = !console;
             if (console) {