-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConEditPlus.Helpers.pas
162 lines (142 loc) · 4.83 KB
/
ConEditPlus.Helpers.pas
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
152
153
154
155
156
157
158
159
160
161
162
//
// Helper functions, utilities, etc.
//
unit ConEditPlus.Helpers;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, System.StrUtils,
Conversation.Classes, VCL.Graphics;
// functions
function ValidateFName(const AString: string): Boolean;
function GetDPIAsRatio(): Single;
function GenerateRandomSuffix(): string;
function FormatConversationDetails(const Conversation: TConversation): string;
// procedures
procedure FilterEditInput(var aKey: Char);
procedure SetConversationEventsIdx(con: TConversation);
procedure ExtractRGB(aColor: TColor; out r, g, b: Byte);
implementation
function ValidateFName(const AString: string): Boolean;
begin
if (AString <> '') and
((CharInSet(AString[1], ['0'..'9'])) or
(Pos(' ', AString) > 0)) then
begin
Result := False;
Exit;
end;
// Ïðîâåðÿåì êàæäûé ñèìâîë
for var i := 1 to Length(AString) do
begin
if not CharInSet(AString[i], ['A'..'Z', 'a'..'z', '0'..'9', '_']) then
begin
Result := False;
Exit;
end;
end;
Result := True;
{ if (AString = '') or
(CharInSet(AString[1], ['0'..'9'])) or
(Pos(' ', AString) > 0) then
begin
Result := False;
Exit;
end;
// Ïðîâåðÿåì êàæäûé ñèìâîë
for var i := 1 to Length(AString) do
begin
if not CharInSet(AString[i], ['A'..'Z', 'a'..'z', '0'..'9', '_']) then
begin
Result := False;
Exit;
end;
end;
Result := True;
}
end;
function GetDPIAsRatio(): Single;
var
DC: HDC;
begin
DC := GetDC(0);
Result := GetDeviceCaps(DC, LOGPIXELSX) / 96.0;
ReleaseDC(0, DC);
end;
function GenerateRandomSuffix(): string;
begin
Randomize();
Result := '_';
for var i := 1 to 3 do
Result := Result + Chr(Ord('a') + Random(26));
end;
function FormatConversationDetails(const Conversation: TConversation): string;
begin
Result := Format('unknown0: %d'#13#10 +
'id: %d'#13#10 +
'conDescription: "%s"'#13#10 +
'conCreatedByDate: "%s"'#13#10 +
'conCreatedByName: "%s"'#13#10 +
'conModifiedByDate: "%s"'#13#10 +
'conModifiedByName: "%s"'#13#10 +
'conOwnerIndex: %d'#13#10 +
'conOwnerName: "%s"'#13#10 +
'bInfoLink: %s'#13#10 +
'conNotes: "%s"'#13#10 +
'bOnlyOnce: %s'#13#10 +
'bFirstPerson: %s'#13#10 +
'bNonInteract: %s'#13#10 +
'bRandomCamera: %s'#13#10 +
'bCanInterrupt: %s'#13#10 +
'bCannotInterrupt: %s'#13#10 +
'bPCBumps: %s'#13#10 +
'bPCFrobs: %s'#13#10 +
'bNPCSees: %s'#13#10 +
'bNPCEnters: %s'#13#10 +
'distance: %d',
[Conversation.unknown0,
Conversation.id,
Conversation.conDescription,
Conversation.conCreatedByDate,
Conversation.conCreatedByName,
Conversation.conModifiedByDate,
Conversation.conModifiedByName,
Conversation.conOwnerIndex,
Conversation.conOwnerName,
BoolToStr(Conversation.bInfoLink, True),
Conversation.conNotes,
BoolToStr(Conversation.bOnlyOnce, True),
BoolToStr(Conversation.bFirstPerson, True),
BoolToStr(Conversation.bNonInteract, True),
BoolToStr(Conversation.bRandomCamera, True),
BoolToStr(Conversation.bCanInterrupt, True),
BoolToStr(Conversation.bCannotInterrupt, True),
BoolToStr(Conversation.bPCBumps, True),
BoolToStr(Conversation.bPCFrobs, True),
BoolToStr(Conversation.bNPCSees, True),
BoolToStr(Conversation.bNPCEnters, True),
Conversation.distance]);
end;
procedure FilterEditInput(var aKey: Char);
begin
if CharInSet(aKey, ['A'..'Z', 'a'..'z', '0'..'9', '_', #8]) then
else
aKey := #0;
end;
procedure SetConversationEventsIdx(con: TConversation);
begin
var NewIndex := 0;
for var Event in con.Events do
begin
Event.EventIdx := NewIndex;
Event.unknown1 := Event.EventIdx + 1;
Inc(NewIndex);
end;
end;
procedure ExtractRGB(aColor: TColor; out r, g, b: Byte);
begin
var rgbColor := VCL.Graphics.ColorToRGB(aColor);
r := Byte(rgbColor);
g := Byte(rgbColor shr 8);
b := Byte(rgbColor shr 16);
end;
end.