summaryrefslogtreecommitdiffstats
path: root/knights/dlg_selectengine.cpp
blob: 2d8a846c6400fb530f1e73baa37120bfc87c815f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/***************************************************************************
                          dlg_selectengine.cpp  -  description
                             -------------------
    begin                : Wed Aug 28 2002
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sf.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "dlg_selectengine.moc"
#include <tqvbox.h>
#include <tqgroupbox.h>
#include <tqslider.h>
#include <tqlabel.h>
#include <kcombobox.h>
#include "resource.h"

dlg_selectengine::dlg_selectengine(TQWidget *parent, resource *Rsrc, bool army ) :
	KDialogBase(	parent,
								0,
								TRUE,
								i18n("Select Computer Player"),
								Help|Ok,
								Ok,
								TRUE )
{
	Resource = Rsrc;
	Army = army;
	BOX_Parent = makeVBoxMainWidget();

	BOX_Engine = new TQGroupBox( 1,
															TQt::Horizontal,
															i18n( "Computer Players" ),
															BOX_Parent );
	COMBO_Engine = new KComboBox( BOX_Engine );
	COMBO_Engine->setEditable( FALSE );

//	BOX_EngineHelper = new TQGroupBox( 1,
//															TQt::Horizontal,
//															i18n( "Computer Players' Helper" ),
//															BOX_Parent );
//	COMBO_EngineHelper = new KComboBox( BOX_Engine );
//	COMBO_EngineHelper->setEditable( FALSE );

	buildEngineData();

	connect( COMBO_Engine, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( slotCurrent(int) ) );
//	connect( COMBO_EngineHelper, TQ_SIGNAL( activated(int) ), this, TQ_SLOT( slotCurrentHelper(int) ) );


	GROUP_Strength = new TQGroupBox( 3,
																	TQt::Horizontal,
																	i18n( "Player Strength" ),
																	BOX_Parent );
	LABEL_Str_Min = new TQLabel( i18n( "Weak" ), GROUP_Strength );
	SLIDER_Strength = new TQSlider ( 1,
																	7,
																	1,
																	Resource->Strength[ 1 * ( Army == BLACK ) ],
																	TQt::Horizontal,
																	GROUP_Strength );
	LABEL_Str_Max = new TQLabel( i18n( "Strong" ), GROUP_Strength );
	SLIDER_Strength->setTickmarks( TQSlider::Below );
	connect( SLIDER_Strength, TQ_SIGNAL( valueChanged(int) ), this, TQ_SLOT( slotStrength(int) ) );
}
dlg_selectengine::~dlg_selectengine()
{
}
///////////////////////////////////////
//
//	dlg_selectengine::buildEngineData
//
///////////////////////////////////////
void dlg_selectengine::buildEngineData( void )
{
	bool FLAG1(FALSE);
//	bool FLAG2(FALSE);
	int Index(0);
	TQStringList EngineList;
	engineList::Iterator enginesIT;

	/* Clear Comboboxes */
	COMBO_Engine->clear();
//	COMBO_EngineHelper->clear();

	/* Handle status of Book-engine boxes */
//	White_Use_Book->setChecked( Resource->OPTION_Book_White );
//	Engines_White_Book->setEnabled( Resource->OPTION_Book_White );

	if( Army == WHITE )
	{
		Engine1F = ENGINE_WHITE;
		Engine2F = ENGINE_WHITE_BK;
	}
	else
	{
		Engine1F = ENGINE_BLACK;
		Engine2F = ENGINE_BLACK_BK;
	}

	/* Read the engine list */
	if( Resource->engines.isEmpty() ) return;
	for ( enginesIT = Resource->engines.begin(); enginesIT != Resource->engines.end(); ++enginesIT )
	{
		EngineList.append( (*enginesIT).Name );
	}

	/* Insert engines into comboboxes */
	EngineList.sort();
	COMBO_Engine->insertStringList( EngineList );
//	COMBO_EngineHelper->insertStringList( EngineList );

	/* Now run the list again, setting the current engine for each combobox */
	for ( enginesIT = Resource->engines.begin(); enginesIT != Resource->engines.end(); ++enginesIT )
	{
		if( (*enginesIT).CurrentRef & Engine1F )
			for( Index = 0; Index < COMBO_Engine->count(); Index++ )
				if( COMBO_Engine->text(Index) == (*enginesIT).Name )
				{
					COMBO_Engine->setCurrentItem(Index);
					FLAG1 = TRUE;
				}
//		if( (*enginesIT).CurrentRef & Engine2F )
//			for( Index = 0; Index < COMBO_Engine->count(); Index++ )
//				if( COMBO_EngineHelper->text(Index) == (*enginesIT).Name )
//				{
//					COMBO_EngineHelper->setCurrentItem(Index);
//					FLAG2 = TRUE;
//				}
	}

	/*
			This prevents a bug where you had to modify the
			current_engine_comboboxes before you could get any engines to run.
	*/
	if( ( !FLAG1 ) && ( COMBO_Engine->count() ) ) slotCurrent( COMBO_Engine->currentItem() );
//	if( ( !FLAG2 ) && ( COMBO_EngineHelper->count() ) ) slotCurrentHelper( COMBO_EngineHelper->currentItem() );
}
///////////////////////////////////////
//
//	dlg_selectengine::slotCurrent
//
///////////////////////////////////////
void dlg_selectengine::slotCurrent( int Index )
{
	TQString Name;
	engineList::Iterator enginesIT;
	
	Name = COMBO_Engine->text(Index);
	for ( enginesIT = Resource->engines.begin(); enginesIT != Resource->engines.end(); ++enginesIT )
	{
		if( (*enginesIT).CurrentRef & Engine1F ) (*enginesIT).CurrentRef -= Engine1F;
		if( (*enginesIT).Name == Name ) (*enginesIT).CurrentRef |= Engine1F;
	}
	emit valuesChanged();
}
///////////////////////////////////////
//
//	dlg_selectengine::slotCurrentHelper
//
///////////////////////////////////////
void dlg_selectengine::slotCurrentHelper( int Index )
{
	TQString Name;
	engineList::Iterator enginesIT;
	
	Name = COMBO_EngineHelper->text(Index);
	for ( enginesIT = Resource->engines.begin(); enginesIT != Resource->engines.end(); ++enginesIT )
	{
		if( (*enginesIT).CurrentRef & Engine2F ) (*enginesIT).CurrentRef -= Engine2F;
		if( (*enginesIT).Name == Name ) (*enginesIT).CurrentRef |= Engine2F;
	}
	emit valuesChanged();
}
///////////////////////////////////////
//
//	dlg_selectengine::strength
//
///////////////////////////////////////
int dlg_selectengine::strength( void )
{
	return SLIDER_Strength->value();
}
///////////////////////////////////////
//
//	dlg_selectengine::slotStrength
//
///////////////////////////////////////
void dlg_selectengine::slotStrength( int value )
{
	Resource->Strength[Army] = value;
	emit valuesChanged();
}