|
@@ -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) {
|