Select Git revision
application.cpp 2.83 KiB
#include "application.hpp"
#include "widget.hpp"
#include "gamemaster.hpp"
#include <set>
#define focus_index 9*focus.sor+focus.oszlop
using namespace genv;
Application::Application(int szel, int mag)
{
gout.open(szel,mag);
}
void Application::event_loop()
{
Index focus(0,0);
event ev;
widgets[focus_index]->kezel(ev);
std::set<int> aura_halmaz = _game->aura(focus); // azert van itt is, hogy a megnyitaskor is rajzoljon aurat
for (int i=0; i<widgets.size(); i++)
{
if (aura_halmaz.find(i) != aura_halmaz.end())
{
action("aura",i,1);
}
else
{
action("aura",i,0);
}
}
for (Widget *w : widgets)
{
w->rajzol();
}
gout << refresh;
while(gin>>ev)
{
if (ev.type==ev_key)
{
if (ev.keycode==key_up || ev.keycode==key_down ||
ev.keycode==key_left || ev.keycode==key_right)
{
widgets[focus_index]->unfocus();
if (ev.keycode==key_up)
{
if (focus.sor >0)
focus.sor -= 1;
}
else if (ev.keycode==key_down)
{
if (focus.sor <8)
focus.sor += 1;
}
else if (ev.keycode==key_left)
{
if (focus.oszlop >0)
focus.oszlop -= 1;
}
else if (ev.keycode==key_right)
{
if (focus.oszlop <8)
focus.oszlop += 1;
}
std::set<int> aura_halmaz = _game->aura(focus);
// std::set<int> aura_ertekek;
for (int i=0; i<widgets.size(); i++)
{
if (aura_halmaz.find(i) != aura_halmaz.end())
{
action("aura",i,1);
}
else
{
action("aura",i,0);
}
}
widgets[focus_index]->kezel(ev);
}
if (ev.keycode >= 49 && ev.keycode <= 57)
{
action("ertek",focus_index, ev.keycode-48);
}
if (ev.keycode==key_delete || ev.keycode==key_backspace)
{
action("ertek",focus_index, 0);
}
}
for (Widget *w : widgets)
{
w->rajzol();
}
gout << refresh;
_game->save_fajlba();
}
}
void Application::register_widget(Widget *w)
{
widgets.push_back(w);
}
void Application::register_gm(GameMaster *gm)
{
_game=gm;
}