- Nous gràfics

- [FIX] text en el combobox
- [NEW] Selector de bitmap
- [NEW] Selector de color
- [NEW] Shortcuts per a esborrar (SUPR) i duplicar (CTRL+D) actors
This commit is contained in:
2024-09-18 13:55:43 +02:00
parent a825581108
commit 99d0583833
10 changed files with 192 additions and 184 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -5,187 +5,11 @@ door-height-xn: 0
door-height-yp: 0 door-height-yp: 0
door-height-yn: 0 door-height-yn: 0
color: PURPLE color: PURPLE
floor-texture: 6 floor-texture: 4
wall-texture: 7 wall-texture: 7
door-texture: 2 door-texture: 5
under-door-texture: 7 under-door-texture: 7
exit-xp: 12 exit-xp: 12
exit-xn: 10 exit-xn: 10
exit-yp: 17 exit-yp: 17
exit-yn: 8 exit-yn: 8
actor{
name: BOX-01
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 8 8 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-02
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 16 8 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-03
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 8 16 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-04
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 40 8 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-05
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 48 8 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-06
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 48 16 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-07
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 48 40 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-08
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 48 48 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-09
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 40 48 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-10
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 16 48 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-11
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 8 48 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-12
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 8 40 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-13
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 24 24 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-14
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 32 24 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-15
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 32 32 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}
actor{
name: BOX-16
bmp: caixes.gif
bmp-rect: 32 0 32 32
bmp-offset: 0 32
pos: 24 32 0
size: 8 8 8
flags: PUSHABLE
movement: CW
}

View File

@@ -100,6 +100,8 @@ namespace ui
draw::rect(x, y, w, h); draw::rect(x, y, w, h);
draw::vline(x+w-11,y+1,h-2); draw::vline(x+w-11,y+1,h-2);
draw::print(label, x+3, y+3, PAPER, 0);
draw::color(WHITE); draw::color(WHITE);
draw::fillrect(x+w-10, y+1, 9, h-2); draw::fillrect(x+w-10, y+1, 9, h-2);
@@ -111,7 +113,6 @@ namespace ui
draw::hline(x+w-10,y+h-2,9); draw::hline(x+w-10,y+h-2,9);
draw::vline(x+w-2,y+1,h-2); draw::vline(x+w-2,y+1,h-2);
draw::print(label, x+3, y+3, PAPER, 0);
draw::print("v", x+w-7, y+2, PAPER, 0); draw::print("v", x+w-7, y+2, PAPER, 0);
if (inside) if (inside)

View File

@@ -0,0 +1,54 @@
#include "m_editor_bitmap_file.h"
#include "jdraw.h"
#include "jinput.h"
#include <SDL2/SDL.h>
#include "room.h"
#include "actor.h"
#include "m_game.h"
namespace modules
{
namespace editor_bitmap_file
{
std::vector<std::string> gifs = { "abad.gif", "altres.gif", "caixes.gif", "gat.gif", "gat2.gif", "objectes.gif", "obrer.gif" };
void init()
{
draw::resetViewport();
//gifs = game::getGifs();
}
bool loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
if (input::mouseClk(1))
{
const int x = input::mouseX()/80;
const int y = input::mouseY()/80;
const int selected = x+y*6;
actor::actor_t* act = actor::getSelected();
strcpy(act->bmp, gifs[selected].c_str());
act->surface = draw::getSurface(gifs[selected]);
return false;
}
draw::cls(2);
int bx = 0;
int by = 0;
for (int i=0; i<gifs.size(); ++i)
{
draw::surface *surf = draw::getSurface(gifs[i].c_str());
draw::setSource(surf);
const float aspect = float(surf->w) / float(surf->h);
const int width = 64.0f*aspect;
draw::draw(2+80*bx, 2+by*80, surf->w, surf->h, 0, 0, 0, 64, 64);
draw::print(gifs[i].c_str(), 2+80*bx + 32 - (gifs[0].size()/2)*4, 70+by*80, LIGHT+WHITE, PAPER);
bx++; if (bx>5) { bx=0; by++; }
}
draw::render();
return true;
}
}
}

View File

@@ -0,0 +1,10 @@
#pragma once
namespace modules
{
namespace editor_bitmap_file
{
void init();
bool loop();
}
}

View File

