- [WIP] Comence amb el propertygrid
- [NEW] Módul aux - [WIP] Módul tilemap ja mostra el mapa - [FIX] japi/draw: les textures han de vores en NEAREST
This commit is contained in:
11
source/aux.cpp
Normal file
11
source/aux.cpp
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
source/aux.h
Normal file
8
source/aux.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace aux
|
||||||
|
{
|
||||||
|
int getColorByName(std::string color);
|
||||||
|
}
|
||||||
@@ -45,7 +45,10 @@ namespace draw
|
|||||||
|
|
||||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h)
|
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)
|
SDL_Texture *loadSurface(const char *filename, const int transparent)
|
||||||
@@ -61,6 +64,7 @@ namespace draw
|
|||||||
uint32_t *pal = LoadPalette(buffer, &paletteSize);
|
uint32_t *pal = LoadPalette(buffer, &paletteSize);
|
||||||
|
|
||||||
SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
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);
|
SDL_SetTextureBlendMode(surf, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
Uint32 *sdl_pixels;
|
Uint32 *sdl_pixels;
|
||||||
|
|||||||
@@ -4,8 +4,12 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "toolbar.h"
|
#include "toolbar.h"
|
||||||
#include "treeview.h"
|
#include "treeview.h"
|
||||||
|
#include "propertygrid.h"
|
||||||
|
#include "tilemap.h"
|
||||||
#include "fkYAML/node.hpp"
|
#include "fkYAML/node.hpp"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
#include "aux.h"
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
@@ -23,6 +27,20 @@ void loadRoom(std::string room_file)
|
|||||||
room = fkyaml::node::deserialize(std::string(f));
|
room = fkyaml::node::deserialize(std::string(f));
|
||||||
current_room = room_file;
|
current_room = room_file;
|
||||||
free(f);
|
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<int>();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tilemap::set(tiles);
|
||||||
|
tilemap::setBackground(aux::getColorByName(room["room"]["bgColor"].get_value<std::string>()));
|
||||||
|
|
||||||
//fkyaml::node name_node = room["room"]["name"];
|
//fkyaml::node name_node = room["room"]["name"];
|
||||||
//printf("%s\n", name_node.get_value<std::string>().c_str());
|
//printf("%s\n", name_node.get_value<std::string>().c_str());
|
||||||
}
|
}
|
||||||
@@ -33,6 +51,7 @@ void game::init()
|
|||||||
game::setState(loop);
|
game::setState(loop);
|
||||||
font::load("font/8bithud");
|
font::load("font/8bithud");
|
||||||
draw::cls(0x00000000);
|
draw::cls(0x00000000);
|
||||||
|
tilemap::init();
|
||||||
|
|
||||||
std::vector<std::string> room_names;
|
std::vector<std::string> room_names;
|
||||||
|
|
||||||
@@ -101,6 +120,12 @@ bool loop()
|
|||||||
}
|
}
|
||||||
treeview::end();
|
treeview::end();
|
||||||
|
|
||||||
|
tilemap::start();
|
||||||
|
tilemap::draw();
|
||||||
|
|
||||||
|
propertygrid::start();
|
||||||
|
propertygrid::end();
|
||||||
|
|
||||||
/*x1 += 6; x2 = x1 + font::len("FILE")+6;
|
/*x1 += 6; x2 = x1 + font::len("FILE")+6;
|
||||||
font::print("FILE", x1, 5); x1=x2;
|
font::print("FILE", x1, 5); x1=x2;
|
||||||
|
|
||||||
|
|||||||
45
source/propertygrid.cpp
Normal file
45
source/propertygrid.cpp
Normal file
@@ -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 && mx<win_size.x && my<draw::getWindowSize().y) {
|
||||||
|
scroll -= input::mouseWheel();
|
||||||
|
if (scroll < 0) scroll = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string stringProperty(std::string label, std::string value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void end()
|
||||||
|
{
|
||||||
|
draw::resetClip();
|
||||||
|
if (element>max_elements && line<max_elements) {
|
||||||
|
scroll -= max_elements-line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
source/propertygrid.h
Normal file
9
source/propertygrid.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace propertygrid
|
||||||
|
{
|
||||||
|
void start();
|
||||||
|
std::string stringProperty(std::string label, std::string value);
|
||||||
|
void end();
|
||||||
|
}
|
||||||
66
source/tilemap.cpp
Normal file
66
source/tilemap.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include "tilemap.h"
|
||||||
|
#include "japi/draw.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
source/tilemap.h
Normal file
14
source/tilemap.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace tilemap
|
||||||
|
{
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void draw();
|
||||||
|
void end();
|
||||||
|
|
||||||
|
void set(uint16_t *tiles);
|
||||||
|
void setBackground(int color);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user