Browse Source

Return of (animated) textile and sprite viewer

Thomas Buck 9 years ago
parent
commit
2382ecf1f8
6 changed files with 226 additions and 229 deletions
  1. 3
    0
      ChangeLog.md
  2. 6
    0
      include/Sprite.h
  3. 3
    1
      include/TextureManager.h
  4. 2
    0
      src/Sprite.cpp
  5. 211
    9
      src/TextureManager.cpp
  6. 1
    219
      src/UI.cpp

+ 3
- 0
ChangeLog.md View File

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140204 ]
6
+    * Return of textile, animated textile and sprite viewer, in TextureManager
7
+
5 8
     [ 20140203 ]
6 9
     * Updated imgui to newest version, supporting Images
7 10
     * Texture viewer is back, using imgui Images

+ 6
- 0
include/Sprite.h View File

@@ -15,9 +15,13 @@ class Sprite {
15 15
     Sprite(int tile, int x, int y, int width, int height);
16 16
     void display(glm::mat4 MVP);
17 17
 
18
+    int getTexture() { return texture; }
19
+    glm::vec4 getUVs() { return uv2D; }
20
+
18 21
   private:
19 22
     int texture;
20 23
     ShaderBuffer vertices, uvs;
24
+    glm::vec4 uv2D;
21 25
 };
22 26
 
