/*
  Copyright (C) 2005 Dan Alcantara (dfalcantara@ucdavis.edu, http://wwwcsif.cs.ucdavis.edu/~alcantar)
  Based on the board game "Blokus" by Educational Insights, Inc.
  
  This program is free software; you can redistribute 
  it and/or modify it under the terms of the GNU General 
  Public License as published by the Free Software Foundation; 
  either version 2 of the License, or (at your option) any later version.
  
  This program is distributed in the hope that it will be useful, but 
  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  more details.
  
  You should have received a copy of the GNU General Public License along 
  with this program; if not, write to the Free Software Foundation, Inc., 
  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  
  Full license visible at http://www.opensource.org/licenses/gpl-license.php
*/


#ifndef OPTIONS_H
#define OPTIONS_H

#include <wx/wx.h>
#include <wx/spinctrl.h>

class OptionsDialog:public wxDialog
{
public:
  OptionsDialog(wxWindow *parent, wxWindowID id, wxString title, std::vector<bool> &isAI, AI::AIOptions *opts)
    :wxDialog(parent, id, title)
  {
    wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
    wxFlexGridSizer *innerSizer = new wxFlexGridSizer(2, 2, 5, 5);

    wxStaticText *label;
    
    for(int i = 0; i < 4; i++)
    {
      char buffer[256];
      sprintf(buffer, "Player %d", i+1);

      wxStaticBoxSizer *aiSizer = new wxStaticBoxSizer(wxVERTICAL, this, wxString::FromAscii(buffer));
      wxFlexGridSizer *fgSizer = new wxFlexGridSizer(5, 2, 3, 3);

      sprintf(buffer, "Computer plays player %d", i+1);
      boxAI[i] = new wxCheckBox(this, -1, wxString::FromAscii(buffer));
      
      if(isAI[i])
      {
        boxAI[i]->SetValue(true);
      }

      sizeWeight[i] = new wxSpinCtrl(this, -1, wxString::FromAscii(""), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS | wxSP_WRAP, 1, 100);
      friendlySpaceWeight[i] = new wxSpinCtrl(this, -1, wxString::FromAscii(""), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS | wxSP_WRAP, 1, 100);
      enemySpaceWeight[i] = new wxSpinCtrl(this, -1, wxString::FromAscii(""), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS | wxSP_WRAP, 1, 100);
      numFriendlyPieces[i] = new wxSpinCtrl(this, -1, wxString::FromAscii(""), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS | wxSP_WRAP, 1, 21);
      numEnemyPieces[i] = new wxSpinCtrl(this, -1, wxString::FromAscii(""), wxDefaultPosition, wxSize(50, 20), wxSP_ARROW_KEYS | wxSP_WRAP, 1, 21);

      sizeWeight[i]->SetValue(opts[i].weightSize);
      friendlySpaceWeight[i]->SetValue(opts[i].weightFriendlySpaces);
      enemySpaceWeight[i]->SetValue(opts[i].weightEnemySpaces);
      numFriendlyPieces[i]->SetValue(opts[i].numFriendlyPiecesToCheck);
      numEnemyPieces[i]->SetValue(opts[i].numEnemyPiecesToCheck);
      
      label = new wxStaticText(this, -1, wxString::FromAscii("Piece size weight: "));
      fgSizer->Add(label);
      fgSizer->Add(sizeWeight[i]);

      label = new wxStaticText(this, -1, wxString::FromAscii("Spaces created weight: "));
      fgSizer->Add(label);
      fgSizer->Add(friendlySpaceWeight[i]);

      label = new wxStaticText(this, -1, wxString::FromAscii("Enemy spaces weight: "));
      fgSizer->Add(label);
      fgSizer->Add(enemySpaceWeight[i]);

      label = new wxStaticText(this, -1, wxString::FromAscii("# friendly pieces to check: "));
      fgSizer->Add(label);
      fgSizer->Add(numFriendlyPieces[i]);
      
      label = new wxStaticText(this, -1, wxString::FromAscii("# enemy pieces to check: "));
      fgSizer->Add(label);
      fgSizer->Add(numEnemyPieces[i]);

      aiSizer->Add(boxAI[i], wxALL, 3);
      aiSizer->Add(fgSizer);
      innerSizer->Add(aiSizer, 0);
    }
    innerSizer->SetSizeHints(this);

    buttonOK = new wxButton(this, wxID_OK, wxString::FromAscii("OK"));
    mainSizer->Add(innerSizer, 0);
    mainSizer->Add(buttonOK, 0, wxALIGN_CENTER);
    mainSizer->SetSizeHints(this);
    SetSizer(mainSizer);
    
    CenterOnScreen();
    ShowModal();
  }
 
  int GetSizeWeight(int index)
  {
    return sizeWeight[index]->GetValue();
  } 
  
  int GetEnemySpaceWeight(int index)
  {
    return enemySpaceWeight[index]->GetValue();
  }
  
  int GetFriendlySpaceWeight(int index)
  {
    return friendlySpaceWeight[index]->GetValue();
  }
  
  int GetNumFriendlyPieces(int index)
  {
    return numFriendlyPieces[index]->GetValue();
  }
  
  int GetNumEnemyPieces(int index)
  {
    return numEnemyPieces[index]->GetValue();
  }
  
  bool IsAI(int index)
  {
    return boxAI[index]->GetValue();
  }
  
protected:
  wxSpinCtrl    *sizeWeight[4];
  wxSpinCtrl    *friendlySpaceWeight[4];
  wxSpinCtrl    *enemySpaceWeight[4];
  wxSpinCtrl    *numEnemyPieces[4];
  wxSpinCtrl    *numFriendlyPieces[4];
  
  wxButton      *buttonOK;
  wxCheckBox    *boxAI[4];
};

#endif
