#pragma once
#include "menu.hpp"
//! строка уровеня сложности
class item_difficulty: public MenuItem {
  nocopy(item_difficulty);
protected:
  utf32 str = {};
  Difficulty* pDifclt = nullptr;
  void_callback pFunc = nullptr;
public:
  explicit item_difficulty(CN(utf32) s, Difficulty* p, void_callback f=nullptr)
  : str(s), pDifclt(p), pFunc(f) {
    IFERROR(!pDifclt, "menu difficulty is null");
  }
  void print(Font* pFont, Image& dst,
  int XPos=0, int YPos=0) const override {
    utf32 str_difclt;
    // TODO localization
    switch ( *pDifclt) {
      default:
      case Difficulty::NORMAL: str_difclt = U"NORMAL"; break; 
      case Difficulty::EASY: str_difclt = U"EASY"; break; 
      case Difficulty::HARD: str_difclt = U"HARD"; break; 
      case Difficulty::DIE: str_difclt = U"DIE"; break; 
    }
    pFont->print(dst, XPos, YPos, str + str_difclt);
  }
  void plus() override {
    int x = int(*pDifclt);
    --x;
    if (x < 0)
      x = 0;
	  *pDifclt = Difficulty(x);
  }
  void sub() override {
    uint x = uint(*pDifclt);
    ++x;
    if (x >= difficulty_max)
      x = difficulty_max - 1;
	  *pDifclt = Difficulty(x);
  }
  bool accept() override {
    if (pFunc)
      return pFunc();
    return true;
  }
}; // item_difficulty