-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHackMailViewer.cpp
136 lines (120 loc) · 3.14 KB
/
HackMailViewer.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
//
// Created by epiphyllum on 22/04/27.
//
#include <iostream>
#include <conio.h>
#include "HackMailViewer.h"
#include "HacknetApplication.h"
#include "AsciiArt.h"
#include "Utility/Util.h"
#include "Utility/UiUtil.h"
void HackMailViewer::Render()
{
using namespace Util;
clearScreen();
// Title
setCursorPos(0, 0);
setColorAttr(BG_WHITE);
setColorAttr(FG_BLACK);
std::cout << " :: JMAIL ::";
clearLine(getCursorPos(), UIUtil::SIZE_ALL.width - getCursorPos().x);
setColorAttr(ATTR_NORMAL);
// Title Sender
setCursorPos(0, 1);
std::wcout << content->getEmailTitle();
setCursorPos(0, 2);
std::cout << "From: ";
std::wcout << content->getSender();
setCursorPos(0, 3);
std::cout << "To: Aiden Pearce";
setColorAttr(BG_LIGHT_BLUE);
clearLine(Coord(0, 4), UIUtil::SIZE_ALL.width);
setColorAttr(ATTR_NORMAL);
// Content
setCursorPos(0, 5);
std::wcout << content->getEmailContent();
// Operations
setCursorPos(0, UIUtil::SIZE_ALL.height - 1);
std::cout << "[ENTER / R] Reply [Q / ESC] Quit";
}
bool HackMailViewer::Exec()
{
content->setRead(true);
Render();
while (true)
{
switch (_getch())
{
case 13:
case 'r':
case 'R':
if (DoReply())
{
return true;
}
else
{
Render();
}
break;
case 'q':
case 'Q':
case 0x1B:
return false;
default:
break;
}
}
}
HackMailViewer::HackMailViewer(HackEmail *content, HacknetApplication *ref) : content(content), ref(ref)
{}
bool HackMailViewer::DoReply()
{
using namespace Util;
if (content->getMode() == MODE_NO_MISSION || content->isCompleted())
{
// return directly
return false;
}
clearScreen();
// Title
setCursorPos(0, 0);
setColorAttr(BG_WHITE);
setColorAttr(FG_BLACK);
std::cout << " :: REPLY MAIL ::";
clearLine(getCursorPos(), UIUtil::SIZE_ALL.width - getCursorPos().x);
setColorAttr(ATTR_NORMAL);
setCursorPos(10, 2);
std::string replyText;
if (content->getMode() == MODE_REPLY_MISSION)
{
std::cout << "Additional Information: ";
setCursorPos(10, 3);
std::getline(std::cin, replyText);
clearLine(Coord(10, 3), UIUtil::SIZE_ALL.width - 10);
clearLine(Coord(10, 2), UIUtil::SIZE_ALL.width - 10);
setCursorPos(10, 2);
}
// check
auto result = (ref->getCheckService().*(content->getCheckerHandler()))(replyText);
if (result)
{
content->setCompleted(true);
return true;
}
else
{
// show a failed box
AsciiArt warningLogo("ASCII/warning.ascii");
setColorAttr(FG_RED);
warningLogo.draw(Coord(64, 3));
setCursorPos(105, 25);
setColorAttr(FG_WHITE);
setColorAttr(BG_RED);
std::cout << "任务未完成";
setColorAttr(ATTR_NORMAL);
while (_kbhit()) _getch();
_getch();
return false;
}
}