diff --git a/source/aux.cpp b/source/aux.cpp new file mode 100644 index 0000000..ea48cf5 --- /dev/null +++ b/source/aux.cpp @@ -0,0 +1,11 @@ +#include "aux.h" + +namespace aux +{ + std::string colors[17] = { "black", "bright_black", "blue", "bright_blue", "red", "bright_red", "magenta", "bright_magenta", "green", "bright_green", "cyan", "bright_cyan", "yellow", "bright_yellow", "white", "bright_white", "transparent" }; + int getColorByName(std::string color) + { + for (int i=0; i<17; ++i) if (colors[i] == color) return i; + return 0; + } +} diff --git a/source/aux.h b/source/aux.h new file mode 100644 index 0000000..34a9559 --- /dev/null +++ b/source/aux.h @@ -0,0 +1,8 @@ +#pragma once +#include +#include + +namespace aux +{ + int getColorByName(std::string color); +} diff --git a/source/japi/draw.cpp b/source/japi/draw.cpp index fbf2da9..095c1f3 100644 --- a/source/japi/draw.cpp +++ b/source/japi/draw.cpp @@ -45,7 +45,10 @@ namespace draw SDL_Texture *createSurface(const uint16_t w, const uint16_t h) { - return SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h); + SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h); + SDL_SetTextureScaleMode(surf, SDL_SCALEMODE_NEAREST); + + return surf; } SDL_Texture *loadSurface(const char *filename, const int transparent) @@ -61,6 +64,7 @@ namespace draw uint32_t *pal = LoadPalette(buffer, &paletteSize); SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h); + SDL_SetTextureScaleMode(surf, SDL_SCALEMODE_NEAREST); SDL_SetTextureBlendMode(surf, SDL_BLENDMODE_BLEND); Uint32 *sdl_pixels; diff --git a/source/main.cpp b/source/main.cpp index 682c629..2e839bc 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -4,8 +4,12 @@ #include "menu.h" #include "toolbar.h" #include "treeview.h" +#include "propertygrid.h" +#include "tilemap.h" #include "fkYAML/node.hpp" #include +#include +#include "aux.h" namespace fs = std::filesystem; @@ -23,6 +27,20 @@ void loadRoom(std::string room_file) room = fkyaml::node::deserialize(std::string(f)); current_room = room_file; free(f); + + uint16_t tiles[32*16]; + int i=0; + for(auto row : room.at("tilemap").as_seq()) + { + for (auto t : row.as_seq()) + { + tiles[i] = t.get_value(); + i++; + } + } + tilemap::set(tiles); + tilemap::setBackground(aux::getColorByName(room["room"]["bgColor"].get_value())); + //fkyaml::node name_node = room["room"]["name"]; //printf("%s\n", name_node.get_value().c_str()); } @@ -33,6 +51,7 @@ void game::init() game::setState(loop); font::load("font/8bithud"); draw::cls(0x00000000); + tilemap::init(); std::vector room_names; @@ -101,6 +120,12 @@ bool loop() } treeview::end(); + tilemap::start(); + tilemap::draw(); + + propertygrid::start(); + propertygrid::end(); + /*x1 += 6; x2 = x1 + font::len("FILE")+6; font::print("FILE", x1, 5); x1=x2; diff --git a/source/propertygrid.cpp b/source/propertygrid.cpp new file mode 100644 index 0000000..0707c33 --- /dev/null +++ b/source/propertygrid.cpp @@ -0,0 +1,45 @@ +#include "propertygrid.h" +#include "japi/draw.h" +#include "japi/font.h" +#include "japi/input.h" + +namespace propertygrid +{ + int width = 200; + int scroll = 0; + int line = 0; + int element = 0; + int max_elements = 0; + + void start() + { + const SDL_Point win_size = draw::getWindowSize(); + draw::setClip(win_size.x-propertygrid::width,48,propertygrid::width, win_size.y-48); + draw::setColor(0xff181818); + draw::fillrect(win_size.x-propertygrid::width,48,propertygrid::width, win_size.y-48); + //current[0] = current[1] = current[2] = + line = element = 0; + + max_elements = (win_size.y-48) / 24; + int mx = input::mouseX(); + int my = input::mouseY(); + if (mx>=win_size.x-propertygrid::width && my>=48 && mxmax_elements && line + +namespace propertygrid +{ + void start(); + std::string stringProperty(std::string label, std::string value); + void end(); +} diff --git a/source/tilemap.cpp b/source/tilemap.cpp new file mode 100644 index 0000000..66356aa --- /dev/null +++ b/source/tilemap.cpp @@ -0,0 +1,66 @@ +#include "tilemap.h" +#include "japi/draw.h" +#include + +namespace tilemap +{ + uint16_t tiles[16*32]; + uint32_t back_color = 0xff000000; + SDL_Texture *tileset; + SDL_Texture *map; + uint32_t paleta[16] = { + 0xff000000, 0xff3c351f, 0xff0000d8, 0xff0000ff, 0xffd80000, 0xffff0000, + 0xffd800d8, 0xffff00ff, 0xff00d800, 0xff00ff00, 0xff00d8d8, 0xff00ffff, + 0xffd8d800, 0xffffff00, 0xffd8d8d8, 0xffffffff + }; + + void init() + { + tileset = draw::loadSurface("tilesets/standard.gif", 16); + map = draw::createSurface(32*8, 16*8); + } + + void start() + { + draw::setClip(200,48,draw::getWindowSize().x-400, draw::getWindowSize().y-48); + draw::setColor(0xff000000); + draw::fillrect(200,48,draw::getWindowSize().x-400, draw::getWindowSize().y-48); + } + + void draw() + { + const int width = draw::getWindowSize().x-400; + const int height = (128*width)/256; + const int x = 200; + const int y = ((draw::getWindowSize().y-48)-height)/2; + draw::setSource(map); + draw::draw({0,0,256,128},{x,y,width,height}); + } + + void end() + { + draw::resetClip(); + } + + void set(uint16_t *tiles) + { + memcpy(tilemap::tiles, tiles, 32*16*2); + draw::setDestination(map); + draw::setSource(tileset); + draw::cls(back_color); + int i=0; + for (int y=0; y<16; ++y) { + for (int x=0; x<32; ++x) { + draw::draw({(tiles[i]%24)*8, (tiles[i]/24)*8, 8, 8}, {x*8, y*8, 8, 8}); + i++; + } + } + draw::setDestination(nullptr); + } + + void setBackground(int color) + { + back_color = paleta[color]; + } + +} diff --git a/source/tilemap.h b/source/tilemap.h new file mode 100644 index 0000000..26f5e62 --- /dev/null +++ b/source/tilemap.h @@ -0,0 +1,14 @@ +#pragma once +#include + +namespace tilemap +{ + void init(); + + void start(); + void draw(); + void end(); + + void set(uint16_t *tiles); + void setBackground(int color); +}