mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 13:55:36 +03:00
* May 18th, 2005: Starting to develop AMXX-Edit v2 as a kind of open source
This commit is contained in:
parent
3642cedd2b
commit
dd6abc5487
38
editor/editor2/AMXX_Edit_v2.cfg
Executable file
38
editor/editor2/AMXX_Edit_v2.cfg
Executable file
@ -0,0 +1,38 @@
|
||||
-$A8
|
||||
-$B-
|
||||
-$C+
|
||||
-$D+
|
||||
-$E-
|
||||
-$F-
|
||||
-$G+
|
||||
-$H+
|
||||
-$I+
|
||||
-$J-
|
||||
-$K-
|
||||
-$L+
|
||||
-$M-
|
||||
-$N+
|
||||
-$O+
|
||||
-$P+
|
||||
-$Q-
|
||||
-$R-
|
||||
-$S-
|
||||
-$T-
|
||||
-$U-
|
||||
-$V+
|
||||
-$W-
|
||||
-$X+
|
||||
-$YD
|
||||
-$Z1
|
||||
-cg
|
||||
-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
|
||||
-H+
|
||||
-W+
|
||||
-M
|
||||
-$M16384,1048576
|
||||
-K$00400000
|
||||
-LE"c:\programme\borland\delphi7\Projects\Bpl"
|
||||
-LN"c:\programme\borland\delphi7\Projects\Bpl"
|
||||
-w-UNSAFE_TYPE
|
||||
-w-UNSAFE_CODE
|
||||
-w-UNSAFE_CAST
|
136
editor/editor2/AMXX_Edit_v2.dof
Executable file
136
editor/editor2/AMXX_Edit_v2.dof
Executable file
@ -0,0 +1,136 @@
|
||||
[FileVersion]
|
||||
Version=7.0
|
||||
[Compiler]
|
||||
A=8
|
||||
B=0
|
||||
C=1
|
||||
D=1
|
||||
E=0
|
||||
F=0
|
||||
G=1
|
||||
H=1
|
||||
I=1
|
||||
J=0
|
||||
K=0
|
||||
L=1
|
||||
M=0
|
||||
N=1
|
||||
O=1
|
||||
P=1
|
||||
Q=0
|
||||
R=0
|
||||
S=0
|
||||
T=0
|
||||
U=0
|
||||
V=1
|
||||
W=0
|
||||
X=1
|
||||
Y=1
|
||||
Z=1
|
||||
ShowHints=1
|
||||
ShowWarnings=1
|
||||
UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
|
||||
NamespacePrefix=
|
||||
SymbolDeprecated=1
|
||||
SymbolLibrary=1
|
||||
SymbolPlatform=1
|
||||
UnitLibrary=1
|
||||
UnitPlatform=1
|
||||
UnitDeprecated=1
|
||||
HResultCompat=1
|
||||
HidingMember=1
|
||||
HiddenVirtual=1
|
||||
Garbage=1
|
||||
BoundsError=1
|
||||
ZeroNilCompat=1
|
||||
StringConstTruncated=1
|
||||
ForLoopVarVarPar=1
|
||||
TypedConstVarPar=1
|
||||
AsgToTypedConst=1
|
||||
CaseLabelRange=1
|
||||
ForVariable=1
|
||||
ConstructingAbstract=1
|
||||
ComparisonFalse=1
|
||||
ComparisonTrue=1
|
||||
ComparingSignedUnsigned=1
|
||||
CombiningSignedUnsigned=1
|
||||
UnsupportedConstruct=1
|
||||
FileOpen=1
|
||||
FileOpenUnitSrc=1
|
||||
BadGlobalSymbol=1
|
||||
DuplicateConstructorDestructor=1
|
||||
InvalidDirective=1
|
||||
PackageNoLink=1
|
||||
PackageThreadVar=1
|
||||
ImplicitImport=1
|
||||
HPPEMITIgnored=1
|
||||
NoRetVal=1
|
||||
UseBeforeDef=1
|
||||
ForLoopVarUndef=1
|
||||
UnitNameMismatch=1
|
||||
NoCFGFileFound=1
|
||||
MessageDirective=1
|
||||
ImplicitVariants=1
|
||||
UnicodeToLocale=1
|
||||
LocaleToUnicode=1
|
||||
ImagebaseMultiple=1
|
||||
SuspiciousTypecast=1
|
||||
PrivatePropAccessor=1
|
||||
UnsafeType=0
|
||||
UnsafeCode=0
|
||||
UnsafeCast=0
|
||||
[Linker]
|
||||
MapFile=0
|
||||
OutputObjs=0
|
||||
ConsoleApp=1
|
||||
DebugInfo=0
|
||||
RemoteSymbols=0
|
||||
MinStackSize=16384
|
||||
MaxStackSize=1048576
|
||||
ImageBase=4194304
|
||||
ExeDescription=
|
||||
[Directories]
|
||||
OutputDir=
|
||||
UnitOutputDir=
|
||||
PackageDLLOutputDir=
|
||||
PackageDCPOutputDir=
|
||||
SearchPath=
|
||||
Packages=vcl;rtl;vclx;vclie;xmlrtl;inetdbbde;inet;inetdbxpress;VclSmp;dbrtl;dbexpress;vcldb;dsnap;dbxcds;inetdb;bdertl;vcldbx;adortl;teeui;teedb;tee;ibxpress;visualclx;visualdbclx;vclactnband;vclshlctrls;IntrawebDB_50_70;Intraweb_50_70;Rave50CLX;Rave50VCL;dclOffice2k;JvStdCtrlsD7R;JvAppFrmD7R;JvCoreD7R;JvBandsD7R;JvBDED7R;JvDBD7R;JvDlgsD7R;JvCmpD7R;JvCryptD7R;JvCtrlsD7R;JvCustomD7R;JvDockingD7R;JvDotNetCtrlsD7R;JvEDID7R;qrpt;JvGlobusD7R;JvHMID7R;JvInspectorD7R;JvInterpreterD7R;JvJansD7R;JvManagedThreadsD7R;JvMMD7R;JvNetD7R;JvPageCompsD7R;JvPluginD7R;JvPrintPreviewD7R;JvSystemD7R;JvTimeFrameworkD7R;JvUIBD7R;JvValidatorsD7R;JvWizardD7R;JvXPCtrlsD7R;Indy70;FlatStyle_D5;CrossKylix;DJcl;DelphiX_for7
|
||||
Conditionals=
|
||||
DebugSourceDirs=
|
||||
UsePackages=0
|
||||
[Parameters]
|
||||
RunParams=
|
||||
HostApplication=
|
||||
Launcher=
|
||||
UseLauncher=0
|
||||
DebugCWD=
|
||||
[Language]
|
||||
ActiveLang=
|
||||
ProjectLang=
|
||||
RootDir=
|
||||
[Version Info]
|
||||
IncludeVerInfo=0
|
||||
AutoIncBuild=0
|
||||
MajorVer=1
|
||||
MinorVer=0
|
||||
Release=0
|
||||
Build=0
|
||||
Debug=0
|
||||
PreRelease=0
|
||||
Special=0
|
||||
Private=0
|
||||
DLL=0
|
||||
Locale=1031
|
||||
CodePage=1252
|
||||
[Version Info Keys]
|
||||
CompanyName=AMX Mod X
|
||||
FileDescription=
|
||||
FileVersion=1.0.0.0
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=1.0.0.0
|
||||
Comments=
|
72
editor/editor2/AMXX_Edit_v2.dpr
Executable file
72
editor/editor2/AMXX_Edit_v2.dpr
Executable file
@ -0,0 +1,72 @@
|
||||
program AMXX_Edit_v2;
|
||||
|
||||
{
|
||||
AMXX-Edit v2
|
||||
|
||||
Editor for AMX Mod X scripts, coded by Basic-Master
|
||||
© by AMX Mod X Development Team
|
||||
|
||||
This application uses the following components:
|
||||
|
||||
DelphiSci: delphisci.sourceforge.net (based on Scintilla library: scintilla.sourceforge.net)
|
||||
FlatStyle by Maik Porkert (found on www.torry.net)
|
||||
GlyFX Icons: www.glyfx.com (using GlyFX Icon Pack of Delphi 2005 PE)
|
||||
Modified CorelButton (see CorelButton.pas, original by ConquerWare)
|
||||
Indy 9 Socket Components: www.indyproject.org
|
||||
|
||||
AMXX-Edit v2 is published under GNU General Public License and comes
|
||||
with ABSOLUTELY NO WARRANTY (see GPL.txt for more information)
|
||||
}
|
||||
|
||||
|
||||
uses
|
||||
Forms,
|
||||
Windows,
|
||||
Classes,
|
||||
SysUtils,
|
||||
UnitfrmMain in 'UnitfrmMain.pas' {frmMain},
|
||||
UnitfrmOptions in 'UnitfrmOptions.pas' {frmSettings},
|
||||
UnitfrmDebug in 'UnitfrmDebug.pas' {frmDebug},
|
||||
UnitFunc in 'UnitFunc.pas',
|
||||
UnitfrmAbout in 'UnitfrmAbout.pas' {frmAbout},
|
||||
UnitfrmGoToLine in 'UnitfrmGoToLine.pas' {frmGoToLine},
|
||||
UnitfrmSaveDialog in 'UnitfrmSaveDialog.pas' {frmSaveDialog},
|
||||
UnitTextAnalyze in 'UnitTextAnalyze.pas',
|
||||
UnitfrmMenuMaker in 'UnitfrmMenuMaker.pas' {frmMenuMaker},
|
||||
UnitAddMenu in 'UnitAddMenu.pas',
|
||||
UnitfrmSelectMenu in 'UnitfrmSelectMenu.pas' {frmSelectMenu},
|
||||
UnitHowToMakePlayerMenu in 'UnitHowToMakePlayerMenu.pas' {frmHowToMakePlayerMenu},
|
||||
UnitfrmSockets in 'UnitfrmSockets.pas' {frmSocketTerminal},
|
||||
UnitReadThread in 'UnitReadThread.pas',
|
||||
UnitfrmLoopGenerator in 'UnitfrmLoopGenerator.pas' {frmLoopGenerator};
|
||||
|
||||
{$R *.res}
|
||||
|
||||
var i: integer;
|
||||
begin
|
||||
if (FindWindow('TfrmMain', 'AMXX-Edit v2') <> 0) then begin // Don't allow 2 starts...
|
||||
for i := 1 to ParamCount do begin
|
||||
if FileExists(ParamStr(i)) then
|
||||
SendOpen(ParamStr(i)); // ... and send open message to the other app
|
||||
end;
|
||||
ShowWindow(FindWindow('TfrmMain', 'AMXX-Edit v2'), SW_SHOW);
|
||||
SetForegroundWindow(FindWindow('TfrmMain', 'AMXX-Edit v2'));
|
||||
exit;
|
||||
end;
|
||||
Application.Initialize;
|
||||
Application.Title := 'AMXX-Edit v2';
|
||||
Application.CreateForm(TfrmMain, frmMain);
|
||||
Application.CreateForm(TfrmSettings, frmSettings);
|
||||
Application.CreateForm(TfrmDebug, frmDebug);
|
||||
Application.CreateForm(TfrmAbout, frmAbout);
|
||||
Application.CreateForm(TfrmGoToLine, frmGoToLine);
|
||||
Application.CreateForm(TfrmSaveDialog, frmSaveDialog);
|
||||
Application.CreateForm(TfrmMenuMaker, frmMenuMaker);
|
||||
Application.CreateForm(TfrmSelectMenu, frmSelectMenu);
|
||||
Application.CreateForm(TfrmHowToMakePlayerMenu, frmHowToMakePlayerMenu);
|
||||
Application.CreateForm(TfrmSocketTerminal, frmSocketTerminal);
|
||||
Application.CreateForm(TfrmLoopGenerator, frmLoopGenerator);
|
||||
Load;
|
||||
Apply;
|
||||
Application.Run;
|
||||
end.
|
436
editor/editor2/UnitAddMenu.pas
Executable file
436
editor/editor2/UnitAddMenu.pas
Executable file
@ -0,0 +1,436 @@
|
||||
unit UnitAddMenu;
|
||||
|
||||
interface
|
||||
|
||||
uses SysUtils, Classes, Graphics, Dialogs, Windows;
|
||||
|
||||
function AddMenu: Boolean;
|
||||
function AddPlayerMenu: Boolean;
|
||||
function GetFirst(eStart: String; eSearchMain: Boolean): Integer;
|
||||
function GetLast(eStart: String; eSearchMain: Boolean): Integer;
|
||||
function AddIfDoesntExist(eInclude: String): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMenuMaker, UnitfrmMain, UnitTextAnalyze, UnitFunc;
|
||||
|
||||
{ Normal Menu }
|
||||
|
||||
function AddMenu: Boolean;
|
||||
var eColoredMenu, DefinedKeys: String;
|
||||
i: integer;
|
||||
eStr: TStringList;
|
||||
begin
|
||||
Result := GetFirst('public Show' + frmMenuMaker.txtMenuName.Text, True) = -1;
|
||||
if not Result then
|
||||
exit;
|
||||
|
||||
eStr := TStringList.Create;
|
||||
{ Transform text }
|
||||
eColoredMenu := frmMenuMaker.GetColoredMenu;
|
||||
if frmMenuMaker.chkAppendOnlyMenuText.Checked then begin
|
||||
frmMain.sciEditor.Lines.Add('// Created menu: ' + eColoredMenu);
|
||||
exit;
|
||||
end;
|
||||
{ Add functions }
|
||||
eStr.Add(Format('public Show%s(id) {', [frmMenuMaker.txtMenuName.Text]));
|
||||
eStr.Add(' show_menu(id, Keys' + frmMenuMaker.txtMenuName.Text + ', "' + eColoredMenu + '", -1, "' + frmMenuMaker.txtMenuName.Text + '")');
|
||||
if frmMenuMaker.chkAddComment.Checked then
|
||||
eStr[eStr.Count -1] := eStr[eStr.Count -1] + ' // Display menu';
|
||||
eStr.Add('}');
|
||||
eStr.Add('');
|
||||
eStr.Add('public Pressed' + frmMenuMaker.txtMenuName.Text + '(id, key) {');
|
||||
if frmMenuMaker.chkAddComment.Checked then begin
|
||||
eStr.Add(' /* Menu:');
|
||||
for i := 0 to frmMenuMaker.rtfEditor.Lines.Count -1 do
|
||||
eStr.Add(' * ' + frmMenuMaker.rtfEditor.Lines[i]);
|
||||
eStr.Add(' */');
|
||||
eStr.Add('');
|
||||
end;
|
||||
eStr.Add(' switch (key) {');
|
||||
DefinedKeys := '';
|
||||
for i := 1 to Length(frmMenuMaker.txtKeys.Text) do begin
|
||||
if frmMenuMaker.txtKeys.Text[i] = '0' then begin
|
||||
DefinedKeys := DefinedKeys + '|(1<<9)';
|
||||
if frmMenuMaker.chkAddComment.Checked then
|
||||
eStr.Add(' case 9: { // 0')
|
||||
else
|
||||
eStr.Add(' case 9: {');
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' }');
|
||||
end
|
||||
else begin
|
||||
DefinedKeys := DefinedKeys + '|(1<<' + IntToStr(StrToInt(frmMenuMaker.txtKeys.Text[i]) -1) + ')';
|
||||
if frmMenuMaker.chkAddComment.Checked then
|
||||
eStr.Add(' case ' + IntToStr(StrToInt(frmMenuMaker.txtKeys.Text[i]) -1) + ': { // ' + frmMenuMaker.txtKeys.Text[i])
|
||||
else
|
||||
eStr.Add(' case ' + IntToStr(StrToInt(frmMenuMaker.txtKeys.Text[i]) -1) + ': {');
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' }');
|
||||
end;
|
||||
end;
|
||||
Delete(DefinedKeys, 1, 1);
|
||||
if frmMenuMaker.chkAddComment.Checked then
|
||||
DefinedKeys := DefinedKeys + ' // Keys: ' + frmMenuMaker.txtKeys.Text;
|
||||
eStr.Add(' }');
|
||||
eStr.Add('}');
|
||||
// Insert
|
||||
AddIfDoesntExist('amxmodx');
|
||||
i := GetFirst('#define', True) +2;
|
||||
if i = 1 then
|
||||
i := GetFirst('#include', True) +2;
|
||||
if i = 1 then
|
||||
i := 0;
|
||||
|
||||
frmMain.sciEditor.Lines.Insert(i, Format('#define Keys%s %s', [frmMenuMaker.txtMenuName.Text, DefinedKeys]));
|
||||
frmMain.sciEditor.Lines.Text := frmMain.sciEditor.Lines.Text + #13 + eStr.Text;
|
||||
if frmMenuMaker.chkRegisterMenuCommand.Checked then begin
|
||||
i := GetFirst('register_plugin', True) +2;
|
||||
if i = 1 then
|
||||
i := GetFirst('public plugin_init()', True) +2;
|
||||
if i = 1 then begin
|
||||
eStr.Clear;
|
||||
eStr.Add('public plugin_init() {');
|
||||
eStr.Add(' register_menucmd(register_menuid("' + frmMenuMaker.txtMenuName.Text + '"), Keys' + frmMenuMaker.txtMenuName.Text + ', "Pressed' + frmMenuMaker.txtMenuName.Text + '")');
|
||||
eStr.Add('}');
|
||||
frmMain.sciEditor.Lines.Insert(GetFirst('#define', True) +2, '');
|
||||
frmMain.sciEditor.Lines.Insert(GetFirst('#define', True) +3, eStr.Text);
|
||||
end
|
||||
else
|
||||
frmMain.sciEditor.Lines.Insert(i, ' register_menucmd(register_menuid("' + frmMenuMaker.txtMenuName.Text + '"), Keys' + frmMenuMaker.txtMenuName.Text + ', "Pressed' + frmMenuMaker.txtMenuName.Text + '")');
|
||||
end;
|
||||
frmMain.SetModified;
|
||||
eStr.Free;
|
||||
UpdateList(frmMain.sciEditor.Lines.Text);
|
||||
end;
|
||||
|
||||
{ Player Menu }
|
||||
|
||||
function AddPlayerMenu: Boolean;
|
||||
function PrepareItem(eItem: String; eDisabled: Boolean): String; // Remove colors etc.
|
||||
begin
|
||||
eItem := StringReplace(eItem, '\w', '', [rfReplaceAll, rfIgnoreCase]);
|
||||
eItem := StringReplace(eItem, '\y', '', [rfReplaceAll, rfIgnoreCase]);
|
||||
eItem := StringReplace(eItem, '\r', '', [rfReplaceAll, rfIgnoreCase]);
|
||||
eItem := StringReplace(eItem, '\d', '', [rfReplaceAll, rfIgnoreCase]);
|
||||
eItem := StringReplace(eItem, '%n', '%i', [rfIgnoreCase]);
|
||||
eItem := StringReplace(eItem, '%v', '%s', [rfIgnoreCase]);
|
||||
if eDisabled then
|
||||
eItem := '\d' + eItem
|
||||
else
|
||||
eItem := '\w' + eItem;
|
||||
Result := eItem + '^n';
|
||||
end;
|
||||
|
||||
var i: integer;
|
||||
eStr: TStringList;
|
||||
ePlayersFrom, ePlayersTo: Integer; // Players
|
||||
ePlayerFormat: String;
|
||||
eNext, eExit: Integer; // Next and Back/Exit
|
||||
eNextText, eBackText, eExitText: String;
|
||||
eCurLineIndex: Integer; // Current ..
|
||||
eCurLine: String; // .. line
|
||||
DefinedKeys: String; // Action Keys
|
||||
begin
|
||||
Result := GetFirst('public Show' + frmMenuMaker.txtMenu.Text, True) = -1;
|
||||
if not Result then begin
|
||||
MessageBox(frmMenuMaker.Handle, 'Menu already exists. Please choose another name.', 'Warning', MB_ICONWARNING);
|
||||
exit;
|
||||
end;
|
||||
|
||||
{
|
||||
Kick player
|
||||
|
||||
$players(1,8,%n. %v)
|
||||
$next(9,9. Next)
|
||||
|
||||
$exitorback(0, 0. Exit, 0. Back)
|
||||
}
|
||||
|
||||
eCurLine := frmMenuMaker.rtfEditor.Lines[0];
|
||||
eCurLineIndex := 0;
|
||||
eNext := -1;
|
||||
eExit := -1;
|
||||
eStr := TStringList.Create;
|
||||
// Prepare Values
|
||||
try
|
||||
{ Players }
|
||||
eCurLineIndex := GetFirst('$players', False);
|
||||
eCurLine := frmMenuMaker.rtfEditor.Lines[eCurLineIndex];
|
||||
ePlayersFrom := StrToInt(Between(LowerCase(Trim(eCurLine)), '$players(', ','));
|
||||
ePlayersTo := StrToInt(Between(Trim(LowerCase(eCurLine)), ',', ','));
|
||||
while CountChars(eCurLine, ',') > 1 do
|
||||
Delete(eCurLine, 1, 1);
|
||||
ePlayerFormat := Between(LowerCase(eCurLine), ',', ')');
|
||||
{ Next }
|
||||
if GetFirst('$next', False) <> -1 then begin
|
||||
eCurLineIndex := GetFirst('$next', False);
|
||||
eCurLine := frmMenuMaker.rtfEditor.Lines[eCurLineIndex];
|
||||
eNext := StrToInt(Trim(Between(eCurLine, '(', ',')));
|
||||
eNextText := Between(eCurLine, ',', ')');
|
||||
end;
|
||||
{ Exit or Back }
|
||||
if GetFirst('$exitorback', False) <> -1 then begin
|
||||
eCurLineIndex := GetFirst('$exitorback', False);
|
||||
eCurLine := frmMenuMaker.rtfEditor.Lines[eCurLineIndex];
|
||||
eExit := StrToInt(Trim(Between(eCurLine, '(', ',')));
|
||||
eExitText := Between(eCurLine, ',', ',');
|
||||
while CountChars(eCurLine, ',') > 1 do
|
||||
Delete(eCurLine, 1, 1);
|
||||
eBackText := Between(eCurLine, ',', ')');
|
||||
end;
|
||||
except
|
||||
MessageBox(frmMenuMaker.Handle, PChar(Format('Syntax error at line %s: ' + #13 + '%s', [IntToStr(eCurLineIndex +1), frmMenuMaker.rtfEditor.Lines[eCurLineIndex]])), 'Error', MB_ICONERROR);
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
// Check Keys
|
||||
{ Players }
|
||||
if (ePlayersFrom < 0) or (ePlayersFrom > ePlayersTo) then begin
|
||||
MessageBox(frmMenuMaker.Handle, 'Invalid start key (players)', 'Warning', MB_ICONWARNING);
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
if (ePlayersTo < 0) or (ePlayersTo > 9) then begin
|
||||
MessageBox(frmMenuMaker.Handle, 'Invalid stop key (players)', 'Warning', MB_ICONWARNING);
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
{ Next, Exit and Custom keys}
|
||||
eCurLine := '';
|
||||
for i := ePlayersFrom to ePlayersTo do
|
||||
eCurLine := eCurLine + IntToStr(i);
|
||||
|
||||
if Pos(IntToStr(eNext), eCurLine) > 0 then begin
|
||||
MessageBox(frmMenuMaker.Handle, PChar(Format('"Next" key already in use (%s). Delete it or choose another one and try again.', [IntToStr(eNext)])), 'Warning', MB_ICONWARNING);
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
if Pos(IntToStr(eExit), eCurLine) > 0 then begin
|
||||
MessageBox(frmMenuMaker.Handle, PChar(Format('"Exit" key already in use (%s). Delete it or choose another one and try again.', [IntToStr(eExit)])), 'Warning', MB_ICONWARNING);
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
eCurLine := eCurLine + IntToStr(eNext);
|
||||
eCurLine := eCurLine + IntToStr(eExit);
|
||||
// Insert Code
|
||||
try
|
||||
{ Includes }
|
||||
AddIfDoesntExist('amxmodx');
|
||||
AddIfDoesntExist('amxmisc');
|
||||
{ Define Keys }
|
||||
DefinedKeys := '';
|
||||
if Length(eCurLine) <> 0 then begin
|
||||
for i := 1 to Length(eCurLine) do begin
|
||||
if eCurLine[i] = '0' then
|
||||
DefinedKeys := DefinedKeys + '|(1<<9)'
|
||||
else begin
|
||||
eCurLine[i] := IntToStr(StrToInt(eCurLine[i]) -1)[1];
|
||||
DefinedKeys := DefinedKeys + '|(1<<' + eCurLine[i] + ')';
|
||||
end;
|
||||
end;
|
||||
Delete(DefinedKeys, 1, 1);
|
||||
end;
|
||||
i := GetLast('#define', True) +2;
|
||||
if i = 1 then
|
||||
i := GetLast('#include', True) +2;
|
||||
if i = 1 then
|
||||
i := 0;
|
||||
frmMain.sciEditor.Lines.Insert(i, Format('#define Keys%s %s', [frmMenuMaker.txtMenu.Text, DefinedKeys]));
|
||||
frmMain.sciEditor.Lines.Insert(i +1, 'new MenuPos' + frmMenuMaker.txtMenu.Text);
|
||||
frmMain.sciEditor.Lines.Insert(i +2, 'new MenuPlayers' + frmMenuMAker.txtMenu.Text + '[32]');
|
||||
{ Register }
|
||||
i := GetFirst('register_plugin', True) +2;
|
||||
if i = 1 then
|
||||
i := GetFirst('public plugin_init()', True) +2;
|
||||
if i = 1 then begin
|
||||
eStr.Clear;
|
||||
eStr.Add('public plugin_init() {');
|
||||
eStr.Add(' register_menucmd(register_menuid("' + frmMenuMaker.txtMenu.Text + '"), Keys' + frmMenuMaker.txtMenu.Text + ', "Pressed' + frmMenuMaker.txtMenu.Text + '")');
|
||||
eStr.Add('}');
|
||||
frmMain.sciEditor.Lines.Insert(GetFirst('#define', True) +2, '');
|
||||
frmMain.sciEditor.Lines.Insert(GetFirst('#define', True) +3, eStr.Text);
|
||||
end
|
||||
else
|
||||
frmMain.sciEditor.Lines.Insert(i, ' register_menucmd(register_menuid("' + frmMenuMaker.txtMenu.Text + '"), Keys' + frmMenuMaker.txtMenu.Text + ', "Pressed' + frmMenuMaker.txtMenu.Text + '")');
|
||||
{ Show Menu Functions (thx to xeroblood for code example) }
|
||||
eStr.Clear;
|
||||
eStr.Add('public Show' + frmMenuMaker.txtMenu.Text + '(id) {');
|
||||
eStr.Add(' ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, MenuPos' + frmMenuMaker.txtMenu.Text + ' = 0)');
|
||||
eStr.Add(' return PLUGIN_HANDLED');
|
||||
eStr.Add('}');
|
||||
eStr.Add('');
|
||||
eStr.Add('public ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, position) {');
|
||||
if frmMenuMaker.chkComments.Checked then
|
||||
eStr.Add(' // Menu stuff //');
|
||||
eStr.Add(' if (position < 0) { return 0; }');
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' new i, k');
|
||||
eStr.Add(' new MenuBody[255]');
|
||||
eStr.Add(' new CurrentKey = ' + IntToStr(ePlayersFrom -1));
|
||||
eStr.Add(' new Start = position * ' + IntToStr(ePlayersTo - ePlayersFrom));
|
||||
eStr.Add(' new Num');
|
||||
eStr.Add(' new UserName[32]');
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' get_players(MenuPlayers' + frmMenuMaker.txtMenu.Text + ', Num)');
|
||||
eStr.Add(' if (Start >= Num) { Start = position = MenuPos' + frmMenuMaker.txtMenu.Text + ' = 0; }');
|
||||
eCurLine := frmMenuMaker.GetColoredMenu;
|
||||
eCurLine := Copy(eCurLine, 1, Pos('$players', eCurLine) -3);
|
||||
Insert('\R%d/%d^n\w', eCurLine, Pos('^n', eCurLine));
|
||||
eStr.Add(' new Len = format(MenuBody, 255, "' + eCurLine + '", position+1, (Num / ' + IntToStr(ePlayersTo - ePlayersFrom) + ' + ((Num % ' + IntToStr(ePlayersTo - ePlayersFrom) + ') ? 1 : 0 )) )');
|
||||
eStr.Add(' new End = Start + ' + IntToStr(ePlayersTo - ePlayersFrom));
|
||||
if eExit = 0 then
|
||||
eStr.Add(' new Keys = (1<<9)')
|
||||
else
|
||||
eStr.Add(' new Keys = (1<<' + IntToStr(eExit -1) + ')');
|
||||
eStr.Add(' if (End > Num) { End = Num; }');
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' for(i=Start;i<End;i++) {');
|
||||
eStr.Add(' k = MenuPlayers' + frmMenuMaker.txtMenu.Text + '[i]');
|
||||
eStr.Add(' get_user_name(k, UserName, 31)');
|
||||
// Any conditions?
|
||||
if (frmMenuMaker.chkImmunity.Checked) and (frmMenuMaker.chkAlive.Checked) then
|
||||
eStr.Add(' if ((get_user_flags(k) & ADMIN_IMMUNITY) || !is_user_alive(k)) {')
|
||||
else if (frmMenuMaker.chkImmunity.Checked) then
|
||||
eStr.Add(' if (get_user_flags(k) & ADMIN_IMMUNITY) {')
|
||||
else if (frmMenuMaker.chkAlive.Checked) then
|
||||
eStr.Add(' if (!is_user_alive(k)) {');
|
||||
if (frmMenuMaker.chkImmunity.Checked) or (frmMenuMaker.chkAlive.Checked) then begin
|
||||
eStr.Add(' CurrentKey++');
|
||||
eStr.Add(' Len += format(MenuBody[Len], (255-Len), "' + PrepareItem(ePlayerFormat, True) + '", CurrentKey, UserName)');
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' else {');
|
||||
eStr.Add(' Keys |= (1<<CurrentKey++)');
|
||||
eStr.Add(' Len += format(MenuBody[Len], (255-Len), "' + PrepareItem(ePlayerFormat, False) + '", CurrentKey, UserName)');
|
||||
eStr.Add(' }');
|
||||
end
|
||||
else begin
|
||||
eStr.Add(' Keys |= (i<<CurrentKey++)');
|
||||
eStr.Add(' Len += format(MenuBody[Len], (255-Len), "' + PrepareItem(ePlayerFormat, False) + '", CurrentKey, UserName)');
|
||||
end;
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' if (End != Num) {');
|
||||
eStr.Add(' format(MenuBody[Len], (255-Len), "^n\w' + eNextText + '^n%s", position ? "\w' + eBackText + '" : "\w' + eExitText + '")');
|
||||
eStr.Add(' Keys |= (1<<' + IntToStr(eNext -1) + ')');
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' else {');
|
||||
eStr.Add(' format(MenuBody[Len], (255-Len), "^n%s", position ? "\w' + eBackText + '" : "\w' + eExitText + '")');
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' show_menu(id, Keys, MenuBody, -1)');
|
||||
eStr.Add(' return 0');
|
||||
eStr.Add('}');
|
||||
eStr.Add('');
|
||||
eStr.Add('public Pressed' + frmMenuMaker.txtMenu.Text + '(id, key) {');
|
||||
eStr.Add(' switch (key) {');
|
||||
if frmMenuMaker.chkComments.Checked then begin
|
||||
if eNext <> 0 then
|
||||
eStr.Add(' case ' + IntToStr(eNext -1) + ': ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, ++MenuPos' + frmMenuMaker.txtMenu.Text + ') // More Option')
|
||||
else
|
||||
eStr.Add(' case 9: ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, ++MenuPos' + frmMenuMaker.txtMenu.Text + ') // More Option');
|
||||
|
||||
if eExit <> 0 then
|
||||
eStr.Add(' case ' + IntToStr(eExit -1) + ': ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, --MenuPos' + frmMenuMaker.txtMenu.Text + ') // Back Option')
|
||||
else
|
||||
eStr.Add(' case 9: ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, --MenuPos' + frmMenuMaker.txtMenu.Text + ') // Back Option');
|
||||
end
|
||||
else begin
|
||||
if eNext <> 0 then
|
||||
eStr.Add(' case ' + IntToStr(eNext -1) + ': ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, ++MenuPos' + frmMenuMaker.txtMenu.Text + ')')
|
||||
else
|
||||
eStr.Add(' case 9: ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, ++MenuPos' + frmMenuMaker.txtMenu.Text + ')');
|
||||
if eExit <> 0 then
|
||||
eStr.Add(' case ' + IntToStr(eExit -1) + ': ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, --MenuPos' + frmMenuMaker.txtMenu.Text + ')')
|
||||
else
|
||||
eStr.Add(' case 9: ShowMenu' + frmMenuMaker.txtMenu.Text + '(id, --MenuPos' + frmMenuMaker.txtMenu.Text + ')');
|
||||
end;
|
||||
eStr.Add(' default: {');
|
||||
if frmMenuMaker.chkComments.Checked then
|
||||
eStr.Add(' // Get User ID and Username');
|
||||
eStr.Add(' new PlayerID = MenuPlayers' + frmMenuMaker.txtMenu.Text + '[MenuPos' + frmMenuMaker.txtMenu.Text + ' * ' + IntToStr(ePlayersTo - ePlayersFrom) + ' + key]');
|
||||
eStr.Add(' new UserName[32]');
|
||||
eStr.Add(' get_user_name(PlayerID, UserName, 31)');
|
||||
if frmMenuMaker.chkComments.Checked then
|
||||
eStr.Add(' // Do actions here')
|
||||
else
|
||||
eStr.Add(' ');
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' }');
|
||||
eStr.Add(' return PLUGIN_HANDLED');
|
||||
eStr.Add('}');
|
||||
frmMain.sciEditor.Lines.Text := frmMain.sciEditor.Lines.Text + #13 + eStr.Text;
|
||||
except
|
||||
MessageBox(frmMenuMaker.Handle, PChar('An error occured while inserting code!'), 'Warning', MB_ICONWARNING);
|
||||
end;
|
||||
frmMain.SetModified;
|
||||
eStr.Free;
|
||||
end;
|
||||
|
||||
{ Functions }
|
||||
|
||||
function GetFirst(eStart: String; eSearchMain: Boolean): Integer;
|
||||
var i: integer;
|
||||
begin
|
||||
eStart := LowerCase(Trim(eStart));
|
||||
Result := -1;
|
||||
if eSearchMain then begin
|
||||
for i := 0 to frmMain.sciEditor.Lines.Count -1 do begin
|
||||
if Pos(eStart, LowerCase(Trim(frmMain.sciEditor.Lines[i]))) = 1 then begin
|
||||
Result := i;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
for i := 0 to frmMenuMaker.rtfEditor.Lines.Count -1 do begin
|
||||
if Pos(eStart, LowerCase(Trim(frmMenuMaker.rtfEditor.Lines[i]))) = 1 then begin
|
||||
Result := i;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function GetLast(eStart: String; eSearchMain: Boolean): Integer;
|
||||
var i: integer;
|
||||
begin
|
||||
eStart := LowerCase(Trim(eStart));
|
||||
Result := -1;
|
||||
if eSearchMain then begin
|
||||
for i := 0 to frmMain.sciEditor.Lines.Count -1 do begin
|
||||
if Pos(eStart, LowerCase(Trim(frmMain.sciEditor.Lines[i]))) = 1 then
|
||||
Result := i;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
for i := 0 to frmMenuMaker.rtfEditor.Lines.Count -1 do begin
|
||||
if Pos(eStart, LowerCase(Trim(frmMenuMaker.rtfEditor.Lines[i]))) = 1 then
|
||||
Result := i;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function AddIfDoesntExist(eInclude: String): Boolean;
|
||||
var i: integer;
|
||||
eLine: String;
|
||||
begin
|
||||
Result := True;
|
||||
eInclude := RemoveSpaces(LowerCase(eInclude));
|
||||
for i := 0 to frmMain.sciEditor.Lines.Count -1 do begin
|
||||
eLine := LowerCase(RemoveSpaces(frmMain.sciEditor.Lines[i]));
|
||||
eLine := StringReplace(eLine, '<', '', [rfReplaceAll]);
|
||||
eLine := StringReplace(eLine, '>', '', [rfReplaceAll]);
|
||||
eLine := StringReplace(eLine, '"', '', [rfReplaceAll]);
|
||||
if eLine = '#include' + eInclude then begin
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
i := GetLast('#include', True);
|
||||
if i = -1 then
|
||||
i := 0;
|
||||
|
||||
frmMain.sciEditor.Lines.Insert(i, '#include <' + eInclude + '>');
|
||||
end;
|
||||
|
||||
end.
|
649
editor/editor2/UnitFunc.pas
Executable file
649
editor/editor2/UnitFunc.pas
Executable file
@ -0,0 +1,649 @@
|
||||
unit UnitFunc;
|
||||
|
||||
interface
|
||||
|
||||
uses SysUtils, Classes, IniFiles, Graphics, ScintillaLanguageManager,
|
||||
Windows, Messages, SciLexerMod, tlhelp32, Controls, Forms, SciDocuments;
|
||||
|
||||
procedure Delay(eTime: Integer);
|
||||
function CountChars(eIn: String; eChar: Char): Integer;
|
||||
function Between(eText, eFirst, eSecond: String): String;
|
||||
procedure SendOpen(eFile: String);
|
||||
procedure Load;
|
||||
procedure Save;
|
||||
procedure Apply;
|
||||
function GetConsoleOutput(const Command: String): Boolean;
|
||||
procedure KillIt(dwProcID: DWORD);
|
||||
function GetProcID(sProcName: String): Integer;
|
||||
procedure DoCompile;
|
||||
function ShowSaveDialog(Caption, SaveCaption, CloseCaption: String): Boolean;
|
||||
procedure AppendFileExt;
|
||||
function RemoveSpaces(eInput: String): String;
|
||||
|
||||
var eErrorLine: Integer;
|
||||
eHints, eWarnings, eErrors: Integer;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMain, UnitfrmOptions, UnitfrmAbout,
|
||||
UnitfrmDebug, UnitfrmSaveDialog;
|
||||
|
||||
procedure Delay(eTime: Integer);
|
||||
var i: integer;
|
||||
begin
|
||||
for i := 1 to eTime do begin
|
||||
Sleep(1);
|
||||
Application.ProcessMessages;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CountChars(eIn: String; eChar: Char): Integer;
|
||||
var i: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
if Length(eIn) <> 0 then begin
|
||||
for i := 1 to Length(eIn) do begin
|
||||
if eIn[i] = eChar then
|
||||
Inc(Result, 1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function Between(eText, eFirst, eSecond: String): String;
|
||||
var eTemp: String;
|
||||
begin
|
||||
if (Pos(eFirst, eText) = 0) or (Pos(eSecond, eText) = 0) then
|
||||
Result := ''
|
||||
else begin
|
||||
eTemp := eText;
|
||||
Delete(eTemp, 1, Pos(eFirst, eText) + Length(eFirst) - 1);
|
||||
Delete(eTemp, Pos(eSecond, eTemp), Length(eTemp));
|
||||
Result := eTemp;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure SendOpen(eFile: String);
|
||||
var HTargetWnd: HWND;
|
||||
ACopyDataStruct: TCopyDataStruct;
|
||||
begin
|
||||
with ACopyDataStruct do
|
||||
begin
|
||||
dwData := 0;
|
||||
cbData := Length(eFile) + 1;
|
||||
lpData := PChar(eFile);
|
||||
end;
|
||||
|
||||
HTargetWnd := FindWindow('TfrmMain', 'AMXX-Edit v2');
|
||||
|
||||
if HTargetWnd <> 0 then
|
||||
SendMessage(HTargetWnd, WM_COPYDATA, 0, LongInt(@ACopyDataStruct));
|
||||
end;
|
||||
|
||||
procedure Load;
|
||||
var eFile: TIniFile;
|
||||
begin
|
||||
if not FileExists(ExtractFilePath(ParamStr(0)) + 'Config.ini') then
|
||||
exit;
|
||||
|
||||
eFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
|
||||
with frmSettings do begin
|
||||
{ Editor }
|
||||
cboFoldingStyle.ItemIndex := eFile.ReadInteger('Editor', 'FoldingStyle', 0);
|
||||
chkAutoComplete.Checked := eFile.ReadBool('Editor', 'Auto-Complete', True);
|
||||
chkHints.Checked := eFile.ReadBool('Editor', 'Hints', True);
|
||||
chkHighlighting.Checked := eFile.ReadBool('Editor', 'Highlighting', True);
|
||||
chkAutoIndent.Checked := eFile.ReadBool('Editor', 'AutoIndent', True);
|
||||
chkBrackets.Checked := eFile.ReadBool('Editor', 'HighlightBrackets', True);
|
||||
{ Directories }
|
||||
txtAMXXPath.Text := eFile.ReadString('Directories', 'AMXX', '');
|
||||
txtHalfLife.Text := eFile.ReadString('Directories', 'Half-Life', '');
|
||||
txtSave.Text := eFile.ReadString('Directories', 'SaveTarget', '');
|
||||
{ Colors }
|
||||
cboComments.Selected := eFile.ReadInteger('Colors', 'Comments', clGreen);
|
||||
cboDirectives.Selected := eFile.ReadInteger('Colors', 'Directives', clTeal);
|
||||
cboOperators.Selected := eFile.ReadInteger('Colors', 'Operators', clNavy);
|
||||
cboStrings.Selected := eFile.ReadInteger('Colors', 'Strings', clBlue);
|
||||
cboKeywords.Selected := eFile.ReadInteger('Colors', 'Keywords', clRed);
|
||||
cboActiveLine.Selected := eFile.ReadInteger('Colors', 'ActiveLine', $00FFE6E6);
|
||||
{ FTP }
|
||||
txtHost.Text := eFile.ReadString('FTP', 'Host', '');
|
||||
txtPort.Text := IntToStr(eFile.ReadInteger('FTP', 'Port', 21));
|
||||
txtUser.Text := eFile.ReadString('FTP', 'Username', '');
|
||||
txtPassword.Text := eFile.ReadString('FTP', 'Password', '');
|
||||
txtStandardDir.Text := eFile.ReadString('FTP', 'DefaultDir', '\');
|
||||
{ View }
|
||||
cboCodeExplorer.ItemIndex := eFile.ReadInteger('View', 'ShowCodeExplorer', 0);
|
||||
chkStatusbar.Checked := eFile.ReadBool('View', 'Statusbar', True);
|
||||
{ Char completer }
|
||||
frmSettings.chkAutoCloseBrackets.Checked := eFile.ReadBool('CharCompleter', 'AutoCloseBrackets', False);
|
||||
frmSettings.chkAutoCloseQuotes.Checked := eFile.ReadBool('CharCompleter', 'AutoCloseQuotes', False);
|
||||
{ Compiler Output }
|
||||
if eFile.ReadBool('View', 'CompileOutputInWindow', True) then
|
||||
frmSettings.optWindow.Checked := True
|
||||
else
|
||||
frmSettings.optList.Checked := True;
|
||||
{ Misc }
|
||||
chkReload.Checked := eFile.ReadBool('Misc', 'AutoReload', True);
|
||||
chkAutoAddPlugins.Checked := eFile.ReadBool('Misc', 'AutoAdd', True);
|
||||
end;
|
||||
eFile.Free;
|
||||
end;
|
||||
|
||||
procedure Save;
|
||||
var eFile: TIniFile;
|
||||
begin
|
||||
eFile := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');
|
||||
with frmSettings do begin
|
||||
{ Editor }
|
||||
eFile.WriteInteger('Editor', 'FoldingStyle', cboFoldingStyle.ItemIndex);
|
||||
eFile.WriteBool('Editor', 'Auto-Complete', chkAutoComplete.Checked);
|
||||
eFile.WriteBool('Editor', 'Hints', chkHints.Checked);
|
||||
eFile.WriteBool('Editor', 'Highlighting', chkHighlighting.Checked);
|
||||
eFile.WriteBool('Editor', 'AutoIndent', chkAutoIndent.Checked);
|
||||
eFile.WriteBool('Editor', 'HighlightBrackets', chkBrackets.Checked);
|
||||
{ Directories }
|
||||
eFile.WriteString('Directories', 'AMXX', txtAMXXPath.Text);
|
||||
eFile.WriteString('Directories', 'Half-Life', txtHalfLife.Text);
|
||||
eFile.WriteString('Directories', 'SaveTarget', txtSave.Text);
|
||||
{ Colors }
|
||||
eFile.WriteInteger('Colors', 'Comments', cboComments.Selected);
|
||||
eFile.WriteInteger('Colors', 'Directives', cboDirectives.Selected);
|
||||
eFile.WriteInteger('Colors', 'Operators', cboOperators.Selected);
|
||||
eFile.WriteInteger('Colors', 'Strings', cboStrings.Selected);
|
||||
eFile.WriteInteger('Colors', 'Keywords', cboKeywords.Selected);
|
||||
eFile.WriteInteger('Colors', 'ActiveLine', cboActiveLine.Selected);
|
||||
{ FTP }
|
||||
eFile.WriteString('FTP', 'Host', txtHost.Text);
|
||||
eFile.WriteString('FTP', 'Port', txtPort.Text);
|
||||
eFile.WriteString('FTP', 'Username', txtUser.Text);
|
||||
eFile.WriteString('FTP', 'Password', txtPassword.Text);
|
||||
eFile.WriteString('FTP', 'DefaultDir', txtStandardDir.Text);
|
||||
{ View }
|
||||
eFile.WriteInteger('View', 'ShowCodeExplorer', cboCodeExplorer.ItemIndex);
|
||||
eFile.WriteBool('View', 'Statusbar', chkStatusbar.Checked);
|
||||
{ Char completer }
|
||||
eFile.WriteBool('CharCompleter', 'AutoCloseBrackets', frmSettings.chkAutoCloseBrackets.Checked);
|
||||
eFile.WriteBool('CharCompleter', 'AutoCloseQuotes', frmSettings.chkAutoCloseQuotes.Checked);
|
||||
{ Compiler Output }
|
||||
eFile.WriteBool('View', 'CompileOutputInWindow', frmSettings.optWindow.Checked);
|
||||
{ Misc }
|
||||
eFile.WriteBool('Misc', 'AutoReload', chkReload.Checked);
|
||||
eFile.WriteBool('Misc', 'AutoAdd', chkAutoAddPlugins.Checked);
|
||||
end;
|
||||
eFile.Free;
|
||||
end;
|
||||
|
||||
procedure Apply;
|
||||
function PathComplete(eInput: String): String;
|
||||
var eBackup: String;
|
||||
begin
|
||||
if Trim(eInput) = '' then
|
||||
exit;
|
||||
|
||||
eBackup := eInput;
|
||||
while Length(eInput) > 1 do
|
||||
Delete(eInput, 1, 1);
|
||||
if eInput <> '\' then
|
||||
Result := eBackup + '\'
|
||||
else
|
||||
Result := eBackup;
|
||||
end;
|
||||
|
||||
begin
|
||||
with frmMain do begin
|
||||
{ Folding }
|
||||
case frmSettings.cboFoldingStyle.ItemIndex of
|
||||
0: sciEditor.FoldMarkerType := sciMarkArrows;
|
||||
1: sciEditor.FoldMarkerType := sciMarkBox;
|
||||
2: sciEditor.FoldMarkerType := sciMarkCircle;
|
||||
3: sciEditor.FoldMarkerType := sciMarkPlusMinus;
|
||||
end;
|
||||
if frmSettings.cboFoldingStyle.ItemIndex = 4 then
|
||||
sciEditor.Folding := sciEditor.Folding - [foldFold]
|
||||
else
|
||||
sciEditor.Folding := sciEditor.Folding + [foldFold];
|
||||
{ Auto Complete }
|
||||
sacComplete.Disabled := not frmSettings.chkAutoComplete.Checked;
|
||||
{ Hints }
|
||||
cltEditor.Disabled := not frmSettings.chkHints.Checked;
|
||||
{ Colors }
|
||||
with sciEditor.LanguageManager.LanguageList.Find('SMALL').Styles do begin
|
||||
TSciStyle(Items[0]).ForeColor := frmSettings.cboComments.Selected;
|
||||
TSciStyle(Items[1]).ForeColor := frmSettings.cboDirectives.Selected;
|
||||
TSciStyle(Items[2]).ForeColor := frmSettings.cboOperators.Selected;
|
||||
TSciStyle(Items[3]).ForeColor := frmSettings.cboStrings.Selected;
|
||||
TSciStyle(Items[4]).ForeColor := frmSettings.cboKeywords.Selected;
|
||||
TSciStyle(Items[5]).ForeColor := frmSettings.cboComments.Selected;
|
||||
TSciStyle(Items[6]).ForeColor := TSciStyle(Items[2]).ForeColor;
|
||||
end;
|
||||
frmMain.sciEditor.Caret.LineBackColor := frmSettings.cboActiveLine.Selected;
|
||||
|
||||
if frmSettings.chkHighlighting.Checked then
|
||||
frmMain.sciEditor.LanguageManager.SelectedLanguage := 'SMALL'
|
||||
else
|
||||
frmMain.sciEditor.LanguageManager.SelectedLanguage := 'null';
|
||||
{ Check directories }
|
||||
frmSettings.txtAMXXPath.Text := PathComplete(frmSettings.txtAMXXPath.Text);
|
||||
frmSettings.txtSave.Text := PathComplete(frmSettings.txtSave.Text);
|
||||
{ View }
|
||||
case frmSettings.cboCodeExplorer.ItemIndex of
|
||||
0: begin
|
||||
frmMain.splFunctions.Visible := True;
|
||||
frmMain.pnlFunctions.Visible := True;
|
||||
frmMain.pnlFunctions.Width := 150;
|
||||
frmMain.pnlSpacerLeft.Cursor := crDefault;
|
||||
end;
|
||||
1: begin
|
||||
frmMain.splFunctions.Visible := False;
|
||||
frmMain.pnlFunctions.Visible := True;
|
||||
frmMain.pnlFunctions.Width := 5;
|
||||
frmMain.pnlSpacerLeft.Cursor := crHSplit;
|
||||
end;
|
||||
2: begin
|
||||
frmMain.pnlFunctions.Visible := False;
|
||||
frmMain.splFunctions.Visible := False;
|
||||
frmMain.pnlSpacerLeft.Cursor := crDefault;
|
||||
end;
|
||||
end;
|
||||
frmMain.sbInfo.Visible := frmSettings.chkStatusbar.Checked;
|
||||
frmMain.sciEditor.BraceHilite := frmSettings.chkBrackets.Checked;
|
||||
{ Char completer }
|
||||
frmMain.sciEditor.AutoCloseBraces := frmSettings.chkAutoCloseBrackets.Checked;
|
||||
frmMain.sciEditor.AutoCloseQuotes := frmSettings.chkAutoCloseQuotes.Checked;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DoAdd(eStream: TMemoryStream);
|
||||
var eStr: TStringList;
|
||||
i: integer;
|
||||
eErrLine: Integer;
|
||||
eType, eBackup, eTemp: String;
|
||||
begin
|
||||
eStr := TStringList.Create;
|
||||
eStr.LoadFromStream(eStream);
|
||||
|
||||
eHints := 0;
|
||||
eWarnings := 0;
|
||||
eErrors := 0;
|
||||
eType := '';
|
||||
eErrorLine := -1;
|
||||
|
||||
for i := 2 to eStr.Count -1 do begin
|
||||
try
|
||||
if eStr[i] <> '' then begin
|
||||
if (Pos(': fatal error', eStr[i]) <> 0) or (Pos(': error', eStr[i]) <> 0) or (Pos(': warning', eStr[i]) <> 0) or (Pos(': hint', eStr[i]) <> 0) then begin
|
||||
eBackup := eStr[i];
|
||||
if (Pos(': fatal error', eStr[i]) <> 0) or (Pos(': error', eStr[i]) <> 0) then begin
|
||||
Inc(eErrors, 1);
|
||||
eType := 'Error';
|
||||
end
|
||||
else if Pos(': warning', eStr[i]) <> 0 then begin
|
||||
Inc(eWarnings, 1);
|
||||
eType := 'Warning';
|
||||
end
|
||||
else if Pos(': hint', eStr[i]) <> 0 then begin
|
||||
Inc(eHints, 1);
|
||||
eType := 'Hint';
|
||||
end;
|
||||
|
||||
eErrLine := -1;
|
||||
while (Pos('(', eStr[i]) <> 1) and (Length(eStr[i]) > 0) do
|
||||
eStr[i] := Copy(eStr[i], 2, Length(eStr[i]));
|
||||
try
|
||||
eTemp := Copy(eStr[i], 2, Pos(')', eStr[i]) -2);
|
||||
if Pos(#32, eTemp) <> 0 then
|
||||
eTemp := Copy(eTemp, 1, Pos(#32, eTemp) -1);
|
||||
eErrLine := StrToInt(eTemp);
|
||||
if (eErrorLine = -1) and (eType = 'Error') then
|
||||
eErrorLine := eErrLine;
|
||||
except
|
||||
if (eErrorLine = -1) and (eType = 'Error') then
|
||||
eErrorLine := frmMain.sciEditor.Lines.Count -1;
|
||||
end;
|
||||
eStr[i] := Copy(eStr[i], 3, Length(eStr[i]));
|
||||
while (Pos(':', eStr[i]) > 3) and (Length(eStr[i]) > 0) do
|
||||
eStr[i] := Copy(eStr[i], 2, Length(eStr[i]));
|
||||
eStr[i] := Copy(eStr[i], 4, Length(eStr[i]));
|
||||
eStr[i] := Copy(eStr[i], Pos(':', eStr[i]) +2, Length(eStr[i]));
|
||||
if Pos(': fatal error', eBackup) <> 0 then
|
||||
eStr[i] := 'Fatal error: ' + eStr[i]
|
||||
else if eStr[i] = '' then
|
||||
eStr[i] := eBackup
|
||||
else
|
||||
eStr[i] := eType + ': ' + eStr[i] + ' on line ' + IntToStr(eErrLine);
|
||||
if frmSettings.optWindow.Checked then begin
|
||||
frmDebug.lblErrors.Caption := ' Errors: ' + IntToStr(eErrors);
|
||||
frmDebug.lblWarnings.Caption := ' Warnings: ' + IntToStr(eWarnings);
|
||||
frmDebug.lblHints.Caption := ' Hints: ' + IntToStr(eHints);
|
||||
end;
|
||||
end
|
||||
else if (eStr[i] = 'Done.') or (Pos(' Error', eStr[i]) <> 0) or (Pos(' Warning', eStr[i]) <> 0) or (Pos(' Hint', eStr[i]) <> 0) then begin
|
||||
if frmSettings.optWindow.Checked then begin
|
||||
if eErrors <> 0 then
|
||||
frmDebug.lblStatus.Caption := ' Done. There are errors.'
|
||||
else if eWarnings <> 0 then
|
||||
frmDebug.lblStatus.Caption := ' Done. There are warnings.'
|
||||
else if eHints <> 0 then
|
||||
frmDebug.lblStatus.Caption := ' Done. There are hints.'
|
||||
else
|
||||
frmDebug.lblStatus.Caption := ' Done.';
|
||||
frmDebug.lblStatus.Font.Style := [fsBold];
|
||||
end
|
||||
else begin
|
||||
if eErrors <> 0 then
|
||||
frmMain.lvDebug.Items.Add.Caption := 'Done. There are errors.'
|
||||
else if eWarnings <> 0 then
|
||||
frmMain.lvDebug.Items.Add.Caption := 'Done. There are warnings.'
|
||||
else if eHints <> 0 then
|
||||
frmMain.lvDebug.Items.Add.Caption := 'Done. There are hints.'
|
||||
else
|
||||
frmMain.lvDebug.Items.Add.Caption := 'Done.';
|
||||
|
||||
if eErrorLine <> -1 then
|
||||
frmMain.ShowErrorLine;
|
||||
eStr.Free;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
if frmSettings.optWindow.Checked then begin
|
||||
frmDebug.lstOutput.Items.Add(eStr[i]);
|
||||
frmDebug.lstOutput.ItemIndex := frmDebug.lstOutput.Items.Count -1;
|
||||
frmDebug.Repaint;
|
||||
end
|
||||
else begin
|
||||
frmMain.lvDebug.Items.Add.Caption := eStr[i];
|
||||
frmMain.lvDebug.ItemIndex := frmDebug.lstOutput.Items.Count -1;
|
||||
frmMain.Repaint;
|
||||
end;
|
||||
end;
|
||||
except
|
||||
// nothing
|
||||
end;
|
||||
end;
|
||||
eStr.Free;
|
||||
end;
|
||||
|
||||
function GetConsoleOutput(const Command: String): Boolean;
|
||||
var
|
||||
StartupInfo: TStartupInfo;
|
||||
ProcessInfo: TProcessInformation;
|
||||
SecurityAttr: TSecurityAttributes;
|
||||
PipeOutputRead: THandle;
|
||||
PipeOutputWrite: THandle;
|
||||
PipeErrorsRead: THandle;
|
||||
PipeErrorsWrite: THandle;
|
||||
Succeed: Boolean;
|
||||
Buffer: array [0..255] of Char;
|
||||
NumberOfBytesRead: DWORD;
|
||||
Stream: TMemoryStream;
|
||||
begin
|
||||
frmDebug.Compiling := True;
|
||||
FillChar(ProcessInfo, SizeOf(TProcessInformation), 0);
|
||||
|
||||
FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);
|
||||
SecurityAttr.nLength := SizeOf(SecurityAttr);
|
||||
SecurityAttr.bInheritHandle := True;
|
||||
SecurityAttr.lpSecurityDescriptor := nil;
|
||||
|
||||
CreatePipe(PipeOutputRead, PipeOutputWrite, @SecurityAttr, 0);
|
||||
CreatePipe(PipeErrorsRead, PipeErrorsWrite, @SecurityAttr, 0);
|
||||
|
||||
FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
|
||||
StartupInfo.cb:=SizeOf(StartupInfo);
|
||||
StartupInfo.hStdInput := 0;
|
||||
StartupInfo.hStdOutput := PipeOutputWrite;
|
||||
StartupInfo.hStdError := PipeErrorsWrite;
|
||||
StartupInfo.wShowWindow := SW_HIDE;
|
||||
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
|
||||
|
||||
if CreateProcess(nil, PChar(command), nil, nil, true,
|
||||
CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil,
|
||||
StartupInfo, ProcessInfo) then begin
|
||||
Result := True;
|
||||
CloseHandle(PipeOutputWrite);
|
||||
CloseHandle(PipeErrorsWrite);
|
||||
|
||||
Stream := TMemoryStream.Create;
|
||||
try
|
||||
while True do begin
|
||||
Succeed := ReadFile(PipeOutputRead, Buffer, 255, NumberOfBytesRead, nil);
|
||||
if not Succeed then Break;
|
||||
Stream.Write(Buffer, NumberOfBytesRead);
|
||||
end;
|
||||
Stream.Position := 0;
|
||||
DoAdd(Stream);
|
||||
finally
|
||||
Stream.Free;
|
||||
end;
|
||||
CloseHandle(PipeOutputRead);
|
||||
|
||||
try
|
||||
while True do
|
||||
begin
|
||||
Succeed := ReadFile(PipeErrorsRead, Buffer, 255, NumberOfBytesRead, nil);
|
||||
if not Succeed then Break;
|
||||
end;
|
||||
finally
|
||||
end;
|
||||
CloseHandle(PipeErrorsRead);
|
||||
|
||||
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
|
||||
CloseHandle(ProcessInfo.hProcess);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := False;
|
||||
CloseHandle(PipeOutputRead);
|
||||
CloseHandle(PipeOutputWrite);
|
||||
CloseHandle(PipeErrorsRead);
|
||||
CloseHandle(PipeErrorsWrite);
|
||||
end;
|
||||
frmDebug.Compiling := False;
|
||||
end;
|
||||
|
||||
|
||||
procedure KillIt(dwProcID: DWORD);
|
||||
var
|
||||
hProcess : Cardinal;
|
||||
begin
|
||||
hProcess := OpenProcess(SYNCHRONIZE or PROCESS_TERMINATE, False, dwProcID);
|
||||
TerminateProcess(hProcess, 0);
|
||||
end;
|
||||
|
||||
function GetProcID(sProcName: String): Integer;
|
||||
var
|
||||
hProcSnap: THandle;
|
||||
pe32: TProcessEntry32;
|
||||
begin
|
||||
result := -1;
|
||||
hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
|
||||
if hProcSnap = INVALID_HANDLE_VALUE then exit;
|
||||
|
||||
pe32.dwSize := SizeOf(ProcessEntry32);
|
||||
|
||||
if Process32First(hProcSnap, pe32) = true then
|
||||
while Process32Next(hProcSnap, pe32) = true do
|
||||
begin
|
||||
if pos(sProcName, pe32.szExeFile) <> 0 then
|
||||
result := pe32.th32ProcessID;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DoCompile;
|
||||
var eStr: TStringList;
|
||||
i: integer;
|
||||
eFound: Boolean;
|
||||
begin
|
||||
if (FileExists(frmSettings.txtAMXXPath.Text + 'scripting\amxxsc.exe')) and (FileExists(frmSettings.txtAMXXPath.Text + 'configs\plugins.ini')) then begin
|
||||
if frmMain.dtcEditor.ActiveDocument.IsUntitled then begin
|
||||
if DirectoryExists(frmSettings.txtSave.Text) then
|
||||
frmMain.sdSave.InitialDir := frmSettings.txtSave.Text;
|
||||
|
||||
if frmMain.sdSave.Execute then begin
|
||||
try
|
||||
AppendFileExt;
|
||||
frmMain.dtcEditor.ActiveDocument.Modified := False;
|
||||
frmMain.dtcEditor.ActiveDocument.FileName := frmMain.sdSave.FileName;
|
||||
frmMain.sciEditor.SaveToFile(frmMain.dtcEditor.ActiveDocument.FileName);
|
||||
except
|
||||
// :F
|
||||
end;
|
||||
end
|
||||
else
|
||||
exit;
|
||||
end
|
||||
else
|
||||
frmMain.acSave.Execute;
|
||||
Screen.Cursor := crHourGlass;
|
||||
if frmSettings.chkAutoAddPlugins.Checked then begin
|
||||
eStr := TStringList.Create;
|
||||
eStr.LoadFromFile(frmSettings.txtAMXXPath.Text + 'configs\plugins.ini');
|
||||
eFound := False;
|
||||
for i := 0 to eStr.Count -1 do begin
|
||||
if Pos(ChangeFileExt(ExtractFileName(frmMain.dtcEditor.ActiveDocument.FileName), '.amxx'), TrimLeft(eStr[i])) = 1 then
|
||||
eFound := True;
|
||||
end;
|
||||
if not eFound then begin
|
||||
eStr.Add(ChangeFileExt(ExtractFileName(frmMain.dtcEditor.ActiveDocument.FileName), '.amxx'));
|
||||
eStr.SaveToFile(frmSettings.txtAMXXPath.Text + 'configs\plugins.ini');
|
||||
end;
|
||||
eStr.Free;
|
||||
end;
|
||||
try
|
||||
frmMain.atbToolBar.RecreateControls;
|
||||
except
|
||||
// :F
|
||||
end;
|
||||
|
||||
if frmSettings.optWindow.Checked then begin
|
||||
frmDebug.lblFile.Caption := ' File: ' + ExtractFileName(frmMain.dtcEditor.ActiveDocument.FileName);
|
||||
frmDebug.lblStatus.Font.Style := [];
|
||||
frmDebug.lblStatus.Caption := ' Status: Compiling...';
|
||||
frmDebug.lblHints.Caption := ' Hints: 0';
|
||||
frmDebug.lblWarnings.Caption := ' Warnings: 0';
|
||||
frmDebug.lblErrors.Caption := ' Errors: 0';
|
||||
frmDebug.lstOutput.Items.Text := 'Compiler Output:';
|
||||
frmDebug.Show;
|
||||
frmDebug.Repaint;
|
||||
end
|
||||
else begin
|
||||
frmMain.lvDebug.Clear;
|
||||
frmMain.lvDebug.Items.Add.Caption := 'Compiling ' + ExtractFileName(frmMain.dtcEditor.ActiveDocument.FileName) + '...';
|
||||
frmMain.lvDebug.Visible := True;
|
||||
frmMain.Repaint;
|
||||
end;
|
||||
GetConsoleOutput(frmSettings.txtAMXXPath.Text + 'scripting\amxxsc.exe ' +
|
||||
'"' + frmMain.dtcEditor.ActiveDocument.FileName + '" ' +
|
||||
'"-o' + frmSettings.txtAMXXPath.Text + 'plugins\' + ChangeFileExt(ExtractFileName(frmMain.dtcEditor.ActiveDocument.FileName), '.amxx') + '"');
|
||||
Screen.Cursor := crDefault;
|
||||
end
|
||||
else
|
||||
MessageBox(frmMain.Handle, 'Couldn''t find amxxsc.exe or plugins.ini. Check your settings and try again.', 'Error', MB_ICONERROR);
|
||||
end;
|
||||
|
||||
function ShowSaveDialog(Caption, SaveCaption, CloseCaption: String): Boolean;
|
||||
function TabByName(eName: String): TSciDoc;
|
||||
var i: integer;
|
||||
begin
|
||||
Result := nil;
|
||||
for i := 0 to frmMain.dtcEditor.Count -1 do begin
|
||||
if frmMain.dtcEditor.Tabs[i] = eName then
|
||||
Result := frmMain.dtcEditor.Document[i];
|
||||
end;
|
||||
end;
|
||||
|
||||
var i: integer;
|
||||
eStr: TStringList;
|
||||
begin
|
||||
eStr := TStringList.Create;
|
||||
frmSaveDialog.Caption := Caption;
|
||||
frmSaveDialog.SaveCaption := SaveCaption;
|
||||
frmSaveDialog.CloseCaption := CloseCaption;
|
||||
frmSaveDialog.cmdSave.Caption := CloseCaption;
|
||||
frmSaveDialog.lstFiles.Clear;
|
||||
for i := 0 to frmMain.dtcEditor.Tabs.Count -1 do begin
|
||||
if (frmMain.dtcEditor.Document[i].Modified) then
|
||||
frmSaveDialog.lstFiles.Items.Add(frmMain.dtcEditor.Tabs[i])
|
||||
else if (frmMain.dtcEditor.Document[i].IsUntitled) then
|
||||
frmSaveDialog.lstFiles.Items.Add(frmMain.dtcEditor.Tabs[i]);
|
||||
end;
|
||||
|
||||
if (frmMain.dtcEditor.Tabs.Count = 1) and (frmMain.sciEditor.Lines.Text = '') then
|
||||
frmSaveDialog.lstFiles.Clear;
|
||||
|
||||
if frmSaveDialog.lstFiles.Items.Count = 0 then begin
|
||||
Result := True;
|
||||
if frmSettings.chkReload.Checked then begin
|
||||
for i := 0 to frmMain.dtcEditor.Tabs.Count -1 do begin
|
||||
if not frmMain.dtcEditor.Document[i].IsUntitled then
|
||||
eStr.Add(frmMain.dtcEditor.Document[i].FileName);
|
||||
end;
|
||||
eStr.SaveToFile(ExtractFilePath(ParamStr(0)) + 'Files.ini');
|
||||
end;
|
||||
eStr.Free;
|
||||
exit;
|
||||
end;
|
||||
|
||||
if frmSaveDialog.ShowModal = mrOk then begin
|
||||
for i := 0 to frmSaveDialog.lstFiles.Items.Count -1 do begin
|
||||
if frmSaveDialog.lstFiles.Checked[i] then begin
|
||||
if (TabByName(frmSaveDialog.lstFiles.Items[i]).IsUntitled) then begin
|
||||
frmMain.sdSave.Title := Format('Save %s (Tab %s)', [TabByName(frmSaveDialog.lstFiles.Items[i]).FileName, IntToStr(TabByName(frmSaveDialog.lstFiles.Items[i]).Index +1)]);
|
||||
if frmMain.sdSave.Execute then begin
|
||||
AppendFileExt;
|
||||
frmMain.dtcEditor.Activate(TabByName(frmSaveDialog.lstFiles.Items[i]).Index);
|
||||
frmMain.sciEditor.SaveToFile(frmMain.sdSave.FileName);
|
||||
frmMain.dtcEditor.ActiveDocument.FileName := frmMain.sdSave.FileName;
|
||||
frmMain.SetSaved;
|
||||
frmMain.sbInfo.Panels[1].Text := '';
|
||||
end
|
||||
else begin
|
||||
frmMain.sdSave.Title := 'Save...';
|
||||
eStr.Free;
|
||||
Result := False;
|
||||
exit;
|
||||
end;
|
||||
frmMain.sdSave.Title := 'Save...';
|
||||
end
|
||||
else begin
|
||||
frmMain.dtcEditor.Activate(TabByName(frmSaveDialog.lstFiles.Items[i]).Index);
|
||||
frmMain.sciEditor.SaveToFile(TabByName(frmSaveDialog.lstFiles.Items[i]).FileName);
|
||||
frmMain.dtcEditor.ActiveDocument.Modified := False;
|
||||
frmMain.SetSaved;
|
||||
frmMain.sbInfo.Panels[1].Text := '';
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
for i := 0 to frmMain.dtcEditor.Tabs.Count -1 do begin
|
||||
if (not frmMain.dtcEditor.Document[i].IsUntitled) and (not frmMain.dtcEditor.Document[i].Modified) then
|
||||
eStr.Add(frmMain.dtcEditor.Document[i].FileName);
|
||||
end;
|
||||
|
||||
if frmSettings.chkReload.Checked then
|
||||
eStr.SaveToFile(ExtractFilePath(ParamStr(0)) + 'Files.ini');
|
||||
Result := True;
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
eStr.Free;
|
||||
end;
|
||||
|
||||
procedure AppendFileExt;
|
||||
var eExt: String;
|
||||
begin
|
||||
eExt := LowerCase(ExtractFileExt(frmMain.sdSave.FileName));
|
||||
if (frmMain.sdSave.FilterIndex = 1) and (eExt <> '.sma') then
|
||||
frmMain.sdSave.FileName := frmMain.sdSave.FileName + '.sma'
|
||||
else if (frmMain.sdSave.FilterIndex = 2) and (eExt <> '.inc') then
|
||||
frmMain.sdSave.FileName := frmMain.sdSave.FileName + '.inc';
|
||||
end;
|
||||
|
||||
function RemoveSpaces(eInput: String): String;
|
||||
begin
|
||||
eInput := StringReplace(eInput, ' ', '', [rfReplaceAll]);
|
||||
eInput := StringReplace(eInput, ' ', '', [rfReplaceAll]);
|
||||
Result := eInput;
|
||||
end;
|
||||
|
||||
end.
|
24
editor/editor2/UnitHowToMakePlayerMenu.pas
Executable file
24
editor/editor2/UnitHowToMakePlayerMenu.pas
Executable file
@ -0,0 +1,24 @@
|
||||
unit UnitHowToMakePlayerMenu;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, CorelButton;
|
||||
|
||||
type
|
||||
TfrmHowToMakePlayerMenu = class(TForm)
|
||||
lblHowTo: TLabel;
|
||||
txtTutorial: TMemo;
|
||||
cmdOK: TCorelButton;
|
||||
cmdExample: TCorelButton;
|
||||
end;
|
||||
|
||||
var
|
||||
frmHowToMakePlayerMenu: TfrmHowToMakePlayerMenu;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
end.
|
60
editor/editor2/UnitReadThread.pas
Executable file
60
editor/editor2/UnitReadThread.pas
Executable file
@ -0,0 +1,60 @@
|
||||
unit UnitReadThread;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Graphics;
|
||||
|
||||
type
|
||||
TReadThread = class(TThread)
|
||||
public
|
||||
ReadTCP: Boolean;
|
||||
protected
|
||||
Read: String;
|
||||
procedure Execute; override;
|
||||
procedure AddRead;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmSockets;
|
||||
|
||||
{ TReadThread }
|
||||
|
||||
procedure TReadThread.AddRead;
|
||||
begin
|
||||
frmSocketTerminal.OnRead(Read);
|
||||
end;
|
||||
|
||||
procedure TReadThread.Execute;
|
||||
begin
|
||||
if ReadTCP then begin
|
||||
frmSocketTerminal.IdTCPClient.ReadTimeout := 50;
|
||||
repeat
|
||||
try
|
||||
Read := frmSocketTerminal.IdTCPClient.ReadLn;
|
||||
Synchronize(AddRead);
|
||||
except
|
||||
// nothing
|
||||
end;
|
||||
until (Terminated) or (not frmSocketTerminal.IdTCPClient.Connected);
|
||||
end
|
||||
else begin
|
||||
frmSocketTerminal.IdUDPClient.ReceiveTimeout := 50;
|
||||
repeat
|
||||
try
|
||||
Read := frmSocketTerminal.IdUDPClient.ReceiveString;
|
||||
if Read <> '' then
|
||||
Synchronize(AddRead);
|
||||
except
|
||||
// nothing
|
||||
end;
|
||||
until (Terminated) or (not frmSocketTerminal.IdUDPClient.Active);
|
||||
end;
|
||||
Free;
|
||||
Read := 'fu@u';
|
||||
Synchronize(AddRead);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
32
editor/editor2/UnitfrmAbout.pas
Executable file
32
editor/editor2/UnitfrmAbout.pas
Executable file
@ -0,0 +1,32 @@
|
||||
unit UnitfrmAbout;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, ShellAPI, TFlatSpeedButtonUnit;
|
||||
|
||||
type
|
||||
TfrmAbout = class(TForm)
|
||||
pnlInfo: TPanel;
|
||||
imgAMXX: TImage;
|
||||
lblCopyright: TLabel;
|
||||
lblComments: TLabel;
|
||||
lblCoder: TLabel;
|
||||
FlatSpeedButton1: TFlatSpeedButton;
|
||||
procedure imgAMXXClick(Sender: TObject);
|
||||
end;
|
||||
|
||||
var
|
||||
frmAbout: TfrmAbout;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmAbout.imgAMXXClick(Sender: TObject);
|
||||
begin
|
||||
ShellExecute(Handle, 'open', 'http://www.amxmodx.org/', nil, nil, SW_SHOW);
|
||||
end;
|
||||
|
||||
end.
|
91
editor/editor2/UnitfrmDebug.pas
Executable file
91
editor/editor2/UnitfrmDebug.pas
Executable file
@ -0,0 +1,91 @@
|
||||
unit UnitfrmDebug;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms;
|
||||
|
||||
type
|
||||
TfrmDebug = class(TForm)
|
||||
cmdMore: TButton;
|
||||
pnlCompile: TPanel;
|
||||
lblFile: TStaticText;
|
||||
lblStatus: TStaticText;
|
||||
lblHints: TStaticText;
|
||||
lblWarnings: TStaticText;
|
||||
lblErrors: TStaticText;
|
||||
cmdCancelOkay: TButton;
|
||||
bvlDelimeter: TBevel;
|
||||
lstOutput: TListBox;
|
||||
procedure cmdMoreClick(Sender: TObject);
|
||||
procedure cmdCancelOkayClick(Sender: TObject);
|
||||
procedure lstOutputDblClick(Sender: TObject);
|
||||
private
|
||||
FCompiling: Boolean;
|
||||
procedure SetCompiling(const Value: Boolean);
|
||||
public
|
||||
property Compiling: Boolean read FCompiling write SetCompiling;
|
||||
end;
|
||||
|
||||
var
|
||||
frmDebug: TfrmDebug;
|
||||
|
||||
const DEFAULT_HEIGHT = 165;
|
||||
MAX_HEIGHT = 277;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMain, UnitFunc, UnitfrmOptions;
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmDebug.cmdMoreClick(Sender: TObject);
|
||||
begin
|
||||
if Height = DEFAULT_HEIGHT then begin
|
||||
Height := MAX_HEIGHT;
|
||||
cmdMore.Caption := '<< Compiler Output';
|
||||
end
|
||||
else begin
|
||||
Height := DEFAULT_HEIGHT;
|
||||
cmdMore.Caption := 'Compiler Output >>';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmDebug.SetCompiling(const Value: Boolean);
|
||||
begin
|
||||
FCompiling := Value;
|
||||
if Value then
|
||||
cmdCancelOkay.Caption := 'Cancel'
|
||||
else
|
||||
cmdCancelOkay.Caption := 'Close';
|
||||
end;
|
||||
|
||||
procedure TfrmDebug.cmdCancelOkayClick(Sender: TObject);
|
||||
var i: integer;
|
||||
begin
|
||||
if Compiling then begin
|
||||
i := GetProcId('amxxsc.exe');
|
||||
if i <> -1 then
|
||||
KillIt(i);
|
||||
Compiling := False;
|
||||
end
|
||||
else begin
|
||||
Hide;
|
||||
frmMain.Show;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmDebug.lstOutputDblClick(Sender: TObject);
|
||||
begin
|
||||
if lstOutput.ItemIndex <> -1 then begin
|
||||
if Pos('Warning', lstOutput.Items[lstOutput.ItemIndex]) = 1 then
|
||||
MessageBox(Handle, PChar(lstOutput.Items[lstOutput.ItemIndex]), 'Warning', MB_ICONWARNING)
|
||||
else if Pos('Error', lstOutput.Items[lstOutput.ItemIndex]) = 1 then
|
||||
MessageBox(Handle, PChar(lstOutput.Items[lstOutput.ItemIndex]), 'Error', MB_ICONERROR)
|
||||
else
|
||||
MessageBox(Handle, PChar(lstOutput.Items[lstOutput.ItemIndex]), 'Information', MB_ICONINFORMATION)
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
48
editor/editor2/UnitfrmGoToLine.pas
Executable file
48
editor/editor2/UnitfrmGoToLine.pas
Executable file
@ -0,0 +1,48 @@
|
||||
unit UnitfrmGoToLine;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, TFlatSpeedButtonUnit, TFlatEditUnit;
|
||||
|
||||
type
|
||||
TfrmGoToLine = class(TForm)
|
||||
lblInfo: TLabel;
|
||||
txtLine: TFlatEdit;
|
||||
cmdOK: TFlatSpeedButton;
|
||||
cmdCancel: TFlatSpeedButton;
|
||||
procedure cmdOKClick(Sender: TObject);
|
||||
procedure txtLineKeyPress(Sender: TObject; var Key: Char);
|
||||
end;
|
||||
|
||||
var
|
||||
frmGoToLine: TfrmGoToLine;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMain;
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmGoToLine.cmdOKClick(Sender: TObject);
|
||||
begin
|
||||
try
|
||||
if (StrToInt(txtLine.Text) < 0) or (StrToInt(txtLine.Text) > frmMain.sciEditor.Lines.Count) then
|
||||
raise Exception.Create('Invalid Line')
|
||||
else
|
||||
ModalResult := mrOK;
|
||||
except
|
||||
MessageBox(Handle, 'Invalid value. Check the entered line and press OK again.', 'Error', MB_ICONERROR);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmGoToLine.txtLineKeyPress(Sender: TObject; var Key: Char);
|
||||
begin
|
||||
if Key = #13 then begin
|
||||
cmdOk.Click;
|
||||
Key := #0;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
66
editor/editor2/UnitfrmLoopGenerator.pas
Executable file
66
editor/editor2/UnitfrmLoopGenerator.pas
Executable file
@ -0,0 +1,66 @@
|
||||
unit UnitfrmLoopGenerator;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, TFlatRadioButtonUnit, TFlatEditUnit,
|
||||
TFlatButtonUnit;
|
||||
|
||||
type
|
||||
TfrmLoopGenerator = class(TForm)
|
||||
optWhile: TFlatRadioButton;
|
||||
pnlWhileCondition: TPanel;
|
||||
lblWhileCondition: TLabel;
|
||||
txtWhileCondition: TFlatEdit;
|
||||
optFor: TFlatRadioButton;
|
||||
pnlForLoop: TPanel;
|
||||
lblForVariable: TLabel;
|
||||
txtVariable: TFlatEdit;
|
||||
lblForCondition: TLabel;
|
||||
txtForCondition: TFlatEdit;
|
||||
Label1: TLabel;
|
||||
txtForAction: TFlatEdit;
|
||||
cmdGenerate: TFlatButton;
|
||||
procedure txtVariableKeyPress(Sender: TObject; var Key: Char);
|
||||
procedure txtWhileConditionKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
procedure cmdGenerateClick(Sender: TObject);
|
||||
end;
|
||||
|
||||
var
|
||||
frmLoopGenerator: TfrmLoopGenerator;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmLoopGenerator.txtVariableKeyPress(Sender: TObject;
|
||||
var Key: Char);
|
||||
begin
|
||||
if Key = #32 then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
procedure TfrmLoopGenerator.txtWhileConditionKeyDown(Sender: TObject;
|
||||
var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if Key = 13 then
|
||||
cmdGenerate.Click;
|
||||
end;
|
||||
|
||||
procedure TfrmLoopGenerator.cmdGenerateClick(Sender: TObject);
|
||||
begin
|
||||
if (txtWhileCondition.Text = '') and (optWhile.Checked) then
|
||||
MessageBox(Handle, 'You forgot to enter the while condition', 'Warning', MB_ICONWARNING)
|
||||
else if (optFor.Checked) then begin
|
||||
if (txtVariable.Text = '') or (txtForCondition.Text = '') or (txtForAction.Text = '') then
|
||||
MessageBox(Handle, 'You must fill out each field to generate a FOR-loop.', 'Warning', MB_ICONWARNING)
|
||||
else
|
||||
ModalResult := mrOk;
|
||||
end
|
||||
else
|
||||
ModalResult := mrOk;
|
||||
end;
|
||||
|
||||
end.
|
5807
editor/editor2/UnitfrmMain.dfm
Executable file
5807
editor/editor2/UnitfrmMain.dfm
Executable file
File diff suppressed because it is too large
Load Diff
1170
editor/editor2/UnitfrmMain.pas
Executable file
1170
editor/editor2/UnitfrmMain.pas
Executable file
File diff suppressed because it is too large
Load Diff
461
editor/editor2/UnitfrmMenuMaker.pas
Executable file
461
editor/editor2/UnitfrmMenuMaker.pas
Executable file
@ -0,0 +1,461 @@
|
||||
unit UnitfrmMenuMaker;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, TFlatMemoUnit, XPStyleActnCtrls, ActnList,
|
||||
ActnMan, ToolWin, ActnCtrls, ComCtrls, CorelButton, ImgList,
|
||||
TFlatEditUnit, TFlatCheckBoxUnit;
|
||||
|
||||
type
|
||||
TfrmMenuMaker = class(TForm)
|
||||
pnlButtons: TPanel;
|
||||
cmdCancel: TCorelButton;
|
||||
ilButtons: TImageList;
|
||||
amButtons: TActionManager;
|
||||
acPaste: TAction;
|
||||
acCopy: TAction;
|
||||
acCut: TAction;
|
||||
acClear: TAction;
|
||||
acMenu: TAction;
|
||||
acGrey: TAction;
|
||||
acRed: TAction;
|
||||
acWhite: TAction;
|
||||
acYellow: TAction;
|
||||
cmdNext: TCorelButton;
|
||||
nbkPages: TNotebook;
|
||||
atbButtons: TActionToolBar;
|
||||
rtfEditor: TRichEdit;
|
||||
pnlSettings: TPanel;
|
||||
chkRegisterMenuCommand: TFlatCheckBox;
|
||||
chkAddComment: TFlatCheckBox;
|
||||
txtKeys: TFlatEdit;
|
||||
lblKeys: TLabel;
|
||||
bvlSpace: TBevel;
|
||||
lblSettings: TLabel;
|
||||
lblName: TLabel;
|
||||
txtMenuName: TFlatEdit;
|
||||
txtTime: TFlatEdit;
|
||||
chkUseTime: TFlatCheckBox;
|
||||
chkAppendOnlyMenuText: TFlatCheckBox;
|
||||
lblNote: TLabel;
|
||||
lblSettingsPlayers: TLabel;
|
||||
pnlSettingsPlayers: TPanel;
|
||||
lblMenu: TLabel;
|
||||
txtMenu: TFlatEdit;
|
||||
lblHelp: TLabel;
|
||||
chkAlive: TFlatCheckBox;
|
||||
bvlSpace2: TBevel;
|
||||
chkRegister: TFlatCheckBox;
|
||||
chkComments: TFlatCheckBox;
|
||||
chkImmunity: TFlatCheckBox;
|
||||
procedure acCopyExecute(Sender: TObject);
|
||||
procedure acCutExecute(Sender: TObject);
|
||||
procedure acPasteExecute(Sender: TObject);
|
||||
procedure acClearExecute(Sender: TObject);
|
||||
procedure acYellowExecute(Sender: TObject);
|
||||
procedure acWhiteExecute(Sender: TObject);
|
||||
procedure acRedExecute(Sender: TObject);
|
||||
procedure acGreyExecute(Sender: TObject);
|
||||
procedure txtKeysChange(Sender: TObject);
|
||||
procedure cmdCancelClick(Sender: TObject);
|
||||
procedure cmdNextClick(Sender: TObject);
|
||||
procedure rtfEditorKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
procedure rtfEditorKeyUp(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
procedure rtfEditorMouseDown(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure rtfEditorMouseUp(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure chkUseTimeClick(Sender: TObject);
|
||||
procedure txtMenuNameKeyPress(Sender: TObject; var Key: Char);
|
||||
procedure chkAppendOnlyMenuTextClick(Sender: TObject);
|
||||
procedure txtTimeChange(Sender: TObject);
|
||||
procedure rtfEditorChange(Sender: TObject);
|
||||
procedure acMenuExecute(Sender: TObject);
|
||||
procedure lblHelpMouseEnter(Sender: TObject);
|
||||
procedure lblHelpMouseLeave(Sender: TObject);
|
||||
procedure lblHelpClick(Sender: TObject);
|
||||
private
|
||||
Editing: Boolean;
|
||||
FDefaultMenu: Boolean;
|
||||
procedure SetDefaultMenu(const Value: Boolean);
|
||||
public
|
||||
property DefaultMenu: Boolean read FDefaultMenu write SetDefaultMenu;
|
||||
function GetColoredMenu: String;
|
||||
procedure SetButton(Action: TAction);
|
||||
procedure UpdateCurColor;
|
||||
procedure Reset;
|
||||
end;
|
||||
|
||||
var
|
||||
frmMenuMaker: TfrmMenuMaker;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitAddMenu, UnitfrmSelectMenu, UnitfrmMain, UnitHowToMakePlayerMenu;
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmMenuMaker.acCopyExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.CopyToClipboard;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acCutExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.CutToClipboard;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acPasteExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.PasteFromClipboard;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acClearExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.Clear;
|
||||
rtfEditor.SelAttributes.Color := clWhite;
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acYellowExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.SelAttributes.Color := clYellow;
|
||||
SetButton(acYellow);
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acWhiteExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.SelAttributes.Color := clWhite;
|
||||
SetButton(acWhite);
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acRedExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.SelAttributes.Color := clRed;
|
||||
SetButton(acRed);
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acGreyExecute(Sender: TObject);
|
||||
begin
|
||||
rtfEditor.SelAttributes.Color := clGray;
|
||||
SetButton(acGrey);
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.SetButton(Action: TAction);
|
||||
begin
|
||||
if Action <> acYellow then
|
||||
acYellow.Checked := False;
|
||||
if Action <> acWhite then
|
||||
acWhite.Checked := False;
|
||||
if Action <> acRed then
|
||||
acRed.Checked := False;
|
||||
if Action <> acGrey then
|
||||
acGrey.Checked := False;
|
||||
Action.Checked := True;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.txtKeysChange(Sender: TObject);
|
||||
begin
|
||||
try
|
||||
StrToInt(Trim((Sender As TFlatEdit).Text));
|
||||
except
|
||||
if Sender = txtKeys then begin
|
||||
(Sender As TFlatEdit).Text := '1';
|
||||
SysUtils.Beep;
|
||||
end
|
||||
else
|
||||
(Sender As TFlatEdit).Text := '';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.cmdCancelClick(Sender: TObject);
|
||||
begin
|
||||
if nbkPages.PageIndex = 0 then
|
||||
ModalResult := mrCancel
|
||||
else begin
|
||||
nbkPages.PageIndex := 0;
|
||||
if not DefaultMenu then begin
|
||||
lblNote.Visible := True;
|
||||
lblHelp.Visible := True;
|
||||
end;
|
||||
cmdCancel.Caption := 'Cancel';
|
||||
cmdNext.Caption := '&Next >';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.cmdNextClick(Sender: TObject);
|
||||
function IsNumeric(eChar: Char): Boolean;
|
||||
begin
|
||||
Result := Pos(eChar, '0123456789') <> 0;
|
||||
end;
|
||||
var i: integer;
|
||||
eColoredMenu: String;
|
||||
begin
|
||||
if Editing then begin
|
||||
eColoredMenu := GetColoredMenu;
|
||||
frmMain.sciEditor.Lines[frmSelectMenu.eLines[frmSelectMenu.GetItemIndex]] := StringReplace(frmMain.sciEditor.Lines[frmSelectMenu.eLines[frmSelectMenu.GetItemIndex]], '"' + frmSelectMenu.eMenuStr[frmSelectMenu.GetItemIndex] + '"', '"' + eColoredMenu + '"', []);
|
||||
Editing := False;
|
||||
ModalResult := mrOk;
|
||||
end
|
||||
else if nbkPages.PageIndex = 0 then begin // Editor
|
||||
if DefaultMenu then begin
|
||||
txtKeys.Text := '0';
|
||||
for i := 0 to rtfEditor.Lines.Count -1 do begin
|
||||
if Length(rtfEditor.Lines[i]) <> 0 then begin
|
||||
if IsNumeric(rtfEditor.Lines[i][1]) then
|
||||
txtKeys.Text := txtKeys.Text + rtfEditor.Lines[i][1];
|
||||
end;
|
||||
end;
|
||||
if Length(txtKeys.Text) <> 1 then
|
||||
txtKeys.Text := Copy(txtKeys.Text, 2, Length(txtKeys.Text));
|
||||
nbkPages.PageIndex := 1;
|
||||
end
|
||||
else begin
|
||||
if Pos('$players', LowerCase(rtfEditor.Lines.Text)) = 0 then begin
|
||||
MessageBox(Handle, 'You forgot to set the players.', 'Warning', MB_ICONWARNING);
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (Pos('$next', LowerCase(rtfEditor.Lines.Text)) = 0) and (Pos('$back', LowerCase(rtfEditor.Lines.Text)) = 0) then
|
||||
MessageBox(Handle, 'You should set a "Next" and a "Back" key.', 'Warning', MB_ICONWARNING)
|
||||
else if Pos('$next', LowerCase(rtfEditor.Lines.Text)) = 0 then
|
||||
MessageBox(Handle, 'You should set a "Next"-key.', 'Warning', MB_ICONWARNING)
|
||||
else if Pos('$exitorback', LowerCase(rtfEditor.Lines.Text)) = 0 then
|
||||
MessageBox(Handle, 'You should set a "Back"-key.', 'Warning', MB_ICONWARNING);
|
||||
|
||||
nbkPages.PageIndex := 2;
|
||||
end;
|
||||
cmdCancel.Caption := '< &Back';
|
||||
cmdNext.Caption := 'Finish';
|
||||
end
|
||||
else if nbkPages.PageIndex = 1 then begin // Default finish
|
||||
if (txtMenuName.Text = '') and (not chkAppendOnlyMenuText.Checked) then
|
||||
MessageBox(Handle, 'Invalid menu name.', 'Warning', MB_ICONWARNING)
|
||||
else begin
|
||||
Screen.Cursor := crHourGlass;
|
||||
if AddMenu then
|
||||
ModalResult := mrOk
|
||||
else
|
||||
MessageBox(Handle, 'Menu already exists. Please choose another name.', 'Warning', MB_ICONWARNING);
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
end
|
||||
else begin // Player finish
|
||||
if (txtMenu.Text = '') then
|
||||
MessageBox(Handle, 'Invalid menu name.', 'Warning', MB_ICONWARNING)
|
||||
else begin
|
||||
if AddPlayerMenu then
|
||||
ModalResult := mrOk;
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
end;
|
||||
lblNote.Visible := False;
|
||||
lblHelp.Visible := False;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.UpdateCurColor;
|
||||
begin
|
||||
case rtfEditor.SelAttributes.Color of
|
||||
clYellow: SetButton(acYellow);
|
||||
clWhite: SetButton(acWhite);
|
||||
clRed: SetButton(acRed);
|
||||
clGray: SetButton(acGrey);
|
||||
end;
|
||||
atbButtons.RecreateControls;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.rtfEditorKeyDown(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.rtfEditorKeyUp(Sender: TObject; var Key: Word;
|
||||
Shift: TShiftState);
|
||||
begin
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.rtfEditorMouseDown(Sender: TObject;
|
||||
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.rtfEditorMouseUp(Sender: TObject;
|
||||
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.chkUseTimeClick(Sender: TObject);
|
||||
begin
|
||||
txtTime.Enabled := chkUseTime.Checked;
|
||||
if not chkUseTime.Checked then
|
||||
txtTime.Text := '-1';
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.txtMenuNameKeyPress(Sender: TObject;
|
||||
var Key: Char);
|
||||
begin
|
||||
if Key = #32 then
|
||||
Key := #0;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.chkAppendOnlyMenuTextClick(Sender: TObject);
|
||||
begin
|
||||
lblKeys.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
txtKeys.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
chkAddComment.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
chkRegisterMenuCommand.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
chkUseTime.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
txtTime.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
lblName.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
txtMenuName.Enabled := not chkAppendOnlyMenuText.Checked;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.txtTimeChange(Sender: TObject);
|
||||
begin
|
||||
try
|
||||
if StrToInt(txtTime.Text) < -1 then begin
|
||||
txtTime.Text := '-1';
|
||||
SysUtils.Beep;
|
||||
end;
|
||||
except
|
||||
txtTime.Text := '1000';
|
||||
SysUtils.Beep;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.rtfEditorChange(Sender: TObject);
|
||||
begin
|
||||
cmdNext.Enabled := rtfEditor.Text <> '';
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.SetDefaultMenu(const Value: Boolean);
|
||||
begin
|
||||
FDefaultMenu := Value;
|
||||
lblNote.Visible := not Value;
|
||||
lblHelp.Visible := not Value;
|
||||
acMenu.Enabled := Value;
|
||||
Editing := False;
|
||||
if Value then
|
||||
Caption := 'Menu Maker'
|
||||
else
|
||||
Caption := 'Player Menu Maker';
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.acMenuExecute(Sender: TObject);
|
||||
var eTemp: String;
|
||||
begin
|
||||
if frmSelectMenu.ShowModal = mrOk then begin
|
||||
atbButtons.RecreateControls;
|
||||
if frmSelectMenu.GetItemIndex = -1 then
|
||||
frmSelectMenu.lstMenu.Selected[0] := True;
|
||||
|
||||
DefaultMenu := True;
|
||||
Editing := True;
|
||||
rtfEditor.Clear;
|
||||
rtfEditor.SelAttributes.Color := clWhite;
|
||||
eTemp := frmSelectMenu.eMenuStr[frmSelectMenu.GetItemIndex];
|
||||
if eTemp <> '' then begin
|
||||
while Length(eTemp) <> 0 do begin
|
||||
if eTemp[1] = '\' then begin
|
||||
if Length(eTemp) <> 1 then begin
|
||||
case LowerCase(eTemp[2])[1] of
|
||||
'w': rtfEditor.SelAttributes.Color := clWhite;
|
||||
'r': rtfEditor.SelAttributes.Color := clRed;
|
||||
'd': rtfEditor.SelAttributes.Color := clGray;
|
||||
'y': rtfEditor.SelAttributes.Color := clYellow;
|
||||
end;
|
||||
end;
|
||||
Delete(eTemp, 1, 2);
|
||||
end
|
||||
else if Copy(eTemp, 1, 2) = '^n' then begin
|
||||
rtfEditor.SelText := #13#10;
|
||||
Delete(eTemp, 1, 2);
|
||||
end
|
||||
else begin
|
||||
rtfEditor.SelText := eTemp[1];
|
||||
Delete(eTemp, 1, 1);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
cmdNext.Caption := 'Finish edit';
|
||||
end
|
||||
else
|
||||
atbButtons.RecreateControls;
|
||||
end;
|
||||
|
||||
function TfrmMenuMaker.GetColoredMenu: String;
|
||||
var i: integer;
|
||||
eCurColor: TColor;
|
||||
begin
|
||||
eCurColor := clWhite;
|
||||
Result := '';
|
||||
for i := 0 to Length(rtfEditor.Lines.Text) -1 do begin
|
||||
rtfEditor.SelStart := i;
|
||||
if rtfEditor.SelAttributes.Color <> eCurColor then begin
|
||||
eCurColor := rtfEditor.SelAttributes.Color;
|
||||
case eCurColor of
|
||||
clWhite : Result := Result + '\w';
|
||||
clYellow: Result := Result + '\y';
|
||||
clRed : Result := Result + '\r';
|
||||
clGray : Result := Result + '\d';
|
||||
end;
|
||||
end;
|
||||
Result := Result + rtfEditor.Lines.Text[i+1];
|
||||
end;
|
||||
rtfEditor.SelStart := 0;
|
||||
Result := StringReplace(Result, #13, '^n', [rfReplaceAll]);
|
||||
Result := StringReplace(Result, #10, '', [rfReplaceAll]);
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.Reset;
|
||||
begin
|
||||
rtfEditor.Clear;
|
||||
rtfEditor.SelAttributes.Color := clWhite;
|
||||
txtKeys.Text := '1';
|
||||
txtMenu.Clear;
|
||||
txtMenuName.Clear;
|
||||
UpdateCurColor;
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.lblHelpMouseEnter(Sender: TObject);
|
||||
begin
|
||||
lblHelp.Font.Color := clBlue;
|
||||
lblHelp.Font.Style := [fsUnderline];
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.lblHelpMouseLeave(Sender: TObject);
|
||||
begin
|
||||
lblHelp.Font.Color := clWindowText;
|
||||
lblHelp.Font.Style := [];
|
||||
end;
|
||||
|
||||
procedure TfrmMenuMaker.lblHelpClick(Sender: TObject);
|
||||
procedure Append(eText: String);
|
||||
begin
|
||||
rtfEditor.SelText := eText + #13#10;
|
||||
rtfEditor.SelStart := Length(rtfEditor.Lines.Text);
|
||||
end;
|
||||
|
||||
begin
|
||||
if frmHowToMakePlayerMenu.ShowModal = mrYes then begin
|
||||
rtfEditor.Clear;
|
||||
rtfEditor.SelAttributes.Color := clYellow;
|
||||
Append('Kick player');
|
||||
Append('');
|
||||
rtfEditor.SelAttributes.Color := clWhite;
|
||||
Append('$players(1,8,%n. %v)');
|
||||
Append('$next(9,9. Next)');
|
||||
Append('');
|
||||
Append('$exitorback(0,0. Exit,0. Back)');
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
156
editor/editor2/UnitfrmOptions.pas
Executable file
156
editor/editor2/UnitfrmOptions.pas
Executable file
@ -0,0 +1,156 @@
|
||||
unit UnitfrmOptions;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, ComCtrls, TFlatEditUnit,
|
||||
TFlatSpeedButtonUnit, TFlatCheckBoxUnit, TFlatComboBoxUnit, FileCtrl,
|
||||
TFlatTabControlUnit, TFlatRadioButtonUnit, Dialogs;
|
||||
|
||||
type
|
||||
TfrmSettings = class(TForm)
|
||||
lblSettings: TLabel;
|
||||
cmdClose: TFlatSpeedButton;
|
||||
odHalfLife: TOpenDialog;
|
||||
ftcPages: TFlatTabControl;
|
||||
nbkPages: TNotebook;
|
||||
pnlHighlighter: TPanel;
|
||||
lblComments: TLabel;
|
||||
lblDirectives: TLabel;
|
||||
lblOperators: TLabel;
|
||||
lblStrings: TLabel;
|
||||
lblKeywords: TLabel;
|
||||
lblActiveLine: TLabel;
|
||||
cboComments: TColorBox;
|
||||
cboDirectives: TColorBox;
|
||||
cboOperators: TColorBox;
|
||||
cboStrings: TColorBox;
|
||||
cboKeywords: TColorBox;
|
||||
cboActiveLine: TColorBox;
|
||||
pnlGeneralSettings: TPanel;
|
||||
lblAMXX: TLabel;
|
||||
cmdBrowseAMXX: TFlatSpeedButton;
|
||||
cmdBrowseHalfLife: TFlatSpeedButton;
|
||||
lblHalfLife: TLabel;
|
||||
cmdBrowseSave: TFlatSpeedButton;
|
||||
lblSave: TLabel;
|
||||
txtAMXXPath: TFlatEdit;
|
||||
txtHalfLife: TFlatEdit;
|
||||
txtSave: TFlatEdit;
|
||||
pnlGeneral: TPanel;
|
||||
lblFoldingStyle: TLabel;
|
||||
chkAutoComplete: TFlatCheckBox;
|
||||
chkHighlighting: TFlatCheckBox;
|
||||
cboFoldingStyle: TFlatComboBox;
|
||||
chkHints: TFlatCheckBox;
|
||||
chkAutoIndent: TFlatCheckBox;
|
||||
chkBrackets: TFlatCheckBox;
|
||||
lblHighlighter: TLabel;
|
||||
lblEditor: TLabel;
|
||||
lblDirectories: TLabel;
|
||||
lblCompilerSettings: TLabel;
|
||||
lblFTP: TLabel;
|
||||
lblMisc: TLabel;
|
||||
lblView: TLabel;
|
||||
pnlCharCompleter: TPanel;
|
||||
chkAutoCloseBrackets: TFlatCheckBox;
|
||||
chkAutoCloseQuotes: TFlatCheckBox;
|
||||
pnlCompilerSettings: TPanel;
|
||||
optWindow: TFlatRadioButton;
|
||||
optList: TFlatRadioButton;
|
||||
pnlFTP: TPanel;
|
||||
lblHost: TLabel;
|
||||
lblPort: TLabel;
|
||||
lblUser: TLabel;
|
||||
lblPassword: TLabel;
|
||||
lblStandardDir: TLabel;
|
||||
cmdCheckFTP: TFlatSpeedButton;
|
||||
txtHost: TFlatEdit;
|
||||
txtPort: TFlatEdit;
|
||||
txtUser: TFlatEdit;
|
||||
txtPassword: TFlatEdit;
|
||||
txtStandardDir: TFlatEdit;
|
||||
pnlMisc: TPanel;
|
||||
chkReload: TFlatCheckBox;
|
||||
chkAutoAddPlugins: TFlatCheckBox;
|
||||
pnlView: TPanel;
|
||||
lblCodeExplorer: TLabel;
|
||||
cboCodeExplorer: TFlatComboBox;
|
||||
chkStatusbar: TFlatCheckBox;
|
||||
lblCharCompleter: TLabel;
|
||||
procedure cmdBrowseAMXXClick(Sender: TObject);
|
||||
procedure cmdBrowseHalfLifeClick(Sender: TObject);
|
||||
procedure cmdBrowseSaveClick(Sender: TObject);
|
||||
procedure chkAutoAddPluginsMouseUp(Sender: TObject;
|
||||
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
procedure ftcPagesTabChanged(Sender: TObject);
|
||||
procedure cmdCheckFTPClick(Sender: TObject);
|
||||
end;
|
||||
|
||||
var
|
||||
frmSettings: TfrmSettings;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMain;
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmSettings.cmdBrowseAMXXClick(Sender: TObject);
|
||||
var eDir: String;
|
||||
begin
|
||||
if SelectDirectory('Please select your AMXX directory:', 'C:', eDir) then
|
||||
txtAMXXPath.Text := eDir;
|
||||
end;
|
||||
|
||||
procedure TfrmSettings.cmdBrowseHalfLifeClick(Sender: TObject);
|
||||
begin
|
||||
if odHalfLife.Execute then
|
||||
txtHalfLife.Text := odHalfLife.FileName;
|
||||
end;
|
||||
|
||||
procedure TfrmSettings.cmdBrowseSaveClick(Sender: TObject);
|
||||
var eDir: String;
|
||||
begin
|
||||
if SelectDirectory('Please select the directory where your files shall be saved:', 'C:', eDir) then
|
||||
txtSave.Text := eDir;
|
||||
end;
|
||||
|
||||
procedure TfrmSettings.chkAutoAddPluginsMouseUp(Sender: TObject;
|
||||
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
if (chkAutoAddPlugins.Checked) and (Button = mbLeft) then
|
||||
MessageBox(Handle, 'Notice: This function works only with plugins which are saved in $AMXXDIR$\scripting.', 'Information', MB_ICONINFORMATION);
|
||||
end;
|
||||
|
||||
procedure TfrmSettings.ftcPagesTabChanged(Sender: TObject);
|
||||
begin
|
||||
nbkPages.PageIndex := ftcPages.ActiveTab;
|
||||
end;
|
||||
|
||||
procedure TfrmSettings.cmdCheckFTPClick(Sender: TObject);
|
||||
begin
|
||||
try
|
||||
with frmMain.IdFTP do begin
|
||||
Host := txtHost.Text;
|
||||
Port := StrToInt(txtPort.Text);
|
||||
Username := txtUser.Text;
|
||||
Password := txtPassword.Text;
|
||||
try
|
||||
Connect;
|
||||
ChangeDir(txtStandardDir.Text);
|
||||
MessageBox(Handle, 'Test successfully done!', 'Information', MB_ICONINFORMATION)
|
||||
except
|
||||
on E: Exception do
|
||||
MessageBox(Handle, PChar(E.Message), 'Error', MB_ICONWARNING);
|
||||
end;
|
||||
if Connected then
|
||||
Disconnect;
|
||||
end;
|
||||
except
|
||||
MessageBox(Handle, 'Invalid FTP port.', 'Warning', MB_ICONWARNING);
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
41
editor/editor2/UnitfrmSaveDialog.pas
Executable file
41
editor/editor2/UnitfrmSaveDialog.pas
Executable file
@ -0,0 +1,41 @@
|
||||
unit UnitfrmSaveDialog;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, CheckLst, TFlatSpeedButtonUnit;
|
||||
|
||||
type
|
||||
TfrmSaveDialog = class(TForm)
|
||||
lstFiles: TCheckListBox;
|
||||
shpFiles: TShape;
|
||||
cmdSave: TFlatSpeedButton;
|
||||
cmdCancel: TFlatSpeedButton;
|
||||
lblInfo: TLabel;
|
||||
procedure lstFilesClickCheck(Sender: TObject);
|
||||
public
|
||||
SaveCaption: String;
|
||||
CloseCaption: String;
|
||||
end;
|
||||
|
||||
var
|
||||
frmSaveDialog: TfrmSaveDialog;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmSaveDialog.lstFilesClickCheck(Sender: TObject);
|
||||
var i: integer;
|
||||
begin
|
||||
for i := 0 to lstFiles.Items.Count -1 do begin
|
||||
if lstFiles.Checked[i] then begin
|
||||
cmdSave.Caption := SaveCaption;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
cmdSave.Caption := CloseCaption;
|
||||
end;
|
||||
|
||||
end.
|
80
editor/editor2/UnitfrmSelectMenu.pas
Executable file
80
editor/editor2/UnitfrmSelectMenu.pas
Executable file
@ -0,0 +1,80 @@
|
||||
unit UnitfrmSelectMenu;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Windows, Messages, Classes, Graphics, Controls,
|
||||
StdCtrls, ExtCtrls, Forms, CorelButton, TFlatListBoxUnit;
|
||||
|
||||
type
|
||||
TfrmSelectMenu = class(TForm)
|
||||
cmdOK: TCorelButton;
|
||||
cmdCancel: TCorelButton;
|
||||
lblSelect: TLabel;
|
||||
lstMenu: TFlatListBox;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
public
|
||||
eMenuStr: TStringList;
|
||||
eLines: array of Integer;
|
||||
function GetItemIndex: Integer;
|
||||
end;
|
||||
|
||||
var
|
||||
frmSelectMenu: TfrmSelectMenu;
|
||||
|
||||
implementation
|
||||
|
||||
uses UnitfrmMenuMaker, UnitfrmMain, UnitAddMenu, UnitFunc, UnitTextAnalyze;
|
||||
|
||||
{$R *.DFM}
|
||||
|
||||
procedure TfrmSelectMenu.FormCreate(Sender: TObject);
|
||||
begin
|
||||
eMenuStr := TStringList.Create;
|
||||
end;
|
||||
|
||||
procedure TfrmSelectMenu.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
eMenuStr.Free;
|
||||
end;
|
||||
|
||||
procedure TfrmSelectMenu.FormShow(Sender: TObject);
|
||||
var i: integer;
|
||||
eTemp: String;
|
||||
begin
|
||||
eMenuStr.Clear;
|
||||
lstMenu.Items.Clear;
|
||||
SetLength(eLines, 0);
|
||||
for i := 0 to frmMain.sciEditor.Lines.Count -1 do begin
|
||||
if Pos('show_menu', Trim(LowerCase(frmMain.sciEditor.Lines[i]))) = 1 then begin
|
||||
SetLength(eLines, eMenuStr.Count +1);
|
||||
eLines[eMenuStr.Count] := i;
|
||||
eTemp := frmMain.sciEditor.Lines[i];
|
||||
if CountChars(frmMain.sciEditor.Lines[i], '"') >= 4 then begin
|
||||
eMenuStr.Add(Between(eTemp, '"', '"'));
|
||||
while CountChars(eTemp, '"') > 2 do
|
||||
Delete(eTemp, 1, 1);
|
||||
lstMenu.Items.Add(Between(eTemp, '"', '"'));
|
||||
end
|
||||
else begin
|
||||
eMenuStr.Add(Between(eTemp, '"', '"'));
|
||||
lstMenu.Items.Add(Format('Unknown Menu on line %s', [IntToStr(i)]));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
cmdOK.Enabled := lstMenu.Items.Count <> 0;
|
||||
end;
|
||||
|
||||
function TfrmSelectMenu.GetItemIndex: Integer;
|
||||
var i: integer;
|
||||
begin
|
||||
Result := -1;
|
||||
for i := 0 to lstMenu.Items.Count -1 do begin
|
||||
if lstMenu.Selected[i] then
|
||||
Result := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
191
editor/editor2/UnitfrmSockets.dfm
Executable file
191
editor/editor2/UnitfrmSockets.dfm
Executable file
@ -0,0 +1,191 @@
|
||||
object frmSocketTerminal: TfrmSocketTerminal
|
||||
Left = 192
|
||||
Top = 110
|
||||
ActiveControl = rtfEnter
|
||||
BorderStyle = bsDialog
|
||||
Caption = 'Socket Terminal'
|
||||
ClientHeight = 230
|
||||
ClientWidth = 324
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
FormStyle = fsStayOnTop
|
||||
OldCreateOrder = False
|
||||
Position = poMainFormCenter
|
||||
OnClose = FormClose
|
||||
PixelsPerInch = 96
|
||||
TextHeight = 13
|
||||
object pnlSettings: TPanel
|
||||
Left = 0
|
||||
Top = 141
|
||||
Width = 324
|
||||
Height = 89
|
||||
Align = alBottom
|
||||
BevelOuter = bvNone
|
||||
TabOrder = 2
|
||||
object lblStatusCaption: TLabel
|
||||
Left = 2
|
||||
Top = 72
|
||||
Width = 35
|
||||
Height = 13
|
||||
Caption = 'Status:'
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
ParentFont = False
|
||||
end
|
||||
object lblStatus: TLabel
|
||||
Left = 40
|
||||
Top = 72
|
||||
Width = 69
|
||||
Height = 13
|
||||
Caption = 'not connected'
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clRed
|
||||
Font.Height = -11
|
||||
Font.Name = 'Tahoma'
|
||||
Font.Style = []
|
||||
ParentFont = False
|
||||
end
|
||||
object lblSettings: TLabel
|
||||
Left = 4
|
||||
Top = 6
|
||||
Width = 43
|
||||
Height = 13
|
||||
Caption = 'Settings:'
|
||||
end
|
||||
object pnlSettings2: TPanel
|
||||
Left = 4
|
||||
Top = 24
|
||||
Width = 311
|
||||
Height = 41
|
||||
BevelOuter = bvLowered
|
||||
TabOrder = 0
|
||||
object lblHost: TLabel
|
||||
Left = 4
|
||||
Top = 3
|
||||
Width = 26
|
||||
Height = 13
|
||||
Caption = 'Host:'
|
||||
end
|
||||
object lblPort: TLabel
|
||||
Left = 130
|
||||
Top = 3
|
||||
Width = 24
|
||||
Height = 13
|
||||
Caption = 'Port:'
|
||||
end
|
||||
object txtHost: TFlatEdit
|
||||
Left = 4
|
||||
Top = 17
|
||||
Width = 121
|
||||
Height = 19
|
||||
ColorFlat = clBtnFace
|
||||
ParentColor = True
|
||||
TabOrder = 0
|
||||
end
|
||||
object txtPort: TFlatEdit
|
||||
Left = 130
|
||||
Top = 17
|
||||
Width = 39
|
||||
Height = 19
|
||||
ColorFlat = clBtnFace
|
||||
ParentColor = True
|
||||
TabOrder = 1
|
||||
Text = '1'
|
||||
OnChange = txtPortChange
|
||||
end
|
||||
object optUDP: TFlatRadioButton
|
||||
Left = 176
|
||||
Top = 20
|
||||
Width = 39
|
||||
Height = 17
|
||||
Caption = 'UDP'
|
||||
TabOrder = 3
|
||||
OnClick = optTCPClick
|
||||
end
|
||||
object optTCP: TFlatRadioButton
|
||||
Left = 176
|
||||
Top = 4
|
||||
Width = 35
|
||||
Height = 15
|
||||
Caption = 'TCP'
|
||||
Checked = True
|
||||
TabOrder = 2
|
||||
TabStop = True
|
||||
OnClick = optTCPClick
|
||||
end
|
||||
object cmdConnect: TFlatButton
|
||||
Left = 224
|
||||
Top = 10
|
||||
Width = 77
|
||||
Height = 21
|
||||
ColorHighLight = 8623776
|
||||
ColorShadow = 8623776
|
||||
Caption = 'Connect'
|
||||
TabOrder = 4
|
||||
OnClick = cmdConnectClick
|
||||
end
|
||||
end
|
||||
end
|
||||
object rtfEnter: TRichEdit
|
||||
Left = 0
|
||||
Top = 121
|
||||
Width = 324
|
||||
Height = 20
|
||||
Align = alBottom
|
||||
TabOrder = 1
|
||||
WantReturns = False
|
||||
OnKeyPress = rtfEnterKeyPress
|
||||
end
|
||||
object rtfReceived: TRichEdit
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 324
|
||||
Height = 121
|
||||
Align = alClient
|
||||
ScrollBars = ssVertical
|
||||
TabOrder = 0
|
||||
end
|
||||
object IdTCPClient: TIdTCPClient
|
||||
MaxLineAction = maSplit
|
||||
OnDisconnected = IdTCPClientDisconnected
|
||||
OnConnected = IdTCPClientConnected
|
||||
Port = 0
|
||||
Left = 4
|
||||
Top = 4
|
||||
end
|
||||
object IdUDPClient: TIdUDPClient
|
||||
OnStatus = IdUDPClientStatus
|
||||
Port = 0
|
||||
Left = 4
|
||||
Top = 34
|
||||
end
|
||||
object alCopyPaste: TActionList
|
||||
Left = 4
|
||||
Top = 64
|
||||
object acCopy: TAction
|
||||
Caption = 'Copy'
|
||||
ShortCut = 16451
|
||||
OnExecute = acCopyExecute
|
||||
end
|
||||
object acPaste: TAction
|
||||
Caption = 'Paste'
|
||||
ShortCut = 16470
|
||||
OnExecute = acPasteExecute
|
||||
end
|
||||
object acUndo: TAction
|
||||
Caption = 'Undo'
|
||||
OnExecute = acUndoExecute
|
||||
end
|
||||
object acSelectAll: TAction
|
||||
Caption = 'Select all'
|
||||
OnExecute = acSelectAllExecute
|
||||
end
|
||||
end
|
||||
end
|
259
editor/editor2/UnitfrmSockets.pas
Executable file
259
editor/editor2/UnitfrmSockets.pas
Executable file
@ -0,0 +1,259 @@
|
||||
unit UnitfrmSockets;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, ExtCtrls, StdCtrls, ComCtrls, TFlatEditUnit,
|
||||
TFlatRadioButtonUnit, TFlatButtonUnit, IdUDPBase, IdUDPClient,
|
||||
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, UnitReadThread,
|
||||
ActnList;
|
||||
|
||||
type
|
||||
TfrmSocketTerminal = class(TForm)
|
||||
pnlSettings: TPanel;
|
||||
rtfEnter: TRichEdit;
|
||||
rtfReceived: TRichEdit;
|
||||
lblStatusCaption: TLabel;
|
||||
lblStatus: TLabel;
|
||||
lblSettings: TLabel;
|
||||
pnlSettings2: TPanel;
|
||||
lblHost: TLabel;
|
||||
txtHost: TFlatEdit;
|
||||
txtPort: TFlatEdit;
|
||||
lblPort: TLabel;
|
||||
optUDP: TFlatRadioButton;
|
||||
optTCP: TFlatRadioButton;
|
||||
cmdConnect: TFlatButton;
|
||||
IdTCPClient: TIdTCPClient;
|
||||
IdUDPClient: TIdUDPClient;
|
||||
alCopyPaste: TActionList;
|
||||
acCopy: TAction;
|
||||
acPaste: TAction;
|
||||
acUndo: TAction;
|
||||
acSelectAll: TAction;
|
||||
procedure txtPortChange(Sender: TObject);
|
||||
procedure cmdConnectClick(Sender: TObject);
|
||||
procedure optTCPClick(Sender: TObject);
|
||||
procedure IdTCPClientConnected(Sender: TObject);
|
||||
procedure IdTCPClientDisconnected(Sender: TObject);
|
||||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||||
procedure rtfEnterKeyPress(Sender: TObject; var Key: Char);
|
||||
procedure IdUDPClientStatus(ASender: TObject; const AStatus: TIdStatus;
|
||||
const AStatusText: String);
|
||||
procedure acCopyExecute(Sender: TObject);
|
||||
procedure acPasteExecute(Sender: TObject);
|
||||
procedure acUndoExecute(Sender: TObject);
|
||||
procedure acSelectAllExecute(Sender: TObject);
|
||||
private
|
||||
ReadThread: TReadThread;
|
||||
public
|
||||
procedure Append(eText: String; eColor: TColor = clBlack);
|
||||
procedure SetStatus(eStatus: String; eColor: TColor);
|
||||
procedure OnRead(eRead: String);
|
||||
procedure EnableControls(eValue: Boolean);
|
||||
end;
|
||||
|
||||
var
|
||||
frmSocketTerminal: TfrmSocketTerminal;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.dfm}
|
||||
|
||||
procedure TfrmSocketTerminal.Append(eText: String; eColor: TColor);
|
||||
begin
|
||||
eText := Format('[%s] %s', [TimeToStr(Time), eText]);
|
||||
rtfReceived.SelStart := Length(rtfReceived.Lines.Text);
|
||||
rtfReceived.SelAttributes.Color := eColor;
|
||||
rtfReceived.SelText := eText + #13#10;
|
||||
rtfReceived.Perform(WM_VSCROLL, SB_BOTTOM, 0);
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.OnRead(eRead: String);
|
||||
begin
|
||||
Append(eRead, clWindowText);
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.SetStatus(eStatus: String; eColor: TColor);
|
||||
begin
|
||||
lblStatus.Caption := eStatus;
|
||||
lblStatus.Font.Color := eColor;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.txtPortChange(Sender: TObject);
|
||||
begin
|
||||
try
|
||||
StrToInt(txtPort.Text);
|
||||
except
|
||||
txtPort.Text := '1';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.cmdConnectClick(Sender: TObject);
|
||||
begin
|
||||
if Tag = 0 then begin
|
||||
if optTCP.Checked then begin
|
||||
IdTCPClient.Host := txtHost.Text;
|
||||
IdTCPClient.Port := StrToInt(txtPort.Text);
|
||||
EnableControls(False);
|
||||
Append('Connecting to ' + txtHost.Text + ':' + txtPort.Text + '...', clHighlight);
|
||||
try
|
||||
IdTCPClient.Connect;
|
||||
ReadThread := TReadThread.Create(True);
|
||||
ReadThread.ReadTCP := True;
|
||||
ReadThread.Resume;
|
||||
except
|
||||
on E: Exception do begin
|
||||
MessageBox(Handle, PChar('Couldn''t connect to server:' + #13 + E.Message), 'Warning', MB_ICONWARNING);
|
||||
EnableControls(True);
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
IdUDPClient.Host := txtHost.Text;
|
||||
IdUDPClient.Port := StrToInt(txtPort.Text);
|
||||
EnableControls(False);
|
||||
try
|
||||
IdUDPClient.Active := True;
|
||||
ReadThread := TReadThread.Create(True);
|
||||
ReadThread.ReadTCP := False;
|
||||
ReadThread.Resume;
|
||||
SetStatus('socket active', clGreen);
|
||||
Append('Opened socket to ' + txtHost.Text + ':' + txtPort.Text + '!', clGreen);
|
||||
except
|
||||
on E: Exception do begin
|
||||
MessageBox(Handle, PChar('Couldn''t activate socket:' + #13 + E.Message), 'Warning', MB_ICONWARNING);
|
||||
EnableControls(True);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
if optTCP.Checked then begin
|
||||
Screen.Cursor := crHourGlass;
|
||||
IdTCPClient.Disconnect;
|
||||
ReadThread.Terminate;
|
||||
while Tag <> 0 do begin
|
||||
Sleep(5);
|
||||
Application.ProcessMessages;
|
||||
end;
|
||||
Screen.Cursor := crDefault;
|
||||
end
|
||||
else begin
|
||||
Screen.Cursor := crHourGlass;
|
||||
IdUDPClient.Active := False;
|
||||
ReadThread.Terminate;
|
||||
EnableControls(True);
|
||||
SetStatus('socket inactive', clRed);
|
||||
Append('Closed socket to ' + txtHost.Text + ':' + txtPort.Text + '!', clRed);
|
||||
Screen.Cursor := crDefault;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.optTCPClick(Sender: TObject);
|
||||
begin
|
||||
if optTCP.Checked then begin
|
||||
if not IdTCPClient.Connected then
|
||||
SetStatus('not connected', clRed);
|
||||
end
|
||||
else begin
|
||||
if not IdUDPClient.Active then
|
||||
SetStatus('socket inactive', clRed);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.EnableControls(eValue: Boolean);
|
||||
begin
|
||||
txtHost.Enabled := eValue;
|
||||
txtPort.Enabled := eValue;
|
||||
lblHost.Enabled := eValue;
|
||||
lblPort.Enabled := eValue;
|
||||
optTCP.Enabled := eValue;
|
||||
optUDP.Enabled := eValue;
|
||||
if eValue then begin
|
||||
cmdConnect.Caption := 'Connect';
|
||||
Tag := 0;
|
||||
end
|
||||
else begin
|
||||
cmdConnect.Caption := 'Disconnect';
|
||||
Tag := 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.IdTCPClientConnected(Sender: TObject);
|
||||
begin
|
||||
Append('Established connection to ' + txtHost.Text + ':' + txtPort.Text, clGreen);
|
||||
SetStatus('connected', clGreen);
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.IdTCPClientDisconnected(Sender: TObject);
|
||||
begin
|
||||
Append('Disconnected from ' + txtHost.Text + ':' + txtPort.Text, clMaroon);
|
||||
EnableControls(True);
|
||||
SetStatus('not connected', clRed);
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.FormClose(Sender: TObject;
|
||||
var Action: TCloseAction);
|
||||
begin
|
||||
if Tag = 1 then
|
||||
cmdConnect.Click;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.rtfEnterKeyPress(Sender: TObject;
|
||||
var Key: Char);
|
||||
begin
|
||||
if Tag = 1 then begin
|
||||
if (Key = #13) and (rtfEnter.Text <> '') then begin
|
||||
if IdTCPClient.Connected then
|
||||
IdTCPClient.WriteLn(rtfEnter.Text)
|
||||
else
|
||||
IdUDPClient.Send(rtfEnter.Text);
|
||||
Append(rtfEnter.Text, clNavy);
|
||||
rtfEnter.Clear;
|
||||
Key := #0;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.IdUDPClientStatus(ASender: TObject;
|
||||
const AStatus: TIdStatus; const AStatusText: String);
|
||||
begin
|
||||
Append(AStatusText, clGray);
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.acCopyExecute(Sender: TObject);
|
||||
begin
|
||||
if (ActiveControl is TRichEdit) then
|
||||
TRichEdit(ActiveControl).CopyToClipboard;
|
||||
if (ActiveControl is TFlatEdit) then
|
||||
TFlatEdit(ActiveControl).CopyToClipboard;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.acPasteExecute(Sender: TObject);
|
||||
begin
|
||||
if (ActiveControl is TRichEdit) then
|
||||
TRichEdit(ActiveControl).PasteFromClipboard;
|
||||
if (ActiveControl is TFlatEdit) then
|
||||
TFlatEdit(ActiveControl).PasteFromClipboard;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.acUndoExecute(Sender: TObject);
|
||||
begin
|
||||
if (ActiveControl is TRichEdit) then
|
||||
TRichEdit(ActiveControl).Undo;
|
||||
if (ActiveControl is TFlatEdit) then
|
||||
TFlatEdit(ActiveControl).Undo;
|
||||
end;
|
||||
|
||||
procedure TfrmSocketTerminal.acSelectAllExecute(Sender: TObject);
|
||||
begin
|
||||
if (ActiveControl is TRichEdit) then
|
||||
TRichEdit(ActiveControl).SelectAll;
|
||||
if (ActiveControl is TFlatEdit) then
|
||||
TFlatEdit(ActiveControl).SelectAll;
|
||||
end;
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user