File: MissionInfoGuiView.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (139 lines) | stat: -rw-r--r-- 3,553 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "MissionInfoGuiView.h"

#include "math/Vector4.h"

namespace ui
{

MissionInfoGuiView::MissionInfoGuiView(wxWindow* parent) :
	GuiView(parent)
{}

void MissionInfoGuiView::setGLViewPort()
{
	double width = _windowDims[0];
	double height = _windowDims[1];

	double aspectRatio = _bgDims[0] / _bgDims[1];

	if (width / height > aspectRatio)
	{
		width = height * aspectRatio;
	}
	else
	{
		height = width / aspectRatio;
	}

	glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
}

void MissionInfoGuiView::setGui(const gui::IGuiPtr& gui)
{
	// Call the base class first
	GuiView::setGui(gui);

	Vector2 topLeft(0, 0);
	Vector2 bottomRight(640, 480);

	if (_gui != NULL)
	{
		gui::IGuiWindowDefPtr bgWindowDef = _gui->findWindowDef(getTargetWindowDefName());

		if (bgWindowDef)
		{
			const Vector4& rect = bgWindowDef->rect;
			topLeft = Vector2(rect[0], rect[1]);
			bottomRight = Vector2(rect[0] + rect[2], rect[1] + rect[3]);
		}
	}

	_bgDims = bottomRight - topLeft;

	_renderer.setVisibleArea(topLeft, bottomRight);

	// Only draw a certain windowDef
	setWindowDefFilter(getTargetWindowDefName());
}

// ---------- Darkmod.xt ----------------

DarkmodTxtGuiView::DarkmodTxtGuiView(wxWindow* parent) :
	MissionInfoGuiView(parent)
{}

void DarkmodTxtGuiView::setMissionInfoFile(const map::DarkmodTxtPtr& file)
{
	_file = file;
}

void DarkmodTxtGuiView::updateGuiState()
{
	const gui::IGuiPtr& gui = getGui();

	if (!_file || !gui) return;

	// This is a localised value, hardcode some for the moment being
	gui->setStateString("details_posx", "100");

	gui->findWindowDef("modTitle")->text.setValue(_file->getTitle());
	gui->findWindowDef("modDescription")->text.setValue(_file->getDescription());
	gui->findWindowDef("modAuthor")->text.setValue(_file->getAuthor());

	// These are internationalised strings in the GUI code, let's hardcode some for the preview
	gui->findWindowDef("modLastPlayedTitle")->text.setValue("Last played:");
	gui->findWindowDef("modCompletedTitle")->text.setValue("Completed:");
	gui->findWindowDef("modLastPlayedValue")->text.setValue("2017-11-19");
	gui->findWindowDef("modCompletedValue")->text.setValue("2017-11-26");
	gui->findWindowDef("modSizeTitle")->text.setValue("Space used:");
	gui->findWindowDef("modSizeValue")->text.setValue("123 MB");

    if (gui->findWindowDef("modSizeEraseFromDiskAction"))
    {
	    gui->findWindowDef("modSizeEraseFromDiskAction")->text.setValue("[Erase from disk]");
    }

	gui->findWindowDef("modLoadN")->text.setValue("Install Mission");
	gui->findWindowDef("modLoadH")->text.setValue("Install Mission");
	gui->findWindowDef("modLoad")->text.setValue("Install Mission");
	gui->findWindowDef("moreInfoH")->text.setValue("Notes");
	gui->findWindowDef("moreInfoN")->text.setValue("Notes");
	gui->findWindowDef("moreInfo")->text.setValue("Notes");

	redraw();
}

std::string DarkmodTxtGuiView::getTargetWindowDefName()
{
	return "ModToInstallParent";
}

// ---------- Readme.xt ----------------

ReadmeTxtGuiView::ReadmeTxtGuiView(wxWindow* parent) :
	MissionInfoGuiView(parent)
{}

void ReadmeTxtGuiView::setMissionInfoFile(const map::ReadmeTxtPtr& file)
{
	_file = file;
}

void ReadmeTxtGuiView::updateGuiState()
{
	const gui::IGuiPtr& gui = getGui();

	if (!_file || !gui) return;

	gui->setStateString("ModNotesText", _file->getContents());
	gui->findWindowDef("ModInstallationNotesButtonOK")->text.setValue("OK");

	redraw();
}

std::string ReadmeTxtGuiView::getTargetWindowDefName()
{
	return "ModInstallationNotesParchment";
}

} // namespace