//
// ColorButton.cpp
//

// Game includes.
#include "ColorButton.h"
#include "utility.h"

ColorButton::ColorButton(df::Sprite *p_sprite) {
  m_p_sprite = p_sprite;
  setBorder(true);
  setLocation(df::BOTTOM_LEFT);
  setColor(p_sprite -> getColor());
  setDefaultColor(p_sprite -> getColor());
  setViewString(df::toString(p_sprite -> getColor()).c_str());
  setType("ColorButton");
}

// On callback, change sprite color.
void ColorButton::callback() {
  df::Color color = m_p_sprite -> getColor();
  std::string str;

  // Switch to next color.
  // Note: BLACK not used since is invisible on black background.
  switch (color) {
  case df::RED:
    color = df::GREEN;
    str = "Green";
    break;
  case df::GREEN:
    color = df::YELLOW;
    str = "Yellow";
    break;
  case df::YELLOW:
    color = df::BLUE;
    str = "Blue";
    break;
  case df::BLUE:
    color = df::MAGENTA;
    str = "Magenta";
    break;
  case df::MAGENTA:
    color = df::CYAN;
    str = "Cyan";
    break;
  case df::CYAN:
    color = df::WHITE;
    str = "White";
    break;
  case df::WHITE:
    color = df::RED;
    str = "Red";
  default:
    break;
  }
  
  // Set to new color.
  setViewString(str);
  setDefaultColor(color);
  if (color == df::RED) {
    setHighlightColor(df::YELLOW);
  } else {
    setHighlightColor(df::RED);
  }
  m_p_sprite -> setColor(color);
}
