/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   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 can find this license in the file 'gpl.txt'.
 *
 *   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
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 *********************************************************************/

#ifndef CLASS_SETTING_HEADER
#define CLASS_SETTING_HEADER

#include "../basistypes.h"

#include "setting.cardsorder.h"

/**
 **
 ** the class for all preferences
 **
 ** @author	Diether Knof
 **
 **/
class Setting {
  public:
    enum TypeBool {
      FIRST,
      BOOL_FIRST = FIRST,

      SAVE_PARTY_CHANGES = BOOL_FIRST,
      SHOW_SPLASH_SCREEN,
      SPLASH_SCREEN_TRANSPARENT,
      SHOW_BUG_REPORT_BUTTON_IN_GAME_FINISHED_WINDOW,
      SAVE_BUG_REPORTS_ON_DESKTOP,
      SOUND,

      AUTOMATIC_CARD_SUGGESTION,
      ANNOUNCE_SWINES_AUTOMATICALLY,

      SHOW_IF_VALID,
      EMPHASIZE_VALID_CARDS,
      SHOW_ALL_HANDS,
      SHOW_TRICKPILES_POINTS,
      SHOW_SPECIAL_POINTS_IN_TRICKPILES,
      SHOW_KNOWN_TEAMS_IN_GAME,
      SHOW_SOLOPLAYER_IN_GAME,

      SHOW_FULL_TRICK_WINDOW,
      SHOW_FULL_TRICK_WINDOW_IF_SPECIAL_POINTS,
      CLOSE_FULL_TRICK_AUTOMATICALLY,

      SHOW_GAMETYPE_WINDOW,
      CLOSE_GAMETYPE_WINDOW_AUTOMATICALLY,
      SHOW_MARRIAGE_WINDOW,
      CLOSE_MARRIAGE_WINDOW_AUTOMATICALLY,
      SHOW_GENSCHER_WINDOW,
      CLOSE_GENSCHER_WINDOW_AUTOMATICALLY,
      SHOW_ANNOUNCEMENT_WINDOW,
      CLOSE_ANNOUNCEMENT_WINDOW_AUTOMATICALLY,
      SHOW_SWINES_WINDOW,
      CLOSE_SWINES_WINDOW_AUTOMATICALLY,

      ROTATE_TRICK_CARDS,

      ORIGINAL_CARDS_SIZE,

      BOOL_LAST = ORIGINAL_CARDS_SIZE
    }; // enum TypeBool
    static unsigned const BOOL_NUMBER;

    enum TypeUnsigned {
      UNSIGNED_FIRST = BOOL_LAST + 1,

      CARD_PLAY_DELAY = UNSIGNED_FIRST,
      FULL_TRICK_CLOSE_DELAY,

      GAMETYPE_WINDOW_CLOSE_DELAY,
      MARRIAGE_WINDOW_CLOSE_DELAY,
      GENSCHER_WINDOW_CLOSE_DELAY,
      ANNOUNCEMENT_WINDOW_CLOSE_DELAY,
      SWINES_WINDOW_CLOSE_DELAY,

      CARDS_HEIGHT,

      UNSIGNED_LAST = CARDS_HEIGHT
    }; // enum TypeUnsigned
    static unsigned const UNSIGNED_NUMBER;

    enum TypeString {
      STRING_FIRST = UNSIGNED_LAST + 1,

      NAME = STRING_FIRST,
      LANGUAGE,
      CARDSET,
      CARDS_BACK,
      BACKGROUND,
      NAME_FONT,
      NAME_FONT_COLOR,
      NAME_ACTIVE_FONT_COLOR,
      TRICKPILE_POINTS_FONT,
      TRICKPILE_POINTS_FONT_COLOR,
      POVERTY_SHIFT_ARROW_COLOR,

      BROWSER,

      STRING_LAST = BROWSER
    }; // enum TypeString
    static unsigned const STRING_NUMBER;

    enum TypeStringConst {
      STRING_CONST_FIRST = STRING_LAST + 1,

