-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountsFrame.cpp
151 lines (132 loc) · 6.36 KB
/
AccountsFrame.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
#include "AccountsFrame.h"
#include <wx/wx.h>
#include <wx/frame.h>
#include <wx/event.h>
#include <wx/settings.h>
#include <wx/hyperlink.h>
#include "RoundedButton.h"
#include <list>
#include "RayUtils.h"
#include "Web.h"
#include "MainFrame.h"
#include <string>
const std::list<std::string> pagesMap = {
"Home", // 99
"Exchange Code", // 0
};
const std::list<std::string> buttonMap = {
"1_1",
"1_2",
"1_3",
"1_4",
"1_5",
};
const wxColour darkPurple = wxColour(113, 96, 232, 100);
const wxColour lightPurple = wxColour(0xa679dc);
const wxColour lightColour = wxColour(0x202020);
const wxColour darkColour = wxColour(0x0a0a0a);
wxTextCtrl* exchangeCodeInput;
AccountsFrame* AccountsFrame::instance = nullptr;
AccountsFrame::AccountsFrame(const wxString& title)
: wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_FRAME_STYLE & ~(wxRESIZE_BORDER | wxMAXIMIZE_BOX))
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
// Top
SetBackgroundColour(lightColour);
SetSizer(mainSizer);
wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
// Left
wxPanel* leftPanel = new wxPanel(this, wxID_ANY); // creates the panel
leftPanel->SetBackgroundColour(lightColour); // sets colour
wxBoxSizer* leftSizer = new wxBoxSizer(wxVERTICAL); // creates sizer
int leftButtonIndex = 0;
for (std::string page : pagesMap) {
RoundedButton* _l_button = new RoundedButton(leftPanel, wxID_ANY, page, wxPoint(5, (5 + (30 * leftButtonIndex))), wxSize(170, 25), darkPurple);
_l_button->Bind(wxEVT_BUTTON, &AccountsFrame::OnButtonClicked, this);
leftButtonIndex++;
} // Left panel buttons
leftPanel->SetSizer(leftSizer); // sets sizer
// Right Panel
rightPanel = new wxPanel(this, wxID_ANY); // makes right panel
rightPanel->SetBackgroundColour(darkColour); // sets colour
wxBoxSizer* rightSizer = new wxBoxSizer(wxVERTICAL); // makes sizer
rightPanel->SetSizer(rightSizer); // sets sizer
// Add panels to horizontal sizer with proportion
horizontalSizer->Add(leftPanel, 30, wxEXPAND); // L
horizontalSizer->Add(rightPanel, 70, wxEXPAND); // R
mainSizer->Add(horizontalSizer, 1, wxEXPAND); // T
SetSizer(mainSizer); // sets main sizer
CreateStatusBar(); // debug bottom bar
Bind(wxEVT_CLOSE_WINDOW, &AccountsFrame::OnCloseWindow, this);
HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(107));
if (hIcon) {
wxIcon icon;
icon.CreateFromHICON(hIcon);
if (icon.IsOk()) {
SetIcon(icon);
}
DestroyIcon(hIcon);
}
instance = this;
}
// # ------------------------------------------------------------------------------------------ Events
void AccountsFrame::OnButtonClicked(wxCommandEvent& event) {
wxButton* button = dynamic_cast<wxButton*>(event.GetEventObject());
if (button) {} // no reg buttons used, this should never be called
else { // the only 2 things that call MainFrame::OnButtonClicked is wxButton and RoundedButton
RoundedButton* button = dynamic_cast<RoundedButton*>(event.GetEventObject());
wxString buttonText = button->GetNewLabel();
if (std::find(pagesMap.begin(), pagesMap.end(), buttonText.ToStdString()) != pagesMap.end()) { // if in pagesMap list
rightPanel->DestroyChildren();
LoadPageContent(buttonText.ToStdString());
}
else { // only possible to be called if: is inside of rightpanel/is logic, or I fucked up somewhere
for (std::string button_id : buttonMap) {
std::vector<std::string> button_id_split = RayUtils::split(button_id, "_");
std::string __button_id = ((std::string)button_id_split[0] + (std::string)button_id_split[1]); // turn button id from x_y to xy (i <3 c++)
if (button->GetId() == std::stoi(__button_id)) {
Logic(std::stoi(__button_id));
break;
}
}
}
}
}
void AccountsFrame::OnTextChanged(wxCommandEvent& event) {
wxTextCtrl* text = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
if (text) {}
}
void AccountsFrame::OnCloseWindow(wxCloseEvent& event) {
MainFrame::WindowClosed(MainFrame::WINDOWS::ACCOUNTS);
AccountsFrame::Destroy();
}
// # ------------------------------------------------------------------------------------------ Logic
void AccountsFrame::LoadPageContent(std::string page) {
if (page == "Home") {
wxStaticText* accountName = RayUtils::CreateCenteredText(rightPanel, 01, "RayLauncher - Accounts", 20, 20, true, RayUtils::Window::ACCOUNTS);
}
else if (page == "Exchange Code") {
wxStaticText* exchangeCode = RayUtils::CreateCenteredText(rightPanel, 11, "Exchange Code", 20, 20, true, RayUtils::Window::ACCOUNTS);
wxStaticText* exchangeCodeDesc = RayUtils::CreateCenteredText(rightPanel, 12, "Enter the code you received from the link", 60, 12, false, RayUtils::Window::ACCOUNTS);
exchangeCodeInput = new wxTextCtrl(rightPanel, 13, "", wxPoint(120, 103), wxSize(290, 20));
wxHyperlinkCtrl* exchangeCodeLink = RayUtils::CreateHyperlink(rightPanel, 14, "Get Code", "https://www.epicgames.com/id/api/redirect?clientId=af43dc71dd91452396fcdffbd7a8e8a9&responseType=code", wxPoint(10, 100), 16);
exchangeCodeLink->Bind(wxEVT_TEXT, &AccountsFrame::OnTextChanged, this);
RoundedButton* exchangeCodeButton = new RoundedButton(rightPanel, 15, "Login", wxPoint(120, 130), wxSize(290, 25), darkPurple);
exchangeCodeButton->Bind(wxEVT_BUTTON, &AccountsFrame::OnButtonClicked, this);
}
else {}
}
void AccountsFrame::Logic(int id) {
switch (id) {
case 15:
if (!(Web::Login((std::string)exchangeCodeInput->GetValue()) == "")) {
wxMessageBox("Exchange Code Invalid, try re-clicking the link\nIf the code is null, login first", "RayLauncher - Accounts", wxICON_ERROR);
exchangeCodeInput->SetValue("");
}
else {
exchangeCodeInput->SetValue("Account Added!");
}
break;
}
}