📄 help.pas
字号:
procedure THelpDlg.FormShow(Sender: TObject);
begin
nHist:=0;
Prepare;
end;
procedure THelpDlg.Prepare(sbPos: integer = 0);
var
i,j,special,Domain,Headline,TerrType: integer;
s: string;
ps: pchar;
List: THyperText;
CheckSeeAlso: boolean;
procedure AddAdv(i: integer);
begin
MainText.AddLine(Phrases.Lookup('ADVANCES',i),pkAdvIcon,i,hkAdv+hkCrossLink,i);
end;
procedure AddPreqAdv(i: integer);
begin
MainText.AddLine(Phrases.Lookup('ADVANCES',i),pkAdvIcon_AsPreq,i,hkAdv+hkCrossLink,i);
end;
procedure AddImp(i: integer);
begin
MainText.AddLine(Phrases.Lookup('IMPROVEMENTS',i),pkSmallIcon,i,hkImp+hkCrossLink,i);
end;
procedure AddPreqImp(i: integer);
begin
MainText.AddLine(Phrases.Lookup('IMPROVEMENTS',i),pkSmallIcon_AsPreq,i,hkImp+hkCrossLink,i);
end;
procedure AddTer(i: integer);
begin
if MainText.Count>1 then MainText.AddLine;
MainText.AddLine(Phrases.Lookup('TERRAIN',i),pkTer,i,hkTer,i);
end;
procedure AddFeature(i: integer);
begin
MainText.AddLine(Phrases.Lookup('FEATURES',i),pkFeature,i,hkFeature+hkCrossLink,i);
end;
procedure AddModel(i: integer);
var
pix: integer;
Name: string;
begin
if MainText.Count>1 then MainText.AddLine;
FindStdModelPicture(SpecialModelPictureCode[i],pix,Name);
MainText.AddLine(Name,pkModel,pix,hkMisc+hkCrossLink,miscModelList);
end;
procedure AddStandardBlock(Item: string);
var
i: integer;
begin
with MainText do
begin
if Item='LOGO' then
begin AddLine('',pkLogo); AddLine; end
else if Item='TECHFORMULA' then
begin
i:=Difficulty;
if i=0 then i:=2;
AddLine(Format(HelpText.Lookup('TECHFORMULA'),[TechFormula_M[i],TechFormula_D[i]]))
end
else if Item='TREATIES' then
for i:=0 to trAlliance do AddLine(Phrases.Lookup('TREATY',i),pkTreaty,i)
else if Item='EXPERIENCE' then
for i:=0 to nExp-1 do AddLine(Phrases.Lookup('EXPERIENCE',i),pkExp,i)
else if Item='MODERN' then
for i:=1 to 3 do
begin
AddLine;
AddLine(Phrases.Lookup('TERRAIN',3*12+i),pkTer,3*12+i);
end
else if Item='EERIE' then
begin
AddLine;
AddLine(Phrases.Lookup('TERRAIN',3*12),pkTer,3*12);
end
end
end;
procedure DecodeItem(s: string; var Category, Index: integer);
var
i: integer;
begin
if (length(s)>0) and (s[1]=':') then
begin
Category:=hkMisc;
Index:=0;
for i:=3 to Length(s) do Index:=Index*10+ord(s[i])-48;
case s[2] of
'A': Category:=hkAdv;
'B': Category:=hkImp;
'T': Category:=hkTer;
'F': Category:=hkFeature;
'E': Category:=hkInternet;
'C': Index:=miscCredits;
'J': Index:=miscJobList;
'G': Index:=miscGovList;
'S': Index:=miscModelList;
end;
if (Category<>hkMisc) and (Index=0) then Index:=200;
end
else
begin
Category:=hkText;
Index:=HelpText.GetHandle(copy(s,1,255));
end;
end;
procedure AddText(s: string);
var
i,p,l,ofs,CurrentFormat,FollowFormat,Picpix,LinkCategory,LinkIndex: integer;
begin
FollowFormat:=pkNormal;
while s<>'' do
begin
Picpix:=0;
LinkCategory:=0;
LinkIndex:=0;
if s[1]='$' then
begin // window caption
p:=1;
repeat inc(p) until (p>Length(s)) or (s[p]='\');
Caption:=Copy(s,2,p-2);
Delete(s,1,p);
end
else if s[1]='&' then
begin // standard block
p:=1;
repeat inc(p) until (p>Length(s)) or (s[p]='\');
AddStandardBlock(Copy(s,2,p-2));
Delete(s,1,p);
end
else if s[1]='@' then
begin // external image
p:=1;
repeat inc(p) until (p>Length(s)) or (s[p]='\');
try
ExtPic.LoadFromFile(HomeDir+'Help\'+Copy(s,2,p-2)+'.bmp');
MainText.AddLine('',pkExternal);
for i:=0 to (ExtPic.Height-12) div 24 do MainText.AddLine;
except
end;
Delete(s,1,p);
end
else
begin
case s[1] of
':',';':
begin // link
p:=1;
repeat inc(p) until (p>Length(s)) or (s[p]='\') or (s[p]=' ');
DecodeItem(copy(s,2,p-2), LinkCategory, LinkIndex);
CurrentFormat:=0;
if (LinkCategory<>hkText) and (LinkIndex<200) then // show icon
case LinkCategory of
hkAdv:
begin CurrentFormat:=pkAdvIcon; Picpix:=LinkIndex end;
hkImp:
begin CurrentFormat:=pkSmallIcon; Picpix:=LinkIndex end;
hkTer:
begin CurrentFormat:=pkTer; Picpix:=LinkIndex end;
hkFeature:
begin CurrentFormat:=pkFeature; Picpix:=LinkIndex end;
end;
if s[1]=':' then LinkCategory:=LinkCategory+hkCrossLink;
Delete(s,1,p);
end;
'!':
begin // highlited
FollowFormat:=pkCaption;
CurrentFormat:=pkCaption;
Delete(s,1,1);
end;
'-':
begin // list
FollowFormat:=pkNormal_Dot;
CurrentFormat:=pkDot;
Delete(s,1,1);
end;
else CurrentFormat:=FollowFormat;
end;
if FollowFormat=pkNormal_Dot then ofs:=20+4+8
else ofs:=8;
p:=0;
repeat
repeat inc(p) until (p>Length(s)) or (s[p]=' ') or (s[p]='\');
if (offscreen.Canvas.TextWidth(Copy(s,1,p-1))<=InnerWidth-16
-GetSystemMetrics(SM_CXVSCROLL)-ofs) then
l:=p-1
else Break;
until (p>=Length(s)) or (s[l+1]='\');
MainText.AddLine(Copy(s,1,l),CurrentFormat,Picpix,LinkCategory,LinkIndex);
if (l<Length(s)) and (s[l+1]='\') then FollowFormat:=pkNormal;
Delete(s,1,l+1);
end
end
end;
procedure AddItem(Item: string);
begin
AddText(HelpText.Lookup(Item));
end;
procedure AddModelText(i: integer);
var
pix: integer;
s: string;
begin
with MainText do
begin
if Count>1 then AddLine;
FindStdModelPicture(SpecialModelPictureCode[i],pix,s);
AddLine(s,pkCaption);
AddLine(Format(HelpText.Lookup('STRENGTH'),
[SpecialModel[i].Attack,SpecialModel[i].Defense]),pkModelFull,pix);
AddLine(Format(HelpText.Lookup('SPEED'),
[SpecialModel[i].Speed]),pkNormal_64);
AddLine(Format(HelpText.Lookup('BUILDCOST'),
[SpecialModel[i].Cost]),pkNormal_64);
s:=HelpText.Lookup('SPECIALMODEL',i);
if (s<>'') and (s<>'*') then AddText(s);
if SpecialModelPreq[i]>=0 then AddPreqAdv(SpecialModelPreq[i])
else if SpecialModelPreq[i]=preBuilder then AddPreqImp(woPyramids)
else if SpecialModelPreq[i]=preLeo then AddPreqImp(woLeo);
if SpecialModelPreq[i]<>preNone then
MainText[Count-1]:=Format(HelpText.Lookup('REQUIRED'),[MainText[Count-1]]);
end
end;
procedure AddJobList;
const
nJobHelp=8;
JobHelp: array[0..nJobHelp-1] of integer=
(jRoad,jRR,jCanal,jIrr,jFarm,jMine,jFort,jBase);
var
i,JobCost: integer;
begin
with MainText do
begin
AddLine(Phrases.Lookup('RIVER'),pkCaption);
AddLine('',pkTerImp,12);
AddLine;
AddText(HelpText.Lookup('RIVERHELP'));
for i:=0 to nJobHelp-1 do
begin
AddLine;
AddLine(Phrases.Lookup('JOBRESULT',JobHelp[i]),pkCaption);
AddLine('',pkTerImp,i);
AddLine;
AddText(HelpText.Lookup('JOBHELP',i));
JobCost:=-1;
case JobHelp[i] of
jCanal: JobCost:=CanalWork;
jFort: JobCost:=FortWork;
jBase: JobCost:=BaseWork;
end;
if JobCost>=0 then
AddText(Format(HelpText.Lookup('JOBCOST'),[JobCost]))
else AddText(HelpText.Lookup('JOBCOSTVAR'));
if JobPreq[JobHelp[i]]<>preNone then
begin
AddPreqAdv(JobPreq[JobHelp[i]]);
MainText[Count-1]:=Format(HelpText.Lookup('REQUIRED'),[MainText[Count-1]]);
end
end;
end
end;
procedure AddGraphicCredits;
var
i: integer;
s: string;
sr: TSearchRec;
List, plus: tstringlist;
begin
List:=tstringlist.Create;
plus:=tstringlist.Create;
if FindFirst(HomeDir+'Graphics\*.credits.txt',$27,sr)=0 then
repeat
plus.LoadFromFile(HomeDir+'Graphics\'+sr.Name);
List.AddStrings(plus);
until FindNext(sr)<>0;
FindClose(sr);
plus.Free;
List.Sort;
i:=1;
while i<List.Count do
if List[i]=List[i-1] then List.Delete(i)
else inc(i);
for i:=0 to List.Count-1 do
begin
s:=List[i];
while offscreen.Canvas.TextWidth(s)>InnerWidth-16
-GetSystemMetrics(SM_CXVSCROLL) do
Delete(s,Length(s),1);
MainText.AddLine(s);
end;
List.Free;
end;
procedure NextSection(Item: string);
begin
if MainText.Count>1 then
if MainText.Count=Headline+1 then MainText.Delete(Headline)
else MainText.AddLine;
MainText.AddLine(HelpText.Lookup(Item),pkCaption);
Headline:=MainText.Count-1;
end;
begin {Prepare}
with MainText do
begin
offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
CheckSeeAlso:=false;
Clear;
Headline:=-1;
if (no>=200) or not (Kind in [hkAdv,hkImp,hkTer,hkFeature]) then
AddLine;
case Kind of
hkText: AddText(HelpText.LookupByHandle(no));
hkMisc:
begin
case no of
miscCredits:
begin
AddItem('CREDITS');
AddLine;
AddGraphicCredits;
NextSection('CRED_CAPAI');
Server(sGetAICredits,0,0,ps);
AddText(ps);
NextSection('CRED_CAPLANG');
AddItem('AUTHOR');
end;
miscJobList:
begin
Caption:=HelpText.Lookup('HELPTITLE_JOBLIST');
AddJobList;
end;
miscModelList:
begin
Caption:=HelpText.Lookup('HELPTITLE_MODELLIST');
for i:=0 to nSpecialModel-1 do if i<>2 then AddModelText(i);
AddLine;
AddItem('MODELNOTE');
end;
miscGovList:
begin
Caption:=HelpText.Lookup('HELPTITLE_GOVLIST');
for i:=0 to nGov-1 do
begin
AddLine(Phrases.Lookup('GOVERNMENT',i),pkCaption);
AddText(HelpText.Lookup('GOVHELP',i));
if i>=2 then
begin
AddPreqAdv(GovPreq[i]);
MainText[Count-1]:=Format(HelpText.Lookup('REQUIRED'),[MainText[Count-1]]);
end;
if i<nGov-1 then AddLine;
end
end;
end; // case no
end;
hkAdv:
if no=200 then
begin // complete advance list
Caption:=HelpText.Lookup('HELPTITLE_TECHLIST');
List:=THyperText.Create;
for j:=0 to 3 do
begin
if j>0 then AddLine;
AddLine(HelpText.Lookup('TECHAGE',j),pkCaption);
if j=1 then
begin
AddLine(Phrases.Lookup('ADVANCES',adScience)+' '
+HelpText.Lookup('BASETECH'),
pkAdvIcon,adScience,hkAdv,adScience);
AddLine;
end;
if j=2 then
begin
AddLine(Phrases.Lookup('ADVANCES',adMassProduction)+' '
+HelpText.Lookup('BASETECH'),
pkAdvIcon,adMassProduction,hkAdv,adMassProduction);
AddLine;
end;
List.Clear;
for i:=0 to nAdv-1 do
if (i<>adScience) and (i<>adMassProduction) and (AdvValue[i] div 1000=j) then
List.AddLine(Phrases.Lookup('ADVANCES',i),pkAdvIcon,i,hkAdv,i);
List.Sort;
AddStrings(List);
end;
List.Free
end
else // single advance
begin
Caption:=Phrases.Lookup('ADVANCES',no);
AddLine(HelpText.Lookup('HELPSPEC_ADV'),pkCenter);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -