X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Feditor%2Ff_main.pas;h=dfb9b75ef200377d2fbf27e5e7d780ac63f3acff;hb=c869f28997ec7308491cbc067ee15d8a53f923e4;hp=186e5071a14b170df054fa6c5cd7a52eccb05d53;hpb=952e5c9c629e44e260c55f2756d72a199d8d9052;p=d2df-editor.git diff --git a/src/editor/f_main.pas b/src/editor/f_main.pas index 186e507..dfb9b75 100644 --- a/src/editor/f_main.pas +++ b/src/editor/f_main.pas @@ -2370,10 +2370,10 @@ begin Result := Res; end; -procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray; - var pmin: TPoint); +procedure StringToCopyBuffer(Str: String; var CopyBuf: TCopyRecArray; var pmin: TPoint); var i, j, t: Integer; + minArea, newArea, newX, newY: LongInt; function GetNext(): String; var @@ -2416,6 +2416,7 @@ var end; begin + minArea := High(minArea); Str := Trim(Str); if GetNext() <> CLIPBOARD_SIG then @@ -2426,8 +2427,7 @@ begin // Тип объекта: t := StrToIntDef(GetNext(), 0); - if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or - (GetNext() <> ';') then + if (t < OBJECT_PANEL) or (t > OBJECT_TRIGGER) or (GetNext() <> ';') then begin // Что-то не то => пропускаем: t := Pos(';', Str); Delete(Str, 1, t); @@ -2453,13 +2453,14 @@ begin PanelType := StrToIntDef(GetNext(), PANEL_WALL); X := StrToIntDef(GetNext(), 0); Y := StrToIntDef(GetNext(), 0); - pmin.X := Min(X, pmin.X); - pmin.Y := Min(Y, pmin.Y); Width := StrToIntDef(GetNext(), 16); Height := StrToIntDef(GetNext(), 16); TextureName := GetNext(); Alpha := StrToIntDef(GetNext(), 0); Blending := (GetNext() = '1'); + newArea := X * Y - Width * Height; + newX := X; + newY := Y; end; end; @@ -2469,10 +2470,11 @@ begin ItemType := StrToIntDef(GetNext(), ITEM_MEDKIT_SMALL); X := StrToIntDef(GetNext(), 0); Y := StrToIntDef(GetNext(), 0); - pmin.X := Min(X, pmin.X); - pmin.Y := Min(Y, pmin.Y); OnlyDM := (GetNext() = '1'); Fall := (GetNext() = '1'); + newArea := X * Y; + newX := X; + newY := Y; end; OBJECT_MONSTER: @@ -2481,13 +2483,12 @@ begin MonsterType := StrToIntDef(GetNext(), MONSTER_DEMON); X := StrToIntDef(GetNext(), 0); Y := StrToIntDef(GetNext(), 0); - pmin.X := Min(X, pmin.X); - pmin.Y := Min(Y, pmin.Y); - - if GetNext() = '1' then - Direction := D_LEFT - else - Direction := D_RIGHT; + if GetNext() = '1' + then Direction := D_LEFT + else Direction := D_RIGHT; + newArea := X * Y; + newX := X; + newY := Y; end; OBJECT_AREA: @@ -2496,12 +2497,12 @@ begin AreaType := StrToIntDef(GetNext(), AREA_PLAYERPOINT1); X := StrToIntDef(GetNext(), 0); Y := StrToIntDef(GetNext(), 0); - pmin.X := Min(X, pmin.X); - pmin.Y := Min(Y, pmin.Y); - if GetNext() = '1' then - Direction := D_LEFT - else - Direction := D_RIGHT; + if GetNext() = '1' + then Direction := D_LEFT + else Direction := D_RIGHT; + newArea := X * Y; + newX := X; + newY := Y; end; OBJECT_TRIGGER: @@ -2510,47 +2511,26 @@ begin TriggerType := StrToIntDef(GetNext(), TRIGGER_EXIT); X := StrToIntDef(GetNext(), 0); Y := StrToIntDef(GetNext(), 0); - pmin.X := Min(X, pmin.X); - pmin.Y := Min(Y, pmin.Y); Width := StrToIntDef(GetNext(), 16); Height := StrToIntDef(GetNext(), 16); ActivateType := StrToIntDef(GetNext(), 0); Key := StrToIntDef(GetNext(), 0); Enabled := (GetNext() = '1'); TexturePanel := StrToIntDef(GetNext(), 0); - - for j := 0 to 127 do - Data.Default[j] := StrToIntDef(GetNext(), 0); - - case TriggerType of - TRIGGER_TELEPORT: - begin - pmin.X := Min(Data.TargetPoint.X, pmin.X); - pmin.Y := Min(Data.TargetPoint.Y, pmin.Y); - end; - TRIGGER_PRESS, TRIGGER_ON, TRIGGER_OFF, TRIGGER_ONOFF: - begin - pmin.X := Min(Data.tX, pmin.X); - pmin.Y := Min(Data.tY, pmin.Y); - end; - TRIGGER_SPAWNMONSTER: - begin - pmin.X := Min(Data.MonPos.X, pmin.X); - pmin.Y := Min(Data.MonPos.Y, pmin.Y); - end; - TRIGGER_SPAWNITEM: - begin - pmin.X := Min(Data.ItemPos.X, pmin.X); - pmin.Y := Min(Data.ItemPos.Y, pmin.Y); - end; - TRIGGER_SHOT: - begin - pmin.X := Min(Data.ShotPos.X, pmin.X); - pmin.Y := Min(Data.ShotPos.Y, pmin.Y); - end; - end; + for j := 0 to 127 + do Data.Default[j] := StrToIntDef(GetNext(), 0); + newArea := X * Y - Width * Height; + newX := X; + newY := Y; end; end; + + if newArea < minArea then + begin + minArea := newArea; + pmin.X := newX; + pmin.Y := newY; + end; end; end; @@ -2882,6 +2862,23 @@ begin e_TextureFontPrintEx(X, Y, Text, FontID, 0, 0, 0, 1.0); end; +procedure InitGraphics; +begin + // FIXME: this is a shitty hack + if not gDataLoaded then + begin + e_WriteLog('Init OpenGL', MSG_NOTIFY); + e_InitGL(); + e_WriteLog('Loading data', MSG_NOTIFY); + LoadStdFont('STDTXT', 'STDFONT', gEditorFont); + e_WriteLog('Loading more data', MSG_NOTIFY); + LoadData(); + e_WriteLog('Loading even more data', MSG_NOTIFY); + gDataLoaded := True; + MainForm.FormResize(nil); + end; +end; + procedure TMainForm.Draw(); var x, y: Integer; @@ -2897,6 +2894,8 @@ begin Width := 0; Height := 0; + InitGraphics(); + e_BeginRender(); e_Clear(GL_COLOR_BUFFER_BIT, @@ -3779,7 +3778,12 @@ begin if Button = mbMiddle then MouseMDown := False; - DrawRect := nil; + if DrawRect <> nil then + begin + Dispose(DrawRect); + DrawRect := nil; + end; + ResizeType := RESIZETYPE_NONE; TextureID := 0; @@ -4344,8 +4348,11 @@ begin end; // Клавиши мыши не зажаты: - if (not MouseRDown) and (not MouseLDown) then + if (not MouseRDown) and (not MouseLDown) and (DrawRect <> nil) then + begin + Dispose(DrawRect); DrawRect := nil; + end; // Строка состояния - координаты мыши: StatusBar.Panels[1].Text := Format('(%d:%d)', @@ -5819,15 +5826,16 @@ begin h := High(CopyBuffer); RemoveSelectFromObjects(); - if h > 0 then + if g_CollidePoint( + pmin.X, pmin.Y, -MapOffset.X-32, -MapOffset.Y-32, RenderPanel.Width, RenderPanel.Height) then begin - xadj := Floor((-pmin.X - MapOffset.X + 32) / DotStep) * DotStep; - yadj := Floor((-pmin.Y - MapOffset.Y + 32) / DotStep) * DotStep; + xadj := DotStep; + yadj := DotStep; end else begin - xadj := DotStep; - yadj := DotStep; + xadj := Floor((-pmin.X - MapOffset.X + 32) / DotStep) * DotStep; + yadj := Floor((-pmin.Y - MapOffset.Y + 32) / DotStep) * DotStep; end; for a := 0 to h do @@ -6708,20 +6716,6 @@ end; procedure TMainForm.OnIdle(Sender: TObject; var Done: Boolean); var f: AnsiString; begin - // FIXME: this is a shitty hack - if not gDataLoaded then - begin - e_WriteLog('Init OpenGL', MSG_NOTIFY); - e_InitGL(); - e_WriteLog('Loading data', MSG_NOTIFY); - LoadStdFont('STDTXT', 'STDFONT', gEditorFont); - e_WriteLog('Loading more data', MSG_NOTIFY); - LoadData(); - e_WriteLog('Loading even more data', MSG_NOTIFY); - gDataLoaded := True; - MainForm.FormResize(nil); - end; - Draw(); if StartMap <> '' then begin f := StartMap;