File size: 1,879 Bytes
b6a38d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
DefineClass.ObjSurfacesLegend = {
	__parents = {"XDialog"},
	
	Padding = box(0, 0, 10, 60),
	Dock = "box",
	ZOrder = 100,
	HAlign = "right",
	VAlign = "bottom",
	UseClipBox = false,
	HandleMouse = true,
}

function ObjSurfacesLegend:Init()
	local parent = XWindow:new({
		LayoutMethod = "VList",
		UniformRowHeight = true,
		Background = const.clrBlack,
	}, self)
	
	for stype, color in sorted_pairs(ObjectSurfaceColors) do
		if color ~= RGBA(0, 0, 0, 0) then
			local background = XWindow:new({
				Margins = box(5, 5, 5, 5),
				HAlign = "left",
				VAlign = "center",
				LayoutMethod = "HList",
				MinWidth = 200,
				MinHeight = 30,
				MaxWidth = 200,
				MaxHeight = 30,
				Background = color,
				Clip = false,
			}, parent)
			local button = XCheckButton:new({
				OnChange = function(button, checked)
					SetObjSurfaceDisabled(stype, not checked)
				end,
			}, background)
			button:SetCheck(not TurnedOffObjSurfaces[stype])
			local text = XText:new({
				Margins = box(5, 0, 5, 0),
				HAlign = "left",
				VAlign = "center",
				MinWidth = 50,
				MaxHeight = 30,
				TextVAlign = "center",
				TextStyle = "GedDefaultDarkModeOutline",
				Clip = false,
			}, background)
			text:SetText(stype)
		end
	end
	
	local close_button = XTextButton:new({
		Margins = box(5, 0, 5, 0),
		HAlign = "center",
		VAlign = "center",
		MinWidth = 50,
		MaxHeight = 30,
		TextVAlign = "center",
		TextStyle = "GedDefault",
		OnPress = function(button)
			for obj in pairs(ObjToShownSurfaces) do
				obj:HideSurfaces()
			end
		end,
	}, parent)
	close_button:SetText("Close")
end

function SetObjSurfaceDisabled(stype, disabled)
	TurnedOffObjSurfaces[stype] = disabled or nil
	for obj, entry in pairs(ObjToShownSurfaces) do
		if disabled then
			if type(entry) == "table" then
				DoneObject(entry[stype])
				entry[stype] = nil
			end
		else
			obj:ShowSurfaces()
		end
	end
end