#pragma once
#include "scene.hpp"
#include "UI/menu.hpp"
//! меню настроек игры
class Scene_graphic : public Scene {
protected:
  Menu menu = {};
  bool ifSelected = false; ///< if 1, item selected
public:
  nocopy(Scene_graphic);
  explicit Scene_graphic(Scene *pv = nullptr);
  ~Scene_graphic() { a83::log("exit from scene GRAPHIC"); }
  void update(float dt) override {
    input();
    if (ifSelected) {
      menu.accept();
      ifSelected = false;
    }
    Scene::update(dt);
  }
  void draw() override;
private:
  void input();
};
Scene_graphic::Scene_graphic(Scene *pv): Scene(pv) {
  a83::log("goto scene GRAPHIC");
// TODO localization:
  menu.add(new item_flag(U"Vsync = ", &Game::status, GF_VSYNC, []()->bool {
    Game::status ^= GF_VSYNC;
    Game::events.push(Event{event_e::SET_VSYNC, int(Game::status & GF_VSYNC)});
    return true;
  }));
  menu.add(new item_int(U"Frame skip = ", &Game::frame_skip, nullptr, 0, 20));
  menu.add(new item_flag(U"High detail = ", &Game::status, GF_HIGH_DETAILED,
    []()->bool { Game::status ^= GF_HIGH_DETAILED; return true; } ));
  menu.add(new item_flag(U"Haze = ", &Game::status, GF_DRAW_HAZE,
    []()->bool { Game::status ^= GF_DRAW_HAZE; return true; } ));
  menu.add(new item_flag(U"Light = ", &Game::status, GF_DRAW_LIGHT,
    []()->bool { Game::status ^= GF_DRAW_LIGHT; return true; } ));
  menu.add(new item_flag(U"Blink optim. = ", &Game::status, GF_BLINK_OPTMZ,
    []()->bool { Game::status ^= GF_BLINK_OPTMZ; return true; } ));
  menu.add(new item_flag(U"Fullscreen = ", &Game::status, GF_FULLSCREEN, []()->bool {
    Game::status ^= GF_FULLSCREEN;
    Game::events.push(Event{event_e::SET_FULLSCREEN, int(Game::status & GF_FULLSCREEN)});
    return true;
  }));
  menu.add(new item_resize_mode(U"Resize type = ", &Game::wnd.mode, []()->bool {
    Game::events.push(Event{event_e::SET_RESIZE_MODE, int(Game::wnd.mode)});
    return true;
  }));
  menu.add(new item_text(U"Back", []()->bool {
    Game::scene_state.push(scene_st::PREV); return false; }));
  menu.init(5,20, 160,60, 5,5, 14);
}
void Scene_graphic::input() {
  // выйти назад
  if (Game::menu_press(KEY_ESCAPE))
    set_scene(scene_st::PREV);
  if (Game::menu_press(KEY_UP))
    menu.up();
  if (Game::menu_press(KEY_DOWN))
    menu.down();
  if (Game::menu_press(KEY_LEFT))
    menu.param_sub();
  if (Game::menu_press(KEY_RIGHT))
    menu.param_plus();
  // выбираем чё-нидь:
  if (Game::menu_press(KEY_ENABLE)) {
    // когда будет в upd, выполнит действия из лябмд
    ifSelected = true;
  } // enter
}

void Scene_graphic::draw() {
  Game::screen.clear(); // фон чёрный
  menu.print(Game::screen);
}
