Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: aa113a71c64674b2a63f436573462568810c6ca9 (plain)
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
140
141
142
/*
   client/mainwindow.cc
   This file is part of the Osirion project and is distributed under
   the terms and conditions of the GNU General Public License version 2
*/

#include "core/application.h"
#include "client/mainwindow.h"
#include "client/video.h"
#include "ui/ui.h"

namespace client
{

MainWindow::MainWindow(ui::Widget *parent) : ui::Widget(parent)
{
	set_label("mainwindow");
	set_border(false);
	set_background(false);

	// console notifications widget
	mainwindow_notificationswidget = new Notifications(this);
	
	// developer info widget
	mainwindow_devinfowidget = new DevInfoWidget(this);
	
	// statistics widget
	mainwindow_statsinfowidget = new StatsInfoWidget(this);
	
	// key info widget
	mainwindow_keyinfowidget = new KeyInfoWidget(this);
	
	// clock widget
	mainwindow_clockwidget = new ClockInfoWidget(this);

	// game window
	mainwindow_gamewindow = new GameWindow(this);	
	mainwindow_gamewindow->raise();
	mainwindow_gamewindow->hide();
	
	// main menus
	mainwindow_mainmenu = new MainMenu(this);
	mainwindow_mainmenu->raise();
	mainwindow_mainmenu->hide();
}

MainWindow::~MainWindow()
{

}

void MainWindow::resize()
{
	set_size(parent()->size());

	//const float largemargin = ui::UI::elementsize.width() * 0.25
	const float smallmargin = ui::UI::elementsize.height();

	// reposition notifications
	mainwindow_notificationswidget->set_size(width() -  smallmargin * 2, height() -  smallmargin * 4);
	mainwindow_notificationswidget->set_location(smallmargin, smallmargin * 2);
	
	// reposition devinfo widget
	mainwindow_devinfowidget->set_size(font()->width()*32, font()->height()*5);
	mainwindow_devinfowidget->set_location(smallmargin, smallmargin);

	// reposition stats widget
	mainwindow_statsinfowidget->set_size(font()->width()*12, font()->height()*5);
	mainwindow_statsinfowidget->set_location(width() - mainwindow_statsinfowidget->width() - smallmargin, smallmargin);
	
	// reposition clock
	mainwindow_clockwidget->set_size(font()->width()*7, font()->height());
	mainwindow_clockwidget->set_location(width() - mainwindow_clockwidget->width() - smallmargin, mainwindow_statsinfowidget->bottom() + smallmargin);

	// reposition keypress widget
	mainwindow_keyinfowidget->set_size(font()->width()*12, font()->height()*1);
	mainwindow_keyinfowidget->set_location(width() - mainwindow_keyinfowidget->width() - smallmargin,
				   height() - mainwindow_keyinfowidget->height() - smallmargin);
	
	// resize game window
	mainwindow_gamewindow->set_size(size());
	
	// resize mainmenu window
	mainwindow_mainmenu->set_size(size());
}

void MainWindow::clear()
{
	// clear console notifications
	mainwindow_notificationswidget->clear();
	
	// clear the game window
	mainwindow_gamewindow->clear();
}

void MainWindow::event_text(const std::string & text)
{
	mainwindow_notificationswidget->event_text(text);
	mainwindow_gamewindow->event_text(text);
}

void MainWindow::draw()
{
	// the mainwindow is only drawn if the application is connected
	// and the loader screen is not shown
	
	mainwindow_devinfowidget->set_visible(draw_devinfo->value() > 0 ? true : false);
	
	mainwindow_statsinfowidget->set_visible(draw_stats->value() > 0 ? true : false);
	
	mainwindow_keyinfowidget->set_visible(draw_keypress->value() > 0 ? true : false);
	
	if (draw_clock->value() <= 0) {
		mainwindow_clockwidget->set_mode(ClockInfoWidget::ClockOff);
	} else if (draw_clock->value() == 1) {
		mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock12Hours);
	} else {
		mainwindow_clockwidget->set_mode(ClockInfoWidget::Clock24Hours);
	}
		
	if (!mainwindow_mainmenu->visible()) {
		
		if (!core::game()->interactive() || !core::localcontrol()) {
			mainwindow_gamewindow->hide();
			mainwindow_mainmenu->show();
			
		} else if (core::localcontrol()->state() == core::Entity::Destroyed) {
			mainwindow_gamewindow->hide();
			// game module sends a messagebox to take approriate action
			
		} else if (mainwindow_gamewindow->hidden()) {
			mainwindow_gamewindow->show();
		}
		
	} else {	
		if (mainwindow_gamewindow->visible()) {
			mainwindow_gamewindow->hide();
		}
	}
}

}