⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.pas

📁 类似文明的游戏源代码。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{$INCLUDE switches}

unit Select;

interface

uses
  Protocol,ClientTools,Term,ScreenTools,IsoEngine,PVSB,BaseWin,

  Windows,Messages,SysUtils,Classes,Graphics,Controls,Forms,
  ExtCtrls,ButtonB, ButtonBase;

const
MaxLayer=3;

type
  TSelectDlg = class(TBaseDlg)
    CloseBtn: TButtonB;
    Layer2Btn: TButtonB;
    Layer1Btn: TButtonB;
    Layer0Btn: TButtonB;
    ToggleBtn: TButtonB;
    procedure PaintBox1MouseMove(Sender:TObject;Shift:TShiftState;x,
      y:integer);
    procedure FormCreate(Sender:TObject);
    procedure PaintBox1MouseDown(Sender:TObject;Button:TMouseButton;
      Shift:TShiftState;x,y:integer);
    procedure FormPaint(Sender:TObject);
    procedure CloseBtnClick(Sender:TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    procedure FormShow(Sender: TObject);
    procedure ModeBtnClick(Sender: TObject);
    procedure ToggleBtnClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: word;
      Shift: TShiftState);
  public
    Kind:(kProject,kAdvance,kFarAdvance,kCities,kCityEvents,kModels,kEModels,
      kAllEModels,kWonders,kTribe,kScience,kDeliver,kCost,kChooseTech,
      kChooseETech,kChooseModel,kChooseEModel,kChooseCity,kChooseECity,
      kStealTech,kGov,kMission);
    cix,result,pOwner:integer;
    procedure OffscreenPaint; override;
  private
    Sel,DispLines, Layer, nColumn: integer;
    sb:TPVScrollbar;
    Lines, FirstShrinkedLine: array[0..MaxLayer-1] of integer;
    code: array[0..MaxLayer-1,0..4095] of integer;
    Column: array[0..nPl-1] of integer;
    Closable: boolean;
    procedure InitLines;
    procedure line(ca: TCanvas; l: integer; NonText, lit: boolean);
    function RenameCity(cix: integer): boolean;
    function RenameModel(mix: integer): boolean;
    procedure OnScroll(var m:TMessage); message WM_VSCROLL;
  end;

  TCityListDlg=TSelectDlg;

const
cpType=$10000;

var
  SelectDlg: TSelectDlg;
  CityListDlg: TCityListDlg;
  {two instances because city list and project selection may be visible
  at the same time}

implementation

uses
CityScreen, Help, UnitStat, Tribes, Inp;

{$R *.DFM}

const
MaxLines=15;
CityNameSpace=112;
TechNameSpace=224;

procedure TSelectDlg.FormCreate(Sender:TObject);
begin
inherited;
Canvas.Font.Assign(UniFont[ftNormal]);
CreatePVSB(sb,Handle,2,361,2+422);
InitButtons(self);
end;

procedure TSelectDlg.CloseBtnClick(Sender:TObject);
begin
Closable:=true; Close
end;

procedure TSelectDlg.FormCloseQuery(Sender: TObject;
  var CanClose: boolean);
begin
CanClose:=Closable or not(Kind in [kAdvance,kTribe])
end;

procedure TSelectDlg.OnScroll(var m:TMessage);
begin
if ProcessPVSB(sb,m) then
  begin Sel:=-2; OffscreenPaint; SmartInvalidate; Update end
end;

procedure TSelectDlg.FormPaint(Sender:TObject);
begin
Canvas.Font.Assign(UniFont[ftCaption]);
inherited;
Canvas.Font.Assign(UniFont[ftNormal]);
if Sel<>-2 then line(Canvas,Sel,false,true);
if ToggleBtn.Visible then BtnFrame(Canvas,ToggleBtn.BoundsRect,OuterTex);
if CloseBtn.Visible then BtnFrame(Canvas,CloseBtn.BoundsRect,OuterTex);
if Layer0Btn.Visible then BtnFrame(Canvas,Layer0Btn.BoundsRect,OuterTex);
if Layer1Btn.Visible then BtnFrame(Canvas,Layer1Btn.BoundsRect,OuterTex);
if Layer2Btn.Visible then BtnFrame(Canvas,Layer2Btn.BoundsRect,OuterTex);
end;

