File: optionsmenu.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (83 lines) | stat: -rw-r--r-- 2,294 bytes parent folder | download
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
#ifdef WIN32
#pragma warning (disable:4355)
#endif

#include <ClanLib/display.h>

#include "optionsmenu.h"
#include "options.h"

/////////////////////////////////////////////////////////////////////////////
// OptionsMenu construction:

OptionsMenu::OptionsMenu(CL_Component *parent, CL_StyleManager *style, Options *_options)
:
	CL_Frame(
		CL_Rect(0, 0, CL_Display::get_width(), CL_Display::get_height()),
		parent,
		style),
	button_ok(CL_Rect(10, 440, 190, 475), "Ok", this, style),
	button_cancel(CL_Rect(10, 400, 190, 435), "Cancel", this, style),
	label_name(CL_Rect(10, 58 + 75, 100, 93 + 75), "Player name:", this, style),
	input_name(CL_Rect(120, 50 + 75, 630, 85 + 75), "Player", this, style),
	checkbox_intro(CL_Point(20, 200), "Show intro on startup", this, style),
	label_message(CL_Rect(125, 100, 630, 125), "You need to set a player name before playing!", this, style),
	options(_options)
{
	slot_paint = sig_paint().connect(this, &OptionsMenu::on_paint);
	slot_ok = button_ok.sig_clicked().connect(this, &OptionsMenu::on_quit, true);
	slot_cancel = button_cancel.sig_clicked().connect(this, &OptionsMenu::on_quit, false);
	slot_name_enter=input_name.sig_return_pressed().connect(this, &OptionsMenu::on_quit,true);

	input_name.set_text(options->get_player_name());
//	input_name.set_focus();

	if(options->get_player_name() != "")
		label_message.show(false);

	title = new CL_Surface("Titles/options", style->get_resources());
}

OptionsMenu::~OptionsMenu()
{
}

/////////////////////////////////////////////////////////////////////////////
// OptionsMenu attributes:

bool OptionsMenu::get_result()
{
	return result;
}

/////////////////////////////////////////////////////////////////////////////
// OptionsMenu operations:

/////////////////////////////////////////////////////////////////////////////
// OptionsMenu callbacks:

void OptionsMenu::on_paint()
{
	title->put_screen(20, 20);
}

void OptionsMenu::on_quit(bool save)
{
	if(save)
	{
		if(input_name.get_length())
			options->set_player_name(input_name.get_text());
		else
		{
			CL_MessageBox::info("You need to fill in a player name", get_gui_manager());
			return;
		}
	}

	result = save;

	quit();
}

/////////////////////////////////////////////////////////////////////////////
// OptionsMenu implementation: