📄 messgex.pas
字号:
{$INCLUDE switches}
unit MessgEx;
interface
uses
Messg,Protocol,ScreenTools,
Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,ButtonA,
ButtonB, ButtonBase;
type
TIconSet=Set of 0..90;
TMessgExDlg = class(TBaseMessgDlg)
Button1: TButtonA;
Button2: TButtonA;
Button3: TButtonA;
DeliverBtn: TButtonB;
CostBtn: TButtonB;
procedure FormCreate(Sender:TObject);
procedure FormPaint(Sender:TObject);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
procedure DeliverBtnClick(Sender: TObject);
procedure CostBtnClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
Kind, BigIcon, TribeIcon, HelpKind, HelpNo: integer;
Icons: TIconSet;
Offer: TOffer;
end;
const
// extra message kinds
mkYesNoCancel=4; mkRebuildSell=5; mkOkHelp=6; mkOffer=7;
var
MessgExDlg:TMessgExDlg;
function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string):
integer;
procedure ContextMessage(SimpleText, SoundItem: string; ContextKind,
ContextNo: integer);
implementation
uses ClientTools,Term,Help, Select, Diplomacy, Inp;
{$R *.DFM}
procedure TMessgExDlg.FormCreate(Sender:TObject);
begin
inherited;
InitButtons(self);
Icons:=[];
BigIcon:=-1;
TribeIcon:=-1;
end;
procedure TMessgExDlg.FormShow(Sender: TObject);
begin
Button1.Visible:=true;
Button2.Visible:= Kind<>mkOK;
Button3.Visible:= Kind in [mkRebuildSell,mkYesNoCancel];
DeliverBtn.Visible:= Kind=mkOffer;
CostBtn.Visible:= Kind=mkOffer;
if Button3.Visible or (Kind=mkOffer) then
begin Button1.Left:=39; Button2.Left:=155; end
else if Button2.Visible then
begin Button1.Left:=97; Button2.Left:=213; end
else Button1.Left:=155;
case Kind of
mkYesNo, mkYesNoCancel:
begin
Button1.Caption:=Phrases.Lookup('BTN_YES');
Button2.Caption:=Phrases.Lookup('BTN_NO')
end;
mkRebuildSell:
begin
Button1.Caption:=Phrases.Lookup('BTN_REBUILD');
Button2.Caption:=Phrases.Lookup('BTN_SELL')
end;
mkOKCancel,mkOffer:
begin
Button1.Caption:=Phrases.Lookup('BTN_OK');
Button2.Caption:=Phrases.Lookup('BTN_CANCEL');
end;
else
begin
Button1.Caption:=Phrases.Lookup('BTN_OK');
Button2.Caption:=Phrases.Lookup('BTN_INFO');
end;
end;
Button3.Caption:=Phrases.Lookup('BTN_CANCEL');
if Kind=mkOffer then
begin
Offer.nDeliver:=0;
Offer.nCost:=0;
MessgText:=Format(Phrases.Lookup('FRWESAY'),[DipCommandToString(me,DipMem[me].pContact,
MyRO.Treaty[DipMem[me].pContact], ClientMode, scDipOffer,
ReceivedOffer, Offer)]);
end;
if TribeIcon>=0 then
Tribe[TribeIcon].InitAge(GetAge(TribeIcon));
if BigIcon>=0 then
TopSpace:=56
else if (TribeIcon>=0) and (Tribe[TribeIcon].faceHGr>=0) then
TopSpace:=64
else if Icons<>[] then TopSpace:=40
else TopSpace:=0;
SplitText(true);
CorrectHeight;
end;
procedure TMessgExDlg.FormPaint(Sender:TObject);
var
i,x,nIcons: integer;
begin
inherited;
if BigIcon>=0 then
FrameImage(Canvas,BigImp,ClientWidth div 2-28,24,xSizeBig,ySizeBig,
BigIcon mod 7*xSizeBig,(BigIcon+SystemIconLines*7) div 7*ySizeBig)
else if (TribeIcon>=0) and (Tribe[TribeIcon].faceHGr>=0) then
begin
Frame(Canvas,ClientWidth div 2-32-1,24-1,ClientWidth div 2+32,
24+48,$000000,$000000);
BitBlt(Canvas.Handle,ClientWidth div 2-32,24,64,48,
GrExt[Tribe[TribeIcon].faceHGr].Data.Canvas.Handle,
1+Tribe[TribeIcon].facepix mod 10 *65,
1+Tribe[TribeIcon].facepix div 10 *49, SRCCOPY)
end
else if Icons<>[] then
begin
nIcons:=0;
for i:=0 to 91 do if i in Icons then inc(nIcons);
x:=ClientWidth div 2-(nIcons-1)*24;
for i:=0 to 91 do if i in Icons then
begin
Frame(Canvas,x-18-1,23-1,x-18+36,23+20,Tex.clBevelLight,Tex.clBevelShade);
if i<84 then
BitBlt(Canvas.Handle,x-18,23,xSizeSmall,ySizeSmall,SmallImp.Canvas.Handle,
i mod 7*xSizeSmall,(i+SystemIconLines*7) div 7*ySizeSmall,SRCCOPY)
else
BitBlt(Canvas.Handle,x-18,23,36,20,GrExt[HGrSystem].Data.Canvas.Handle,
1+(i-84)*37,295,SRCCOPY);
inc(x,48);
end;
end;
if Button1.Visible then BtnFrame(Canvas,Button1.BoundsRect,Tex);
if Button2.Visible then BtnFrame(Canvas,Button2.BoundsRect,Tex);
if Button3.Visible then BtnFrame(Canvas,Button3.BoundsRect,Tex);
if DeliverBtn.Visible then BtnFrame(Canvas,DeliverBtn.BoundsRect,Tex);
if CostBtn.Visible then BtnFrame(Canvas,CostBtn.BoundsRect,Tex);
end; {FormPaint}
procedure TMessgExDlg.Button1Click(Sender: TObject);
begin
ModalResult:=mrOK;
end;
procedure TMessgExDlg.Button2Click(Sender: TObject);
begin
if Kind=mkOkHelp then HelpDlg.ShowPage(HelpKind,HelpNo)
else ModalResult:=mrIgnore;
end;
procedure TMessgExDlg.Button3Click(Sender: TObject);
begin
ModalResult:=mrCancel
end;
procedure TMessgExDlg.FormKeyPress(Sender: TObject; var Key: char);
begin
if Key=#13 then ModalResult:=mrOK
else if (Key=#27) then
if Button3.Visible then ModalResult:=mrCancel
else if Button2.Visible then ModalResult:=mrIgnore
end;
procedure TMessgExDlg.DeliverBtnClick(Sender: TObject);
var
Price,a,i: integer;
begin
if Offer.nDeliver+Offer.nCost=12 then exit; // maximum
SelectDlg.Caption:=Phrases.Lookup('TITLE_OFFERDELIVER');
SelectDlg.Kind:=kDeliver;
SelectDlg.ShowModal;
Price:=SelectDlg.result;
if Price>=0 then
begin
case Price of
opCivilReport, opMilReport:
inc(Price,me shl 16); // !!! choose player and year!
opShipParts..opShipParts+(nShipPart-1) shl 16, opMoney, opTribute:
begin // choose amount
if Price and opMask=opShipParts then
InputDlg.Caption:=Phrases.Lookup('TITLE_NUMBER')
else InputDlg.Caption:=Phrases.Lookup('TITLE_AMOUNT');
InputDlg.EInput.Text:='';
InputDlg.ShowModal;
if InputDlg.ModalResult=mrOK then
begin
val(InputDlg.EInput.Text,a,i);
if (i=0) and (a>0) and (a<MaxMoneyPrice) then inc(Price,a)
else Price:=-1
end
else Price:=-1
end;
opTech:
begin // choose technology
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSETECH');
SelectDlg.Kind:=kChooseTech;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then inc(Price,SelectDlg.result)
else Price:=-1
end;
opModel:
begin // choose model
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSEMODEL');
SelectDlg.Kind:=kChooseModel;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then
inc(Price,SelectDlg.result)
else Price:=-1
end;
{ opCity:
begin // choose city
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSECITY');
SelectDlg.Kind:=kChooseCity;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then
inc(Price,MyCity[SelectDlg.result].ID)
else Price:=-1
end}
end;
end;
if Price>=0 then
begin
move(Offer.Price[Offer.nDeliver],Offer.Price[Offer.nDeliver+1],4*Offer.nCost);
Offer.Price[Offer.nDeliver]:=Price;
inc(Offer.nDeliver);
MessgText:=Format(Phrases.Lookup('FRWESAY'),[DipCommandToString(me,DipMem[me].pContact,
MyRO.Treaty[DipMem[me].pContact], ClientMode, scDipOffer,
ReceivedOffer, Offer)]);
SplitText(true);
CorrectHeight;
Top:=(Screen.Height-ClientHeight) div 2;
Button1.Visible:= Server(scDipOffer-sExecute,me,0,Offer)>=rExecuted;
Invalidate
end;
end;
procedure TMessgExDlg.CostBtnClick(Sender: TObject);
var
Price,a,i: integer;
begin
if Offer.nDeliver+Offer.nCost=12 then exit; // maximum
SelectDlg.Caption:=Phrases.Lookup('TITLE_OFFERCOST');
SelectDlg.Kind:=kCost;
SelectDlg.ShowModal;
Price:=SelectDlg.result;
if Price>=0 then
begin
case Price of
opCivilReport, opMilReport:
inc(Price,DipMem[me].pContact shl 16); // !!! choose player and year!
opShipParts..opShipParts+(nShipPart-1) shl 16, opMoney, opTribute:
begin // choose number/amount
if Price and opMask=opShipParts then
InputDlg.Caption:=Phrases.Lookup('TITLE_NUMBER')
else InputDlg.Caption:=Phrases.Lookup('TITLE_AMOUNT');
InputDlg.EInput.Text:='';
InputDlg.ShowModal;
if InputDlg.ModalResult=mrOK then
begin
val(InputDlg.EInput.Text,a,i);
if (i=0) and (a>0) and (a<MaxMoneyPrice) then inc(Price,a)
else Price:=-1
end
else Price:=-1
end;
opTech:
begin // choose technology
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSETECH');
SelectDlg.Kind:=kChooseETech;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then inc(Price,SelectDlg.result)
else Price:=-1
end;
opModel:
begin // choose model
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSEMODEL');
SelectDlg.Kind:=kChooseEModel;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then
inc(Price,MyRO.EnemyModel[SelectDlg.result].mix)
else Price:=-1
end;
{ opCity:
begin // choose city
SelectDlg.Caption:=Phrases.Lookup('TITLE_CHOOSECITY');
SelectDlg.Kind:=kChooseECity;
SelectDlg.ShowModal;
if SelectDlg.result>=0 then
inc(Price,MyRO.EnemyCity[SelectDlg.result].ID)
else Price:=-1
end}
end;
end;
if Price>=0 then
begin
Offer.Price[Offer.nDeliver+Offer.nCost]:=Price;
inc(Offer.nCost);
MessgText:=Format(Phrases.Lookup('FRWESAY'),[DipCommandToString(me,DipMem[me].pContact,
MyRO.Treaty[DipMem[me].pContact], ClientMode, scDipOffer,
ReceivedOffer, Offer)]);
SplitText(true);
CorrectHeight;
Top:=(Screen.Height-ClientHeight) div 2;
Button1.Visible:= Server(scDipOffer-sExecute,me,0,Offer)>=rExecuted;
Invalidate
end;
end;
function SimpleQuery(QueryKind: integer; SimpleText, SoundItem: string):
integer;
begin
with MessgExDlg do
begin
Play(SoundItem);
MessgText:=SimpleText;
Kind:=QueryKind;
ShowModal;
result:=ModalResult
end
end;
procedure ContextMessage(SimpleText, SoundItem: string; ContextKind,
ContextNo: integer);
begin
with MessgExDlg do
begin
Play(SoundItem);
MessgText:=SimpleText;
Kind:=mkOkHelp;
HelpKind:=ContextKind;
HelpNo:=ContextNo;
ShowModal;
end
end;
procedure TMessgExDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Icons:=[];
BigIcon:=-1;
TribeIcon:=-1;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -