settings_gui.c
changeset 759 a445474d7c21
parent 654 838561602834
child 776 5b14f0b1e6d3
equal deleted inserted replaced
758:423ae0bcba07 759:a445474d7c21
   143 				LoadCustomEngineNames();
   143 				LoadCustomEngineNames();
   144 				MarkWholeScreenDirty();
   144 				MarkWholeScreenDirty();
   145 			}
   145 			}
   146 			break;
   146 			break;
   147 		case 5:
   147 		case 5:
       
   148 			if (e->dropdown.index == 23)
       
   149 				ShowCustCurrency();
   148 			_opt_mod_ptr->currency = _opt.currency = e->dropdown.index;
   150 			_opt_mod_ptr->currency = _opt.currency = e->dropdown.index;
   149 			MarkWholeScreenDirty();
   151 			MarkWholeScreenDirty();
   150 			break;
   152 			break;
   151 		case 8:
   153 		case 8:
   152 			_opt_mod_ptr->kilometers = e->dropdown.index;
   154 			_opt_mod_ptr->kilometers = e->dropdown.index;
   182 			SetScreenshotFormat(e->dropdown.index);
   184 			SetScreenshotFormat(e->dropdown.index);
   183 			SetWindowDirty(w);
   185 			SetWindowDirty(w);
   184 			break;
   186 			break;
   185 		}
   187 		}
   186 		break;
   188 		break;
   187 	}
   189 
       
   190 	case WE_DESTROY:
       
   191 		DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
       
   192 		break;
       
   193 	}
       
   194 
   188 }
   195 }
   189 
   196 
   190 int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   197 int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   191 {
   198 {
   192 	if (flags & DC_EXEC) {
   199 	if (flags & DC_EXEC) {
  1260 	w->vscroll.count = _grffile_count;
  1267 	w->vscroll.count = _grffile_count;
  1261 	w->vscroll.pos = 0;
  1268 	w->vscroll.pos = 0;
  1262 	w->disabled_state = (1 << 5) | (1 << 6) | (1 << 7);
  1269 	w->disabled_state = (1 << 5) | (1 << 6) | (1 << 7);
  1263 }
  1270 }
  1264 
  1271 
       
  1272 /* state: 0 = none clicked, 0x01 = first clicked, 0x02 = second clicked */
       
  1273 void DrawArrowButtons(int x, int y, int state)
       
  1274 {
       
  1275 	DrawFrameRect(x, y+1, x+9, y+9, 3, (state&0x01) ? 0x20 : 0);
       
  1276 	DrawFrameRect(x+10, y+1, x+19, y+9, 3, (state&0x02) ? 0x20 : 0);
       
  1277 	DrawStringCentered(x+5, y+1, STR_6819, 0);
       
  1278 	DrawStringCentered(x+15, y+1, STR_681A, 0);
       
  1279 }
       
  1280 
       
  1281 char str_separator[2];
       
  1282 
       
  1283 static void CustCurrencyWndProc(Window *w, WindowEvent *e)
       
  1284 {
       
  1285 	switch (e->event) {
       
  1286 	case WE_PAINT: {
       
  1287 		int x=35, y=20, i=0;
       
  1288 		int clk = WP(w,def_d).data_1;
       
  1289 		DrawWindowWidgets(w);
       
  1290 
       
  1291 		// exchange rate
       
  1292 		DrawArrowButtons(10, y, (clk >> (i*2)) & 0x03);
       
  1293 		SetDParam(0, 1);
       
  1294 		SetDParam(1, 1);
       
  1295 		DrawString(x, y + 1, STR_CURRENCY_EXCHANGE_RATE, 0);
       
  1296 		x = 35;
       
  1297 		y+=12;
       
  1298 		i++;
       
  1299 
       
  1300 		// separator
       
  1301 		DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03)?0x20:0x00);
       
  1302 		x = DrawString(x, y + 1, STR_CURRENCY_SEPARATOR, 0);
       
  1303 		DoDrawString(str_separator, x + 4, y + 1, 6);
       
  1304 		x = 35;
       
  1305 		y+=12;
       
  1306 		i++;
       
  1307 
       
  1308 		// prefix
       
  1309 		DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03)?0x20:0x00);
       
  1310 		x = DrawString(x, y + 1, STR_CURRENCY_PREFIX, 0);
       
  1311 		DoDrawString(_currency_specs[23].pre, x + 4, y + 1, 6);
       
  1312 		x = 35;
       
  1313 		y+=12;
       
  1314 		i++;
       
  1315 
       
  1316 		// postfix
       
  1317 		DrawFrameRect(10, y+1, 29, y+9, 0, ((clk >> (i*2)) & 0x03)?0x20:0x00);
       
  1318 		x = DrawString(x, y + 1, STR_CURRENCY_POSTFIX, 0);
       
  1319 		DoDrawString(_currency_specs[23].post, x + 4, y + 1, 6);
       
  1320 		x = 35;
       
  1321 		y+=12;
       
  1322 		i++;
       
  1323 
       
  1324 		// switch to euro
       
  1325 		DrawArrowButtons(10, y, (clk >> (i*2)) & 0x03);
       
  1326 		SetDParam(0, _currency_specs[23].to_euro);
       
  1327 		DrawString(x, y + 1, (_currency_specs[23].to_euro)?STR_CURRENCY_SWITCH_TO_EURO:STR_CURRENCY_SWITCH_TO_EURO_NEVER, 0);
       
  1328 		x = 35;
       
  1329 		y+=12;
       
  1330 		i++;
       
  1331 
       
  1332 		// Preview
       
  1333 		y+=12;
       
  1334 		SetDParam(0, 10000);
       
  1335 		DrawString(x, y + 1, STR_CURRENCY_PREVIEW, 0);
       
  1336 	} break;
       
  1337 
       
  1338 	case WE_CLICK: {
       
  1339 		bool edittext = false;
       
  1340 		int line = (e->click.pt.y - 20)/12;
       
  1341 		int len;
       
  1342 		int x = e->click.pt.x;
       
  1343 		StringID str;
       
  1344 
       
  1345 		switch ( line ) {
       
  1346 			case 0: // rate
       
  1347 				if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
       
  1348 					if (x < 20) {
       
  1349 						_currency_specs[23].rate = max(1, _currency_specs[23].rate-1);
       
  1350 						WP(w,def_d).data_1 =  (1 << (line * 2 + 0));
       
  1351 					} else {
       
  1352 						_currency_specs[23].rate = min(5000, _currency_specs[23].rate+1);
       
  1353 						WP(w,def_d).data_1 =  (1 << (line * 2 + 1));
       
  1354 					}
       
  1355 				} else { // enter text
       
  1356 					SetDParam(0, _currency_specs[23].rate);
       
  1357 					str = STR_CONFIG_PATCHES_INT32;
       
  1358 					len = 4;
       
  1359 					edittext = true;
       
  1360 				}
       
  1361 			break;
       
  1362 			case 1: // separator
       
  1363 				if ( IS_INT_INSIDE(x, 10, 30) )  // clicked button
       
  1364 					WP(w,def_d).data_1 =  (1 << (line * 2 + 1));
       
  1365 				str = AllocateName(str_separator, 0);
       
  1366 				len = 1;
       
  1367 				edittext = true;
       
  1368 			break;
       
  1369 			case 2: // prefix
       
  1370 				if ( IS_INT_INSIDE(x, 10, 30) )  // clicked button
       
  1371 					WP(w,def_d).data_1 =  (1 << (line * 2 + 1));
       
  1372 				str = AllocateName(_currency_specs[23].pre, 0);
       
  1373 				len = 12;
       
  1374 				edittext = true;
       
  1375 			break;
       
  1376 			case 3: // postfix
       
  1377 				if ( IS_INT_INSIDE(x, 10, 30) )  // clicked button
       
  1378 					WP(w,def_d).data_1 =  (1 << (line * 2 + 1));
       
  1379 				str = AllocateName(_currency_specs[23].post, 0);
       
  1380 				len = 12;
       
  1381 				edittext = true;
       
  1382 			break;
       
  1383 			case 4: // to euro
       
  1384 				if ( IS_INT_INSIDE(x, 10, 30) ) { // clicked buttons
       
  1385 					if (x < 20) {
       
  1386 						if(_currency_specs[23].to_euro <= 2000) _currency_specs[23].to_euro = 0;
       
  1387 						else _currency_specs[23].to_euro--;
       
  1388 						WP(w,def_d).data_1 = (1 << (line * 2 + 0));
       
  1389 					} else {
       
  1390 						if(_currency_specs[23].to_euro == 0) _currency_specs[23].to_euro = 2000;
       
  1391 						else _currency_specs[23].to_euro++;
       
  1392 						_currency_specs[23].to_euro = min(2090, _currency_specs[23].to_euro);
       
  1393 						WP(w,def_d).data_1 = (1 << (line * 2 + 1));
       
  1394 					}
       
  1395 				} else { // enter text
       
  1396 					SetDParam(0, _currency_specs[23].to_euro);
       
  1397 					str = STR_CONFIG_PATCHES_INT32;
       
  1398 					len = 4;
       
  1399 					edittext = true;
       
  1400 				}
       
  1401 			break;
       
  1402 		}
       
  1403 		
       
  1404 		if(edittext) {
       
  1405 			WP(w,def_d).data_2 = line;
       
  1406 			ShowQueryString(
       
  1407 			str,
       
  1408 			STR_CURRENCY_CHANGE_PARAMETER,
       
  1409 			len, // maximum number of characters OR
       
  1410 			250, // characters up to this width pixels, whichever is satisfied first
       
  1411 			w->window_class,
       
  1412 			w->window_number);
       
  1413 			if (str !=  STR_CONFIG_PATCHES_INT32) DeleteName(str);
       
  1414 		}
       
  1415 		
       
  1416 		w->flags4 |= 5 << WF_TIMEOUT_SHL;
       
  1417 		SetWindowDirty(w);
       
  1418 	} break;
       
  1419 
       
  1420 	case WE_ON_EDIT_TEXT: {
       
  1421 			int val;
       
  1422 			byte *b = e->edittext.str;
       
  1423 			switch (WP(w,def_d).data_2) {
       
  1424 				case 0:
       
  1425 					val = atoi(b);
       
  1426 					val = clamp(val, 1, 5000);
       
  1427 					_currency_specs[23].rate = val;
       
  1428 				break;
       
  1429 				case 1:
       
  1430 					_currency_specs[23].separator = b[0];
       
  1431 					ttd_strlcpy(str_separator, b, 16);
       
  1432 				break;
       
  1433 				case 2:
       
  1434 					ttd_strlcpy(_currency_specs[23].pre, b, 16);
       
  1435 				break;
       
  1436 				case 3:
       
  1437 					ttd_strlcpy(_currency_specs[23].post, b, 16);
       
  1438 				break;
       
  1439 				case 4:
       
  1440 					val = atoi(b);
       
  1441 					val = clamp(val, 1999, 2090);
       
  1442 					if (val == 1999) val = 0;
       
  1443 					_currency_specs[23].to_euro = val;
       
  1444 				break;
       
  1445 			}
       
  1446 		MarkWholeScreenDirty();
       
  1447 			
       
  1448 		
       
  1449 	} break;
       
  1450 
       
  1451 	case WE_TIMEOUT:
       
  1452 		WP(w,def_d).data_1 = 0;
       
  1453 		SetWindowDirty(w);
       
  1454 		break;
       
  1455 
       
  1456 	case WE_DESTROY:
       
  1457 		DeleteWindowById(WC_QUERY_STRING, 0);
       
  1458 		MarkWholeScreenDirty();
       
  1459 		break;
       
  1460 	}
       
  1461 }
       
  1462 
       
  1463 static const Widget _cust_currency_widgets[] = {
       
  1464 {   WWT_CLOSEBOX,    14,     0,    10,     0,    13, STR_00C5,						STR_018B_CLOSE_WINDOW},
       
  1465 {    WWT_CAPTION,    14,    11,   229,     0,    13, STR_CURRENCY_WINDOW,	STR_018C_WINDOW_TITLE_DRAG_THIS},
       
  1466 {      WWT_PANEL,    14,     0,   229,    14,   119, 0x0,									STR_NULL},
       
  1467 {   WIDGETS_END},
       
  1468 };
       
  1469 
       
  1470 static const WindowDesc _cust_currency_desc = {
       
  1471 	WDP_CENTER, WDP_CENTER, 230, 120,
       
  1472 	WC_CUSTOM_CURRENCY, 0,
       
  1473 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
       
  1474 	_cust_currency_widgets,
       
  1475 	CustCurrencyWndProc,
       
  1476 };
       
  1477 
       
  1478 void ShowCustCurrency()
       
  1479 {
       
  1480 	Window *w;
       
  1481 
       
  1482 	str_separator[0] = _currency_specs[23].separator;
       
  1483 	str_separator[1] = '\0';
       
  1484 
       
  1485 	DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
       
  1486 	w = AllocateWindowDesc(&_cust_currency_desc);
       
  1487 }
       
  1488