Compare commits
3 Commits
1c53f49125
...
241ae1bd8e
| Author | SHA1 | Date | |
|---|---|---|---|
| 241ae1bd8e | |||
| ecd4f7d6b4 | |||
| 39b304c265 |
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
category{
|
||||||
|
name: default
|
||||||
|
|
||||||
actor{
|
actor{
|
||||||
name: BOX
|
name: BOX
|
||||||
bmp: caixes.gif
|
bmp: caixes.gif
|
||||||
@@ -278,3 +281,43 @@ actor{
|
|||||||
size: 8 8 8
|
size: 8 8 8
|
||||||
movement: CW
|
movement: CW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actor{
|
||||||
|
name: MANCUERNA
|
||||||
|
bmp: altres.gif
|
||||||
|
bmp-rect: 106 33 17 14
|
||||||
|
bmp-offset: -6 20
|
||||||
|
pos: 24 25 0
|
||||||
|
size: 6 4 2
|
||||||
|
movement: CW
|
||||||
|
}
|
||||||
|
|
||||||
|
actor{
|
||||||
|
name: CADIRA
|
||||||
|
bmp: caixes.gif
|
||||||
|
bmp-rect: 64 96 20 32
|
||||||
|
bmp-offset: -8 40
|
||||||
|
pos: 8 51 0
|
||||||
|
size: 5 4 8
|
||||||
|
orient: YP
|
||||||
|
movement: CW
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
category{
|
||||||
|
name: coses
|
||||||
|
|
||||||
|
actor{
|
||||||
|
name: PILA
|
||||||
|
bmp: caixes.gif
|
||||||
|
bmp-rect: 160 96 32 32
|
||||||
|
bmp-offset: 0 32
|
||||||
|
pos: 24 8 0
|
||||||
|
size: 8 8 8
|
||||||
|
orient: YP
|
||||||
|
flags: ORIENTABLE
|
||||||
|
movement: CW
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
127
source/actor.cpp
127
source/actor.cpp
@@ -88,6 +88,7 @@ namespace actor
|
|||||||
act->anim_frame=0;
|
act->anim_frame=0;
|
||||||
act->react_mask = act->react_push = 0;
|
act->react_mask = act->react_push = 0;
|
||||||
act->flags = FLAG_NONE;
|
act->flags = FLAG_NONE;
|
||||||
|
act->template_category = 0;
|
||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,6 +205,16 @@ namespace actor
|
|||||||
|
|
||||||
char tmp[255];
|
char tmp[255];
|
||||||
|
|
||||||
|
void cleanName(actor_t *act)
|
||||||
|
{
|
||||||
|
int size = strlen(act->name);
|
||||||
|
if (act->name[size-3] == '-' && act->name[size-1] >= 48 && act->name[size-1] <= 57 && act->name[size-2] >= 48 && act->name[size-2] <= 57 )
|
||||||
|
{
|
||||||
|
act->name[size-3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Li donem al actor un nom únic
|
// Li donem al actor un nom únic
|
||||||
void setUniqueName(actor_t *act)
|
void setUniqueName(actor_t *act)
|
||||||
{
|
{
|
||||||
@@ -217,11 +228,12 @@ namespace actor
|
|||||||
// ... però tenim el mateix nom...
|
// ... però tenim el mateix nom...
|
||||||
if (strcmp(act->name, other->name)==0)
|
if (strcmp(act->name, other->name)==0)
|
||||||
{
|
{
|
||||||
// Si el nom actual no acaba en dos digits, li afegim "01" al final
|
// Si el nom actual no acaba en guió + dos digits, li afegim "-01" al final
|
||||||
int size = strlen(act->name);
|
int size = strlen(act->name);
|
||||||
if (act->name[size-1] < 48 || act->name[size-1] > 57 || act->name[size-2] < 48 || act->name[size-2] > 57 )
|
if (act->name[size-3] != '-' || act->name[size-1] < 48 || act->name[size-1] > 57 || act->name[size-2] < 48 || act->name[size-2] > 57 )
|
||||||
{
|
{
|
||||||
strcat(act->name, "01");
|
strcat(other->name, "-00");
|
||||||
|
strcat(act->name, "-01");
|
||||||
} else {
|
} else {
|
||||||
// Si ja acaba en dos digits, agafem el numero, li sumem 1, i li'l tornem a ficar
|
// Si ja acaba en dos digits, agafem el numero, li sumem 1, i li'l tornem a ficar
|
||||||
int num = (act->name[size-1]-48) + (act->name[size-2]-48)*10;
|
int num = (act->name[size-1]-48) + (act->name[size-2]-48)*10;
|
||||||
@@ -332,23 +344,25 @@ namespace actor
|
|||||||
return alpha;
|
return alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveToFile(FILE *f, actor_t *act)
|
void saveToFile(FILE *f, actor_t *act, bool tab)
|
||||||
{
|
{
|
||||||
fprintf(f, "\nactor{\n");
|
char ws[5] = "";
|
||||||
fprintf(f, " name: %s\n", act->name);
|
if (tab) strcpy(ws, " ");
|
||||||
fprintf(f, " bmp: %s\n", act->bmp);
|
fprintf(f, "\n%sactor{\n", ws);
|
||||||
fprintf(f, " bmp-rect: %i %i %i %i\n", act->bmp_rect.x, act->bmp_rect.y, act->bmp_rect.w, act->bmp_rect.h);
|
fprintf(f, " %sname: %s\n", ws, act->name);
|
||||||
fprintf(f, " bmp-offset: %i %i\n", act->bmp_offset.x, act->bmp_offset.y);
|
fprintf(f, " %sbmp: %s\n", ws, act->bmp);
|
||||||
fprintf(f, " pos: %i %i %i\n", act->pos.x, act->pos.y, act->pos.z);
|
fprintf(f, " %sbmp-rect: %i %i %i %i\n", ws, act->bmp_rect.x, act->bmp_rect.y, act->bmp_rect.w, act->bmp_rect.h);
|
||||||
fprintf(f, " size: %i %i %i\n", act->size.x, act->size.y, act->size.z);
|
fprintf(f, " %sbmp-offset: %i %i\n", ws, act->bmp_offset.x, act->bmp_offset.y);
|
||||||
if (act->orient!=0) fprintf(f, " orient: %s\n", numToOrient(act->orient));
|
fprintf(f, " %spos: %i %i %i\n", ws, act->pos.x, act->pos.y, act->pos.z);
|
||||||
if (act->anim_cycle!=0) fprintf(f, " anim-cycle: %s\n", act->anim_cycle==0 ? "WALK" : act->anim_cycle==1 ? "SEQ" : "MIN");
|
fprintf(f, " %ssize: %i %i %i\n", ws, act->size.x, act->size.y, act->size.z);
|
||||||
if (act->anim_wait!=0) fprintf(f, " anim-wait: %i\n", act->anim_wait);
|
if (act->orient!=0) fprintf(f, " %sorient: %s\n", ws, numToOrient(act->orient));
|
||||||
if (act->flags!=0) fprintf(f, " flags: %s\n", numToFlags(act->flags));
|
if (act->anim_cycle!=0) fprintf(f, " %sanim-cycle: %s\n", ws, act->anim_cycle==0 ? "WALK" : act->anim_cycle==1 ? "SEQ" : "MIN");
|
||||||
if (act->react_mask!=0) fprintf(f, " react-mask: %s\n", numToOrient(act->react_mask));
|
if (act->anim_wait!=0) fprintf(f, " %sanim-wait: %i\n", ws, act->anim_wait);
|
||||||
if (act->react_push!=0) fprintf(f, " react-push: %s\n", numToOrient(act->react_push));
|
if (act->flags!=0) fprintf(f, " %sflags: %s\n", ws, numToFlags(act->flags));
|
||||||
if (act->movement!=0) fprintf(f, " movement: %s\n", numToMov(act->movement));
|
if (act->react_mask!=0) fprintf(f, " %sreact-mask: %s\n", ws, numToOrient(act->react_mask));
|
||||||
fprintf(f, "}\n");
|
if (act->react_push!=0) fprintf(f, " %sreact-push: %s\n", ws, numToOrient(act->react_push));
|
||||||
|
if (act->movement!=0) fprintf(f, " %smovement: %s\n", ws, numToMov(act->movement));
|
||||||
|
fprintf(f, "%s}\n", ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool check_2d_collision(actor_t *obj1, actor_t *obj2)
|
const bool check_2d_collision(actor_t *obj1, actor_t *obj2)
|
||||||
@@ -1306,14 +1320,18 @@ namespace actor
|
|||||||
namespace templates
|
namespace templates
|
||||||
{
|
{
|
||||||
std::vector<actor_t> templates;
|
std::vector<actor_t> templates;
|
||||||
|
std::vector<std::string> categories;
|
||||||
|
|
||||||
void load()
|
void load()
|
||||||
{
|
{
|
||||||
|
//newCategory("default");
|
||||||
|
categories.clear();
|
||||||
templates.clear();
|
templates.clear();
|
||||||
char filename[] = "templates.txt";
|
char filename[] = "templates.txt";
|
||||||
int filesize=0;
|
int filesize=0;
|
||||||
char *buffer = file::getFileBuffer(filename, filesize, true);
|
char *buffer = file::getFileBuffer(filename, filesize, true);
|
||||||
char *original_buffer = buffer;
|
char *original_buffer = buffer;
|
||||||
|
int current_category = 0;
|
||||||
|
|
||||||
if (buffer)
|
if (buffer)
|
||||||
{
|
{
|
||||||
@@ -1321,12 +1339,25 @@ namespace actor
|
|||||||
{
|
{
|
||||||
const char* key = file::readString(&buffer);
|
const char* key = file::readString(&buffer);
|
||||||
|
|
||||||
if (util::strcomp(key, "actor{"))
|
if (util::strcomp(key, "category{"))
|
||||||
|
{
|
||||||
|
const char* key = file::readString(&buffer);
|
||||||
|
if (util::strcomp(key, "name:")) {
|
||||||
|
const char *val = file::readString(&buffer);
|
||||||
|
current_category = newCategory(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (util::strcomp(key, "actor{"))
|
||||||
{
|
{
|
||||||
actor_t *t = createFromFile(&buffer);
|
actor_t *t = createFromFile(&buffer);
|
||||||
|
t->template_category = current_category;
|
||||||
templates.push_back(*t);
|
templates.push_back(*t);
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
|
else if (util::strcomp(key, "}")) {
|
||||||
|
current_category = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
free(original_buffer);
|
free(original_buffer);
|
||||||
}
|
}
|
||||||
@@ -1336,18 +1367,56 @@ namespace actor
|
|||||||
{
|
{
|
||||||
FILE *f = fopen("data/templates.txt", "w");
|
FILE *f = fopen("data/templates.txt", "w");
|
||||||
|
|
||||||
for (int i=0; i<templates.size(); ++i)
|
for (auto cat_name : categories)
|
||||||
|
{
|
||||||
|
|
||||||
|
fprintf(f, "\ncategory{\n");
|
||||||
|
fprintf(f, " name: %s\n", cat_name.c_str());
|
||||||
|
|
||||||
|
auto actors = getByCategory(cat_name.c_str());
|
||||||
|
for (auto t : actors )
|
||||||
|
{
|
||||||
|
saveToFile(f, &t, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(f, "\n}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*for (int i=0; i<templates.size(); ++i)
|
||||||
{
|
{
|
||||||
actor_t t = templates[i];
|
actor_t t = templates[i];
|
||||||
saveToFile(f, &t);
|
saveToFile(f, &t);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int size()
|
/*const int size()
|
||||||
{
|
{
|
||||||
return templates.size();
|
return templates.size();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
std::vector<actor::actor_t> getByCategory(const char* category)
|
||||||
|
{
|
||||||
|
std::string catname = category;
|
||||||
|
std::vector<actor_t> actors;
|
||||||
|
for (auto act : templates)
|
||||||
|
{
|
||||||
|
if (act.template_category>=categories.size()) act.template_category = 0;
|
||||||
|
if (categories[act.template_category]==catname) actors.push_back(act);
|
||||||
|
}
|
||||||
|
return actors;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> getCategories()
|
||||||
|
{
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int newCategory(const char *name)
|
||||||
|
{
|
||||||
|
categories.push_back(name);
|
||||||
|
return categories.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
actor_t *get(const int index)
|
actor_t *get(const int index)
|
||||||
@@ -1381,16 +1450,22 @@ namespace actor
|
|||||||
|
|
||||||
void add(actor_t *act)
|
void add(actor_t *act)
|
||||||
{
|
{
|
||||||
|
// Fem una copia del actor
|
||||||
|
actor_t new_template;
|
||||||
|
copy(&new_template, act);
|
||||||
|
// Li fiquem la categoria per defecte
|
||||||
|
new_template.template_category = 0;
|
||||||
|
// Netejem el nom de numerets
|
||||||
|
cleanName(&new_template);
|
||||||
|
|
||||||
// Si ja hi ha una plantilla amb eixe nom...
|
// Si ja hi ha una plantilla amb eixe nom...
|
||||||
if (actor::templates::getByName(act->name))
|
if (actor::templates::getByName(act->name))
|
||||||
{
|
{
|
||||||
// ... la actualitzem amb les dades del actor seleccionat
|
// ... la actualitzem amb les dades del actor seleccionat
|
||||||
actor_t *existing_template = actor::templates::getByName(act->name);
|
actor_t *existing_template = actor::templates::getByName(act->name);
|
||||||
copy(existing_template, act);
|
copy(existing_template, &new_template);
|
||||||
} else {
|
} else {
|
||||||
// ... i sinó, afegim el actor seleccionat a la llista de plantilles
|
// ... i sinó, afegim el actor seleccionat a la llista de plantilles
|
||||||
actor_t new_template;
|
|
||||||
copy(&new_template, act);
|
|
||||||
templates.push_back(new_template);
|
templates.push_back(new_template);
|
||||||
}
|
}
|
||||||
save();
|
save();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// Flags que defineixen les capacitats de l'actor
|
// Flags que defineixen les capacitats de l'actor
|
||||||
@@ -106,6 +106,7 @@ namespace actor
|
|||||||
int inner_y;
|
int inner_y;
|
||||||
|
|
||||||
int tag;
|
int tag;
|
||||||
|
int template_category;
|
||||||
};
|
};
|
||||||
|
|
||||||
void resetTag();
|
void resetTag();
|
||||||
@@ -130,11 +131,13 @@ namespace actor
|
|||||||
|
|
||||||
actor_t *replaceWithTemplate(actor_t *act, const char *name);
|
actor_t *replaceWithTemplate(actor_t *act, const char *name);
|
||||||
|
|
||||||
|
void cleanName(actor_t *act);
|
||||||
|
|
||||||
void setUniqueName(actor_t *act);
|
void setUniqueName(actor_t *act);
|
||||||
|
|
||||||
actor_t *alphaOrder(actor_t *act);
|
actor_t *alphaOrder(actor_t *act);
|
||||||
|
|
||||||
void saveToFile(FILE *f, actor_t *act);
|
void saveToFile(FILE *f, actor_t *act, bool tab=false);
|
||||||
|
|
||||||
void setDirty(actor_t *act, const bool force = false);
|
void setDirty(actor_t *act, const bool force = false);
|
||||||
|
|
||||||
@@ -172,7 +175,10 @@ namespace actor
|
|||||||
{
|
{
|
||||||
void load();
|
void load();
|
||||||
void save();
|
void save();
|
||||||
const int size();
|
//const int size();
|
||||||
|
std::vector<actor::actor_t> getByCategory(const char* category);
|
||||||
|
std::vector<std::string> getCategories();
|
||||||
|
const int newCategory(const char *name);
|
||||||
actor_t *get(const int index);
|
actor_t *get(const int index);
|
||||||
actor_t *getByName(const char *name);
|
actor_t *getByName(const char *name);
|
||||||
void copy(actor_t *dest, actor_t *source);
|
void copy(actor_t *dest, actor_t *source);
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,8 @@ namespace modules
|
|||||||
{
|
{
|
||||||
int edit_mode = EDITING_BITMAP_POS;
|
int edit_mode = EDITING_BITMAP_POS;
|
||||||
draw::surface *surf = nullptr;
|
draw::surface *surf = nullptr;
|
||||||
|
int lastMX, lastMY;
|
||||||
|
bool lastMB = false;
|
||||||
|
|
||||||
void init(int editing)
|
void init(int editing)
|
||||||
{
|
{
|
||||||
@@ -23,16 +25,47 @@ namespace modules
|
|||||||
bool loop()
|
bool loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
|
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
|
||||||
|
const bool ctrl = input::keyDown(SDL_SCANCODE_LCTRL);
|
||||||
|
|
||||||
|
actor::actor_t *sel = actor::getSelected();
|
||||||
|
|
||||||
|
if (input::keyDown(SDL_SCANCODE_UP)) if (!ctrl) sel->bmp_rect.y--; else sel->bmp_rect.h--;
|
||||||
|
if (input::keyDown(SDL_SCANCODE_DOWN)) if (!ctrl) sel->bmp_rect.y++; else sel->bmp_rect.h++;
|
||||||
|
if (input::keyDown(SDL_SCANCODE_LEFT)) if (!ctrl) sel->bmp_rect.x--; else sel->bmp_rect.w--;
|
||||||
|
if (input::keyDown(SDL_SCANCODE_RIGHT)) if (!ctrl) sel->bmp_rect.x++; else sel->bmp_rect.w++;
|
||||||
|
|
||||||
|
if (input::mouseBtn(1))
|
||||||
|
{
|
||||||
|
int mx = input::mouseX();
|
||||||
|
int my = input::mouseY();
|
||||||
|
if (!lastMB) {
|
||||||
|
lastMB = true;
|
||||||
|
lastMX = mx;
|
||||||
|
lastMY = my;
|
||||||
|
} else {
|
||||||
|
int dx = 0, dy = 0;
|
||||||
|
if (lastMX != mx) { dx = mx - lastMX; }
|
||||||
|
if (lastMY != my) { dy = my - lastMY; }
|
||||||
|
lastMX = mx;
|
||||||
|
lastMY = my;
|
||||||
|
if (!ctrl) {
|
||||||
|
sel->bmp_rect.x += dx;
|
||||||
|
sel->bmp_rect.y += dy;
|
||||||
|
} else {
|
||||||
|
sel->bmp_rect.w += dx;
|
||||||
|
sel->bmp_rect.h += dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const int tx = (520-surf->w)/2;
|
const int tx = (520-surf->w)/2;
|
||||||
const int ty = (240-surf->h)/2;
|
const int ty = (240-surf->h)/2;
|
||||||
|
|
||||||
draw::cls(PAPER);
|
draw::cls(PAPER);
|
||||||
draw::setSource(surf);
|
draw::setSource(surf);
|
||||||
draw::color(BLUE);
|
draw::color(100);
|
||||||
draw::setViewport(tx, ty, surf->w, surf->h);
|
draw::setViewport(tx, ty, surf->w, surf->h);
|
||||||
draw::fillrect(0, 0, surf->w, surf->h);
|
draw::fillrect(0, 0, surf->w, surf->h);
|
||||||
draw::color(BLUE+LIGHT);
|
draw::color(101);
|
||||||
int x=0, y=0;
|
int x=0, y=0;
|
||||||
while(y*32<surf->h)
|
while(y*32<surf->h)
|
||||||
{
|
{
|
||||||
@@ -41,19 +74,25 @@ namespace modules
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw::resetViewport();
|
draw::resetViewport();
|
||||||
draw::color(WHITE);
|
draw::color(LIGHT+WHITE);
|
||||||
draw::rect(((520-surf->w)/2)-1, ((240-surf->h)/2)-1, surf->w+2, surf->h+2);
|
draw::rect(((520-surf->w)/2)-1, ((240-surf->h)/2)-1, surf->w+2, surf->h+2);
|
||||||
|
draw::swapcol(1, LIGHT+WHITE);
|
||||||
draw::draw((520-surf->w)/2, (240-surf->h)/2, surf->w, surf->h, 0, 0, 0);
|
draw::draw((520-surf->w)/2, (240-surf->h)/2, surf->w, surf->h, 0, 0, 0);
|
||||||
|
|
||||||
draw::setViewport(tx, ty, surf->w, surf->h);
|
draw::setViewport(tx, ty, surf->w, surf->h);
|
||||||
draw::color(RED+LIGHT);
|
draw::color(RED+LIGHT);
|
||||||
draw::hline(0, actor::getSelected()->bmp_rect.y, surf->w);
|
draw::hline(0, sel->bmp_rect.y, surf->w);
|
||||||
draw::vline(actor::getSelected()->bmp_rect.x, 0, surf->h);
|
draw::vline(sel->bmp_rect.x, 0, surf->h);
|
||||||
draw::color(YELLOW);
|
draw::color(YELLOW);
|
||||||
draw::hline(0, actor::getSelected()->bmp_rect.y+actor::getSelected()->bmp_rect.h, surf->w);
|
draw::hline(0, sel->bmp_rect.y+sel->bmp_rect.h-1, surf->w);
|
||||||
draw::vline(actor::getSelected()->bmp_rect.x+actor::getSelected()->bmp_rect.w, 0, surf->h);
|
draw::vline(sel->bmp_rect.x+sel->bmp_rect.w-1, 0, surf->h);
|
||||||
draw::resetViewport();
|
draw::resetViewport();
|
||||||
|
|
||||||
|
draw::print2(sel->bmp_rect.x, 3, 1, 4, LIGHT+WHITE, FONT_ZOOM_VERTICAL);
|
||||||
|
draw::print2(sel->bmp_rect.y, 3, 5, 4, LIGHT+WHITE, FONT_ZOOM_VERTICAL);
|
||||||
|
draw::print2(sel->bmp_rect.w, 3, 1, 7, LIGHT+WHITE, FONT_ZOOM_VERTICAL);
|
||||||
|
draw::print2(sel->bmp_rect.h, 3, 5, 7, LIGHT+WHITE, FONT_ZOOM_VERTICAL);
|
||||||
|
|
||||||
draw::render();
|
draw::render();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
@@ -26,6 +27,8 @@ namespace modules
|
|||||||
|
|
||||||
if (editor::isDevMode())
|
if (editor::isDevMode())
|
||||||
{
|
{
|
||||||
|
draw::setPaletteColor(100, 0xbb, 0x80, 0x80);
|
||||||
|
draw::setPaletteColor(101, 0xff, 0xc0, 0xc0);
|
||||||
draw::stencil::init();
|
draw::stencil::init();
|
||||||
|
|
||||||
FILE* f = fopen("data/gifs.txt", "r");
|
FILE* f = fopen("data/gifs.txt", "r");
|
||||||
@@ -153,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);
|
||||||
@@ -175,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,11 +258,13 @@ namespace modules
|
|||||||
|
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
||||||
{
|
{
|
||||||
if (console::isEnabled())
|
if (console::isEnabled()) {
|
||||||
console::toggle();
|
console::toggle();
|
||||||
else
|
} else {
|
||||||
|
if (editor::isEditing()) room::editor::save();
|
||||||
return GAME_MENU;
|
return GAME_MENU;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WHILE EDITING...
|
// WHILE EDITING...
|
||||||
if (editor::isEditing())
|
if (editor::isEditing())
|
||||||
@@ -431,6 +427,7 @@ namespace modules
|
|||||||
draw::color(WHITE);
|
draw::color(WHITE);
|
||||||
draw::fillrect(0, 0, 100, 240);
|
draw::fillrect(0, 0, 100, 240);
|
||||||
|
|
||||||
|
/*
|
||||||
int result = ui::combo(actor::templates::get(editor::getCurrentTemplate())->name, 2, 2, 76, 11);
|
int result = ui::combo(actor::templates::get(editor::getCurrentTemplate())->name, 2, 2, 76, 11);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
@@ -447,7 +444,7 @@ namespace modules
|
|||||||
actor::select(new_act);
|
actor::select(new_act);
|
||||||
room::editor::modify();
|
room::editor::modify();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
draw::color(LIGHT+WHITE);
|
draw::color(LIGHT+WHITE);
|
||||||
draw::fillrect(2, 15, 96, 223);
|
draw::fillrect(2, 15, 96, 223);
|
||||||
draw::color(PAPER);
|
draw::color(PAPER);
|
||||||
|
|||||||
Reference in New Issue
Block a user