      PUBLIC_DATA_DIRECTORY = STRING_CONST_FIRST,
      PRIVATE_DATA_DIRECTORY,
      SETTINGS_FILE,
      LANGUAGES_DIRECTORY,
      LANGUAGE_FILE,
      GRAPHIC_EXTENSION,
      CARDSETS_DIRECTORY,
      CARDS_DIRECTORY,
      CARDS_BACK_DIRECTORY,
      ICONS_DIRECTORY,
      BACKGROUNDS_DIRECTORY,
      SOUND_DIRECTORY,
      AI_DIRECTORY,
      RULES_DIRECTORY,
      SETTINGS_DIRECTORY,
      HELP_DIRECTORY,

      STRING_CONST_LAST = HELP_DIRECTORY
    }; // enum TypeStringConst
    static unsigned const STRING_CONST_NUMBER;

    enum TypeCardsOrder {
      CARDS_ORDER = STRING_CONST_LAST + 1,

      LAST = CARDS_ORDER
    }; // enum TypeCardsOrder

  public:
    Setting();
    Setting(Setting const& setting);
    Setting& operator=(Setting const& setting);

    vector<string> data_directories() const;

    // returns, whether the setting is activ or not (or the value)
    bool operator()(const TypeBool type) const;
    unsigned operator()(const TypeUnsigned type) const;
    string operator()(const TypeString type) const;
    string operator()(const TypeStringConst type) const;
    CardsOrder const& operator()(const TypeCardsOrder type) const;
    CardsOrder& operator()(const TypeCardsOrder type);

    // returns the type with the name
    int type(string const& name) const;
    // returns the type with the translated name
    int type_translated(string const& name) const;
    // returns the type with the translated or normal name
    int type_translated_or_normal(string const& name) const;
    
    // returns, whether the dependencies of the settings are met
    bool dependencies(TypeBool const& type) const;
    bool dependencies(TypeUnsigned const& type) const;
    bool dependencies(TypeString const& type) const;

    // returns the setting
    bool const& value(TypeBool const type) const;
    unsigned const& value(TypeUnsigned const type) const;
    string const& value(TypeString const type) const;
    string const value(TypeStringConst const type) const;
    CardsOrder const& value(TypeCardsOrder const type) const;
    CardsOrder& value(TypeCardsOrder const type);

    // the minimum and maximum value
    unsigned min(TypeUnsigned const& type) const;
    unsigned max(TypeUnsigned const& type) const;

    // sets the setting
    bool set(string const& type, string const& value);
    bool set(const TypeBool type, bool const value);
    bool set(const TypeBool type, string const& value);
    string set(const TypeString type, string const& value);
    unsigned set(const TypeUnsigned type, unsigned const value);
    unsigned set(const TypeUnsigned type, string const& value);
    CardsOrder const& set(const TypeCardsOrder type,
			  CardsOrder const& value);
    CardsOrder const& set(const TypeCardsOrder type,
			  string const& value);

    void update_all();

    void load();
    void load(string const& filename,
		  bool filename_not_exists_output = true);

    bool save() const;
    bool save(string const& filename) const;

    // output of the settings
    ostream& out(ostream& ostr) const;

  private:
    vector<bool> bool_p;
    vector<unsigned> unsigned_p;
    vector<string> string_p;
    CardsOrder cards_order_p;

}; // class Setting

// conversion in a string
string name(Setting::TypeBool const& type);
string name(Setting::TypeUnsigned const& type);
string name(Setting::TypeString const& type);
string name(Setting::TypeStringConst const& type);
string name(Setting::TypeCardsOrder const& type);

// output of the name
ostream& operator<<(ostream& ostr, Setting::TypeBool const& type);
ostream& operator<<(ostream& ostr, Setting::TypeUnsigned const& type);
ostream& operator<<(ostream& ostr, Setting::TypeString const& type);
ostream& operator<<(ostream& ostr, Setting::TypeStringConst const& type);
ostream& operator<<(ostream& ostr, Setting::TypeCardsOrder const& type);

// output of the Settings
ostream& operator<<(ostream& ostr, Setting const& setting);

// comparison of two settings (value)
bool operator==(Setting const& setting1, Setting const& setting2);
bool operator!=(Setting const& setting1, Setting const& setting2);

extern Setting setting;
extern Setting setting_default;

extern string GPL;
extern string cardset_license;

#endif // #ifndef CLASS_SETTING_HEADER