@@ -0,0 +1,59 @@
#include "m_editor_colors.h"
#include "jdraw.h"
#include "jinput.h"
#include <SDL2/SDL.h>
#include "room.h"
namespace modules
{
namespace editor_colors
{
void init()
{
draw::setViewport(468, 117, 52, 52);
}
bool loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
const char *colors[] = {"PURPLE", "GREEN", "CYAN", "YELLOW", "WHITE"};
const int color = room::editor::refColor();
const int mx = input::mouseX()-468;
const int my = input::mouseY()-117;
const bool mouse_inside = mx>=0 && mx<52 && my>=0 && my<52;
if (input::mouseClk(1))
{
if (mouse_inside) {
const int new_color = (my-1)/10;
room::editor::refColor() = new_color;
return false;
} else {
return false;
}
}
draw::color(WHITE);
draw::fillrect(0,0,52,52);
draw::color(LIGHT+WHITE);
draw::hline(0, 0, 52);
draw::vline(0, 0, 52);
draw::color(BLACK);
draw::hline(0, 51, 52);
draw::vline(51, 0, 52);
const int hovered_element = mouse_inside ? (my-1)/10 : -1;
for (int i=0; i<5; ++i)
{
if (hovered_element==i) { draw::color(LIGHT+BLUE); draw::fillrect(1,1+i*10,50,10); }
draw::print(colors[i], 5, 3+i*10, LIGHT+(color==i?YELLOW:WHITE), PAPER);
draw::color(LIGHT+i+7); draw::fillrect(40,2+i*10,7,7);draw::color(PAPER); draw::rect(40,2+i*10,7,7);
}
draw::render();
return true;
}
}
}

10
source/m_editor_colors.h Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
namespace modules
{
namespace editor_colors
{
void init();
bool loop();
}
}

View File

@@ -16,6 +16,8 @@ namespace modules
std::vector<std::string> gifs; std::vector<std::string> gifs;
int treeview_scroll = 0; int treeview_scroll = 0;
std::vector<std::string> getGifs() { return gifs; }
void init() void init()
{ {
actor::clear(true); actor::clear(true);
@@ -256,6 +258,8 @@ namespace modules
int loop() int loop()
{ {
int return_value = GAME_NONE;
if (actor::hero::isDead()) return GAME_DEAD; if (actor::hero::isDead()) return GAME_DEAD;
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) if (input::keyPressed(SDL_SCANCODE_ESCAPE))
@@ -609,8 +613,19 @@ namespace modules
ui::label("TEXTURES", 2, line, 96, 11, GRAY); line+=10; ui::label("TEXTURES", 2, line, 96, 11, GRAY); line+=10;
changed |= btn_opt("COLOR", 2, line, room::editor::refColor(), {0, 1, 2, 3, 4}, {"PURPLE", "GREEN", "CYAN", "YELLOW", "WHITE"}, 47); //ui::label("COLOR", 2, line, 64, 11); //changed |= btn_opt("COLOR", 2, line, room::editor::refColor(), {0, 1, 2, 3, 4}, {"PURPLE", "GREEN", "CYAN", "YELLOW", "WHITE"}, 47); //ui::label("COLOR", 2, line, 64, 11);
//changed |= btn_small(64, line, room::editor::refColor(), 5, 11); {
const char *colors[] = {"PURPLE", "GREEN", "CYAN", "YELLOW", "WHITE"};
ui::label("COLOR", 2, line, 48, 11);
const int color = room::editor::refColor();
if (ui::combo(colors[color], 48, line, 49, 11)) {
//if (ui::button(colors[room::editor::refColor()], 48, line+1, 49, 9)) {
//ui::button(colors[room::editor::refColor()], 48, line+1, 49, 9, true);
return_value = GAME_EDITOR_COLORS;
}
draw::color(LIGHT+color+7); draw::fillrect(77,2+line,7,7);draw::color(PAPER); draw::rect(77,2+line,7,7);
}
line += 10; line += 10;
ui::label("FLOOR", 2, line, 48, 11); ui::label("FLOOR", 2, line, 48, 11);
changed |= btn_small(48, line, room::editor::refFloorTex(), 0, room::getFloorCount()-1, 50); changed |= btn_small(48, line, room::editor::refFloorTex(), 0, room::getFloorCount()-1, 50);
@@ -694,11 +709,22 @@ namespace modules
ui::label("BITMAP", 2, line, 96, 11, GRAY); line+=10; ui::label("BITMAP", 2, line, 96, 11, GRAY); line+=10;
{
ui::label("FILE", 2, line, 49, 11);
if (ui::combo(act->bmp, 49, line, 48, 11)) {
//if (ui::button(colors[room::editor::refColor()], 48, line+1, 49, 9)) {
//ui::button(colors[room::editor::refColor()], 48, line+1, 49, 9, true);
return_value = GAME_EDITOR_BITMAP_FILE;
}
}
/*
if (btn_opt2("FILE", 2, line, act->bmp, gifs)) { if (btn_opt2("FILE", 2, line, act->bmp, gifs)) {
//draw::freeSurface(act->surface); //draw::freeSurface(act->surface);
act->surface = draw::getSurface(act->bmp); act->surface = draw::getSurface(act->bmp);
changed = true; changed = true;
} }
*/
line+=10; line+=10;
ui::label("POS", 2, line, 48, 11); ui::label("POS", 2, line, 48, 11);
changed |= btn_small(49, line, act->bmp_rect.x, 0, 512, 25); changed |= btn_small(49, line, act->bmp_rect.x, 0, 512, 25);
@@ -771,7 +797,7 @@ namespace modules
draw::color(PAPER); draw::color(PAPER);
draw::rect(2, 0, 96, 204); draw::rect(2, 0, 96, 204);
if (ui::button("DUPLICATE", 2, line, 48, 11)) if (ui::button("DUPLICATE", 2, line, 48, 11) || (input::keyDown(SDL_SCANCODE_LCTRL) && input::keyPressed(SDL_SCANCODE_D)))
{ {
actor::actor_t *new_act = actor::duplicate(act); actor::actor_t *new_act = actor::duplicate(act);
actor::setUniqueName(new_act); actor::setUniqueName(new_act);
@@ -780,7 +806,7 @@ namespace modules
actor::select(new_act); actor::select(new_act);
changed = true; changed = true;
} }
if (ui::button("DELETE", 48, line, 48, 11)) if (ui::button("DELETE", 48, line, 48, 11) || input::keyPressed(SDL_SCANCODE_DELETE))
{ {
actor::remove(act); actor::remove(act);
act = nullptr; act = nullptr;
@@ -801,7 +827,7 @@ namespace modules
}; };
draw::render(); draw::render();
return GAME_NONE; return return_value;
} }
} }

