1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef SELECTIONWIDGET_H
4 #define SELECTIONWIDGET_H
5 
6 #include <string>
7 #include <boost/bind.hpp>
8 
9 #include "aGui/GuiElement.h"
10 #include "aGui/Window.h"
11 #include "aGui/List.h"
12 #include "aGui/Gui.h"
13 #include "aGui/VerticalLayout.h"
14 #include "aGui/HorizontalLayout.h"
15 #include "aGui/Button.h"
16 #include "aGui/LineEdit.h"
17 #include "aGui/TextElement.h"
18 
19 namespace agui
20 {
21 class Button;
22 class TextElement;
23 }
24 
25 class ListSelectWnd : public agui::Window
26 {
27 public:
ListSelectWnd(const std::string & title)28 	ListSelectWnd(const std::string& title) : agui::Window(title)
29 	{
30 		agui::gui->AddElement(this);
31 		SetPos(0.5, 0.2);
32 		SetSize(0.4, 0.7);
33 
34 		agui::VerticalLayout* modWindowLayout = new agui::VerticalLayout(this);
35 		list = new agui::List(modWindowLayout);
36 		list->FinishSelection.connect(boost::bind(&ListSelectWnd::SelectButton, this));
37 		agui::HorizontalLayout* buttons = new agui::HorizontalLayout(modWindowLayout);
38 		buttons->SetSize(0.0f, 0.04f, true);
39 		agui::Button* select = new agui::Button("Select", buttons);
40 		select->Clicked.connect(boost::bind(&ListSelectWnd::SelectButton, this));
41 		agui::Button* cancel = new agui::Button("Close", buttons);
42 		cancel->Clicked.connect(boost::bind(&ListSelectWnd::CancelButton, this));
43 		GeometryChange();
44 	}
45 
46 	boost::signals2::signal<void (std::string)> Selected;
47 	agui::List* list;
48 
49 private:
SelectButton()50 	void SelectButton()
51 	{
52 		list->SetFocus(false);
53 		Selected(list->GetCurrentItem());
54 	}
CancelButton()55 	void CancelButton()
56 	{
57 		WantClose();
58 	}
59 };
60 
61 class SelectionWidget : public agui::GuiElement
62 {
63 public:
64 	static const std::string NoModSelect;
65 	static const std::string NoMapSelect;
66 	static const std::string NoScriptSelect;
67 	static const std::string SandboxAI;
68 
69 	SelectionWidget(agui::GuiElement* parent);
70 	~SelectionWidget();
71 
72 	void ShowModList();
73 	void ShowMapList();
74 	void ShowScriptList();
75 
76 	void SelectMod(std::string);
77 	void SelectScript(std::string);
78 	void SelectMap(std::string);
79 
80 	std::string userScript;
81 	std::string userMap;
82 	std::string userMod;
83 
84 private:
85 	void CleanWindow();
86 
87 	agui::Button* mod;
88 	agui::TextElement* modT;
89 	agui::Button* map;
90 	agui::TextElement* mapT;
91 	agui::Button* script;
92 	agui::TextElement* scriptT;
93 	ListSelectWnd* curSelect;
94 };
95 
96 #endif
97