Browse Source

Press dot key in Menu to see hidden files

Thomas Buck 9 years ago
parent
commit
3088d9685a
7 changed files with 72 additions and 33 deletions
  1. 3
    0
      ChangeLog.md
  2. 7
    2
      include/Font.h
  3. 3
    4
      include/Menu.h
  4. 32
    1
      src/Font.cpp
  5. 16
    24
      src/Menu.cpp
  6. 1
    0
      src/OpenRaider.cpp
  7. 10
    2
      src/utils/Folder.cpp

+ 3
- 0
ChangeLog.md View File

7
       into their own file
7
       into their own file
8
     * Menu now acts like a file-manager, only showing one folder,
8
     * Menu now acts like a file-manager, only showing one folder,
9
       and has the ability to go to the parent folder, and do mouse scrolling
9
       and has the ability to go to the parent folder, and do mouse scrolling
10
+    * Added API to Font to draw strings centered
11
+    * Folder sorts its items alphabetically
12
+    * Press dot key in Menu to see hidden files and folders
10
 
13
 
11
     [ 20140809 ]
14
     [ 20140809 ]
12
     * Script Unit Test brings it’s own scripts to test
15
     * Script Unit Test brings it’s own scripts to test

+ 7
- 2
include/Font.h View File

35
 
35
 
36
     virtual void writeString(FontString &s) = 0;
36
     virtual void writeString(FontString &s) = 0;
37
 
37
 
38
-    virtual void drawText(unsigned int x, unsigned int y, float scale, const unsigned char color[4], const char *s, ...)
39
-        __attribute__((format(printf, 6, 0)));
38
+    virtual void drawText(unsigned int x, unsigned int y, float scale,
39
+            const unsigned char color[4], const char *s, ...)
40
+            __attribute__((format(printf, 6, 0)));
41
+
42
+    virtual void drawTextCentered(unsigned int x, unsigned int y, float scale,
43
+            const unsigned char color[4], unsigned int width, const char *s, ...)
44
+            __attribute__((format(printf, 7, 0)));
40
 
45
 
41
 protected:
46
 protected:
42
     bool mFontInit;
47
     bool mFontInit;

+ 3
- 4
include/Menu.h View File

10
 
10
 
11
 #include <memory>
11
 #include <memory>
12
 
12
 
13
-#include "Font.h"
14
 #include "utils/Folder.h"
13
 #include "utils/Folder.h"
15
 
14
 
