View difference between Paste ID: 1qyJDYnv and nqtsfNUC
SHOW: | | - or go back to the newest paste.
1
	void CreateOptionsMenu() 
2
	{
3
		//resolution
4
		//fullscreen
5
		//sound volume
6
		//music volume
7
		//Main Menu button
8
		GuiHelper gh;
9
		gh.base.x_ = GetSubsystem<Graphics>()->GetWidth();
10
		gh.base.y_ = GetSubsystem<Graphics>()->GetHeight();
11
		OptionsMenu = GetSubsystem<UI>()->GetRoot()->CreateChild<UIElement>("UIElement");
12
		OptionsMenu->SetStyleAuto();
13
		OptionsMenu->SetVisible(false);
14
15
		Button* backButton = CreateButton("Back", OptionsMenu, 0.5, 0.64, 0.2, 0.05);
16
		SubscribeToEvent(backButton, E_RELEASED, URHO3D_HANDLER(Game, backButtonHandle));
17
		///Screen Resolution
18
		Text* resText = new Text(context_);
19
		resText->SetText("Screen Resolution");
20
		resText->SetStyleAuto();
21
		resText->SetHorizontalAlignment(HorizontalAlignment::HA_CENTER);
22
		gh.SetControlSizePos(resText, 0.5, 0.37, 0.2, 0.03, false);
23
		OptionsMenu->AddChild(resText);
24
25
		DropDownList* list = new DropDownList(context_);
26
		unsigned selection = M_MAX_UNSIGNED;
27
		list->SetSelection(selection);
28
		list->SetStyleAuto();
29
		gh.SetControlSizePos(list, 0.5, 0.4, 0.2, 0.025,true);
30
		list->SetResizePopup(true);
31
		list->SetName("SR");
32
		OptionsMenu->AddChild(list);
33
34
		VideoModes = GetSubsystem<Graphics>()->GetResolutions();
35
		for (int i = 0; i < VideoModes.Size(); ++i) 
36
		{
37
			String str = String(VideoModes[i].x_) + " x " + String(VideoModes[i].y_);
38
			Text * t = new Text(context_);
39
			t->SetText(str);
40
			t->SetHorizontalAlignment(HorizontalAlignment::HA_CENTER);
41
			t->SetStyle("ConsoleText");
42
			list->AddItem(t);
43
		}
44
		///Fullscreen
45
		Text* fsText = new Text(context_);
46
		fsText->SetText("Fullscreen");
47
		fsText->SetStyleAuto();
48
		fsText->SetHorizontalAlignment(HorizontalAlignment::HA_RIGHT);
49
		gh.SetControlSizePos(fsText, 0.5, 0.44, 0.2, 0.03, false);
50
		OptionsMenu->AddChild(fsText);
51
52
		CheckBox* fsBox = new CheckBox(context_);
53
		fsBox->SetStyleAuto();
54
		fsBox->SetName("FS");
55
		gh.SetControlSizePos(fsBox, 0.4, 0.44, 0.2, 0.03, false);
56
		OptionsMenu->AddChild(fsBox);
57
		SubscribeToEvent(fsBox, E_CLICK, URHO3D_HANDLER(Game, fsHandle));
58
59
		///sound
60
		Text* st = new Text(context_);
61
		st->SetText("Sound Volume");
62
		st->SetStyleAuto();
63
		st->SetHorizontalAlignment(HorizontalAlignment::HA_CENTER);
64
		gh.SetControlSizePos(st, 0.5, 0.48, 0.2, 0.03, false);
65
		OptionsMenu->AddChild(st);
66
67
		Slider* sound = new Slider(context_);
68
		gh.SetControlSizePos(sound, 0.5, 0.52, 0.2, 0.03, true);
69
		sound->SetName("sound");
70
		sound->SetStyleAuto();
71
		sound->SetRange(10);
72
		sound->SetMinWidth(sound->GetWidth());
73
		OptionsMenu->AddChild(sound);
74
		//slider->SetValue(audio->GetMasterGain(SOUND_EFFECT));
75
		//SubscribeToEvent(slider, E_SLIDERCHANGED, URHO3D_HANDLER(SoundEffects, HandleSoundVolume));
76
		///music
77
		Text* mt = new Text(context_);
78
		mt->SetText("Music Volume");
79
		mt->SetStyleAuto();
80
		mt->SetHorizontalAlignment(HorizontalAlignment::HA_CENTER);
81
		gh.SetControlSizePos(mt, 0.5, 0.56, 0.2, 0.03, false);
82
		OptionsMenu->AddChild(mt);
83
84
		Slider* music = new Slider(context_);
85
		gh.SetControlSizePos(music, 0.5, 0.60, 0.2, 0.03, true);
86
		music->SetName("music");
87
		music->SetStyleAuto();
88
		music->SetRange(10);
89
		music->SetMinWidth(music->GetWidth());
90
		OptionsMenu->AddChild(music);
91
92
		OptionsMenu->Remove();
93
		OptionsMenu->SetVisible(true);
94
95-
	}
95+
	}
96
struct  GuiHelper
97
{
98
	IntVector2 base;
99
	IntVector2 AbsoluteFromRelative(float x, float y) 
100
	{
101
		return IntVector2(base.x_ * x, base.y_*y);
102
	}
103
104
	void SetControlSizePos(UIElement* ui, float pos_x, float pos_y, float size_x, float size_y, bool halfSizeOffset)
105
	{
106
		ui->SetWidth(base.x_ * size_x);
107
		ui->SetHeight(base.y_ * size_y);
108
		float half = 0;
109
		if(halfSizeOffset)
110
			half = ui->GetWidth() / 2;
111
		ui->SetPosition((base.x_* pos_x)- half, base.y_ * pos_y);
112
	}
113
};