#include "japi/draw.h"
#include "japi/game.h"
#include "japi/font.h"
#include "menu.h"
#include "toolbar.h"
#include "treeview.h"

bool loop();

void game::init()
{
    draw::init("DILEMMAKER v0.1", 800, 600);
    game::setState(loop);
    font::load("font/8bithud");
    draw::cls(0x00000000);
}

bool loop()
{
    menu::start();
    if (menu::option("FILE")) {
        menu::popup::start();
        menu::popup::option("New...");
        menu::popup::option("Load...");
        menu::popup::option("Save...");
        menu::popup::end();
    }
    if (menu::option("EDIT"))  {
        menu::popup::start();
        menu::popup::end();
    }
    if (menu::option("SELECTION"))  {
        menu::popup::start();
        menu::popup::end();
    }
    if (menu::option("VIEW"))  {
        menu::popup::start();
        menu::popup::end();
    }
    if (menu::end()) { draw::render(); return true; }

    toolbar::start();

    treeview::start();
    if (treeview::option("room01", 0)) {
        treeview::option("abad", 1);
        treeview::option("Jailer", 1);
    }
    if (treeview::option("room02", 0)) {
        treeview::option("abad", 1);
        treeview::option("Jailer", 1);
    }
    if (treeview::option("room03", 0)) {
        treeview::option("abad", 1);
        treeview::option("Jailer", 1);
    }
    treeview::end();

    /*x1 += 6; x2 = x1 + font::len("FILE")+6;
    font::print("FILE", x1, 5); x1=x2;

    font::print("EDIT", x, 5); x+= font::len("EDIT")+12;
    font::print("SELECTION", x, 5); x+= font::len("SELECTION")+12;
    font::print("VIEW", x, 5); x+= font::len("VIEW")+12;*/
    draw::render();
    return true;
}
