Browse Source

Removed Menu play button

Thomas Buck 10 years ago
parent
commit
8bedd53014
5 changed files with 37 additions and 45 deletions
  1. 0
    4
      .travis.yml
  2. 1
    0
      ChangeLog.md
  3. 3
    3
      include/Menu.h
  4. 30
    33
      src/Menu.cpp
  5. 3
    5
      src/utils/File.cpp

+ 0
- 4
.travis.yml View File

35
     - linux
35
     - linux
36
     - osx
36
     - osx
37
 
37
 
38
-matrix:
39
-    allow_failures:
40
-        - os: osx
41
-
42
 env:
38
 env:
43
     global:
39
     global:
44
         # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
40
         # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created

+ 1
- 0
ChangeLog.md View File

5
     [ 20140809 ]
5
     [ 20140809 ]
6
     * Script Unit Test brings it’s own scripts to test
6
     * Script Unit Test brings it’s own scripts to test
7
     * Fixed binary Unit Test not deleting it’s tmp file in case of error
7
     * Fixed binary Unit Test not deleting it’s tmp file in case of error
8
+    * Removed Menu play button
8
 
9
 
9
     [ 20140808 ]
10
     [ 20140808 ]
10
     * Added unit test for file-system utils
11
     * Added unit test for file-system utils

+ 3
- 3
include/Menu.h View File

46
     void play();
46
     void play();
47
 
47
 
48
     bool mVisible;
48
     bool mVisible;
49
-    unsigned long mCursor;
50
-    unsigned long mMin;
49
+    long mCursor;
50
+    long mMin;
51
 
51
 
52
-    FontString mainText;
52
+    FontString mainText; //!< Used to draw heading centered
53
 
53
 
54
     Folder *mapFolder;
54
     Folder *mapFolder;
55
 };
55
 };

+ 30
- 33
src/Menu.cpp View File

43
 }
43
 }
44
 
44
 
