This repository has been archived by the owner on Jun 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoapplication.cpp
151 lines (123 loc) · 3.11 KB
/
aoapplication.cpp
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
143
144
145
146
147
148
149
150
151
//////////////////////////////////////////////////
//
// This work is licensed under the MIT license.
//
// You are free to copy, modify and distribute
// this work freely given that proper attribution
// is supplied and the author is not held liable.
// See LICENSE for details.
//
// Copyright (c) 2016-2018 David "OmniTroid" Skoland
//
//////////////////////////////////////////////////
#include "aoapplication.h"
#include "lobby.h"
#include "courtroom.h"
#include "networkmanager.h"
#include "misc_functions.h"
#include <QDebug>
#include <QRect>
#include <QDesktopWidget>
AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv)
{
net_manager = new NetworkManager(this);
}
AOApplication::~AOApplication()
{
destruct_lobby();
destruct_courtroom();
}
void AOApplication::construct_lobby()
{
if (lobby_constructed)
{
qDebug() << "W: lobby was attempted constructed when it already exists";
return;
}
w_lobby = new Lobby(this);
lobby_constructed = true;
QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width()-w_lobby->width()) / 2;
int y = (screenGeometry.height()-w_lobby->height()) / 2;
w_lobby->move(x, y);
w_lobby->show();
}
void AOApplication::destruct_lobby()
{
if(!lobby_constructed)
{
qDebug() << "W: lobby was attempted destructed when it did not exist";
return;
}
delete w_lobby;
lobby_constructed = false;
}
void AOApplication::construct_courtroom()
{
if (courtroom_constructed)
{
qDebug() << "W: courtroom was attempted constructed when it already exists";
return;
}
w_courtroom = new Courtroom(this);
courtroom_constructed = true;
QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width()-w_courtroom->width()) / 2;
int y = (screenGeometry.height()-w_courtroom->height()) / 2;
w_courtroom->move(x, y);
}
void AOApplication::destruct_courtroom()
{
if (!courtroom_constructed)
{
qDebug() << "W: courtroom was attempted destructed when it did not exist";
return;
}
delete w_courtroom;
courtroom_constructed = false;
}
QString AOApplication::get_version_string()
{
return
QString::number(RELEASE) + "." +
QString::number(MAJOR_VERSION) + "." +
QString::number(MINOR_VERSION);
}
void AOApplication::reload_theme()
{
current_theme = read_theme();
}
void AOApplication::set_favorite_list()
{
favorite_list = read_serverlist_txt();
}
QString AOApplication::get_current_char()
{
if (courtroom_constructed)
return w_courtroom->get_current_char();
else
return "";
}
void AOApplication::add_favorite_server(int p_server)
{
if (p_server < 0 || p_server >= server_list.size())
return;
server_type fav_server = server_list.at(p_server);
QString str_port = QString::number(fav_server.port);
QString server_line = fav_server.ip + ":" + str_port + ":" + fav_server.name;
write_to_serverlist_txt(server_line);
}
void AOApplication::server_disconnected()
{
if (courtroom_constructed)
{
call_notice("Disconnected from server.");
construct_lobby();
destruct_courtroom();
}
}
void AOApplication::loading_cancelled()
{
destruct_courtroom();
w_lobby->hide_loading_overlay();
}