procedure TSelectDlg.line(ca: TCanvas; l: integer; NonText, lit: boolean);
// paint a line

  procedure DisplayProject(x,y,pix: integer);
  begin
  if pix and (cpType or cpImp)=0 then
    with Tribe[me].ModelPicture[pix and cpIndex] do
      Sprite(offscreen,HGr,x,y,64,48,pix mod 10*65+1, pix div 10 *49+1)
  else
    begin
    Frame(offscreen.Canvas,x+(16-1),y+(16-2),x+(16+xSizeSmall),
      y+(16-1+ySizeSmall),InnerTex.clBevelLight,InnerTex.clBevelShade);
    if pix and cpType=0 then
      BitBlt(offscreen.Canvas.Handle,x+16,y+(16-1),xSizeSmall,ySizeSmall,
        SmallImp.Canvas.Handle,pix and cpIndex mod 7*xSizeSmall,
        (pix and cpIndex+SystemIconLines*7) div 7*ySizeSmall,SRCCOPY)
    else Dump(offscreen,HGrSystem,x+16,y+(16-1),36,20,1+37*(pix and cpIndex),316)
    end;
  end;

  procedure ReplaceText(x,y,Color: integer; s: string);
  var
  TextSize: TSize;
  begin
  if ca=Canvas then
    begin
    TextSize:=ca.TextExtent(s);
    if y+TextSize.cy>=WideFrame+InnerHeight then
      TextSize.cy:=WideFrame+InnerHeight-y;
    Fill(ca,x,y,TextSize.cx,TextSize.cy,-SideFrame,sb.si.npos*24-WideFrame,InnerTex);
    end;
  LoweredTextOut(ca,Color,InnerTex,x,y,s);
  end;

(*  procedure ReplaceText_Tribe(x,y,Color,TribeColor: integer; s: string);
  var
  TextSize: TSize;
  begin
  if ca=Canvas then
    begin
    TextSize:=ca.TextExtent(s);
    if TextSize.cy<19 then TextSize.cy:=19;
    if y+TextSize.cy>=WideFrame+InnerHeight then
      TextSize.cy:=WideFrame+InnerHeight-y;
    Fill(ca,SideFrame,y,InnerWidth,TextSize.cy,-SideFrame,sb.si.npos*24-WideFrame,InnerTex);
    if color>=0 then
      begin
      x:=x+10;
      LightGradient(ca,x-18,y+1,12,TribeColor);
      end
    end;
  LoweredTextOut(ca,Color,InnerTex,x,y,s);
  end;
*)
var
icon,ofs,x,y,y0,lix,i,j,TextColor,Available,Cost,first,test:integer;
CityReport: TCityReport;
CityInfo: TCityInfo;
mox: ^TModelInfo;
s:string;
begin
lix:=code[Layer,sb.si.npos+l];
y0:=26+l*24;
if sb.si.npos+l>=FirstShrinkedLine[Layer] then
  ofs:=(sb.si.npos+l-FirstShrinkedLine[Layer]) and 1 *33
else {if FirstShrinkedLine[Layer]<Lines[Layer] then} ofs:=33;

