]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/playerdg.cpp
minsize and attribute tweaks
[wxWidgets.git] / demos / forty / playerdg.cpp
CommitLineData
63cafd27
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: playerdg.cpp
3// Purpose: Forty Thieves patience game
4// Author: Chris Breeze
5// Modified by:
6// Created: 21/07/97
7// RCS-ID: $Id$
8// Copyright: (c) 1993-1998 Chris Breeze
2a21ac15 9// Licence: wxWindows licence
63cafd27
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#pragma interface
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
28#include "scorefil.h"
29#include "playerdg.h"
30
31const int ID_LISTBOX = 101;
32
33BEGIN_EVENT_TABLE(PlayerSelectionDialog, wxDialog)
2a21ac15
DS
34 EVT_SIZE(PlayerSelectionDialog::OnSize)
35 EVT_BUTTON(wxID_OK, PlayerSelectionDialog::ButtonCallback)
36 EVT_BUTTON(wxID_CANCEL, PlayerSelectionDialog::ButtonCallback)
37 EVT_LISTBOX(ID_LISTBOX, PlayerSelectionDialog::SelectCallback)
e3065973 38 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow)
63cafd27
JS
39END_EVENT_TABLE()
40
41PlayerSelectionDialog::PlayerSelectionDialog(
2a21ac15
DS
42 wxWindow* parent,
43 ScoreFile* file
44 ) :
45 wxDialog(parent, wxID_ANY, _T("Player Selection"), wxDefaultPosition),
46 m_scoreFile(file)
63cafd27 47{
2a21ac15
DS
48 wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:"));
49
50 wxListBox* list = new wxListBox(
51 this, ID_LISTBOX,
52 wxDefaultPosition, wxDefaultSize,
53 0, 0,
54 wxLB_SINGLE
55 );
56
57 wxArrayString players;
58 m_scoreFile->GetPlayerList(players);
59 for (unsigned int i = 0; i < players.Count(); i++)
60 {
61 list->Append(players[i]);
62 }
63
64 m_textField = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize);
65
66 m_OK = new wxButton(this, wxID_OK, _T("OK"));
67 m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel"));
68
69 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
70 button_sizer->Add( m_OK, 0, wxALL, 10 );
71 button_sizer->Add( m_cancel, 0, wxALL, 10 );
72
73 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
74 topsizer->Add( msg, 0, wxALL , 10 );
75 topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
76 topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );
77 topsizer->Add( button_sizer, 0, wxALIGN_LEFT );
78
79 SetSizer( topsizer );
80
81 topsizer->SetSizeHints( this );
82
82ea63e6 83 CentreOnParent();
63cafd27
JS
84}
85
86PlayerSelectionDialog::~PlayerSelectionDialog()
87{
88}
89
cb43b372 90void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event))
63cafd27 91{
2a21ac15 92 Layout();
63cafd27
JS
93}
94
95const wxString& PlayerSelectionDialog::GetPlayersName()
96{
7b5408ea 97/*
2a21ac15
DS
98 m_player = wxEmptyString;
99 Show(true);
7b5408ea 100*/
2a21ac15 101 return m_player;
63cafd27
JS
102}
103
babd36de 104void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
63cafd27 105{
2a21ac15 106 m_player = wxEmptyString;
e3065973 107 EndModal(wxID_CANCEL);
63cafd27
JS
108}
109
110void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event)
111{
2a21ac15
DS
112 if (event.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED)
113 {
114// if (event.IsSelection())
115 m_textField->SetValue(event.GetString());
116 }
63cafd27
JS
117}
118
119void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
120{
2a21ac15
DS
121 if (event.GetId() == wxID_OK)
122 {
123 wxString name = m_textField->GetValue();
124 if (!name.IsNull() && name.Length() > 0)
125 {
126 if (name.Contains(_T('@')))
127 {
128 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
129 }
130 else
131 {
132 m_player = name;
133 EndModal(wxID_OK);
134 }
135 }
136 else
137 {
138 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
139 }
140 }
141 else
142 {
143 m_player = wxEmptyString;
144 EndModal(wxID_CANCEL);
145 }
63cafd27 146}