View File

@@ -1,4 +1,6 @@
#pragma once #pragma once
#include <vector>
#include <string>
namespace modules namespace modules
{ {
@@ -9,8 +11,12 @@ namespace modules
#define GAME_DEAD 1 #define GAME_DEAD 1
#define GAME_EDITOR_MAP 2 #define GAME_EDITOR_MAP 2
#define GAME_EDITOR_TEMPLATES 3 #define GAME_EDITOR_TEMPLATES 3
#define GAME_EDITOR_COLORS 4
#define GAME_EDITOR_BITMAP_FILE 5
void init(); void init();
int loop(); int loop();
std::vector<std::string> getGifs();
} }
} }

View File

@@ -21,6 +21,8 @@
#include "m_menu_audio.h" #include "m_menu_audio.h"
#include "m_editor_map.h" #include "m_editor_map.h"
#include "m_editor_templates.h" #include "m_editor_templates.h"
#include "m_editor_colors.h"
#include "m_editor_bitmap_file.h"
#define M_LOGO 0 #define M_LOGO 0
#define M_MENU 1 #define M_MENU 1
@@ -32,6 +34,8 @@
#define M_MENU_AUDIO 7 #define M_MENU_AUDIO 7
#define M_EDITOR_MAP 8 #define M_EDITOR_MAP 8
#define M_EDITOR_TEMPLATES 9 #define M_EDITOR_TEMPLATES 9
#define M_EDITOR_COLORS 10
#define M_EDITOR_BITMAP_FILE 11
int current_module = M_LOGO; int current_module = M_LOGO;
int zoom = 3; int zoom = 3;
@@ -142,6 +146,10 @@ bool game::loop()
modules::editor_map::init(); current_module = M_EDITOR_MAP; modules::editor_map::init(); current_module = M_EDITOR_MAP;
} else if (option==GAME_EDITOR_TEMPLATES) { } else if (option==GAME_EDITOR_TEMPLATES) {
modules::editor_templates::init(); current_module = M_EDITOR_TEMPLATES; modules::editor_templates::init(); current_module = M_EDITOR_TEMPLATES;
} else if (option==GAME_EDITOR_COLORS) {
modules::editor_colors::init(); current_module = M_EDITOR_COLORS;
} else if (option==GAME_EDITOR_BITMAP_FILE) {
modules::editor_bitmap_file::init(); current_module = M_EDITOR_BITMAP_FILE;
} }
} }
break; break;
@@ -155,6 +163,16 @@ bool game::loop()
current_module = M_GAME; current_module = M_GAME;
} }
break; break;
case M_EDITOR_COLORS:
if (!modules::editor_colors::loop()) {
current_module = M_GAME;
}
break;
case M_EDITOR_BITMAP_FILE:
if (!modules::editor_bitmap_file::loop()) {
current_module = M_GAME;
}
break;
case M_INGAME: case M_INGAME:
option = modules::ingame::loop(); option = modules::ingame::loop();
if (option != INGAME_NONE) { if (option != INGAME_NONE) {