16
 /*!
15
 /*!
30
     ~Menu();
29
     ~Menu();
31
 
30
 
32
     int initialize();
31
     int initialize();
33
-    int initialize(Folder folder);
32
+    int initialize(std::string folder);
33
+    int initialize(Folder *folder);
34
 
34
 
35
     void setVisible(bool visible);
35
     void setVisible(bool visible);
36
 
36
 
52
     long mCursor;
52
     long mCursor;
53
     long mMin;
53
     long mMin;
54
 
54
 
55
-    FontString mainText; //!< Used to draw heading centered
56
-
57
     Folder *mapFolder;
55
     Folder *mapFolder;
56
+    bool hiddenState;
58
 };
57
 };
59
 
58
 
60
 Menu &getMenu();
59
 Menu &getMenu();

+ 32
- 1
src/Font.cpp View File

10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
 #include "utils/strings.h"
12
 #include "utils/strings.h"
13
+#include "Window.h"
13
 #include "Font.h"
14
 #include "Font.h"
14
 
15
 
15
 Font::~Font() {
16
 Font::~Font() {
25
     mFontName = fullPath(font, 0);
26
     mFontName = fullPath(font, 0);
26
 }
27
 }
27
 
28
 
28
-void Font::drawText(unsigned int x, unsigned int y, float scale, const unsigned char color[4], const char *s, ...) {
29
+void Font::drawText(unsigned int x, unsigned int y, float scale,
30
+        const unsigned char color[4], const char *s, ...) {
29
     FontString tempText;
31
     FontString tempText;
30
     va_list args;
32
     va_list args;
31
     va_start(args, s);
33
     va_start(args, s);
49
     va_end(args);
51
     va_end(args);
50
 }
52
 }
51
 
53
 
54
+void Font::drawTextCentered(unsigned int x, unsigned int y, float scale,
55
+        const unsigned char color[4], unsigned int width, const char *s, ...) {
56
+    FontString tempText;
57
+    va_list args;
58
+    va_start(args, s);
59
+
60
+    tempText.text = new char[256];
61
+    tempText.scale = scale;
62
+    tempText.w = 0;
63
+    tempText.h = 0;
64
+    tempText.x = x;
65
+    tempText.y = y + getWindow().getHeight(); //! \fixme Ugly hack to hide first draw
66
+    tempText.color[0] = color[0];
67
+    tempText.color[1] = color[1];
68
+    tempText.color[2] = color[2];
69
+    tempText.color[3] = color[3];
70
+
71
+    vsnprintf(tempText.text, 256, s, args);
72
+    tempText.text[255] = '\0';
73
+    writeString(tempText);
74
+
75
+    tempText.x = (width / 2) - ((unsigned int)(tempText.w / 2));
76
+    tempText.y = y;
77
+    writeString(tempText);
78
+
79
+    delete [] tempText.text;
80
+    va_end(args);
81
+}
82
+

+ 16
- 24
src/Menu.cpp View File

10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
 #include "Console.h"
12
 #include "Console.h"
13
+#include "Font.h"
13
 #include "OpenRaider.h"
14
 #include "OpenRaider.h"
14
 #include "utils/strings.h"
15
 #include "utils/strings.h"
15
 #include "TombRaider.h"
16
 #include "TombRaider.h"
16
 #include "Window.h"
17
 #include "Window.h"
17
 #include "Menu.h"
18
 #include "Menu.h"
18
 
19
 
19
-// TODO
20
-// Going up to / leads to the current working directory
21
-
22
 Menu::Menu() {
20
 Menu::Menu() {
23
     mVisible = false;
21
     mVisible = false;
24
     mCursor = 0;
22
     mCursor = 0;
25
     mMin = 0;
23
     mMin = 0;
26
     mapFolder = nullptr;
24
     mapFolder = nullptr;
27
-
28
-    mainText.text = bufferString("%s", VERSION);
29
-    mainText.color[0] = BLUE[0];
30
-    mainText.color[1] = BLUE[1];
31
-    mainText.color[2] = BLUE[2];
32
-    mainText.color[3] = BLUE[3];
33
-    mainText.scale = 1.2f;
34
-    mainText.y = 10;
35
-    mainText.w = 0;
36
-    mainText.h = 0;
25
+    hiddenState = false;
37
 }
26
 }
38
 
27
 
39
 Menu::~Menu() {
28
 Menu::~Menu() {
40
-    delete [] mainText.text;
41
-    mainText.text = nullptr;
42
-
43
     delete mapFolder;
29
     delete mapFolder;
44
     mapFolder = nullptr;
30
     mapFolder = nullptr;
45
 }
31
 }
46
 
32
 
47
 int Menu::initialize() {
33
 int Menu::initialize() {
48
-    return initialize(Folder(getOpenRaider().mPakDir));
34
+    return initialize(getOpenRaider().mPakDir);
35
+}
36
+
37
+int Menu::initialize(std::string folder) {
38
+    return initialize(new Folder(folder, hiddenState));
49
 }
39
 }
50
 
40
 
51
-int Menu::initialize(Folder folder) {
41
+int Menu::initialize(Folder *folder) {
52
     if (mapFolder != nullptr)
42
     if (mapFolder != nullptr)
53
         delete mapFolder;
43
         delete mapFolder;
54
-    mapFolder = new Folder(folder);
44
+    mapFolder = folder;
55
     mMin = mCursor = 0;
45
     mMin = mCursor = 0;
56
 
46
 
57
     mapFolder->executeRemoveFiles([](File &f) {
47
     mapFolder->executeRemoveFiles([](File &f) {
58
         // Filter files based on file name
48
         // Filter files based on file name
59
-        if ((f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
49
+        if ((f.getName().length() > 4)
50
+            && (f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
60
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
51
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
61
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
52
             && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
62
             && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
53
             && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
98
     glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
89
     glRecti(0, 0, (GLint)getWindow().getWidth(), (GLint)getWindow().getHeight());
99
     glEnable(GL_TEXTURE_2D);
90
     glEnable(GL_TEXTURE_2D);
100
 
91
 
101
-    // Draw heading text, using FontString so we can get the
102
-    // width of the drawn text to center it
103
-    mainText.x = (getWindow().getWidth() / 2) - ((unsigned int)(mainText.w / 2));
104
-    getFont().writeString(mainText);
92
+    // Draw heading
93
+    getFont().drawTextCentered(0, 10, 1.2f, BLUE, getWindow().getWidth(), "%s", VERSION);
105
 
94
 
106
     // Estimate displayable number of items
95
     // Estimate displayable number of items
107
     int items = (getWindow().getHeight() - 60) / 25;
96
     int items = (getWindow().getHeight() - 60) / 25;
161
             mCursor = 0;
150
             mCursor = 0;
162
     } else if (key == enterKey) {
151
     } else if (key == enterKey) {
163
         play();
152
         play();
153
+    } else if (key == dotKey) {
154
+        hiddenState = !hiddenState;
155
+        initialize(mapFolder->getPath());
164
     }
156
     }
165
 
157
 
166
     if (mCursor > (mMin + items - 1)) {
158
     if (mCursor > (mMin + items - 1)) {

+ 1
- 0
src/OpenRaider.cpp View File

10
 
10
 
11
 #include "global.h"
11
 #include "global.h"
12
 #include "Console.h"
12
 #include "Console.h"
13
+#include "Font.h"
13
 #include "Game.h"
14
 #include "Game.h"
14
 #include "Menu.h"
15
 #include "Menu.h"
15
 #include "Render.h"
16
 #include "Render.h"

+ 10
- 2
src/utils/Folder.cpp View File

54
         pos = path.find('\\');
54
         pos = path.find('\\');
55
     }
55
     }
56
 
56
 
57
-    size_t last = path.rfind('/', path.length() - 2);
57
+    size_t last = 0;
58
+    if (path.length() > 1)
59
+        last = path.rfind('/', path.length() - 2);
58
     name = path.substr(last + 1);
60
     name = path.substr(last + 1);
59
     if (name.back() == '/')
61
     if (name.back() == '/')
60
         name.erase(name.length() - 1);
62
         name.erase(name.length() - 1);
100
 
102
 
101
 Folder Folder::getParent() {
103
 Folder Folder::getParent() {
102
     size_t last = path.rfind('/', path.length() - 2);
104
     size_t last = path.rfind('/', path.length() - 2);
103
-    return Folder(path.substr(0, last), listDot);
105
+    std::string parent = path.substr(0, last);
106
+    if (parent.length() == 0)
107
+        parent = "/";
108
+    return Folder(parent, listDot);
104
 }
109
 }
105
 
110
 
106
 void Folder::executeRemoveFiles(std::function<bool (File &f)> func) {
111
 void Folder::executeRemoveFiles(std::function<bool (File &f)> func) {
140
         }
145
         }
141
     }
146
     }
142
 
147
 
148
+    std::sort(foundFiles.begin(), foundFiles.end());
149
+    std::sort(foundFolders.begin(), foundFolders.end());
150
+
143
     for (unsigned long i = 0; i < foundFiles.size(); i++)
151
     for (unsigned long i = 0; i < foundFiles.size(); i++)
144
         files.emplace_back(File(foundFiles.at(i)));
152
         files.emplace_back(File(foundFiles.at(i)));
145
 
153
 

Loading…
Cancel
Save