Переглянути джерело

Main menu rewrite as imgui window

Thomas Buck 9 роки тому
джерело
коміт
8ebbd705a4

+ 5
- 0
ChangeLog.md Переглянути файл

@@ -2,6 +2,11 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140312 ]
6
+    * Now including imguifilesystem dependency
7
+    * Completely re-wrote Main menu, now reading TOMBPC.DAT scripts
8
+    * Main menu is now just a full-screen ImGui window
9
+
5 10
     [ 20140310 ]
6 11
     * Tried to fix moveable loading. Fixed TR1 angle parser, but still not working better.
7 12
 

+ 3
- 1
README.md Переглянути файл

@@ -187,5 +187,7 @@ See the respective files in `cmake` for their licensing.
187 187
 
188 188
 The [clibs/commander](https://github.com/clibs/commander) dependency is Copyright (c) 2012 TJ Holowaychuk (tj@vision-media.ca) and licensed under the [MIT License](http://opensource.org/licenses/MIT).
189 189
 
190
-The included GUI lib, [imgui](https://github.com/ocornut/imgui/) is Copyright (c) 2014 Omar Cornut. See src/deps/imgui/LICENSE for more informations about the MIT license used.
190
+The included GUI lib, [imgui](https://github.com/ocornut/imgui/) is Copyright (c) 2014 Omar Cornut. See src/deps/imgui/LICENSE for more informations about the MIT license used. 
191
+
192
+Also included is the imgui addon [imguifilesystem by Flix01](https://gist.github.com/Flix01/f34b5efa91e50a241c1b).
191 193
 

+ 1
- 2
include/Game.h Переглянути файл

@@ -9,7 +9,6 @@
9 9
 #define _GAME_H_
10 10
 
11 11
 #include <string>
12
-#include <vector>
13 12
 
14 13
 #include "Entity.h"
15 14
 
@@ -18,7 +17,7 @@ class Game {
18 17
     static void destroy();
19 18
 
20 19
     static bool isLoaded() { return mLoaded; }
21
-    static int loadLevel(const char* level);
20
+    static int loadLevel(std::string level);
22 21
 
23 22
     static void handleAction(ActionEvents action, bool isFinished);
24 23
     static void handleMouseMotion(int xrel, int yrel, int xabs, int yabs);

+ 16
- 43
include/Menu.h Переглянути файл

@@ -1,6 +1,6 @@
1 1
 /*!
2 2
  * \file include/Menu.h
3
- * \brief Menu 'overlay' interface
3
+ * \brief Main Menu
4 4
  *
5 5
  * \author xythobuz
6 6
  */
@@ -8,57 +8,30 @@
8 8
 #ifndef _MENU_H_
9 9
 #define _MENU_H_
10 10
 
11
-#include <functional>
11
+#include <vector>
12
+
13
+#include "Script.h"
14
+#include "utils/Folder.h"
12 15
 
13 16
 class Menu {
14 17
   public:
18
+    static int initialize();
19
+    static void shutdown();
20
+    static void display();
15 21
 
16
-    virtual ~Menu() { }
17
-
18
-    virtual int initialize() = 0;
19
-
20
-    virtual void display() = 0;
21
-
22
-    virtual void handleKeyboard(KeyboardButton key, bool pressed) = 0;
23
-
24
-    virtual void handleMouseClick(unsigned int x, unsigned int y,
25
-                                  KeyboardButton button, bool released) = 0;
26
-
27
-    virtual void handleMouseScroll(int xrel, int yrel) = 0;
28
-
29
-    bool isVisible() { return visible; }
30
-
31
-    void setVisible(bool v) { visible = v; }
22
+    static bool isVisible() { return visible; }
23
+    static void setVisible(bool v) { visible = v; }
32 24
 
33 25
     static const glm::vec4 textColor;
34 26
     static const glm::vec4 selectedColor;
35 27
 
36
-  protected:
37
-
38
-    virtual void showDialog(std::string msg, std::string btn1, std::string btn2 = "",
39
-                            std::function<int (bool state)> callback = std::function<int (bool)>());
40
-
41
-    virtual void ackDialog();
42
-
43
-    virtual bool handleKeyboardDialog(KeyboardButton key, bool pressed);
44
-
45
-    virtual bool handleMouseClickDialog(unsigned int x, unsigned int y,
46
-                                        KeyboardButton button, bool released);
47
-
48
-    virtual bool handleMouseScrollDialog(int xrel, int yrel);
49
-
50
-    virtual void displayDialog();
51
-
52
-    bool dialogState;
53
-    std::string dialogText;
54
-    std::string dialogButton1;
55
-    std::string dialogButton2;
56
-    std::function<int (bool state)> dialogFunction;
57
-
58
-    bool visible;
28
+  private:
29
+    static bool visible;
30
+    static Folder* mapFolder;
31
+    static std::vector<Script> scripts;
32
+    static std::vector<Folder> paths;
33
+    static std::vector<int> images;
59 34
 };
60 35
 
61
-Menu& getMenu();
62
-
63 36
 #endif
64 37
 

+ 0
- 52
include/MenuFolder.h Переглянути файл

@@ -1,52 +0,0 @@
1
-/*!
2
- * \file include/MenuFolder.h
3
- * \brief File-Explorer like Menu
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _MENU_FOLDER_H_
9
-#define _MENU_FOLDER_H_
10
-
11
-#include "Menu.h"
12
-#include "utils/Folder.h"
13
-
14
-/*!
15
- * \brief Menu 'overlay'
16
- */
17
-class MenuFolder : public Menu {
18
-  public:
19
-
20
-    /*!
21
-     * \brief Constructs an object of MenuFolder
22
-     */
23
-    MenuFolder();
24
-
25
-    /*!
26
-     * \brief Deconstructs an object of MenuFolder
27
-     */
28
-    virtual ~MenuFolder();
29
-
30
-    virtual int initialize();
31
-
32
-    virtual void display();
33
-    virtual void handleKeyboard(KeyboardButton key, bool pressed);
34
-    virtual void handleMouseClick(unsigned int x, unsigned int y,
35
-                                  KeyboardButton button, bool released);
36
-    virtual void handleMouseScroll(int xrel, int yrel);
37
-
38
-  private:
39
-
40
-    int init(std::string s);
41
-    int init(Folder* folder, bool filter = true);
42
-    virtual void loadOrOpen();
43
-
44
-    long mCursor;
45
-    long mMin;
46
-
47
-    Folder* mapFolder;
48
-    bool hiddenState;
49
-};
50
-
51
-#endif
52
-

+ 4
- 2
include/Script.h Переглянути файл

@@ -91,9 +91,8 @@ class Script {
91 91
     } ScriptItem;
92 92
 
93 93
     Script();
94
-    ~Script();
95 94
 
96
-    int load(const char* file);
95
+    int load(std::string file);
97 96
 
98 97
     unsigned int levelCount();
99 98
     std::string getLevelName(unsigned int i);
@@ -124,6 +123,9 @@ class Script {
124 123
     void registerScriptHandler(ScriptOpCode op, std::function<int (bool, uint16_t)> func);
125 124
     int runScript(unsigned int level);
126 125
 
126
+    std::string getDescription() { return description; }
127
+    std::string getLanguage();
128
+
127 129
   private:
128 130
 
129 131
     typedef enum {

+ 6
- 0
include/utils/strings.h Переглянути файл

@@ -16,5 +16,11 @@ std::string expandHomeDirectory(std::string s);
16 16
 
17 17
 bool stringEndsWith(std::string s, std::string suffix, bool casesensitive = false);
18 18
 
19
+std::string removeLastPathElement(std::string s);
20
+
21
+std::string getLastPathElement(std::string s);
22
+
23
+std::string convertPathDelimiter(std::string s);
24
+
19 25
 #endif
20 26
 

+ 0
- 1
src/CMakeLists.txt Переглянути файл

@@ -63,7 +63,6 @@ set (SRCS ${SRCS} "Game.cpp" "../include/Game.h")
63 63
 set (SRCS ${SRCS} "Log.cpp" "../include/Log.h")
64 64
 set (SRCS ${SRCS} "main.cpp")
65 65
 set (SRCS ${SRCS} "Menu.cpp" "../include/Menu.h")
66
-set (SRCS ${SRCS} "MenuFolder.cpp" "../include/MenuFolder.h")
67 66
 set (SRCS ${SRCS} "Mesh.cpp" "../include/Mesh.h")
68 67
 set (SRCS ${SRCS} "Render.cpp" "../include/Render.h")
69 68
 set (SRCS ${SRCS} "Room.cpp" "../include/Room.h")

+ 3
- 3
src/Game.cpp Переглянути файл

@@ -11,6 +11,7 @@
11 11
 #include "Game.h"
12 12
 #include "loader/Loader.h"
13 13
 #include "Log.h"
14
+#include "Menu.h"
14 15
 #include "Render.h"
15 16
 #include "SoundManager.h"
16 17
 #include "TextureManager.h"
@@ -37,7 +38,7 @@ void Game::destroy() {
37 38
     getWorld().destroy();
38 39
 }
39 40
 
40
-int Game::loadLevel(const char* level) {
41
+int Game::loadLevel(std::string level) {
41 42
     destroy();
42 43
 
43 44
     Log::get(LOG_INFO) << "Loading " << level << Log::endl;
@@ -63,11 +64,10 @@ int Game::loadLevel(const char* level) {
63 64
 
64 65
         mLoaded = true;
65 66
         Render::setMode(RenderMode::Texture);
67
+        Menu::setVisible(false);
66 68
 
67 69
         if (mLara == -1) {
68 70
             Log::get(LOG_WARNING) << "Can't find Lara entity in level?!" << Log::endl;
69
-            Console::setVisible(true);
70
-            UI::setVisible(true);
71 71
         } else {
72 72
             Camera::setPosition(glm::vec3(getLara().getPosition().x,
73 73
                                           getLara().getPosition().y - 1024.0f,

+ 189
- 132
src/Menu.cpp Переглянути файл

@@ -1,173 +1,230 @@
1 1
 /*!
2 2
  * \file src/Menu.cpp
3
- * \brief Menu 'overlay'
3
+ * \brief Main Menu
4 4
  *
5 5
  * \author xythobuz
6 6
  */
7 7
 
8
+#include "imgui/imgui.h"
9
+
8 10
 #include "global.h"
11
+#include "Console.h"
12
+#include "Game.h"
9 13
 #include "Log.h"
10
-#include "Menu.h"
14
+#include "RunTime.h"
15
+#include "UI.h"
16
+#include "TextureManager.h"
11 17
 #include "system/Font.h"
12 18
 #include "system/Window.h"
19
+#include "utils/random.h"
20
+#include "utils/strings.h"
21
+#include "Menu.h"
13 22
 
14 23
 const glm::vec4 Menu::textColor(0.5f, 0.7f, 1.0f, 1.0f);
15 24
 const glm::vec4 Menu::selectedColor(1.0f, 0.0f, 0.0f, 1.0f);
16 25
 
17
-void Menu::showDialog(std::string msg, std::string btn1, std::string btn2,
18
-                      std::function<int (bool state)> callback) {
19
-    // Only show one dialog at a time
20
-    assertEqual(dialogText.length(), 0);
21
-    assertEqual(dialogButton1.length(), 0);
22
-    assertEqual(dialogButton2.length(), 0);
23
-
24
-    assertGreaterThan(msg.length(), 0);
25
-    assertGreaterThan(btn1.length(), 0);
26
-
27
-    dialogText = msg;
28
-    dialogButton1 = btn1;
29
-    dialogButton2 = btn2;
30
-    dialogState = false;
31
-    dialogFunction = callback;
26
+bool Menu::visible = false;
27
+Folder* Menu::mapFolder = nullptr;
28
+std::vector<Script> Menu::scripts;
29
+std::vector<Folder> Menu::paths;
30
+std::vector<int> Menu::images;
31
+
32
+int Menu::initialize() {
33
+    shutdown();
34
+    mapFolder = new Folder(RunTime::getPakDir());
35
+
36
+    std::vector<File> files;
37
+    mapFolder->findRecursiveFilesEndingWith(files, "tombpc.dat");
38
+    for (auto& f : files) {
39
+        scripts.emplace_back();
40
+        auto s = scripts.size() - 1;
41
+
42
+        images.push_back(-1);
43
+        auto i = images.size() - 1;
44
+
45
+        std::string path = convertPathDelimiter(removeLastPathElement(f.getPath()));
46
+        paths.emplace_back(path);
47
+        auto p = paths.size() - 1;
48
+
49
+        if (scripts.at(s).load(f.getPath()) != 0) {
50
+            Log::get(LOG_ERROR) << "Invalid Script: \"" << f.getPath()
51
+                                << "\"!" << Log::endl;
52
+            scripts.pop_back();
53
+        } else {
54
+            // Load one of the pictures of this level
55
+            std::vector<File> texFiles;
56
+            paths.at(p).findRecursiveFilesEndingWith(texFiles, ".pcx");
57
+            paths.at(p).findRecursiveFilesEndingWith(texFiles, ".bmp");
58
+            paths.at(p).findRecursiveFilesEndingWith(texFiles, ".png");
59
+            paths.at(p).findRecursiveFilesEndingWith(texFiles, ".tga");
60
+            paths.at(p).findRecursiveFilesEndingWith(texFiles, ".jpg");
61
+
62
+            if (texFiles.size() > 0) {
63
+                int which = randomInteger(texFiles.size() - 1);
64
+                images.at(i) = TextureManager::loadImage(texFiles.at(which).getPath(),
65
+                               TextureStorage::SYSTEM);
66
+            }
67
+        }
68
+    }
32 69
 
33
-    Log::get(LOG_USER) << dialogText << Log::endl;
70
+    return 0;
34 71
 }
35 72
 
36
-void Menu::ackDialog() {
37
-    dialogText = "";
38
-    dialogButton1 = "";
39
-    dialogButton2 = "";
40
-
41
-    if (dialogFunction) {
42
-        int error = dialogFunction(dialogState);
43
-        if (error != 0) {
44
-            showDialog("Error processing dialog callback!", "OK", "");
45
-        }
73
+void Menu::shutdown() {
74
+    if (mapFolder != nullptr) {
75
+        delete mapFolder;
76
+        mapFolder = nullptr;
46 77
     }
47 78
 
48
-    dialogState = false;
79
+    scripts.clear();
80
+    paths.clear();
81
+    images.clear(); //! \TODO free texture slots
49 82
 }
50 83
 
51
-bool Menu::handleKeyboardDialog(KeyboardButton key, bool pressed) {
52
-    if (!pressed)
53
-        return (dialogText.length() > 0);
84
+void Menu::display() {
85
+    if (!visible)
86
+        return;
54 87
 
55
-    if (dialogText.length() > 0) {
56
-        if (dialogButton2.length() == 0) {
57
-            if (key == enterKey) {
58
-                ackDialog();
59
-            }
60
-        } else {
61
-            if (key == enterKey) {
62
-                ackDialog();
63
-            } else if (key == leftKey) {
64
-                dialogState = !dialogState;
65
-            } else if (key == rightKey) {
66
-                dialogState = !dialogState;
67
-            } else if (key == upKey) {
68
-                dialogState = !dialogState;
69
-            } else if (key == downKey) {
70
-                dialogState = !dialogState;
71
-            }
88
+    glm::vec2 size = Window::getSize();
89
+    if (!ImGui::Begin("Menu", nullptr, ImVec2(size.x, size.y), -1.0f, ImGuiWindowFlags_NoTitleBar
90
+                      | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse
91
+                      | ImGuiWindowFlags_NoSavedSettings)) {
92
+        ImGui::End();
93
+        return;
94
+    }
95
+
96
+    ImGui::SetWindowPos(ImVec2(0, 0));
97
+    ImGui::SetWindowSize(ImVec2(size.x, size.y));
98
+
99
+    // Draw heading with version string
100
+    auto headingSize = ImGui::CalcTextSize(VERSION);
101
+    headingSize.x *= 3.0f; headingSize.y *= 3.0f;
102
+    ImGui::SetWindowFontScale(3.0f);
103
+    ImGui::SameLine(0, (size.x / 2) - (headingSize.x / 2));
104
+    ImGui::TextColored(textColor, VERSION);
105
+    ImGui::SetWindowFontScale(1.0f);
106
+
107
+    static ImGuiFs::Dialog* dialog = nullptr;
108
+    const bool browseButtonPressed = ImGui::Button("Select Level File");
109
+    if (browseButtonPressed) {
110
+        if (dialog != nullptr)
111
+            delete dialog;
112
+        dialog = new ImGuiFs::Dialog();
113
+    }
114
+    if (dialog) {
115
+        dialog->chooseFileDialog(browseButtonPressed, RunTime::getPakDir().c_str(),
116
+                                 ".phd;.psx;.tub;.tr2", nullptr, ImVec2(400, 300), ImGui::GetMousePos());
117
+        std::string selectedFile = dialog->getChosenPath();
118
+        if (selectedFile.length() > 0) {
119
+            Game::loadLevel(selectedFile);
120
+            delete dialog;
121
+            dialog = nullptr;
72 122
         }
73
-        return true;
123
+    }
124
+    ImGui::SameLine();
125
+    if (ImGui::Button("Toggle Console")) {
126
+        Console::setVisible(!Console::isVisible());
127
+    }
128
+    ImGui::SameLine();
129
+    if (ImGui::Button("Toggle Debug Window")) {
130
+        UI::setVisible(!UI::isVisible());
74 131
     }
75 132
 
76
-    return false;
77
-}
133
+    ImGui::Separator();
78 134
 
79
-bool Menu::handleMouseClickDialog(unsigned int x, unsigned int y,
80
-                                  KeyboardButton button, bool released) {
81
-    //! \todo Allow mouse usage of Menu dialogs!
82
-    return (dialogText.length() > 0);
83
-}
135
+    // Set up columns for game list
136
+    ImGui::Columns(3, "menuscripts");
137
+    static bool offsets = false;
138
+    if (!offsets) {
139
+        ImGui::SetColumnOffset(1, 140.0f);
140
+        ImGui::SetColumnOffset(2, size.x - 200.0f);
141
+        offsets = true;
142
+    }
84 143
 
85
-bool Menu::handleMouseScrollDialog(int xrel, int yrel) {
86
-    //! \todo Allow mouse usage of Menu dialogs!
87
-    return (dialogText.length() > 0);
88
-}
144
+    // List found games
145
+    for (int i = 0; i < scripts.size(); i++) {
146
+        ImGui::PushID(i);
147
+        Script& s = scripts.at(i);
89 148
 
90
-void Menu::displayDialog() {
91
-    if (dialogText.length() > 0) {
92
-        unsigned int wMax = ((unsigned int)(Window::getSize().x * 0.66f));
93
-
94
-        unsigned int w0 = Font::widthText(1.0f, dialogText) + 20;
95
-        if (w0 > wMax)
96
-            w0 = wMax;
97
-        unsigned int h0 =  Font::heightText(1.0f, w0, dialogText) + 10;
98
-
99
-        assertGreaterThan(dialogButton1.length(), 0);
100
-        unsigned int w1 = Font::widthText(1.0f, dialogButton1) + 20;
101
-        if (w1 > wMax)
102
-            w1 = wMax;
103
-        unsigned int h1 = Font::heightText(1.0f, w1, dialogButton1) + 10;
104
-
105
-        unsigned int wOverlay = wMax, hOverlay, w2 = 0;
106
-
107
-        if (dialogButton2.length() > 0) {
108
-            // Show text and two buttons
109
-            w2 = Font::widthText(1.0f, dialogButton2) + 20;
110
-            if (w2 > wMax)
111
-                w2 = wMax;
112
-            unsigned int h2 = Font::heightText(1.0f, w2, dialogButton2) + 10;
113
-
114
-            if (w0 > (w1 + w2)) {
115
-                if (w0 < wMax) {
116
-                    wOverlay = w0;
117
-                }
118
-            } else if (w0 < (w1 + w2)) {
119
-                if ((w1 + w2) < wMax) {
120
-                    wOverlay = (w1 + w2);
149
+        if (images.at(i) >= 0) {
150
+            auto bm = TextureManager::getBufferManager(images.at(i), TextureStorage::SYSTEM);
151
+            ImGui::Image(bm, ImVec2(128, 128));
152
+        }
153
+        ImGui::NextColumn();
154
+
155
+        ImGui::TextWrapped("Language: %s", s.getLanguage().c_str());
156
+        ImGui::TextWrapped("Description: %s", s.getDescription().c_str());
157
+
158
+        if (ImGui::TreeNode("", "%d Levels", s.levelCount())) {
159
+            for (int l = 0; l < s.levelCount(); l++) {
160
+                ImGui::PushID(l);
161
+                ImGui::Bullet();
162
+                ImGui::TextWrapped("%s (%s)", s.getLevelName(l).c_str(), s.getLevelFilename(l).c_str());
163
+                ImGui::SameLine();
164
+                if (ImGui::Button("Play level")) {
165
+                    std::vector<File> levelFiles;
166
+                    paths.at(i).findRecursiveFilesEndingWith(levelFiles,
167
+                            getLastPathElement(s.getLevelFilename(l)));
168
+                    if (levelFiles.size() == 0) {
169
+                        Log::get(LOG_ERROR) << "Could not find level \""
170
+                                            << getLastPathElement(s.getLevelFilename(l))
171
+                                            << "\"!" << Log::endl;
172
+                    } else {
173
+                        Game::loadLevel(levelFiles.at(0).getPath());
174
+                    }
121 175
                 }
176
+                ImGui::PopID();
122 177
             }
178
+            ImGui::TreePop();
179
+        }
123 180
 
124
-            if ((w1 + w2) <= wMax) {
125
-                hOverlay = h0 + ((h1 + h2) / 2);
126
-            } else {
127
-                hOverlay = h0 + h1 + h2;
181
+        if (ImGui::TreeNode("", "%d Cut-Scenes", s.cutsceneCount())) {
182
+            for (int c = 0; c < s.cutsceneCount(); c++) {
183
+                ImGui::Bullet();
184
+                ImGui::TextWrapped("%s", s.getCutsceneFilename(c).c_str());
128 185
             }
129
-        } else {
130
-            // Show text and one button
131
-            if (w0 > w1) {
132
-                if (w0 < wMax) {
133
-                    wOverlay = w0;
134
-                }
135
-            } else if (w0 < w1) {
136
-                if (w1 < wMax) {
137
-                    wOverlay = w1;
138
-                }
186
+            ImGui::TreePop();
187
+        }
188
+
189
+        if (ImGui::TreeNode("", "%d Videos", s.videoCount())) {
190
+            for (int v = 0; v < s.videoCount(); v++) {
191
+                ImGui::Bullet();
192
+                ImGui::TextWrapped("%s", s.getVideoFilename(v).c_str());
139 193
             }
194
+            ImGui::TreePop();
195
+        }
140 196
 
141
-            hOverlay = h0 + h1;
197
+        if (ImGui::TreeNode("", "%d Pictures", s.pictureCount())) {
198
+            for (int p = 0; p < s.pictureCount(); p++) {
199
+                ImGui::Bullet();
200
+                ImGui::TextWrapped("%s", s.getPictureFilename(p).c_str());
201
+            }
202
+            ImGui::TreePop();
142 203
         }
143 204
 
144
-        unsigned int xOverlay = (Window::getSize().x - wOverlay) / 2;
145
-        unsigned int yOverlay = (Window::getSize().y - hOverlay) / 2;
146
-
147
-        /*
148
-        glColor4f(0.0f, 0.0f, 0.0f, 0.75f);
149
-        glDisable(GL_TEXTURE_2D);
150
-        glRecti(xOverlay, yOverlay, xOverlay + wOverlay, yOverlay + hOverlay);
151
-        glEnable(GL_TEXTURE_2D);
152
-        */
153
-
154
-        Font::drawTextWrapped(xOverlay + 10, yOverlay + 5, 1.0f, textColor, w0, dialogText);
155
-        if (dialogButton2.length() > 0) {
156
-            if ((w1 + w2) <= wMax) {
157
-                Font::drawTextWrapped(xOverlay + 10, yOverlay + 10 + h0, 1.0f,
158
-                                      dialogState ? textColor : selectedColor, w1, dialogButton1);
159
-                Font::drawTextWrapped(xOverlay + 10 + w1, yOverlay + 10 + h0,
160
-                                      1.0f, dialogState ? selectedColor : textColor, w2, dialogButton2);
161
-            } else {
162
-                Font::drawTextWrapped((Window::getSize().x - w1) / 2,
163
-                                      yOverlay + 10 + h0, 1.0f, dialogState ? textColor : selectedColor, w1, dialogButton1);
164
-                Font::drawTextWrapped((Window::getSize().x - w2) / 2,
165
-                                      yOverlay + 10 + h0 + h1, 1.0f, dialogState ? selectedColor : textColor, w2, dialogButton2);
205
+        if (ImGui::TreeNode("", "%d Titles", s.titleCount())) {
206
+            for (int t = 0; t < s.titleCount(); t++) {
207
+                ImGui::Bullet();
208
+                ImGui::TextWrapped("%s", s.getTitleFilename(t).c_str());
166 209
             }
167
-        } else {
168
-            Font::drawTextWrapped((Window::getSize().x - w1) / 2,
169
-                                  yOverlay + 10 + h0, 1.0f, selectedColor, w1, dialogButton1);
210
+            ImGui::TreePop();
170 211
         }
212
+
213
+        ImGui::NextColumn();
214
+        ImGui::TextWrapped("Real Gameplay not yet implemented!");
215
+        ImGui::NextColumn();
216
+
217
+        if (i < (scripts.size() - 1))
218
+            ImGui::Separator();
219
+        ImGui::PopID();
220
+    }
221
+    ImGui::Columns(1);
222
+
223
+    if (scripts.size() == 0) {
224
+        ImGui::TextWrapped("OpenRaiders built-in TombRaider-Script detection mechanism could not find any suitable TR2/TR3 script files (called \"TOMBPC.DAT\") in your PAK folder \"%s\"! Use the \"Select Level File\" Button to load a single level without starting the entire game.",
225
+                           RunTime::getPakDir().c_str());
171 226
     }
227
+
228
+    ImGui::End();
172 229
 }
173 230
 

+ 0
- 215
src/MenuFolder.cpp Переглянути файл

@@ -1,215 +0,0 @@
1
-/*!
2
- * \file src/MenuFolder.cpp
3
- * \brief File-Explorer like menu
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "Game.h"
10
-#include "loader/Loader.h"
11
-#include "Log.h"
12
-#include "Render.h"
13
-#include "RunTime.h"
14
-#include "MenuFolder.h"
15
-#include "system/Font.h"
16
-#include "system/Window.h"
17
-
18
-MenuFolder::MenuFolder() {
19
-    mCursor = 0;
20
-    mMin = 0;
21
-    mapFolder = nullptr;
22
-    hiddenState = false;
23
-    dialogState = false;
24
-    visible = false;
25
-}
26
-
27
-MenuFolder::~MenuFolder() {
28
-    delete mapFolder;
29
-    mapFolder = nullptr;
30
-}
31
-
32
-int MenuFolder::initialize() {
33
-    return init(RunTime::getPakDir());
34
-}
35
-
36
-int MenuFolder::init(std::string s) {
37
-    return init(new Folder(s));
38
-}
39
-
40
-int MenuFolder::init(Folder* folder, bool filter) {
41
-    if (mapFolder != nullptr)
42
-        delete mapFolder;
43
-
44
-    mapFolder = folder;
45
-    mMin = mCursor = 0;
46
-
47
-    if (filter) {
48
-        mapFolder->executeRemoveFiles([](File & f) {
49
-            // Filter files based on file name
50
-            if ((f.getName().length() > 4)
51
-                && (f.getName().compare(f.getName().length() - 4, 4, ".phd") != 0)
52
-                && (f.getName().compare(f.getName().length() - 4, 4, ".psx") != 0)
53
-                && (f.getName().compare(f.getName().length() - 4, 4, ".tub") != 0)
54
-                && (f.getName().compare(f.getName().length() - 4, 4, ".tr2") != 0)
55
-                && (f.getName().compare(f.getName().length() - 4, 4, ".tr4") != 0)
56
-                && (f.getName().compare(f.getName().length() - 4, 4, ".trc") != 0)) {
57
-                return true; // delete file from list
58
-            }
59
-
60
-            // Check maps for validity
61
-            Loader::LoaderVersion version = Loader::checkFile(f.getPath());
62
-            if (version == Loader::TR_UNKNOWN) {
63
-                Log::get(LOG_ERROR) << "Error: pak file '" << f.getName().c_str()
64
-                                    << "' invalid" << Log::endl;
65
-                return true; // delete file from list
66
-            }
67
-
68
-            return false; // keep file on list
69
-        });
70
-    }
71
-
72
-    if ((mapFolder->fileCount() + mapFolder->folderCount()) > 0)
73
-        mCursor = 1; // Don't select ".." by default
74
-
75
-    return 0;
76
-}
77
-
78
-void MenuFolder::display() {
79
-    if (!visible)
80
-        return;
81
-
82
-    Font::drawTextCentered(0, 10, 1.2f, textColor, Window::getSize().x, VERSION);
83
-
84
-    // Draw half-transparent overlay
85
-    glm::vec4 color(0.0f, 0.0f, 0.0f, 0.75f);
86
-    Render::drawTexture(0.0f, 0.0f, Window::getSize().x, Window::getSize().y,
87
-                        color, TEXTURE_WHITE, TextureStorage::SYSTEM);
88
-
89
-    // Draw heading
90
-    Font::drawTextCentered(0, 10, 1.2f, textColor, Window::getSize().x, VERSION);
91
-
92
-    // Estimate displayable number of items
93
-    int items = (Window::getSize().y - 60) / 25;
94
-
95
-    // Print list of "..", folders, files
96
-    for (long i = mMin; (i < (mMin + items))
97
-         && (i < (mapFolder->folderCount() + mapFolder->fileCount() + 1)); i++) {
98
-        if (i == 0) {
99
-            Font::drawText(25, 50, 0.75f, (mCursor == i) ? selectedColor : textColor, "..");
100
-        } else {
101
-            Font::drawText(25, (unsigned int)(50 + (25 * (i - mMin))), 0.75f,
102
-                           (mCursor == i) ? selectedColor : textColor,
103
-                           ((i - 1) < mapFolder->folderCount()) ?
104
-                           (mapFolder->getFolder(i - 1).getName() + "/")
105
-                           : mapFolder->getFile(i - 1 - mapFolder->folderCount()).getName());
106
-        }
107
-    }
108
-
109
-    displayDialog();
110
-}
111
-
112
-void MenuFolder::loadOrOpen() {
113
-    if (mCursor == 0) {
114
-        if (init(mapFolder->getParent().getPath()) != 0) {
115
-            showDialog("Error reading parent folder!", "OK", "");
116
-        }
117
-    } else if ((mCursor - 1) < mapFolder->folderCount()) {
118
-        if (init(mapFolder->getFolder(mCursor - 1).getPath()) != 0) {
119
-            showDialog("Error reading subfolder!", "OK", "");
120
-        }
121
-    } else {
122
-        showDialog("Loading...", "OK");
123
-        renderFrame();
124
-        int error = Game::loadLevel(mapFolder->getFile((unsigned long)mCursor
125
-                                    - 1 - mapFolder->folderCount()).getPath().c_str());
126
-        ackDialog();
127
-        if (error == 0) {
128
-            visible = false;
129
-        } else {
130
-            std::ostringstream err;
131
-            err << "Error loading map: " << error << "!";
132
-            showDialog(err.str(), "OK", "");
133
-        }
134
-    }
135
-}
136
-
137
-void MenuFolder::handleKeyboard(KeyboardButton key, bool pressed) {
138
-    if (handleKeyboardDialog(key, pressed))
139
-        return;
140
-
141
-    if (!pressed)
142
-        return;
143
-
144
-    assert(mapFolder != nullptr);
145
-    int items = (Window::getSize().y - 60) / 25;
146
-
147
-    if (key == upKey) {
148
-        if (mCursor > 0)
149
-            mCursor--;
150
-        else
151
-            mCursor = (long)(mapFolder->folderCount() + mapFolder->fileCount());
152
-    } else if (key == downKey) {
153
-        if (mCursor < (long)(mapFolder->folderCount() + mapFolder->fileCount()))
154
-            mCursor++;
155
-        else
156
-            mCursor = 0;
157
-    } else if (key == enterKey) {
158
-        loadOrOpen();
159
-    } else if (key == dotKey) {
160
-        hiddenState = !hiddenState;
161
-        init(mapFolder->getPath());
162
-    }
163
-
164
-    if (mCursor > (mMin + items - 1)) {
165
-        mMin = mCursor - items + 1;
166
-    } else if (mCursor < mMin) {
167
-        mMin = mCursor;
168
-    }
169
-}
170
-
171
-void MenuFolder::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button,
172
-                                  bool released) {
173
-    if (handleMouseClickDialog(x, y, button, released))
174
-        return;
175
-
176
-    int items = (Window::getSize().y - 60) / 25;
177
-
178
-    if (released || (button != leftmouseKey))
179
-        return;
180
-
181
-    if ((y >= 50) && (y <= (unsigned int)(50 + (25 * items)))
182
-        && ((mMin + (y / 25)) <= (mapFolder->folderCount() + mapFolder->fileCount() + 2))) {
183
-        y -= 50;
184
-        if (mCursor == (mMin + (y / 25)))
185
-            loadOrOpen();
186
-        else
187
-            mCursor = mMin + (y / 25);
188
-    }
189
-}
190
-
191
-void MenuFolder::handleMouseScroll(int xrel, int yrel) {
192
-    if (handleMouseScrollDialog(xrel, yrel))
193
-        return;
194
-
195
-    assert((xrel != 0) || (yrel != 0));
196
-    assert(mapFolder != nullptr);
197
-    int items = (Window::getSize().y - 60) / 25;
198
-
199
-    if ((mapFolder->folderCount() + mapFolder->fileCount() + 1) > items) {
200
-        if (yrel < 0) {
201
-            if (mMin < (mapFolder->folderCount() + mapFolder->fileCount() + 1 - items))
202
-                mMin++;
203
-        } else if (yrel > 0) {
204
-            if (mMin > 0)
205
-                mMin--;
206
-        }
207
-
208
-        if (mCursor < mMin) {
209
-            mCursor = mMin;
210
-        } else if (mCursor > (mMin + items - 1)) {
211
-            mCursor = mMin + items - 1;
212
-        }
213
-    }
214
-}
215
-

+ 5
- 0
src/Render.cpp Переглянути файл

@@ -12,6 +12,7 @@
12 12
 #include "global.h"
13 13
 #include "Camera.h"
14 14
 #include "Log.h"
15
+#include "Menu.h"
15 16
 #include "StaticMesh.h"
16 17
 #include "World.h"
17 18
 #include "system/Font.h"
@@ -280,6 +281,10 @@ void Render::displayUI() {
280 281
         if (ImGui::Button("New Splash##render")) {
281 282
             TextureManager::initializeSplash();
282 283
         }
284
+        ImGui::SameLine();
285
+        if (ImGui::Button("New Menu##render")) {
286
+            Menu::initialize();
287
+        }
283 288
     }
284 289
 }
285 290
 

+ 17
- 5
src/Script.cpp Переглянути файл

@@ -40,11 +40,7 @@ Script::Script() : puzzles(4), pickups(2), keys(4) {
40 40
     numGameStrings = 0;
41 41
 }
42 42
 
43
-Script::~Script() {
44
-
45
-}
46
-
47
-int Script::load(const char* file) {
43
+int Script::load(std::string file) {
48 44
     BinaryFile f;
49 45
 
50 46
     if (f.open(file) != 0)
@@ -351,3 +347,19 @@ int Script::runScript(unsigned int level) {
351 347
     return 0;
352 348
 }
353 349
 
350
+std::string Script::getLanguage() {
351
+    if (language == S_English) {
352
+        return "English (UK)";
353
+    } else if (language == S_French) {
354
+        return "French";
355
+    } else if (language == S_German) {
356
+        return "German";
357
+    } else if (language == S_American) {
358
+        return "English (US)";
359
+    } else if (language == S_Japanese) {
360
+        return "Japanese";
361
+    } else {
362
+        return "Unknown";
363
+    }
364
+}
365
+

+ 4
- 0
src/TextureManager.cpp Переглянути файл

@@ -84,6 +84,10 @@ int TextureManager::initializeSplash() {
84 84
     Folder f(RunTime::getPakDir());
85 85
     std::vector<File> files;
86 86
     f.findRecursiveFilesEndingWith(files, ".pcx");
87
+    f.findRecursiveFilesEndingWith(files, ".bmp");
88
+    f.findRecursiveFilesEndingWith(files, ".png");
89
+    f.findRecursiveFilesEndingWith(files, ".tga");
90
+    f.findRecursiveFilesEndingWith(files, ".jpg");
87 91
     if (files.size() == 0) {
88 92
         if (loadImage(RunTime::getDataDir() + "/splash.tga", TextureStorage::SYSTEM, TEXTURE_SPLASH) < 0) {
89 93
             return -2;

+ 22
- 48
src/UI.cpp Переглянути файл

@@ -88,7 +88,7 @@ int UI::initialize() {
88 88
     int width, height;
89 89
     io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
90 90
     fontTex = TextureManager::loadBufferSlot(pixels, width, height, ColorMode::RGBA, 32,
91
-              TextureStorage::SYSTEM, -1, false);
91
+              TextureStorage::SYSTEM, -1, true);
92 92
     auto bm = TextureManager::getBufferManager(fontTex, TextureStorage::SYSTEM);
93 93
     io.Fonts->TexID = bm;
94 94
 
@@ -156,56 +156,27 @@ void UI::eventsFinished() {
156 156
 
157 157
     ImGui::NewFrame();
158 158
 
159
-    if (!(visible || Console::isVisible())) {
160
-        while (!clickEvents.empty()) {
161
-            auto i = clickEvents.front();
162
-            if (getMenu().isVisible()) {
163
-                getMenu().handleMouseClick(std::get<0>(i), std::get<1>(i),
164
-                                           std::get<2>(i), std::get<3>(i));
165
-            }
166
-            clickEvents.pop_front();
167
-        }
168
-
159
+    if (!(visible || Console::isVisible() || Menu::isVisible())) {
169 160
         while (!motionEvents.empty()) {
170 161
             auto i = motionEvents.front();
171
-            if (!getMenu().isVisible()) {
172
-                Game::handleMouseMotion(std::get<0>(i), std::get<1>(i),
173
-                                        std::get<2>(i), std::get<3>(i));
174
-            }
162
+            Game::handleMouseMotion(std::get<0>(i), std::get<1>(i),
163
+                                    std::get<2>(i), std::get<3>(i));
175 164
             motionEvents.pop_front();
176 165
         }
177
-
178
-        while (!scrollEvents.empty()) {
179
-            auto i = scrollEvents.front();
180
-            if (getMenu().isVisible()) {
181
-                getMenu().handleMouseScroll(std::get<0>(i), std::get<1>(i));
182
-            }
183
-            scrollEvents.pop_front();
184
-        }
185 166
     }
186 167
 
187 168
     while (!keyboardEvents.empty()) {
188 169
         auto i = keyboardEvents.front();
189 170
 
190
-        if (!(visible || Console::isVisible())) {
191
-            if (getMenu().isVisible()) {
192
-                getMenu().handleKeyboard(std::get<0>(i), std::get<1>(i));
193
-            } else {
194
-                for (int n = forwardAction; n < ActionEventCount; n++) {
195
-                    if (RunTime::getKeyBinding((ActionEvents)n) == std::get<0>(i))
196
-                        Game::handleAction((ActionEvents)n, !std::get<1>(i));
197
-                }
171
+        if (!(visible || Console::isVisible() || Menu::isVisible())) {
172
+            for (int n = forwardAction; n < ActionEventCount; n++) {
173
+                if (RunTime::getKeyBinding((ActionEvents)n) == std::get<0>(i))
174
+                    Game::handleAction((ActionEvents)n, !std::get<1>(i));
198 175
             }
199 176
         }
200 177
 
201 178
         if (std::get<1>(i)) {
202
-            if (!(visible || Console::isVisible())) {
203
-                if (RunTime::getKeyBinding(menuAction) == std::get<0>(i)) {
204
-                    getMenu().setVisible(!getMenu().isVisible());
205
-                }
206
-            }
207
-
208
-            if ((!io.WantCaptureKeyboard) || (!(visible || Console::isVisible()))) {
179
+            if ((!io.WantCaptureKeyboard) || (!(visible || Console::isVisible() || Menu::isVisible()))) {
209 180
                 if (!metaKeyIsActive) {
210 181
                     if (RunTime::getKeyBinding(debugAction) == std::get<0>(i)) {
211 182
                         visible = !visible;
@@ -214,6 +185,10 @@ void UI::eventsFinished() {
214 185
                     if (RunTime::getKeyBinding(consoleAction) == std::get<0>(i)) {
215 186
                         Console::setVisible(!Console::isVisible());
216 187
                     }
188
+
189
+                    if (RunTime::getKeyBinding(menuAction) == std::get<0>(i)) {
190
+                        Menu::setVisible(!Menu::isVisible());
191
+                    }
217 192
                 }
218 193
             }
219 194
         }
@@ -226,18 +201,16 @@ void UI::eventsFinished() {
226 201
     motionEvents.clear();
227 202
     scrollEvents.clear();
228 203
 
229
-    if ((visible || Console::isVisible()) && (
230
-            ((!io.WantCaptureKeyboard) && io.KeysDown[escapeKey])
231
-            || ((!io.WantCaptureMouse) && clicked)
232
-        )) {
204
+    // Allow clicking into the game to hide debug UI
205
+    if ((visible || Console::isVisible()) && ((!io.WantCaptureMouse) && clicked)) {
233 206
         visible = false;
234 207
         Console::setVisible(false);
235 208
     }
236 209
 
237
-    if (Window::getTextInput() != (visible || Console::isVisible()))
210
+    if (Window::getTextInput() != (visible || Console::isVisible() || Menu::isVisible()))
238 211
         Window::setTextInput(visible || Console::isVisible());
239 212
 
240
-    bool input = !(visible || Console::isVisible() || getMenu().isVisible());
213
+    bool input = !(visible || Console::isVisible() || Menu::isVisible());
241 214
     if (Window::getMousegrab() != input)
242 215
         Window::setMousegrab(input);
243 216
 
@@ -245,7 +218,7 @@ void UI::eventsFinished() {
245 218
 }
246 219
 
247 220
 void UI::display() {
248
-    if (RunTime::getShowFPS() && (!getMenu().isVisible())) {
221
+    if (RunTime::getShowFPS() && (!Menu::isVisible())) {
249 222
         if (ImGui::Begin("Debug Overlay", nullptr, ImVec2(0, 0), -1.0f,
250 223
                          ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
251 224
                          | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings
@@ -266,6 +239,7 @@ void UI::display() {
266 239
         Camera::displayUI();
267 240
 
268 241
     Console::display();
242
+    Menu::display();
269 243
 
270 244
     if (!visible) {
271 245
         ImGui::Render();
@@ -441,7 +415,7 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
441 415
     if (visible || Console::isVisible())
442 416
         return;
443 417
 
444
-    if (getMenu().isVisible()) {
418
+    if (Menu::isVisible()) {
445 419
         if (button == aButton) {
446 420
             handleKeyboard(enterKey, !released);
447 421
         } else if (button == padUp) {
@@ -454,7 +428,7 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
454 428
             handleKeyboard(rightKey, !released);
455 429
         } else if (button == startButton) {
456 430
             if (!released)
457
-                getMenu().setVisible(false);
431
+                Menu::setVisible(false);
458 432
         }
459 433
     } else {
460 434
         if (button == aButton) {
@@ -477,7 +451,7 @@ void UI::handleControllerButton(KeyboardButton button, bool released) {
477 451
             Game::handleAction(walkAction, released);
478 452
         } else if (button == startButton) {
479 453
             if (!released)
480
-                getMenu().setVisible(true);
454
+                Menu::setVisible(true);
481 455
         }
482 456
     }
483 457
 }

+ 11
- 11
src/deps/imgui/imconfig.h Переглянути файл

@@ -24,21 +24,21 @@
24 24
 //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS
25 25
 
26 26
 //---- Include imgui_user.inl at the end of imgui.cpp so you can include code that extends ImGui using its private data/functions.
27
-//#define IMGUI_INCLUDE_IMGUI_USER_INL
27
+#define IMGUI_INCLUDE_IMGUI_USER_INL
28 28
 
29 29
 //---- Include imgui_user.h at the end of imgui.h
30
-//#define IMGUI_INCLUDE_IMGUI_USER_H
30
+#define IMGUI_INCLUDE_IMGUI_USER_H
31 31
 
32 32
 //---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4.
33
-/*
34
-#define IM_VEC2_CLASS_EXTRA                                                 \
35
-        ImVec2(const MyVec2& f) { x = f.x; y = f.y; }                       \
36
-        operator MyVec2() const { return MyVec2(x,y); }
37
-
38
-#define IM_VEC4_CLASS_EXTRA                                                 \
39
-        ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; }     \
40
-        operator MyVec4() const { return MyVec4(x,y,z,w); }
41
-*/
33
+#include <glm/vec2.hpp>
34
+#define IM_VEC2_CLASS_EXTRA                                                \
35
+        ImVec2(const glm::vec2& f) { x = f.x; y = f.y; }                   \
36
+        operator glm::vec2() const { return glm::vec2(x, y); }
37
+
38
+#include <glm/vec4.hpp>
39
+#define IM_VEC4_CLASS_EXTRA                                                \
40
+        ImVec4(const glm::vec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
41
+        operator glm::vec4() const { return glm::vec4(x,y,z,w); }
42 42
 
43 43
 //---- Freely implement extra functions within the ImGui:: namespace.
44 44
 //---- Declare helpers or widgets implemented in imgui_user.inl or elsewhere, so end-user doesn't need to include multiple files.

+ 2
- 0
src/deps/imgui/imgui_user.h Переглянути файл

@@ -0,0 +1,2 @@
1
+#include "imguifilesystem/imguifilesystem.h"
2
+

+ 2
- 0
src/deps/imgui/imgui_user.inl Переглянути файл

@@ -0,0 +1,2 @@
1
+#include "imguifilesystem/imguifilesystem.cpp"
2
+

+ 13
- 0
src/deps/imguifilesystem/README.txt Переглянути файл

@@ -0,0 +1,13 @@
1
+imguifilesystem dialogs for imgui v.1.17 wip (https://github.com/ocornut/imgui).
2
+See also: https://github.com/ocornut/imgui/issues/88
3
+
4
+It's composed by three files:
5
+
6
+-    imguifilesystem.h (usage instructions are here)
7
+-    imguifilesystem.cpp
8
+-    dirent_portable.h
9
+
10
+It needs testing and feedback (expecially for Windows/VisualC++ and MacOS).
11
+
12
+It does not use any C++ string class: so it should be straightforward to merge its code
13
+into imgui.h/imgui.cpp if we want to (and if the code is robust enough). 

+ 1040
- 0
src/deps/imguifilesystem/dirent_portable.h
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 1655
- 0
src/deps/imguifilesystem/imguifilesystem.cpp
Різницю між файлами не показано, бо вона завелика
Переглянути файл


+ 95
- 0
src/deps/imguifilesystem/imguifilesystem.h Переглянути файл

@@ -0,0 +1,95 @@
1
+// This software is provided 'as-is', without any express or implied
2
+// warranty.  In no event will the authors be held liable for any damages
3
+// arising from the use of this software.
4
+// Permission is granted to anyone to use this software for any purpose,
5
+// including commercial applications, and to alter it and redistribute it
6
+// freely, subject to the following restrictions:
7
+// 1. The origin of this software must not be misrepresented; you must not
8
+//    claim that you wrote the original software. If you use this software
9
+//    in a product, an acknowledgment in the product documentation would be
10
+//    appreciated but is not required.
11
+// 2. Altered source versions must be plainly marked as such, and must not be
12
+//    misrepresented as being the original software.
13
+// 3. This notice may not be removed or altered from any source distribution.
14
+
15
+#ifndef IMGUI_FILESYSTEM_H_
16
+#define IMGUI_FILESYSTEM_H_
17
+
18
+// USAGE EXAMPLE:
19
+/*
20
+#include "imguifilesystem.h"                            // imguifilesystem.cpp must be compiled
21
+
22
+// Inside a ImGui window:
23
+const bool browseButtonPressed = ImGui::Button("...");  // we need a trigger boolean variable
24
+static ImGuiFs::Dialog dlg;                             // one per dialog (and must be static)
25
+dlg.chooseFileDialog(browseButtonPressed);              // see other dialog types and the full list of arguments for advanced usage
26
+if (strlen(dlg.getChosenPath())>0) {
27
+    ImGui::Text("Chosen file: \"%s\"",dlg.getChosenPath());
28
+}
29
+
30
+// If you want to copy the (valid) returned path somewhere, you can use something like:
31
+static char myPath[ImGuiFs::MAX_PATH_BYTES];
32
+if (strlen(dlg.getChosenPath())>0) {
33
+    strcpy(myPath,dlg.getChosenPath());
34
+}
35
+*/
36
+
37
+// MISSING FEATURES:
38
+/*
39
+-> [File and Folder] Links are NOT supported (they don't show up).
40
+-> Multiselections in chooseFileDialogs are NOT supported.
41
+-> Hidden and temporary files don't show up on nix systems (by design). Nothing has been done for Windows about it yet.
42
+*/
43
+
44
+// COMPILING AND TESTING:
45
+/*
46
+-> Compiled and tested using "ImGui library v1.17 wip"
47
+
48
+-> Successfully compiled using gcc, clang and mingw32 compilers.
49
+x> Never compiled on any other compiler (Visual C++'s cl.exe included).
50
+
51
+-> Tested on Ubuntu 64bit and Wine 32bit.
52
+x> Never tested on a real Windows OS and on MacOS.
53
+*/
54
+
55
+//#define DIRENT_USES_UTF8_CHARS  // Optional. Affects Windows users only. Needs recompilation of imguifilesystem.cpp. Enables long UTF8 paths instead of short ASCII paths.
56
+                                // Unfortunately it's NOT 100% functional (in my tests some folders can't be browsed). Patches are welcome. See "dirent_portable.h" for further info.
57
+                                // When experiencing problems on Windows, trying commenting this definition out is a good start.
58
+                                // On a second thought, I think we should leave this definition commented out (Windows users can always define it at the project level, if needed).
59
+
60
+namespace ImGuiFs {
61
+
62
+
63
+extern const int MAX_FILENAME_BYTES;
64
+extern const int MAX_PATH_BYTES;
65
+
66
+
67
+struct Dialog {
68
+    public:
69
+
70
+    // default arguments are usually what most users expect (better not touch them in most cases)
71
+    Dialog(bool noKnownDirectoriesSection=false,bool noCreateDirectorySection=false,bool noFilteringSection=false,bool detectKnownDirectoriesAtEachOpening=false,bool addDisplayByOption=false,bool dontFilterSaveFilePathsEnteredByTheUser=false);
72
+    ~Dialog();
73
+
74
+    // "dialogTriggerButton" is usually a bool variable connected to a ImGui::Button(...).
75
+    // returns the chosen path (internally stored). Users can check when the returned path has strlen()>0.
76
+    // "fileFilterExtensionString" can be something like ".png;.jpg;.jpeg;.bmp;.tga;.gif;.tiff;.txt". It's case insensitive.
77
+    // "directory" and "startingFileNameEntry" (only available in saveFileDialog(...)) are quite flexible and can be set to almost everything: the method will use the most resonable choice.
78
+    const char* chooseFileDialog(bool dialogTriggerButton,const char* directory=NULL,const char* fileFilterExtensionString=NULL,const char* windowTitle=NULL,const ImVec2& windowSize=ImVec2(-1,-1),const ImVec2& windowPos=ImVec2(-1,-1),const float windowAlpha=0.875f);
79
+    const char* chooseFolderDialog(bool dialogTriggerButton,const char* directory=NULL,const char* windowTitle=NULL,const ImVec2& windowSize=ImVec2(-1,-1),const ImVec2& windowPos=ImVec2(-1,-1),const float windowAlpha=0.875f);
80
+    const char* saveFileDialog(bool dialogTriggerButton,const char* directory=NULL,const char* startingFileNameEntry=NULL,const char* fileFilterExtensionString=NULL,const char* windowTitle=NULL,const ImVec2& windowSize=ImVec2(-1,-1),const ImVec2& windowPos=ImVec2(-1,-1),const float windowAlpha=0.875f);
81
+
82
+    // gets the chosen path (internally stored). It's valid (its strlen()>0) only when the user performs a valid selection.
83
+    const char* getChosenPath() const;
84
+    // returns the last directory browsed by the user using this class (internally stored). Can be passed as "directory" parameter in the methods above to reuse last used directory.
85
+    const char* getLastDirectory() const;
86
+
87
+    private:
88
+    struct Internal* internal;
89
+    friend const char* ChooseFileMainMethod(Dialog& ist,const char* directory,const bool _isFolderChooserDialog,const bool _isSaveFileDialog,const char* _saveFileName,const char* fileFilterExtensionString,const char* windowTitle,const ImVec2& windowSize,const ImVec2& windowPos,const float windowAlpha);
90
+};
91
+
92
+
93
+} // namespace ImGuiFs
94
+
95
+#endif //IMGUI_FILESYSTEM_H_

+ 11
- 11
src/loader/LoaderTR2.cpp Переглянути файл

@@ -931,20 +931,20 @@ void LoaderTR2::loadMoveables() {
931 931
         /*
932 932
         if (animation == 0xFFFF) {
933 933
         */
934
-            // Just add the frame indicated in frameOffset, nothing else
935
-            char* tmp = reinterpret_cast<char*>(&frames[0]) + frameOffset;
936
-            BinaryMemory frame(tmp, (numFrames * 2) - frameOffset);
934
+        // Just add the frame indicated in frameOffset, nothing else
935
+        char* tmp = reinterpret_cast<char*>(&frames[0]) + frameOffset;
936
+        BinaryMemory frame(tmp, (numFrames * 2) - frameOffset);
937 937
 
938
-            if (((numFrames * 2) - frameOffset) <= 0)
939
-                continue; // TR1/LEVEL3A crashes without this?!
938
+        if (((numFrames * 2) - frameOffset) <= 0)
939
+            continue; // TR1/LEVEL3A crashes without this?!
940 940
 
941
-            BoneFrame* bf = loadFrame(frame, numMeshes, startingMesh, meshTree, numMeshTrees, meshTrees);
942
-            AnimationFrame* af = new AnimationFrame(0);
943
-            af->add(bf);
941
+        BoneFrame* bf = loadFrame(frame, numMeshes, startingMesh, meshTree, numMeshTrees, meshTrees);
942
+        AnimationFrame* af = new AnimationFrame(0);
943
+        af->add(bf);
944 944
 
945
-            SkeletalModel* sm = new SkeletalModel(objectID);
946
-            sm->add(af);
947
-            getWorld().addSkeletalModel(sm);
945
+        SkeletalModel* sm = new SkeletalModel(objectID);
946
+        sm->add(af);
947
+        getWorld().addSkeletalModel(sm);
948 948
         /*
949 949
         } else {
950 950
             // TODO Add the whole animation hierarchy

+ 9
- 16
src/main.cpp Переглянути файл

@@ -11,7 +11,7 @@
11 11
 #include "global.h"
12 12
 #include "Camera.h"
13 13
 #include "Log.h"
14
-#include "MenuFolder.h"
14
+#include "Menu.h"
15 15
 #include "Render.h"
16 16
 #include "RunTime.h"
17 17
 #include "SoundManager.h"
@@ -27,14 +27,8 @@
27 27
 #include "utils/time.h"
28 28
 
29 29
 static std::string configFileToUse;
30
-
31
-static std::shared_ptr<MenuFolder> gMenu;
32 30
 static std::shared_ptr<World> gWorld;
33 31
 
34
-Menu& getMenu() {
35
-    return *gMenu;
36
-}
37
-
38 32
 World& getWorld() {
39 33
     return *gWorld;
40 34
 }
@@ -52,7 +46,6 @@ int main(int argc, char* argv[]) {
52 46
     // RunTime is required by other constructors
53 47
     RunTime::initialize();
54 48
 
55
-    gMenu.reset(new MenuFolder());
56 49
     gWorld.reset(new World());
57 50
 
58 51
     Command::fillCommandList();
@@ -106,23 +99,23 @@ int main(int argc, char* argv[]) {
106 99
         return -5;
107 100
     }
108 101
 
109
-    // Initialize Menu
110
-    error = getMenu().initialize();
102
+    // Initialize Debug UI
103
+    error = UI::initialize();
111 104
     if (error != 0) {
112
-        std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
105
+        std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
113 106
         return -6;
114 107
     }
115 108
 
116
-    // Initialize Debug UI
117
-    error = UI::initialize();
109
+    // Initialize Menu
110
+    error = Menu::initialize();
118 111
     if (error != 0) {
119
-        std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
112
+        std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
120 113
         return -7;
121 114
     }
122 115
 
123 116
     Log::get(LOG_INFO) << "Starting " << VERSION << Log::endl;
124 117
     Camera::setSize(Window::getSize());
125
-    getMenu().setVisible(true);
118
+    Menu::setVisible(true);
126 119
     systemTimerReset();
127 120
     RunTime::setRunning(true);
128 121
     Render::setMode(RenderMode::LoadScreen);
@@ -132,6 +125,7 @@ int main(int argc, char* argv[]) {
132 125
         renderFrame();
133 126
     }
134 127
 
128
+    Menu::shutdown();
135 129
     UI::shutdown();
136 130
     Font::shutdown();
137 131
     Sound::shutdown();
@@ -152,7 +146,6 @@ int main(int argc, char* argv[]) {
152 146
 
153 147
 void renderFrame() {
154 148
     Render::display();
155
-    getMenu().display();
156 149
     UI::display();
157 150
     Window::swapBuffers();
158 151
     RunTime::updateFPS();

+ 30
- 0
src/utils/strings.cpp Переглянути файл

@@ -43,3 +43,33 @@ bool stringEndsWith(std::string s, std::string suffix, bool casesensitive) {
43 43
     return false;
44 44
 }
45 45
 
46
+std::string removeLastPathElement(std::string s) {
47
+    auto pos = s.find_last_of("/\\");
48
+    if (pos == std::string::npos)
49
+        return s;
50
+    return s.erase(pos);
51
+}
52
+
53
+std::string getLastPathElement(std::string s) {
54
+    auto pos = s.find_last_of("/\\");
55
+    if (pos == std::string::npos)
56
+        return s;
57
+    return s.erase(0, pos + 1);
58
+}
59
+
60
+std::string convertPathDelimiter(std::string s) {
61
+    std::string::size_type pos;
62
+
63
+#ifdef _WIN32
64
+    while ((pos = s.find('/')) != std::string::npos) {
65
+        s.replace(pos, 1, 1, '\\');
66
+    }
67
+#else
68
+    while ((pos = s.find('\\')) != std::string::npos) {
69
+        s.replace(pos, 1, 1, '/');
70
+    }
71
+#endif
72
+
73
+    return s;
74
+}
75
+

Завантаження…
Відмінити
Зберегти