if Kind in [kCities,kCityEvents] then with MyCity[lix] do
  begin
  x:=104; y:=y0;
  if ca=Canvas then
    begin x:=x+SideFrame; y:=y+WideFrame end;
  if lit then TextColor:=InnerTex.clLitText else TextColor:=-1;
  ReplaceText(x+15,y,TextColor,CityName(ID));
  if Kind=kCityEvents then
    begin
    first:=-1;
    for j:=0 to nCityEventPriority-1 do
      if (Flags and CityRepMask and CityEventPriority[j]<>0) then
        begin first:=j; Break end;
    if first>=0 then
      begin
      i:=0;
      test:=1;
      while test<CityEventPriority[first] do
        begin inc(i); inc(test,test) end;
      s:=Phrases.Lookup('CITYEVENTS',i);
      if CityEventPriority[first]=chNoGrowthWarning then
        if Built[imAqueduct]=0 then
          s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imAqueduct)])
        else begin s:=Format(s,[Phrases.Lookup('IMPROVEMENTS',imSewer)]); i:=17 end;
      ReplaceText(x+(CityNameSpace+40+18+8),y,TextColor,s);
      if NonText then
        begin
        Sprite(offscreen,HGrSystem,105+CityNameSpace+40,y0+1,18,18,
          1+i mod 3 *19,1+i div 3 *19);
        x:=InnerWidth-26;
        for j:=nCityEventPriority-1 downto first+1 do
          if (Flags and CityRepMask and CityEventPriority[j]<>0) then
            begin
            i:=0;
            test:=1;
            while test<CityEventPriority[j] do
              begin inc(i); inc(test,test) end;
            if (CityEventPriority[j]=chNoGrowthWarning)
              and (Built[imAqueduct]>0) then
              i:=17;
            Sprite(offscreen,HGrSystem,x,y0+1,18,18,1+i mod 3 *19,
              1+i div 3 *19);
            dec(x,20)
            end
        end
      end
    end
  else
    begin
    CityReport.HypoTiles:=-1;
    CityReport.HypoTax:=-1;
    CityReport.HypoLux:=-1;
    Server(sGetCityReport,me,lix,CityReport);
    s:=''; // disorder info
    if Flags and chCaptured<>0 then
      s:=Phrases.Lookup('CITYEVENTS',13)
    else if CityReport.Working-CityReport.Happy>Size div 2 then
      s:=Phrases.Lookup('CITYEVENTS',0);
    if s<>'' then
      begin {disorder}
      if NonText then
        begin
        DarkGradient(offscreen.Canvas,99+31+CityNameSpace,y0+1,179,3);
        ca.Font.Assign(UniFont[ftSmall]);
        RisedTextout(offscreen.canvas,103+CityNameSpace+31,y0,s);
        ca.Font.Assign(UniFont[ftNormal]);
        end
      end
    else
      begin
      if Project=cpImp+imTrGoods then
        inc(CityReport.Tax,CityReport.ProdRep-CityReport.Support);
      for j:=0 to nImp-1 do if Built[j]=1 then
        dec(CityReport.Tax,Imp[j].Maint);
      s:=IntToStr(CityReport.FoodRep-CityReport.Eaten);
      ReplaceText(x+(CityNameSpace+47)-ca.TextWidth(s),y,TextColor,s);
      s:=IntToStr(CityReport.Science);
      ReplaceText(x+(CityNameSpace+95)-ca.TextWidth(s),y,TextColor,s);
      s:=IntToStr(CityReport.Tax);
      ReplaceText(x+(CityNameSpace+143)-ca.TextWidth(s),y,TextColor,s);
      s:=IntToStr(CityReport.ProdRep);
      ReplaceText(x+(CityNameSpace+191)-ca.TextWidth(s),y,TextColor,s);
      if NonText then
        begin
        Sprite(offscreen,HGrSystem,105+CityNameSpace+48,y+5,10,10,66,115);
        Sprite(offscreen,HGrSystem,105+CityNameSpace+96,y+5,10,10,77,126);
        Sprite(offscreen,HGrSystem,105+CityNameSpace+144,y+5,10,10,132,115);
        Sprite(offscreen,HGrSystem,105+CityNameSpace+192,y+5,10,10,88,115);
        end
      end;
    if Project and (cpImp+cpIndex)<>cpImp+imTrGoods then
      begin
      Cost:=CityReport.ProdCost;
      ReplaceText(x+(CityNameSpace+304),y,TextColor,Format('%d/%d',[Prod,Cost]));
      end;
    if NonText then
      begin
      if Project<>cpImp+imTrGoods then
        DisplayProject(ofs+(104+CityNameSpace+206),y0-17,Project);
      end
    end;

  if NonText then
    begin // paint city picture
    CityInfo.Loc:=Loc;
    CityInfo.Owner:=me;
    CityInfo.Size:=Size;
    CityInfo.Flags:=0;
    if Built[imPalace]=1 then inc(CityInfo.Flags,ciCapital);
    if (Built[imWalls]=1) or (MyMap[Loc] and fGrWall<>0) then
      inc(CityInfo.Flags,ciWalled);
    offscreen.Canvas.Font.Assign(UniFont[ftSmall]);
    NoMap.SetOutput(offscreen);
    NoMap.PaintCity(ofs+8,y0+1,CityInfo);
    offscreen.Canvas.Font.Assign(UniFont[ftNormal]);
    end;
  end