45
 int Menu::initialize() {
45
 int Menu::initialize() {
46
+    if (mapFolder != nullptr)
47
+        delete mapFolder;
46
     mapFolder = new Folder(getOpenRaider().mPakDir);
48
     mapFolder = new Folder(getOpenRaider().mPakDir);
47
 
49
 
48
     mapFolder->executeRemoveRecursiveItems([](File &f) {
50
     mapFolder->executeRemoveRecursiveItems([](File &f) {
51
+        // Filter files based on file name
49
         if ((f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
52
         if ((f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
50
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
53
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
51
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
54
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
52
             && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
55
             && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
53
-            return true;
56
+            return true; // delete file from list
54
         }
57
         }
58
+
59
+        // Check maps for validity
55
         int error = TombRaider::checkMime(f.getPath().c_str());
60
         int error = TombRaider::checkMime(f.getPath().c_str());
56
         if (error != 0) {
61
         if (error != 0) {
57
             getConsole().print("Error: pak file '%s' %s",
62
             getConsole().print("Error: pak file '%s' %s",
58
                     f.getName().c_str(), (error == -1) ? "not found" : "invalid");
63
                     f.getName().c_str(), (error == -1) ? "not found" : "invalid");
59
-            return true;
64
+            return true; // delete file from list
60
         }
65
         }
61
-        return false;
66
+
67
+        return false; // keep file on list
62
     });
68
     });
63
 
69
 
64
     return 0;
70
     return 0;
79
     // Draw half-transparent *overlay*
85
     // Draw half-transparent *overlay*
80
     glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
86
     glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
81
     glDisable(GL_TEXTURE_2D);
87
     glDisable(GL_TEXTURE_2D);
82
-    glRecti(0, 0, getWindow().getWidth(), getWindow().getHeight());
88
+    glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
83
     glEnable(GL_TEXTURE_2D);
89
     glEnable(GL_TEXTURE_2D);
84
 
90
 
85
     // Draw heading text, using FontString so we can get the
91
     // Draw heading text, using FontString so we can get the
86
     // width of the drawn text to center it
92
     // width of the drawn text to center it
87
-    mainText.x = (getWindow().getWidth() / 2) - (mainText.w / 2);
93
+    mainText.x = (getWindow().getWidth() / 2) - ((unsigned int)(mainText.w / 2));
88
     getFont().writeString(mainText);
94
     getFont().writeString(mainText);
89
 
95
 
90
     if ((mapFolder == nullptr) || (mapFolder->countRecursiveItems() == 0)) {
96
     if ((mapFolder == nullptr) || (mapFolder->countRecursiveItems() == 0)) {
91
         getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");
97
         getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");
92
         return;
98
         return;
93
     } else {
99
     } else {
94
-        // draw *play button* above list
95
-        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
96
-        glDisable(GL_TEXTURE_2D);
97
-        glRecti(25, 25, 100, 75);
98
-        glEnable(GL_TEXTURE_2D);
99
-        getFont().drawText(40, 35, 0.75f, BLACK, "Play");
100
-
101
         // Estimate displayable number of items
100
         // Estimate displayable number of items
102
-        int items = (getWindow().getHeight() - 110) / 25;
101
+        int items = (getWindow().getHeight() - 60) / 25;
103
 
102
 
104
         // Select which part of the list to show
103
         // Select which part of the list to show
105
         long min, max;
104
         long min, max;
108
         else
107
         else
109
             min = 0;
108
             min = 0;
110
 
109
 
111
-        if ((mCursor + (items / 2)) < mapFolder->countRecursiveItems())
110
+        if ((mCursor + (items / 2)) < (long)mapFolder->countRecursiveItems())
112
             max = mCursor + (items / 2);
111
             max = mCursor + (items / 2);
113
         else
112
         else
114
-            max = mapFolder->countRecursiveItems();
113
+            max = (long)mapFolder->countRecursiveItems();
115
 
114
 
116
         while ((max - min) < items) {
115
         while ((max - min) < items) {
117
             if (min > 0)
116
             if (min > 0)
124
 
123
 
125
         mMin = min;
124
         mMin = min;
126
 
125
 
127
-        for (int i = 0; i < (max - min); i++) {
128
-            const char *map = mapFolder->getRecursiveItemName(i + min).c_str();
129
-            if ((i + min) == (int)mCursor)
130
-                getFont().drawText(25, 100 + (25 * i), 0.75f, RED, "%s", map);
131
-            else
132
-                getFont().drawText(25, 100 + (25 * i), 0.75f, BLUE, "%s", map);
126
+        for (long i = 0; i < (max - min); i++) {
127
+            const char *map = mapFolder->getRecursiveItemName((unsigned long)(i + min)).c_str();
128
+            getFont().drawText(25, (unsigned int)(50 + (25 * i)), 0.75f,
129
+                    ((i + min) == mCursor) ? RED : BLUE, "%s", map);
133
         }
130
         }
134
     }
131
     }
135
 }
132
 }
136
 
133
 
137
 void Menu::play() {
134
 void Menu::play() {
138
-    char *tmp = bufferString("load %s", mapFolder->getRecursiveItemName(mCursor).c_str());
135
+    char *tmp = bufferString("load %s", mapFolder->getRecursiveItemName((unsigned long)mCursor).c_str());
139
     if (getOpenRaider().command(tmp) == 0) {
136
     if (getOpenRaider().command(tmp) == 0) {
140
         setVisible(false);
137
         setVisible(false);
141
     } else {
138
     } else {
152
         if (mCursor > 0)
149
         if (mCursor > 0)
153
             mCursor--;
150
             mCursor--;
154
         else
151
         else
155
-            mCursor = mapFolder->countRecursiveItems() - 1;
152
+            mCursor = (long)mapFolder->countRecursiveItems() - 1;
156
     } else if (key == downKey) {
153
     } else if (key == downKey) {
157
-        if (mCursor < (mapFolder->countRecursiveItems() - 1))
154
+        if (mCursor < (long)(mapFolder->countRecursiveItems() - 1))
158
             mCursor++;
155
             mCursor++;
159
         else
156
         else
160
             mCursor = 0;
157
             mCursor = 0;
161
     } else if (key == rightKey) {
158
     } else if (key == rightKey) {
162
         long i = 10;
159
         long i = 10;
163
-        if (mCursor > (mapFolder->countRecursiveItems() - 11))
164
-            i = mapFolder->countRecursiveItems() - 1 - mCursor;
160
+        if (mCursor > (long)(mapFolder->countRecursiveItems() - 11))
161
+            i = ((long)mapFolder->countRecursiveItems()) - 1 - mCursor;
165
         while (i-- > 0)
162
         while (i-- > 0)
166
             handleKeyboard(downKey, true);
163
             handleKeyboard(downKey, true);
167
     } else if (key == leftKey) {
164
     } else if (key == leftKey) {
176
 }
173
 }
177
 
174
 
178
 void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
175
 void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
179
-    int items = (getWindow().getHeight() - 110) / 25;
176
+    int items = (getWindow().getHeight() - 60) / 25;
180
 
177
 
181
     if (released || (button != leftmouseKey))
178
     if (released || (button != leftmouseKey))
182
         return;
179
         return;
183
 
180
 
184
-    if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {
185
-        y -= 100;
186
-        mCursor = mMin + (y / 25);
187
-    } else if ((y >= 25) && (y <= 100) && (x >= 25) && (x <= 125)) {
188
-        // Play button
189
-        play();
181
+    if ((y >= 50) && (y <= (unsigned int)(50 + (25 * items)))) {
182
+        y -= 50;
183
+        if (mCursor == (mMin + (y / 25)))
184
+            play();
185
+        else
186
+            mCursor = mMin + (y / 25);
190
     }
187
     }
191
 }
188
 }
192
 
189
 

+ 3
- 5
src/utils/File.cpp View File

11
 #include "utils/File.h"
11
 #include "utils/File.h"
12
 #include "utils/Folder.h"
12
 #include "utils/Folder.h"
13
 
13
 
14
-File::File(std::string file) {
15
-    path = file;
16
-
17
-    size_t pos = path.rfind('/', path.length() - 2);
18
-    name = path.substr(pos + 1);
14
+File::File(std::string file) : path(file) {
15
+    size_t pos = file.rfind('/', file.length() - 2);
16
+    name = file.substr(pos + 1);
19
     std::transform(name.begin(), name.end(), name.begin(), ::tolower);
17
     std::transform(name.begin(), name.end(), name.begin(), ::tolower);
20
 }
18
 }
21
 
19
 

Loading…
Cancel
Save