Files
thepool/source/m_editor_templates.cpp

67 lines
1.9 KiB
C++

#include "m_editor_templates.h"
#include "jdraw.h"
#include "jinput.h"
#include "misc.h"
#include <SDL2/SDL.h>
#include "actor.h"
#include <vector>
#include "room.h"
namespace modules
{
namespace editor_templates
{
std::vector<actor::actor_t*> templates;
void init()
{
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)
templates.push_back(actor::duplicate(actor::templates::get(i)));
draw::resetViewport();
}
bool loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_TAB)) return false;
draw::cls(2);
//draw::stencil::enable();
//draw::stencil::clear(255);
int x=0, y=0;
for (int i=0; i<templates.size(); ++i)
{
//draw::stencil::set(i);
draw::swapcol(1, TEAL);
actor::drawAt(templates[i], x*65, y*40);
draw::print(templates[i]->name, (x*65), (y*40)+30, LIGHT+WHITE, BLACK);
x++; if (x==8) { x=0;y++; }
}
draw::render();
if (input::mouseClk(1)) {
//const int clicked = draw::stencil::query(input::mouseX(), input::mouseY());
const int clicked = (input::mouseX()/65) + (input::mouseY()/40) * 8;
if (clicked<=actor::templates::size()) {
actor::actor_t *new_act = actor::duplicate(actor::templates::get(clicked));
actor::setUniqueName(new_act);
actor::setDirty(new_act, true);
actor::select(new_act);
room::editor::modify();
return false;
}
}
return true;
}
}
}