else if Kind in [kModels,kEModels] then
  begin
  x:=104; y:=y0;
  if ca=Canvas then
    begin x:=x+SideFrame; y:=y+WideFrame end;
  if lit then TextColor:=InnerTex.clLitText else TextColor:=-1;
  if Kind=kModels then
    begin
    Available:=0;
    for j:=0 to MyRO.nUn-1 do
      if (MyUn[j].Loc>=0) and (MyUn[j].mix=lix) then inc(Available);
    if MainScreen.mNames.Checked then
      s:=Tribe[me].ModelName[lix]
    else s:=Format(Tribe[me].TPhrase('GENMODEL'),[lix]);
    if NonText then DisplayProject(8+ofs,y0-15,lix);
    end
  else
    begin
    Available:=MyRO.EnemyReport[pOwner].UnCount[lix];
    if MainScreen.mNames.Checked then
      s:=Tribe[pOwner].ModelName[lix]
    else s:=Format(Tribe[pOwner].TPhrase('GENMODEL'),[lix]);
    if NonText then
      with Tribe[pOwner].ModelPicture[lix] do
        Sprite(offscreen,HGr,8+ofs,y0-15,64,48,pix mod 10*65+1, pix div 10 *49+1);
    end;
  if Available>0 then
    ReplaceText(x+32-ca.TextWidth(IntToStr(Available)),y,TextColor,
      IntToStr(Available));
  ReplaceText(x+40,y,TextColor,s);
  end
else
  begin
  case Kind of
    kAllEModels, kChooseEModel:
      begin
      mox:=@MyRO.EnemyModel[lix];
      if MainScreen.mNames.Checked then
        begin
        s:=Tribe[mox.Owner].ModelName[mox.mix];
        if (Kind=kAllEModels) and (code[1,sb.si.npos+l]=0) then
          s:=Format(Tribe[mox.Owner].TPhrase('OWNED'), [s]);
        end
      else s:=Format(Tribe[mox.Owner].TPhrase('GENMODEL'),[mox.mix]);
      if NonText then
        with Tribe[mox.Owner].ModelPicture[mox.mix] do
          Sprite(offscreen,HGr,8+ofs,y0-15,64,48,pix mod 10*65+1, pix div 10 *49+1);
      end;
    kChooseModel:
      begin
      s:=Tribe[me].ModelName[lix];
      if NonText then DisplayProject(8+ofs,y0-15,lix);
      end;
{    kChooseCity:
      begin
      s:=CityName(MyCity[lix].ID);
      if NonText then; //!!! display city picture
      end;
    kChooseECity:
      begin
      s:=CityName(MyRO.EnemyCity[lix].ID);
      if NonText then; //!!! display city picture
      end;}
    kWonders:
      begin
      if MyRO.Wonder[lix].CityID=-2 then
        s:=Format(Phrases.Lookup('DESTROYED'),[Phrases.Lookup('IMPROVEMENTS',lix)])
      else
        begin
        if MyRO.Wonder[lix].EffectiveOwner<0 then s:=Phrases.Lookup('EXPIRED')
        else s:=Tribe[MyRO.Wonder[lix].EffectiveOwner].TPhrase('SHORTNAME');
        s:=Format(Phrases.Lookup('WONDEROF'),[Phrases.Lookup('IMPROVEMENTS',lix),
          CityName(MyRO.Wonder[lix].CityID),s]);
        end;
      if NonText then DisplayProject(8+ofs,y0-15,lix+cpImp);
      end;
    kProject:
      begin
      if lix and cpType<>0 then s:=Phrases.Lookup('CITYTYPE',lix and cpIndex)
      else if lix and cpImp=0 then with MyModel[lix and cpIndex] do
        begin
        s:=Tribe[me].ModelName[lix and cpIndex];
        if lix and cpConscripts<>0 then
          s:=Format(Phrases.Lookup('CONSCRIPTS'),[s]);
        end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -