- Treballant en el editor de templates
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#include "jutil.h"
|
#include "jutil.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values)
|
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values)
|
||||||
@@ -23,4 +23,14 @@ namespace util
|
|||||||
if (a==nullptr || b==nullptr) return false;
|
if (a==nullptr || b==nullptr) return false;
|
||||||
return (strcmp(a,b)==0);
|
return (strcmp(a,b)==0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t scancode_to_char(const uint8_t scancode)
|
||||||
|
{
|
||||||
|
if (scancode == SDL_SCANCODE_0 || scancode == SDL_SCANCODE_KP_0) return '0';
|
||||||
|
if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19;
|
||||||
|
if (scancode >= SDL_SCANCODE_KP_1 && scancode <= SDL_SCANCODE_KP_9) return scancode-40;
|
||||||
|
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61;
|
||||||
|
//if (scancode == SDL_SCANCODE_MINUS) return '-';
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stdint.h>
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values);
|
int stringToInt(const char *value, std::vector<const char*> strings, std::vector<int> values);
|
||||||
|
|
||||||
const bool strcomp(const char *a, const char* b);
|
const bool strcomp(const char *a, const char* b);
|
||||||
|
|
||||||
|
const uint8_t scancode_to_char(const uint8_t scancode);
|
||||||
}
|
}
|
||||||
@@ -6,50 +6,105 @@
|
|||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "jutil.h"
|
||||||
|
|
||||||
|
#define EDITING_NORMAL 0
|
||||||
|
#define EDITING_CATEGORY_NAME 1
|
||||||
|
#define EDITING_ACTOR_NAME 2
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
namespace editor_templates
|
namespace editor_templates
|
||||||
{
|
{
|
||||||
std::vector<actor::actor_t*> templates;
|
//std::vector<actor::actor_t*> templates;
|
||||||
|
int current_category;
|
||||||
|
int edit_mode = EDITING_NORMAL;
|
||||||
|
actor::actor_t *actor_edited = nullptr;
|
||||||
|
char name[13];
|
||||||
|
uint32_t time = 0;
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
for (int i=0; i<templates.size(); ++i) if (templates[i] != nullptr) actor::remove(templates[i]);
|
current_category = 0;
|
||||||
templates.clear();
|
edit_mode = EDITING_NORMAL;
|
||||||
|
//for (int i=0; i<templates.size(); ++i) if (templates[i] != nullptr) actor::remove(templates[i]);
|
||||||
|
//templates.clear();
|
||||||
|
|
||||||
for (int i=0; i<actor::templates::size(); ++i)
|
//for (int i=0; i<actor::templates::size(); ++i)
|
||||||
templates.push_back(actor::duplicate(actor::templates::get(i)));
|
// templates.push_back(actor::duplicate(actor::templates::get(i)));
|
||||||
draw::resetViewport();
|
draw::resetViewport();
|
||||||
|
time = SDL_GetTicks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_text_edit()
|
||||||
|
{
|
||||||
|
draw::color(WHITE);
|
||||||
|
draw::fillrect(217,106,86,30);
|
||||||
|
draw::color(LIGHT+WHITE);
|
||||||
|
draw::hline(217, 106, 86);
|
||||||
|
draw::vline(217, 106, 30);
|
||||||
|
draw::color(BLACK);
|
||||||
|
draw::hline(217, 106+29, 86);
|
||||||
|
draw::vline(217+85, 106, 30);
|
||||||
|
|
||||||
|
if (edit_mode == EDITING_CATEGORY_NAME) {
|
||||||
|
strcpy(name, "HOLA");
|
||||||
|
draw::print("CATEGORY NAME:", 227, 110, LIGHT+WHITE, PAPER);
|
||||||
|
} else {
|
||||||
|
strcpy(name, actor_edited->name);
|
||||||
|
draw::print("ACTOR NAME:", 227, 110, LIGHT+WHITE, PAPER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loop()
|
bool loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
|
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
|
||||||
|
|
||||||
|
if (edit_mode == EDITING_NORMAL)
|
||||||
|
{
|
||||||
draw::cls(2);
|
draw::cls(2);
|
||||||
|
|
||||||
//draw::stencil::enable();
|
|
||||||
//draw::stencil::clear(255);
|
|
||||||
|
|
||||||
int x=0, y=0;
|
int x=0, y=0;
|
||||||
|
|
||||||
for (int i=0; i<templates.size(); ++i)
|
draw::color(BLUE);
|
||||||
|
draw::fillrect(8, 0, 512, 11);
|
||||||
|
|
||||||
|
auto categories = actor::templates::getCategories();
|
||||||
|
|
||||||
|
draw::color(GREEN);
|
||||||
|
draw::fillrect(0, 0, 11, 11);
|
||||||
|
draw::print("+", 4, 3, WHITE, BLACK);
|
||||||
|
|
||||||
|
for (auto category : categories)
|
||||||
|
{
|
||||||
|
if (current_category == x) { draw::color(BLACK); draw::fillrect(11+x*40, 0, 40, 11); }
|
||||||
|
|
||||||
|
draw::print(category.c_str(), 11+((40-category.size()*4)/2)+x*40, 3, LIGHT+WHITE, BLACK);
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
auto actors = actor::templates::getByCategory(categories[current_category].c_str());
|
||||||
|
for (auto actor : actors)
|
||||||
{
|
{
|
||||||
//draw::stencil::set(i);
|
|
||||||
draw::swapcol(1, TEAL);
|
draw::swapcol(1, TEAL);
|
||||||
actor::drawAt(templates[i], x*65, y*40);
|
actor::drawAt(&actor, 10+x*65, 14+y*40);
|
||||||
draw::print(templates[i]->name, (x*65), (y*40)+30, LIGHT+WHITE, BLACK);
|
draw::print(actor.name, 10+(x*65), (y*40)+44, LIGHT+WHITE, BLACK);
|
||||||
x++; if (x==8) { x=0;y++; }
|
x++; if (x==8) { x=0;y++; }
|
||||||
}
|
}
|
||||||
|
|
||||||
draw::render();
|
draw::render();
|
||||||
|
|
||||||
if (input::mouseClk(1)) {
|
current_category += input::mouseWheel();
|
||||||
//const int clicked = draw::stencil::query(input::mouseX(), input::mouseY());
|
if (current_category < 0) current_category = categories.size()-1;
|
||||||
const int clicked = (input::mouseX()/65) + (input::mouseY()/40) * 8;
|
if (current_category >= categories.size()) current_category = 0;
|
||||||
if (clicked<=actor::templates::size()) {
|
|
||||||
actor::actor_t *new_act = actor::duplicate(actor::templates::get(clicked));
|
if (input::mouseClk(1))
|
||||||
|
{
|
||||||
|
if (input::mouseX()>12) {
|
||||||
|
const int clicked = ((input::mouseX()-10)/65) + ((input::mouseY()-14)/40) * 8;
|
||||||
|
if (clicked<=actors.size()) {
|
||||||
|
actor::actor_t *new_act = actor::duplicate(&actors[clicked]);
|
||||||
actor::setUniqueName(new_act);
|
actor::setUniqueName(new_act);
|
||||||
actor::setDirty(new_act, true);
|
actor::setDirty(new_act, true);
|
||||||
actor::select(new_act);
|
actor::select(new_act);
|
||||||
@@ -57,6 +112,49 @@ namespace modules
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
edit_mode = EDITING_CATEGORY_NAME;
|
||||||
|
init_text_edit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (input::mouseClk(3))
|
||||||
|
{
|
||||||
|
if (input::mouseX()>12) {
|
||||||
|
const int clicked = ((input::mouseX()-10)/65) + ((input::mouseY()-14)/40) * 8;
|
||||||
|
if (clicked<=actors.size()) {
|
||||||
|
actor_edited = actor::templates::getByName(actors[clicked].name);
|
||||||
|
edit_mode = EDITING_CATEGORY_NAME;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
draw::color(LIGHT+WHITE);
|
||||||
|
draw::fillrect(217+10,106+15,66,11);
|
||||||
|
draw::color(BLACK);
|
||||||
|
draw::rect(217+10,106+15,66,11);
|
||||||
|
draw::print(name, 217+12, 106+17, BLACK, 0);
|
||||||
|
if (SDL_GetTicks()-time < 500) draw::print("_", 217+12+strlen(name)*4, 106+17, BLACK, 0);
|
||||||
|
if (SDL_GetTicks()-time >= 500) time = SDL_GetTicks();
|
||||||
|
draw::render();
|
||||||
|
|
||||||
|
int result = input::getKeyPressed();
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
const int len = strlen(name);
|
||||||
|
if (result == SDL_SCANCODE_BACKSPACE) {
|
||||||
|
if (len>0) name[len-1] = 0;
|
||||||
|
} else {
|
||||||
|
if (len<15) {
|
||||||
|
name[len] = util::scancode_to_char(result);
|
||||||
|
name[len+1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "jgame.h"
|
#include "jgame.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "editor.h"
|
#include "editor.h"
|
||||||
|
#include "jutil.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
@@ -155,15 +156,6 @@ namespace modules
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t scancode_to_char(const uint8_t scancode)
|
|
||||||
{
|
|
||||||
if (scancode == SDL_SCANCODE_0) return '0';
|
|
||||||
if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19;
|
|
||||||
if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61;
|
|
||||||
//if (scancode == SDL_SCANCODE_MINUS) return '-';
|
|
||||||
return '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool btn_txt(const char* label, const int x, const int y, char *var)
|
const bool btn_txt(const char* label, const int x, const int y, char *var)
|
||||||
{
|
{
|
||||||
//draw::print(label, x, y+3, PAPER, 0);
|
//draw::print(label, x, y+3, PAPER, 0);
|
||||||
@@ -177,7 +169,7 @@ namespace modules
|
|||||||
if (len>0) var[len-1] = 0;
|
if (len>0) var[len-1] = 0;
|
||||||
} else {
|
} else {
|
||||||
if (len<15) {
|
if (len<15) {
|
||||||
var[len] = scancode_to_char(result);
|
var[len] = util::scancode_to_char(result);
|
||||||
var[len+1] = 0;
|
var[len+1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user