- [FIX] Per a crear noves habitacions descartar clicks fora del canvas
- [FIX] Nomes crear nova habitació si s'està pulsant LCTRL - [NEW] Minimapa en l'editor
This commit is contained in:
109
source/m_editor_map.cpp
Normal file
109
source/m_editor_map.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "m_editor_map.h"
|
||||
#include "jdraw.h"
|
||||
#include "jinput.h"
|
||||
#include "misc.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "room.h"
|
||||
|
||||
namespace modules
|
||||
{
|
||||
namespace editor_map
|
||||
{
|
||||
draw::surface *surf;
|
||||
vec2_t scroll {0,0};
|
||||
bool drawn[64];
|
||||
int current_room;
|
||||
|
||||
struct miniroom_t
|
||||
{
|
||||
uint8_t w;
|
||||
uint8_t h;
|
||||
uint8_t color;
|
||||
uint8_t exits[6];
|
||||
};
|
||||
miniroom_t minirooms[64];
|
||||
|
||||
void loadMiniRoom()
|
||||
{
|
||||
const int room = room::getCurrent();
|
||||
if (drawn[room]) return;
|
||||
drawn[room] = true;
|
||||
|
||||
minirooms[room].color = room::getColor(0);
|
||||
minirooms[room].w = (room::getSize().x >> 1)-1;
|
||||
minirooms[room].h = (room::getSize().y >> 1)-1;
|
||||
for (int i=0; i<ZN; ++i) minirooms[room].exits[i] = room::getExit(i);
|
||||
|
||||
for (int i=0; i<ZN; ++i) {
|
||||
const int next_room = minirooms[room].exits[i];
|
||||
if ( (next_room >= 0) && (next_room <= 64) && (!drawn[next_room]) ) {
|
||||
room::load(next_room);
|
||||
loadMiniRoom();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
surf = draw::getSurface("mapa.gif");
|
||||
scroll = {260,120};
|
||||
draw::resetViewport();
|
||||
for (int i=0;i<64;++i) drawn[i]=false;
|
||||
|
||||
current_room = room::getCurrent();
|
||||
loadMiniRoom();
|
||||
room::load(current_room);
|
||||
}
|
||||
|
||||
void drawRoom(const int room, const int x, const int y)
|
||||
{
|
||||
if (drawn[room]) return;
|
||||
drawn[room] = true;
|
||||
if ( (x>=-32) && (x<520) && (y>=-16) && (y<240) )
|
||||
{
|
||||
draw::stencil::set(room);
|
||||
draw::swapcol(1, minirooms[room].color);
|
||||
draw::draw(x-16, y-8, 32, 16, minirooms[room].w*32, minirooms[room].h*16);
|
||||
|
||||
draw::swapcol(1, RED);
|
||||
if (minirooms[room].exits[XN] != 255) draw::draw(x-4-(minirooms[room].w*2), y-5-(minirooms[room].w),4,5,0,64);
|
||||
if (minirooms[room].exits[YN] != 255) draw::draw(x+(minirooms[room].h*2), y-5-(minirooms[room].h),4,5,3,64);
|
||||
if (minirooms[room].exits[XP] != 255) draw::draw(x+(minirooms[room].w*2), y-3+(minirooms[room].w),4,5,0,64);
|
||||
if (minirooms[room].exits[YP] != 255) draw::draw(x-4-(minirooms[room].h*2), y-3+(minirooms[room].h),4,5,3,64);
|
||||
|
||||
char num[] = "00"; num[0] = 48+(room/10); num[1] = 48+(room%10);
|
||||
draw::print(num, x-4, y-3, LIGHT+(room==current_room?YELLOW:WHITE), BLACK);
|
||||
}
|
||||
if (minirooms[room].exits[XN] != 255) drawRoom(minirooms[room].exits[XN], x-24, y-12);
|
||||
if (minirooms[room].exits[XP] != 255) drawRoom(minirooms[room].exits[XP], x+24, y+12);
|
||||
if (minirooms[room].exits[YN] != 255) drawRoom(minirooms[room].exits[YN], x+24, y-12);
|
||||
if (minirooms[room].exits[YP] != 255) drawRoom(minirooms[room].exits[YP], x-24, y+12);
|
||||
}
|
||||
|
||||
bool loop()
|
||||
{
|
||||
for (int i=0;i<64;++i) drawn[i]=false;
|
||||
|
||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
|
||||
|
||||
draw::cls(2);
|
||||
draw::setSource(surf);
|
||||
|
||||
draw::stencil::enable();
|
||||
draw::stencil::clear(255);
|
||||
|
||||
drawRoom(room::getCurrent(), scroll.x, scroll.y);
|
||||
draw::render();
|
||||
|
||||
if (input::mouseClk(1)) {
|
||||
const int clicked = draw::stencil::query(input::mouseX(), input::mouseY());
|
||||
if (clicked!=255) {
|
||||
room::load(clicked);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user