Kaynağa Gözat

Removed Menu play button

Thomas Buck 9 yıl önce
ebeveyn
işleme
8bedd53014
5 değiştirilmiş dosya ile 37 ekleme ve 45 silme
  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 Dosyayı Görüntüle

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

+ 1
- 0
ChangeLog.md Dosyayı Görüntüle

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

+ 3
- 3
include/Menu.h Dosyayı Görüntüle

@@ -46,10 +46,10 @@ private:
46 46
     void play();
47 47
 
48 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 54
     Folder *mapFolder;
55 55
 };

+ 30
- 33
src/Menu.cpp Dosyayı Görüntüle

@@ -43,22 +43,28 @@ Menu::~Menu() {
43 43
 }
44 44
 
45 45
 int Menu::initialize() {
46
+    if (mapFolder != nullptr)
47
+        delete mapFolder;
46 48
     mapFolder = new Folder(getOpenRaider().mPakDir);
47 49
 
48 50
     mapFolder->executeRemoveRecursiveItems([](File &f) {
51
+        // Filter files based on file name
49 52
         if ((f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
50 53
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
51 54
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
52 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 60
         int error = TombRaider::checkMime(f.getPath().c_str());
56 61
         if (error != 0) {
57 62
             getConsole().print("Error: pak file '%s' %s",
58 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 70
     return 0;
@@ -79,27 +85,20 @@ void Menu::display() {
79 85
     // Draw half-transparent *overlay*
80 86
     glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
81 87
     glDisable(GL_TEXTURE_2D);
82
-    glRecti(0, 0, getWindow().getWidth(), getWindow().getHeight());
88
+    glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
83 89
     glEnable(GL_TEXTURE_2D);
84 90
 
85 91
     // Draw heading text, using FontString so we can get the
86 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 94
     getFont().writeString(mainText);
89 95
 
90 96
     if ((mapFolder == nullptr) || (mapFolder->countRecursiveItems() == 0)) {
91 97
         getFont().drawText(25, (getWindow().getHeight() / 2) - 20, 0.75f, RED, "No maps found! See README.md");
92 98
         return;
93 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 100
         // Estimate displayable number of items
102
-        int items = (getWindow().getHeight() - 110) / 25;
101
+        int items = (getWindow().getHeight() - 60) / 25;
103 102
 
104 103
         // Select which part of the list to show
105 104
         long min, max;
@@ -108,10 +107,10 @@ void Menu::display() {
108 107
         else
109 108
             min = 0;
110 109
 
111
-        if ((mCursor + (items / 2)) < mapFolder->countRecursiveItems())
110
+        if ((mCursor + (items / 2)) < (long)mapFolder->countRecursiveItems())
112 111
             max = mCursor + (items / 2);
113 112
         else
114
-            max = mapFolder->countRecursiveItems();
113
+            max = (long)mapFolder->countRecursiveItems();
115 114
 
116 115
         while ((max - min) < items) {
117 116
             if (min > 0)
@@ -124,18 +123,16 @@ void Menu::display() {
124 123
 
125 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 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 136
     if (getOpenRaider().command(tmp) == 0) {
140 137
         setVisible(false);
141 138
     } else {
@@ -152,16 +149,16 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
152 149
         if (mCursor > 0)
153 150
             mCursor--;
154 151
         else
155
-            mCursor = mapFolder->countRecursiveItems() - 1;
152
+            mCursor = (long)mapFolder->countRecursiveItems() - 1;
156 153
     } else if (key == downKey) {
157
-        if (mCursor < (mapFolder->countRecursiveItems() - 1))
154
+        if (mCursor < (long)(mapFolder->countRecursiveItems() - 1))
158 155
             mCursor++;
159 156
         else
160 157
             mCursor = 0;
161 158
     } else if (key == rightKey) {
162 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 162
         while (i-- > 0)
166 163
             handleKeyboard(downKey, true);
167 164
     } else if (key == leftKey) {
@@ -176,17 +173,17 @@ void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
176 173
 }
177 174
 
178 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 178
     if (released || (button != leftmouseKey))
182 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 Dosyayı Görüntüle

@@ -11,11 +11,9 @@
11 11
 #include "utils/File.h"
12 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 17
     std::transform(name.begin(), name.end(), name.begin(), ::tolower);
20 18
 }
21 19
 

Loading…
İptal
Kaydet