23 27
 class SpriteSequence {
@@ -27,6 +31,8 @@ class SpriteSequence {
27 31
     void display(glm::mat4 MVP, int index);
28 32
 
29 33
     int getID() { return id; }
34
+    int getStart() { return start; }
35
+    int size() { return length; }
30 36
 
31 37
   private:
32 38
     int id;

+ 3
- 1
include/TextureManager.h View File

@@ -106,10 +106,12 @@ class TextureManager {
106 106
     static void addAnimatedTile(int index, int tile);
107 107
     static int numAnimatedTiles();
108 108
     static int getFirstTileAnimation(int index);
109
-    static int getNextTileAnimation(int tile);
109
+    static int getNextTileAnimation(int index, int tile);
110 110
 
111 111
     static BufferManager* getBufferManager(int tex, TextureStorage store);
112 112
 
113
+    static void display();
114
+
113 115
   private:
114 116
     static std::vector<unsigned int>& getIds(TextureStorage s);
115 117
     static std::vector<int>& getUnits(TextureStorage s);

+ 2
- 0
src/Sprite.cpp View File

@@ -41,6 +41,8 @@ Sprite::Sprite(int tile, int x, int y, int width, int height) : texture(tile) {
41 41
 
42 42
     vertices.bufferData(vert);
43 43
     uvs.bufferData(uv);
44
+
45
+    uv2D = glm::vec4(uv.at(0), uv.at(2));
44 46
 }
45 47
 
46 48
 void Sprite::display(glm::mat4 MVP) {

+ 211
- 9
src/TextureManager.cpp View File

@@ -6,11 +6,14 @@
6 6
  * \author xythobuz
7 7
  */
8 8
 
9
+#include "imgui/imgui.h"
9 10
 #include "stb/stb_image.h"
10 11
 
11 12
 #include "global.h"
13
+#include "Game.h"
12 14
 #include "Log.h"
13 15
 #include "RunTime.h"
16
+#include "World.h"
14 17
 #include "utils/Folder.h"
15 18
 #include "utils/pcx.h"
16 19
 #include "utils/pixel.h"
@@ -228,15 +231,14 @@ int TextureManager::getFirstTileAnimation(int index) {
228 231
     return animations.at(index).at(0);
229 232
 }
230 233
 
231
-int TextureManager::getNextTileAnimation(int tile) {
232
-    for (int a = 0; a < animations.size(); a++) {
233
-        for (int i = 0; i < animations.at(a).size(); i++) {
234
-            if (animations.at(a).at(i) == tile) {
235
-                if (i < (animations.at(a).size() - 1))
236
-                    return animations.at(a).at(i + 1);
237
-                else
238
-                    return animations.at(a).at(0);
239
-            }
234
+int TextureManager::getNextTileAnimation(int index, int tile) {
235
+    assert(index < animations.size());
236
+    for (int i = 0; i < animations.at(index).size(); i++) {
237
+        if (animations.at(index).at(i) == tile) {
238
+            if (i < (animations.at(index).size() - 1))
239
+                return animations.at(index).at(i + 1);
240
+            else
241
+                return animations.at(index).at(0);
240 242
         }
241 243
     }
242 244
     return -1;
@@ -313,6 +315,206 @@ std::vector<int>& TextureManager::getUnits(TextureStorage s) {
313 315
         return systemUnits;
314 316
 }
315 317
 
318
+void TextureManager::display() {
319
+    if (ImGui::CollapsingHeader("Texture Viewer")) {
320
+        static bool game = Game::isLoaded();
321
+        static int index = 0;
322
+        ImGui::SliderInt("##texslide", &index, 0, TextureManager::numTextures(
323
+                             game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1);
324
+        ImGui::SameLine();
325
+        if (ImGui::Button("+##texplus", ImVec2(0, 0), true)) {
326
+            if (index < (numTextures(
327
+                             game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1))
328
+                index++;
329
+            else
330
+                index = 0;
331
+        }
332
+        ImGui::SameLine();
333
+        if (ImGui::Button("-##texminus", ImVec2(0, 0), true)) {
334
+            if (index > 0)
335
+                index--;
336
+            else
337
+                index = numTextures(
338
+                            game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
339
+        }
340
+
341
+        if ((numTextures(TextureStorage::GAME) > 0)) {
342
+            ImGui::SameLine();
343
+            ImGui::Checkbox("Game##texgame", &game);
344
+        } else {
345
+            game = false;
346
+        }
347
+
348
+        if (index >= numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM)) {
349
+            index = numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
350
+            if (index < 0) {
351
+                game = false;
352
+                index = 0;
353
+            }
354
+        }
355
+
356
+        auto bm = getBufferManager(index, game ? TextureStorage::GAME
357
+                                                            : TextureStorage::SYSTEM);
358
+        ImGui::Image(bm, ImVec2(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3));
359
+    }
360
+
361
+    if (ImGui::CollapsingHeader("Textile Viewer")) {
362
+        if (numTiles() > 0) {
363
+            static int index = 0;
364
+            ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
365
+            ImGui::SliderInt("##tileslide", &index, 0, numTiles() - 1);
366
+            ImGui::PopItemWidth();
367
+            ImGui::SameLine();
368
+            if (ImGui::Button("+##tileplus", ImVec2(0, 0), true)) {
369
+                if (index < (numTiles() - 1))
370
+                    index++;
371
+                else
372
+                    index = 0;
373
+            }
374
+            ImGui::SameLine();
375
+            if (ImGui::Button("-##tileminus", ImVec2(0, 0), true)) {
376
+                if (index > 0)
377
+                    index--;
378
+                else
379
+                    index = numTiles() - 1;
380
+            }
381
+
382
+            if (index >= numTiles())
383
+                index = 0;
384
+
385
+            auto& tile = getTile(index);
386
+            auto bm = getBufferManager(tile.getTexture(), TextureStorage::GAME);
387
+            ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
388
+            auto uvA = tile.getUV(0);
389
+            auto uvB = tile.getUV(2);
390
+            ImVec2 uv1(uvA.x, uvA.y);
391
+            ImVec2 uv2(uvB.x, uvB.y);
392
+            ImGui::Image(bm, size, uv1, uv2);
393
+        } else {
394
+            ImGui::Text("No textiles are currently loaded...!");
395
+        }
396
+    }
397
+
398
+    if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
399
+        if (numAnimatedTiles() > 0) {
400
+            static int index = 0;
401
+            static int tile = getFirstTileAnimation(index);
402
+            if (ImGui::SliderInt("##animslide", &index, 0, numAnimatedTiles() - 1)) {
403
+                tile = getFirstTileAnimation(index);
404
+            }
405
+            ImGui::SameLine();
406
+            if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
407
+                if (index < (numAnimatedTiles() - 1))
408
+                    index++;
409
+                else
410
+                    index = 0;
411
+                tile = getFirstTileAnimation(index);
412
+            }
413
+            ImGui::SameLine();
414
+            if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
415
+                if (index > 0)
416
+                    index--;
417
+                else
418
+                    index = numAnimatedTiles() - 1;
419
+                tile = getFirstTileAnimation(index);
420
+            }
421
+
422
+            if (index >= numAnimatedTiles()) {
423
+                index = 0;
424
+                tile = getFirstTileAnimation(index);
425
+            }
426
+
427
+            int next = getNextTileAnimation(index, tile);
428
+            if (next == -1) {
429
+                index = 0;
430
+                tile = getFirstTileAnimation(index);
431
+            }
432
+
433
+            ImGui::SameLine();
434
+            ImGui::Text("%d", tile);
435
+
436
+            auto& t = getTile(tile);
437
+            auto bm = getBufferManager(t.getTexture(), TextureStorage::GAME);
438
+            ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
439
+            auto uvA = t.getUV(0);
440
+            auto uvB = t.getUV(2);
441
+            ImVec2 uv1(uvA.x, uvA.y);
442
+            ImVec2 uv2(uvB.x, uvB.y);
443
+            ImGui::Image(bm, size, uv1, uv2);
444
+
445
+            static int fr = 0;
446
+            if (fr > 0) {
447
+                fr--;
448
+            } else {
449
+                fr = RunTime::getFPS() / 2;
450
+                tile = next;
451
+            }
452
+        } else {
453
+            ImGui::Text("No animated textures are currently loaded...!");
454
+        }
455
+    }
456
+
457
+    if (ImGui::CollapsingHeader("Sprite Sequence Viewer")) {
458
+        if (getWorld().sizeSprite() <= 0) {
459
+            ImGui::Text("Please load a level containing sprites!");
460
+        } else {
461
+            static int index = 0;
462
+            static int sprite = 0;
463
+            if (ImGui::SliderInt("##spriteslide", &index, 0, getWorld().sizeSpriteSequence() - 1)) {
464
+                sprite = 0;
465
+            }
466
+            ImGui::SameLine();
467
+            if (ImGui::Button("+##spriteplus", ImVec2(0, 0), true)) {
468
+                if (index < (getWorld().sizeSpriteSequence() - 1))
469
+                    index++;
470
+                else
471
+                    index = 0;
472
+                sprite = 0;
473
+            }
474
+            ImGui::SameLine();
475
+            if (ImGui::Button("-##spriteminus", ImVec2(0, 0), true)) {
476
+                if (index > 0)
477
+                    index--;
478
+                else
479
+                    index = getWorld().sizeSpriteSequence() - 1;
480
+                sprite = 0;
481
+            }
482
+
483
+            if (index >= getWorld().sizeSpriteSequence()) {
484
+                index = 0;
485
+                sprite = 0;
486
+            }
487
+
488
+            if (sprite >= getWorld().getSpriteSequence(index).size()) {
489
+                sprite = 0;
490
+            }
491
+
492
+            ImGui::SameLine();
493
+            ImGui::Text("Sprite %d/%d", sprite + 1, getWorld().getSpriteSequence(index).size());
494
+
495
+            auto& s = getWorld().getSprite(getWorld().getSpriteSequence(index).getStart() + sprite);
496
+            auto bm = getBufferManager(s.getTexture(), TextureStorage::GAME);
497
+            ImVec2 size(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3);
498
+            auto uv = s.getUVs();
499
+            ImVec2 uv1(uv.x, uv.w);
500
+            ImVec2 uv2(uv.z, uv.y);
501
+            ImGui::Image(bm, size, uv1, uv2);
502
+
503
+            static int fr = 0;
504
+            if (fr > 0) {
505
+                fr--;
506
+            } else {
507
+                fr = RunTime::getFPS() / 10;
508
+                if (sprite < (getWorld().getSpriteSequence(index).size() - 1))
509
+                    sprite++;
510
+                else
511
+                    sprite = 0;
512
+            }
513
+
514
+        }
515
+    }
516
+}
517
+
316 518
 // ----------------------------------------------------------------------------
317 519
 
318 520
 glm::vec2 TextureTile::getUV(unsigned int i) {

+ 1
- 219
src/UI.cpp View File

@@ -16,9 +16,6 @@
16 16
 #include "RunTime.h"
17 17
 #include "SoundManager.h"
18 18
 #include "TextureManager.h"
19
-#include "World.h"
20
-#include "commands/Command.h"
21
-#include "system/Sound.h"
22 19
 #include "system/Window.h"
23 20
 #include "utils/time.h"
24 21
 #include "UI.h"
@@ -273,225 +270,10 @@ void UI::display() {
273 270
     if (ImGui::Begin("Engine", &visible, ImVec2(400, 400))) {
274 271
         Render::displayUI();
275 272
         RunTime::display();
276
-
277
-        if (ImGui::CollapsingHeader("Texture Viewer")) {
278
-            static bool game = Game::isLoaded();
279
-            static int index = 0;
280
-            ImGui::SliderInt("##texslide", &index, 0, TextureManager::numTextures(
281
-                                 game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1);
282
-            ImGui::SameLine();
283
-            if (ImGui::Button("+##texplus", ImVec2(0, 0), true)) {
284
-                if (index < (TextureManager::numTextures(
285
-                                 game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1))
286
-                    index++;
287
-                else
288
-                    index = 0;
289
-            }
290
-            ImGui::SameLine();
291
-            if (ImGui::Button("-##texminus", ImVec2(0, 0), true)) {
292
-                if (index > 0)
293
-                    index--;
294
-                else
295
-                    index = TextureManager::numTextures(
296
-                                game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
297
-            }
298
-
299
-            if ((TextureManager::numTextures(TextureStorage::GAME) > 0)) {
300
-                ImGui::SameLine();
301
-                ImGui::Checkbox("Game##texgame", &game);
302
-            } else {
303
-                game = false;
304
-            }
305
-
306
-            if (index >= TextureManager::numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM)) {
307
-                index = TextureManager::numTextures(game ? TextureStorage::GAME : TextureStorage::SYSTEM) - 1;
308
-                if (index < 0) {
309
-                    game = false;
310
-                    index = 0;
311
-                }
312
-            }
313
-
314
-            auto bm = TextureManager::getBufferManager(index, game ? TextureStorage::GAME
315
-                                                                : TextureStorage::SYSTEM);
316
-            ImGui::Image(bm, ImVec2(ImGui::GetColumnWidth() * 2 / 3, ImGui::GetColumnWidth() * 2 / 3));
317
-        }
318
-
273
+        TextureManager::display();
319 274
         SoundManager::display();
320 275
 
321
-        /*
322
-        static bool visibleTex = false;
323
-        static bool visibleTile = false;
324
-        static bool visibleAnim = false;
325
-        static bool visibleSprite = false;
326
-
327
-
328
-        if (ImGui::CollapsingHeader("Textile Viewer")) {
329
-            if (TextureManager::numTiles() > 0) {
330
-                static int index = 0;
331
-                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
332
-                ImGui::SliderInt("##tileslide", &index, 0, TextureManager::numTiles() - 1);
333
-                ImGui::PopItemWidth();
334
-                ImGui::SameLine();
335
-                if (ImGui::Button("+##tileplus", ImVec2(0, 0), true)) {
336
-                    if (index < (TextureManager::numTiles() - 1))
337
-                        index++;
338
-                    else
339
-                        index = 0;
340
-                }
341
-                ImGui::SameLine();
342
-                if (ImGui::Button("-##tileminus", ImVec2(0, 0), true)) {
343
-                    if (index > 0)
344
-                        index--;
345
-                    else
346
-                        index = TextureManager::numTiles() - 1;
347
-                }
348
-                ImGui::SameLine();
349
-                if (ImGui::Button("Show##tileshow")) {
350
-                    visibleTile = true;
351
-                    visibleTex = false;
352
-                    visibleAnim = false;
353
-                    visibleSprite = false;
354
-                }
355
-                ImGui::SameLine();
356
-                if (ImGui::Button("Clear##tileclear")) {
357
-                    getRender().debugDisplayTextile();
358
-                    visibleTile = false;
359
-                }
360
-                if (visibleTile && (index < TextureManager::numTiles())) {
361
-                    ImGui::Text(TextureManager::.getTile(index).isTriangle() ? "Triangle" : "Rectangle");
362
-                }
363
-                if (visibleTile) {
364
-                    getRender().debugDisplayTextile(index,
365
-                                                    ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
366
-                                                    ImGui::GetWindowPos().y,
367
-                                                    (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
368
-                }
369
-            } else {
370
-                ImGui::Text("Please load a level using the new loader!");
371
-            }
372
-        }
373
-
374
-        if (ImGui::CollapsingHeader("Animated Textile Viewer")) {
375
-            if (TextureManager::.numAnimatedTiles() > 0) {
376
-                static int index = 0;
377
-                static int tile = TextureManager::.getFirstTileAnimation(index);
378
-                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
379
-                if (ImGui::SliderInt("##animslide", &index, 0, TextureManager::.numAnimatedTiles() - 1)) {
380
-                    tile = TextureManager::.getFirstTileAnimation(index);
381
-                }
382
-                ImGui::PopItemWidth();
383
-                ImGui::SameLine();
384
-                if (ImGui::Button("+##animplus", ImVec2(0, 0), true)) {
385
-                    if (index < (TextureManager::.numAnimatedTiles() - 1))
386
-                        index++;
387
-                    else
388
-                        index = 0;
389
-                    tile = TextureManager::.getFirstTileAnimation(index);
390
-                }
391
-                ImGui::SameLine();
392
-                if (ImGui::Button("-##animminus", ImVec2(0, 0), true)) {
393
-                    if (index > 0)
394
-                        index--;
395
-                    else
396
-                        index = TextureManager::.numAnimatedTiles() - 1;
397
-                    tile = TextureManager::.getFirstTileAnimation(index);
398
-                }
399
-                ImGui::SameLine();
400
-                if (ImGui::Button("Show##animshow")) {
401
-                    visibleAnim = true;
402
-                    visibleTex = false;
403
-                    visibleTile = false;
404
-                    visibleSprite = false;
405
-                }
406
-                ImGui::SameLine();
407
-                if (ImGui::Button("Clear##animclear")) {
408
-                    getRender().debugDisplayTextile();
409
-                    visibleAnim = false;
410
-                }
411
-                if (visibleAnim) {
412
-                    static int fr = 0;
413
-                    if (fr > 0) {
414
-                        fr--;
415
-                    } else {
416
-                        getRender().debugDisplayTextile(tile,
417
-                                                        ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
418
-                                                        ImGui::GetWindowPos().y,
419
-                                                        (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
420
-                        fr = RunTime::getFPS() / 2;
421
-                        tile = TextureManager::.getNextTileAnimation(tile);
422
-                    }
423
-                    ImGui::Text("Current Tile: %d", tile);
424
-                }
425
-            } else {
426
-                ImGui::Text("Please load a level with animated textures!");
427
-            }
428
-        }
429
-
430
-        if (ImGui::CollapsingHeader("Sprite Sequence Viewer")) {
431
-            if (getWorld().sizeSprite() <= 0) {
432
-                ImGui::Text("Please load a level containing sprites!");
433
-            } else {
434
-                static int index = 0;
435
-                static int sprite = 0;
436
-                ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
437
-                if (ImGui::SliderInt("##spriteslide", &index, 0, getWorld().sizeSprite() - 1))
438
-                    sprite = 0;
439
-                ImGui::PopItemWidth();
440
-                ImGui::SameLine();
441
-                if (ImGui::Button("+##spriteplus", ImVec2(0, 0), true)) {
442
-                    if (index < (getWorld().sizeSprite() - 1))
443
-                        index++;
444
-                    else
445
-                        index = 0;
446
-                    sprite = 0;
447
-                }
448
-                ImGui::SameLine();
449
-                if (ImGui::Button("-##spriteminus", ImVec2(0, 0), true)) {
450
-                    if (index > 0)
451
-                        index--;
452
-                    else
453
-                        index = getWorld().sizeSprite() - 1;
454
-                    sprite = 0;
455
-                }
456
-                ImGui::SameLine();
457
-                if (ImGui::Button("Show##spriteshow")) {
458
-                    visibleSprite = true;
459
-                    visibleTex = false;
460
-                    visibleTile = false;
461
-                    visibleAnim = false;
462
-                    sprite = 0;
463
-                }
464
-                ImGui::SameLine();
465
-                if (ImGui::Button("Clear##spriteclear")) {
466
-                    getRender().debugDisplaySprite();
467
-                    visibleSprite = false;
468
-                }
469
-                if (visibleSprite) {
470
-                    static int fr = 0;
471
-                    if (fr > 0) {
472
-                        fr--;
473
-                    } else {
474
-                        getRender().debugDisplaySprite(index, sprite,
475
-                                                       ImGui::GetWindowPos().x - (ImGui::GetWindowWidth() / 2),
476
-                                                       ImGui::GetWindowPos().y,
477
-                                                       (ImGui::GetWindowWidth() / 2), (ImGui::GetWindowWidth() / 2));
478
-                        fr = RunTime::getFPS() / 10;
479
-                        if (sprite < (getWorld().getSprite(index).size() - 1))
480
-                            sprite++;
481
-                        else
482
-                            sprite = 0;
483
-                    }
484
-
485
-                    ImGui::Text("Sprite %d/%d", sprite + 1, getWorld().getSprite(index).size());
486
-                }
487
-            }
488
-        }
489
-        */
490
-
491 276
         if (ImGui::CollapsingHeader("ImGui/Debug UI Help")) {
492
-            //ImGui::TextWrapped("DebugViewer Textures/Textiles/Sprites will be drawn on"
493
-            //                   " the left side and scale with the size of this window!");
494
-            //ImGui::Separator();
495 277
             ImGui::ShowUserGuide();
496 278
             ImGui::Separator();
497 279
             if (ImGui::Button("Show/Hide Test Window")) {

Loading…
Cancel
Save