///////////////////////////////////////////////////////////////////////////// // Name: playerprefs.cpp // tag: a player preferences tab. // Author: David Roundy // Modified by: // Copyright: (c) 2002 David Roundy // Licence: GPL /* 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 */ ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes . #include #ifndef WX_PRECOMP #include #include #include #include #include #include #include #endif #include "globals.h" #include "prefmacros.h" #include "debug.h" // include config.h for VERSION #include "config.h" #include "playerprefs.h" enum Boxes_and_stuff { ASK_SERVER=37, ASK_NAME, PLAYER_BLURB, PLAYER_NAME, PLAYER_PIC, PICFILE_BUTTON }; BEGIN_EVENT_TABLE(aPlayerPreferences, wxPanel) EVT_CHECKBOX(ASK_SERVER, aPlayerPreferences::OnAskServerClicked) EVT_CHECKBOX(ASK_NAME, aPlayerPreferences::OnAskNameClicked) EVT_BUTTON(PICFILE_BUTTON, aPlayerPreferences::OnChoosePlayerPicClicked) END_EVENT_TABLE() // My frame constructor aPlayerPreferences::aPlayerPreferences(wxWindow *parent) : wxPanel(parent, -1) { m_playerpic_bitmap = new wxStaticBitmap(this, -1, GetPlayerBitmap(GetPlayerName()), wxPoint(0,0), wxSize(64,64)); wxLayoutConstraints *c; wxCheckBox *ask_server_box = new wxCheckBox(this, ASK_SERVER, "Ask which server to use on startup."); ask_server_box ->SetValue(GetAskServer()); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.SameAs(this, wxTop, 5); c->height.AsIs(); c->right.LeftOf(m_playerpic_bitmap, 10); ask_server_box->SetConstraints(c); wxCheckBox *ask_playername_box = new wxCheckBox(this, ASK_NAME, "Always ask for my player name."); ask_playername_box ->SetValue(GetAskName()); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.Below(ask_server_box, 5); c->height.AsIs(); c->right.LeftOf(m_playerpic_bitmap, 10); ask_playername_box->SetConstraints(c); // // Player Name // wxStaticText *name_prompt_string = new wxStaticText(this, -1, "Player name", wxPoint(0,0)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.Below(ask_playername_box, 10); c->height.AsIs(); c->width.AsIs(); name_prompt_string->SetConstraints(c); wxString playername_str = GetPlayerName(); m_playername = new wxTextCtrl(this, PLAYER_NAME, playername_str); c = new wxLayoutConstraints; c->left.RightOf(name_prompt_string, 10); c->centreY.SameAs(name_prompt_string, wxCentreY,0); c->height.AsIs(); c->right.LeftOf(m_playerpic_bitmap, 10); m_playername->SetConstraints(c); // // Player Picture // wxStaticText *pic_prompt_string = new wxStaticText(this, -1, "Player picture", wxPoint(0,0)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.Below(m_playername, 5); c->height.AsIs(); c->width.AsIs(); pic_prompt_string->SetConstraints(c); c = new wxLayoutConstraints; c->right.SameAs(this, wxRight, 10); c->bottom.Above(m_playername, 5); c->height.AsIs(); c->width.AsIs(); m_playerpic_bitmap->SetConstraints(c); wxButton *picfile_button = new wxButton(this, PICFILE_BUTTON, "Choose..."); c = new wxLayoutConstraints; c->centreY.SameAs(pic_prompt_string, wxCentreY, 0); c->height.AsIs(); c->width.AsIs(); c->right.SameAs(this, wxRight, 10); picfile_button->SetConstraints(c); wxString playerpic_str = GetPlayerPic(); m_playerpic = new wxTextCtrl(this, PLAYER_PIC, playerpic_str); c = new wxLayoutConstraints; c->left.RightOf(pic_prompt_string, 10); c->right.LeftOf(picfile_button, 10); c->centreY.SameAs(pic_prompt_string, wxCentreY, 0); c->height.AsIs(); m_playerpic->SetConstraints(c); // // Player Blurb // wxStaticText *blurb_string = new wxStaticText(this, -1, "Enter here the blurb other people will be able to see about you.", wxPoint(0,0)); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.Below(pic_prompt_string, 5); c->height.AsIs(); c->right.SameAs(this, wxRight, 10); blurb_string->SetConstraints(c); wxString blurb_str = wxConfig::Get()->Read("/Player/Blurb", "Enter info about yourself here."); m_blurb = new wxTextCtrl(this, PLAYER_BLURB, blurb_str, wxDefaultPosition, wxSize(50,150), wxTE_MULTILINE); c = new wxLayoutConstraints; c->left.SameAs(this, wxLeft, 10); c->top.Below(blurb_string, 5); c->height.AsIs(); c->right.SameAs(this, wxRight, 10); m_blurb->SetConstraints(c); SetAutoLayout( TRUE ); DebugMsg("End of aPlayerPreferences::aPlayerPreferences"); } void aPlayerPreferences::ApplyChanges() { wxConfig::Get()->Write("/Player/Blurb", m_blurb->GetValue()); wxConfig::Get()->Write("/Player/Name", m_playername->GetValue()); SetPlayerPic(m_playerpic->GetValue()); wxConfig::Get()->Flush(); } aPlayerPreferences::~aPlayerPreferences() { ApplyChanges(); } void aPlayerPreferences::OnAskServerClicked(wxCommandEvent &evt) { wxConfig::Get()->Write("/General/AskServer", (long)evt.IsChecked()); wxConfig::Get()->Flush(); } void aPlayerPreferences::OnAskNameClicked(wxCommandEvent &evt) { wxConfig::Get()->Write("/General/AskName", (long)evt.IsChecked()); wxConfig::Get()->Flush(); } void aPlayerPreferences::OnChoosePlayerPicClicked(wxCommandEvent &evt) { wxString dir = wxPathOnly(m_playerpic->GetValue()); wxString hello = wxFileSelector("Choose player picture...", dir, "", "", "PNG files (*.png) |*.png| BMP files (*.bmp) |*.bmp| GIF files (*.gif) |*.gif| All (*.*) |*.*"); if (wxFileExists(hello)) { m_playerpic->SetValue(hello); wxImage my_image; if (wxFileExists(hello)) { if (my_image.LoadFile(hello)) { DebugMsg("Found image file " + hello); my_image.Rescale(64,64); m_playerpic_bitmap->SetBitmap(my_image.ConvertToBitmap()); } } } }