File: SelectionWidget.h

package info (click to toggle)
spring 106.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 55,260 kB
  • sloc: cpp: 543,946; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (120 lines) | stat: -rw-r--r-- 2,779 bytes parent folder | download | duplicates (3)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef SELECTIONWIDGET_H
#define SELECTIONWIDGET_H

#include <string>
#include <vector>
#include <functional>

#include "aGui/GuiElement.h"
#include "aGui/Window.h"
#include "aGui/List.h"
#include "aGui/Gui.h"
#include "aGui/VerticalLayout.h"
#include "aGui/HorizontalLayout.h"
#include "aGui/Button.h"
#include "aGui/LineEdit.h"
#include "aGui/TextElement.h"

namespace agui
{
class Button;
class TextElement;
}

class ListSelectWnd : public agui::Window
{
public:
	ListSelectWnd(const std::string& title) : agui::Window(title)
	{
		agui::gui->AddElement(this);
		SetPos(0.5, 0.2);
		SetSize(0.4, 0.7);
		// SetDepth(-0.5f);

		agui::VerticalLayout* modWindowLayout = new agui::VerticalLayout(this);

		list = new agui::List(modWindowLayout);
		list->FinishSelection.connect(std::bind(&ListSelectWnd::SelectButton, this));
		list->SetDepth(this->depth);

		agui::HorizontalLayout* buttons = new agui::HorizontalLayout(modWindowLayout);
		buttons->SetSize(0.0f, 0.04f, true);
		buttons->SetDepth(this->depth);

		agui::Button* select = new agui::Button("Select", buttons);
		select->Clicked.connect(std::bind(&ListSelectWnd::SelectButton, this));
		select->SetDepth(this->depth);

		agui::Button* cancel = new agui::Button("Close", buttons);
		cancel->Clicked.connect(std::bind(&ListSelectWnd::CancelButton, this));
		cancel->SetDepth(this->depth);

		GeometryChange();
	}

	slimsig::signal<void (std::string)> Selected;
	agui::List* list;

private:
	void SelectButton()
	{
		list->SetFocus(false);
		Selected.emit(list->GetCurrentItem());
	}
	void CancelButton()
	{
		WantClose.emit();
	}
};

class SelectionWidget : public agui::GuiElement
{
public:
	static const std::string NoDemoSelect;
	static const std::string NoModSelect;
	static const std::string NoMapSelect;
	static const std::string NoScriptSelect;
	static const std::string SandboxAI;

	SelectionWidget(agui::GuiElement* parent);
	~SelectionWidget();

	void ShowDemoList(const std::function<void(const std::string&)>& demoSelectedCB);
	void ShowModList();
	void ShowMapList();
	void ShowScriptList();

	void SelectDemo(const std::string&);
	void SelectMod(const std::string&);
	void SelectScript(const std::string&);
	void SelectMap(const std::string&);

	std::string userDemo;
	std::string userScript;
	std::string userMap;
	std::string userMod;

private:
	void CleanWindow();
	void UpdateAvailableScripts();
	void AddAIScriptsFromArchive();


	agui::Button* mod;
	agui::Button* map;
	agui::Button* script;

	agui::TextElement* modT;
	agui::TextElement* mapT;
	agui::TextElement* scriptT;

	ListSelectWnd* curSelect;

	std::function<void(const std::string&)> demoSelectedCB;

	std::vector<std::string> availableScripts;
};

#endif