From 73a7d4f6168ec3906e2bf71cbd32da1451b55278 Mon Sep 17 00:00:00 2001 From: Nick's Hardware Youtube Channel <56885781+nickshardware@users.noreply.github.com> Date: Sat, 27 May 2023 13:48:17 -0400 Subject: [PATCH] Map Editor improvements --- mapcore.pas | 6 +- mapeditor.lfm | 26 +++- mapeditor.pas | 402 +++++++++++++++++++++++++++++++------------------- rmabout.pas | 2 +- rmmain.lfm | 4 +- rmmain.pas | 8 +- rwpal.pas | 14 +- 7 files changed, 287 insertions(+), 175 deletions(-) diff --git a/mapcore.pas b/mapcore.pas index e507b21..bfe76e4 100644 --- a/mapcore.pas +++ b/mapcore.pas @@ -15,6 +15,10 @@ interface RMMapSig = 'RMM'; RMMapVersion = 2; + + TileClear = -1; + TileMissing = -2; + type TileRec = packed Record @@ -230,7 +234,7 @@ procedure TMapCoreBase.ClearMap(index, value : integer); begin For i:=0 to DefMaxMapHeight-1 do begin -// Map[index].Tile[i,j].ImageUID:=0; +// Map[index].Tile[i,j].ImageUID:=''; Map[index].Tile[i,j].ImageIndex:=value; end; end; diff --git a/mapeditor.lfm b/mapeditor.lfm index e215f5c..ac58345 100644 --- a/mapeditor.lfm +++ b/mapeditor.lfm @@ -7,6 +7,7 @@ object MapEdit: TMapEdit ClientHeight = 662 ClientWidth = 1130 Menu = MainMenu1 + OnActivate = FormActivate OnClose = FormClose OnCreate = FormCreate OnShow = FormShow @@ -87,6 +88,7 @@ object MapEdit: TMapEdit Caption = 'LeftBottomPanel' ClientHeight = 482 ClientWidth = 216 + ParentColor = False ParentFont = False TabOrder = 2 object TileListView: TListView @@ -124,6 +126,7 @@ object MapEdit: TMapEdit Caption = 'RightPanel' ClientHeight = 662 ClientWidth = 188 + ParentColor = False ParentFont = False TabOrder = 0 object MapListView: TListView @@ -255,6 +258,7 @@ object MapEdit: TMapEdit Caption = 'MiddlePanel' ClientHeight = 560 ClientWidth = 706 + ParentColor = False ParentFont = False TabOrder = 5 object MapScrollBox: TScrollBox @@ -262,9 +266,11 @@ object MapEdit: TMapEdit Height = 558 Top = 1 Width = 704 - HorzScrollBar.Page = 90 + HorzScrollBar.Increment = 10 + HorzScrollBar.Page = 105 HorzScrollBar.Tracking = True - VertScrollBar.Page = 90 + VertScrollBar.Increment = 10 + VertScrollBar.Page = 105 VertScrollBar.Tracking = True Align = alClient BorderStyle = bsNone @@ -272,17 +278,19 @@ object MapEdit: TMapEdit ClientWidth = 704 ParentFont = False TabOrder = 0 - object MapImage: TImage + object MapPaintBox: TPaintBox AnchorSideLeft.Control = MapScrollBox AnchorSideTop.Control = MapScrollBox Left = 0 - Height = 90 + Height = 105 Top = 0 - Width = 90 + Width = 105 + Color = clRed + ParentColor = False OnMouseDown = MapImageMouseDown - OnMouseLeave = MapImageMouseLeave OnMouseMove = MapImageMouseMove OnMouseUp = MapImageMouseUp + OnPaint = MapPaintBoxPaint end end end @@ -430,4 +438,10 @@ object MapEdit: TMapEdit OnClick = MenuMapPropsClick end end + object TileImageList: TImageList + Height = 256 + Width = 256 + Left = 156 + Top = 210 + end end diff --git a/mapeditor.pas b/mapeditor.pas index 9e99eff..651166d 100644 --- a/mapeditor.pas +++ b/mapeditor.pas @@ -5,18 +5,14 @@ interface uses - Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,LMessages,Types, + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,Types, ComCtrls, Menus,rmthumb,mapcore,rwmap,mapexiportprops,rmcodegen; type - (* TScrollBox = class(Forms.TScrollBox) - procedure WMHScroll(var Message : TLMHScroll); message LM_HScroll; - procedure WMVScroll(var Message : TLMVScroll); message LM_VScroll; - end; - *) { TMapEdit } TMapEdit = class(TForm) + TileImageList: TImageList; MenuItem10: TMenuItem; Clear: TMenuItem; MenuItem11: TMenuItem; @@ -31,6 +27,7 @@ TMapEdit = class(TForm) MenuNew: TMenuItem; OpenDialog1: TOpenDialog; ExportMapsPropsMenu: TPopupMenu; + MapPaintBox: TPaintBox; RadioDraw: TRadioButton; RadioErase: TRadioButton; SaveDialog1: TSaveDialog; @@ -46,7 +43,6 @@ TMapEdit = class(TForm) MenuToolErase: TMenuItem; SelectedTileImage: TImage; MainMenu1: TMainMenu; - MapImage: TImage; ImageList1: TImageList; MapInfoLabel: TLabel; FileMenuItem: TMenuItem; @@ -76,6 +72,7 @@ TMapEdit = class(TForm) RightSplitter: TSplitter; TileZoom: TTrackBar; + procedure FormActivate(Sender: TObject); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); @@ -89,6 +86,7 @@ TMapEdit = class(TForm) Shift: TShiftState; X, Y: Integer); procedure ClearMapClick(Sender: TObject); procedure MapListViewClick(Sender: TObject); + procedure MapPaintBoxPaint(Sender: TObject); procedure MenuDeleteClick(Sender: TObject); procedure MenuExportBasicLNMapData(Sender: TObject); @@ -120,20 +118,28 @@ TMapEdit = class(TForm) CTile : TileRec; CTileBitMap : TBitMap; CTool : integer; + FormShowActivate : boolean; procedure PlotTileAt(x,y : integer; TTile : TileRec); procedure PlotTile(mx,my : integer; TTile : TileRec); + procedure ImageListPlotTile(mx,my : integer;var TTile : TileRec); + procedure ClearTile(mx,my : integer); procedure PlotMissingTile(mx,my : integer); Procedure SetMapTool(Tool : integer); + procedure APlotTile(x,y : integer;var TTile : TileRec); //convert to grid format and store on array + procedure AClearTile(x,y : integer); + procedure CPlotTile(ColX,ColY : integer;var TTile : TileRec); //draw to canvas - do not store + procedure CClearTile(ColX,ColY : integer); + procedure LoadTile(index : integer); + procedure LoadTilesToTileImageList; + procedure VerifyTileImageList; procedure UpdateTileView; procedure UpdateCurrentTile; - procedure UpdateMapInfo(x,y : integer); - procedure UpdateMapView; Procedure UpdateMapListView; procedure UpdatePageSize; @@ -144,22 +150,6 @@ TMapEdit = class(TForm) implementation -(* -procedure TScrollBox.WMHScroll(var Message : TLMHScroll); - - -begin - inherited WMHScroll(Message); -// Form1.WMHScroll(Message); -end; - -procedure TScrollBox.WMVScroll(var Message : TLMVScroll); -begin - inherited WMVScroll(Message); - // Form1.WMVScroll(Message); -end; - - *) {$R *.lfm} @@ -170,32 +160,26 @@ procedure TMapEdit.FormCreate(Sender: TObject); SetMapTool(1); //draw CurrentMap:=MapCoreBase.GetCurrentMap; MapCoreBase.SetZoomSize(CurrentMap,4); - //TileZoom.Position:=4; MapCoreBase.SetMapTileSize(CurrentMap,32,32); - CTileBitmap:=TBitMAp.Create; - - MapImage.Width:=MapCoreBase.GetZoomMapPageWidth(CurrentMap); - MapImage.height:=MapCoreBase.GetZoomMapPageHeight(CurrentMap); + CTileBitmap:=TBitMap.Create; TileWidth:=MapCoreBase.GetZoomMapTileWidth(CurrentMap); TileHeight:=MapCoreBase.GetZoomMapTileHeight(CurrentMap); MDownLeft:=False; MDownRight:=False; - CTile.ImageIndex:=-1; + CTile.ImageIndex:=TileMissing; + FormShowActivate:=false; end; procedure TMapEdit.FormShow(Sender: TObject); begin - //bug fix scrollbox scrollbars not displaying correctly after onshow event - MapImage.AutoSize:=true; - MapImage.Picture.Bitmap.SetSize(1,1); - MapImage.Picture.Bitmap.SetSize(MapCoreBase.GetZoomMapPageWidth(CurrentMap),MapCoreBase.GetZoomMapPageHeight(CurrentMap)); - MapImage.AutoSize:=false; - //end big fix - if CTile.ImageIndex = -1 then + LoadTilesToTileImageList; + VerifyTileImageList; + + if CTile.ImageIndex = TileMissing then begin LoadTile(0); // first time opening MApEdit Window end @@ -203,9 +187,21 @@ procedure TMapEdit.FormShow(Sender: TObject); begin LoadTile(CTile.ImageIndex); // Follow up open windows - reload current tile incase it was edited end; + UpdateCurrentTile; UpdateMapListView; - UpdateMapView; + + MapPaintBox.Width:=0; //this hack updated the scrollbars properly after the 2nd and following attempts + MapPaintBox.Height:=0; + MapPaintBox.Invalidate; + MapPaintBox.Width:=MapCoreBase.GetZoomMapPageWidth(CurrentMap); + MapPaintBox.Height:=MapCoreBase.GetZoomMapPageHeight(CurrentMap); + MapPaintBox.Invalidate; //forces a paint which draws the map + + MapScrollBox.HorzScrollBar.Position:=hpos; + MapScrollBox.VertScrollBar.Position:=vpos; + + FormShowActivate:=true; //this is going to also trigger an onfocus even - letting event handler know it was because of onopen end; procedure TMapEdit.FormClose(Sender: TObject; var CloseAction: TCloseAction); @@ -214,6 +210,32 @@ procedure TMapEdit.FormClose(Sender: TObject; var CloseAction: TCloseAction); vpos:=MapScrollBox.VertScrollBar.Position; end; +procedure TMapEdit.FormActivate(Sender: TObject); +begin + if FormShowActivate then + begin + FormShowActivate:=false; //next on focus will be real onfocus + end; + + ImageThumbBase.CopyCoreToIndexImage(ImageThumbBase.GetCurrent); + + LoadTilesToTileImageList; + VerifyTileImageList; + + if CTile.ImageIndex = TileMissing then + begin + LoadTile(0); // first time opening MApEdit Window + end + else + begin + LoadTile(CTile.ImageIndex); // Follow up open windows - reload current tile incase it was edited + end; + UpdateCurrentTile; + + UpdateTileView; + MapPaintBox.Invalidate; +end; + procedure TMapEdit.PlotTile(mx,my : integer; TTile : TileRec); var gx,gy : integer; @@ -223,115 +245,156 @@ procedure TMapEdit.PlotTile(mx,my : integer; TTile : TileRec); gx:=mx*TileWidth; gy:=my*TileHeight; - MapImage.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height)); + MapPaintBox.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height)); end; -procedure TMapEdit.ClearTile(mx,my : integer); +procedure TMapEdit.ImageListPlotTile(mx,my : integer;var TTile : TileRec); var gx,gy : integer; - T : TileRec; begin - if (mx < 0) or (my<0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; - T.ImageIndex:=-1; - MapCoreBase.SetMapTile(CurrentMap,mx,my,T); - gx:=mx*TileWidth; gy:=my*TileHeight; +// MapPaintBox.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height)); + TileImageList.Draw(MapPaintBox.Canvas,gx,gy,TTile.ImageIndex,true); +end; - MapImage.Canvas.Brush.Color:=clBlack; - MapImage.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight); +procedure TMapEdit.ClearTile(mx,my : integer); +var + T : TileRec; +begin + if (mx < 0) or (my<0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; + T.ImageIndex:=TileClear; + MapCoreBase.SetMapTile(CurrentMap,mx,my,T); end; procedure TMapEdit.PlotMissingTile(mx,my : integer); var gx,gy : integer; begin - if (mx < 0) or (my<0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; - gx:=mx*TileWidth; gy:=my*TileHeight; //red circle on white background - MapImage.Canvas.Brush.Color:=clWhite; - MapImage.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight); - MapImage.Canvas.Brush.Color:=clRed; - MapImage.Canvas.Ellipse(gx,gy,gx+TileWidth,gy+TileHeight); + MapPaintBox.Canvas.Brush.Color:=clWhite; + MapPaintBox.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight); + MapPaintBox.Canvas.Brush.Color:=clRed; + MapPaintBox.Canvas.Ellipse(gx,gy,gx+TileWidth,gy+TileHeight); end; - procedure TMapEdit.PlotTileAt(x,y : integer;TTile : TileRec); var mx,my : integer; begin - mx:=x div TileWidth; - my:=y div TileHeight; - PlotTile(mx,my,TTile); + mx:=x div TileWidth; + my:=y div TileHeight; + PlotTile(mx,my,TTile); end; -procedure TMapEdit.MapImageMouseMove(Sender: TObject; Shift: TShiftState; X, - Y: Integer); -var - mx,my : integer; +procedure TMapEdit.MapImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin UpdateMapInfo(x,y); - mx:=x div TileWidth; - my:=y div TileHeight; - if MDOwnLeft and (CTool=1) then begin - PlotTileAt(x,y,CTile); + APlotTile(x,y,CTile); + //MapCoreBase.SetMapTile(CurrentMap,mx,my,CTile); end else if (MDOwnRight=true) or ((MDownLeft=true) and (CTool=0)) then begin - ClearTile(mx,my); + AClearTile(x,y); end; + MapPaintBox.Invalidate; end; -procedure TMapEdit.MapImageMouseDown(Sender: TObject; Button: TMouseButton; - Shift: TShiftState; X, Y: Integer); +procedure TMapEdit.APlotTile(x,y : integer;var TTile : TileRec); var mx,my : integer; begin - MDownLeft:=False; - MDownRight:=False; + mx:=(x div TileWidth); + if (mx < 0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) then exit; + my:=(y div TileHeight); + if (my<0) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; + MapCoreBase.SetMapTile(CurrentMap,mx,my,TTile); +end; +procedure TMapEdit.AClearTile(x,y : integer); +var + mx,my : integer; + T : TileRec; +begin mx:=(x div TileWidth); + if (mx < 0) or (mx >= MapCoreBase.GetMapWidth(CurrentMap)) then exit; my:=(y div TileHeight); + if (my<0) or (my >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; + T.ImageIndex:=TileClear; + MapCoreBase.SetMapTile(CurrentMap,mx,my,T); +end; + +//called from onpaint +procedure TMapEdit.CPlotTile(ColX,ColY : integer;var TTile : TileRec); //draw to canvas - do not store +var + gx,gy : integer; +begin + if (ColX < 0) or (ColY<0) or (ColX >= MapCoreBase.GetMapWidth(CurrentMap)) or (ColY >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; + //MapCoreBase.SetMapTile(CurrentMap,mx,my,CTile); + + gx:=ColX*TileWidth; + gy:=ColY*TileHeight; + MapPaintBox.canvas.CopyRect(Rect(gx, gy, gx+TileWidth, gy+TileHeight), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height)); +end; + +//called from onpaint +procedure TMapEdit.CClearTile(ColX,ColY : integer); +var + gx,gy : integer; +begin + if (ColX < 0) or (ColY<0) or (ColX >= MapCoreBase.GetMapWidth(CurrentMap)) or (ColY >= MapCoreBase.GetMapHeight(CurrentMap)) then exit; + gx:=ColX*TileWidth; + gy:=ColY*TileHeight; + + MapPaintBox.Canvas.Brush.Color:=clBlack; + MapPaintBox.Canvas.FillRect(gx,gy,gx+TileWidth,gy+TileHeight); +end; + +procedure TMapEdit.MapImageMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +begin + MDownLeft:=False; + MDownRight:=False; if Button = mbRight then begin MDownRight:=True; - ClearTile(mx,my); + AClearTile(x,y); end else if Button = mbLeft then begin MDownLeft:=True; if CTool = 1 then begin - PlotTileAt(x,y,CTile); + APlotTile(x,y,CTile); end else if CTool = 0 then begin - ClearTile(mx,my); + AClearTile(x,y); end; end; + MapPaintbox.Invalidate end; - procedure TMapEdit.MapImageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin MDownLeft:=False; MDownRight:=False; + MapPaintBox.Invalidate; end; procedure TMapEdit.ClearMapClick(Sender: TObject); begin - MapCoreBase.ClearMap(CurrentMap,-1); - MapImage.Canvas.Brush.Color:=clBlack; - MapImage.Canvas.FillRect(0,0,MapImage.Width,MApImage.HEight); -// UpdateMapView; + MapCoreBase.ClearMap(CurrentMap,TileClear); + VerifyTileImageList; + MapPaintBox.Invalidate; end; procedure TMapEdit.MapListViewClick(Sender: TObject); @@ -344,11 +407,15 @@ procedure TMapEdit.MapListViewClick(Sender: TObject); MapCoreBase.SetCurrentMap(item.Index); CurrentMap:=MapCoreBase.GetCurrentMap; UpdatePageSize; - UpdateMapView; + //UpdateMapView; + MapPaintBox.Invalidate; end; end; - +procedure TMapEdit.MapPaintBoxPaint(Sender: TObject); +begin + UpdateMapView; +end; procedure TMapEdit.MenuDeleteClick(Sender: TObject); begin @@ -363,14 +430,16 @@ procedure TMapEdit.MenuDeleteClick(Sender: TObject); end; UpdateMapListView; UpdatePageSize; - UpdateMapView; + //UpdateMapView; + MapPaintBox.Invalidate; end; end else begin - MapCoreBase.ClearMap(0,-1); // if there is only one map we just clear it + MapCoreBase.ClearMap(0,TileClear); // if there is only one map we just clear it UpdatePageSize; - UpdateMapView; + //UpdateMapView; + MapPaintBox.Invalidate; end; end; @@ -388,7 +457,7 @@ procedure TMapEdit.MenuExportBasicMapData(Sender: TObject); SaveDialog1.Filter := 'Basic|*.bas|All Files|*.*'; if SaveDialog1.Execute then begin - ExportMap(SaveDialog1.FileName,BasicLan); + ExportMap(SaveDialog1.FileName,BasicLan); end; end; @@ -397,7 +466,7 @@ procedure TMapEdit.MenuExportCArray(Sender: TObject); SaveDialog1.Filter := 'c|*.c|All Files|*.*'; if SaveDialog1.Execute then begin - ExportMap(SaveDialog1.FileName,CLan); + ExportMap(SaveDialog1.FileName,CLan); end; end; @@ -417,7 +486,6 @@ procedure TMapEdit.MenuMapPropsClick(Sender: TObject); begin index:=MapListView.ItemIndex; if index = -1 then index:=0; - // ShowMessage(IntToStr(index)); MapCoreBase.GetMapExportProps(index,EO); MapExportForm.InitComboBoxes; MapExportForm.SetExportProps(EO); @@ -435,7 +503,8 @@ procedure TMapEdit.MenuNewClick(Sender: TObject); CurrentMap:=MapCoreBase.GetCurrentMap; UpdateMapListView; UpdatePageSize; - UpdateMapView; + //UpdateMapView; + MapPaintBox.Invalidate; end; procedure TMapEdit.MenuOpenClick(Sender: TObject); @@ -445,11 +514,11 @@ procedure TMapEdit.MenuOpenClick(Sender: TObject); begin ReadMap(OpenDialog1.FileName); UpdatePageSize; - UpdateMapView; + //UpdateMapView; + MapPaintBox.Invalidate; end; end; - procedure TMapEdit.MenuSaveClick(Sender: TObject); begin SaveDialog1.Filter := 'RM MAP Files|*.map|All Files|*.*'; @@ -484,7 +553,8 @@ procedure TMapEdit.ReSizeMapClick(Sender: TObject); // TileWidth:=MapCoreBase.GetZoomMapTileWidth(CurrentMap); // TileHeight:=MapCoreBase.GetZoomMapTileHeight(CurrentMap); UpdatePageSize; - UpdateMapView; +// UpdateMapView; + MapPaintBox.Invalidate; end; procedure TMapEdit.MenuToolDrawClick(Sender: TObject); @@ -541,8 +611,7 @@ procedure TMapEdit.ReSizeTiles(Sender: TObject); th:=256; zs:=6; end; - End; - + End; MapCoreBase.SetZoomSize(CurrentMap,zs); TileZoom.Position:=zs; @@ -550,11 +619,12 @@ procedure TMapEdit.ReSizeTiles(Sender: TObject); TileWidth:=MapCoreBase.GetZoomMapTileWidth(CurrentMap); TileHeight:=MapCoreBase.GetZoomMapTileHeight(CurrentMap); UpdatePageSize; - UpdateMapView; + LoadTilesToTileImageList; + //UpdateMapView; + MapPaintBox.Invalidate; end; - //0 erase 1 draw tile Procedure TMapEdit.SetMapTool(Tool : integer); begin @@ -603,6 +673,73 @@ procedure TMapEdit.LoadTile(index : integer); end; end; + +procedure TMapEdit.LoadTilesToTileImageList; +var + index,i,j,awidth,aheight : integer; + SrcBitMap,DstBitMap : TBitMap; +begin + TileImageList.Width:=TileWidth; + TileImageList.Height:=TileHeight; + TileImageList.Clear; + + DstBitMap:=TBitMap.Create; + DstBitMap.SetSize(TileWidth,TileHeight); + + for index:=0 to ImageThumbBase.GetCount-1 do + begin + awidth:=ImageThumbBase.GetWidth(index); + aheight:=ImageThumbBase.GetHeight(index); + + SrcBitMap:=TBitMap.Create; + SrcBitMap.SetSize(awidth,aheight); + For j:=0 to aheight-1 do + begin + For i:=0 to awidth-1 do + begin + SrcBitMap.Canvas.Pixels[i,j]:=ImageThumbBase.GetPixelTColor(Index,i,j); + end; + end; + + DstBitMap.Canvas.Clear; + DstBitMap.Canvas.CopyRect( Rect(0, 0, TileWidth, TileHeight), SrcBitMap.Canvas, Rect(0, 0,aWidth, aHeight)); + + TileImageList.Add(DstBitMap,NIL); + SrcBitMap.Free; + end; + + DstBitMap.Free; +end; + +Procedure TMapEdit.VerifyTileImageList; +var + i,j : integer; + T : TileRec; + FIndex : integer; +begin + for j:=0 to MapCoreBase.GetMapWidth(CurrentMap)-1 do + begin + for i:=0 to MapCoreBase.GetMapHeight(CurrentMap)-1 do + begin + MapCoreBase.GetMapTile(CurrentMap,i,j,T); + if (T.ImageIndex<>TileMissing) and (T.ImageIndex<>TileClear) then + begin + FIndex:=ImageThumbBase.FindUID(T.ImageUID); + if FIndex = -1 then // if -1 it was deleted lets update map info + begin + T.ImageIndex:=TileMissing; + MapCoreBase.SetMapTile(CurrentMap,i,j,T); + end + else if Findex<>T.ImageIndex then //oh oh image is in a different index now - lets update + begin + T.ImageIndex:=FIndex; + MapCoreBase.SetMapTile(CurrentMap,i,j,T); + end; + end; + end; + end; +end; + procedure TMapEdit.TileListViewClick(Sender: TObject); var item : TListItem; @@ -620,15 +757,6 @@ procedure TMapEdit.TileListViewClick(Sender: TObject); SelectedTilePanel.AutoSize:=false; SelectedTileImage.AutoSize:=false; - (* SelectedTileImage.Canvas.Clear; - For j:=0 to aheight-1 do - begin - For i:=0 to awidth-1 do - begin - SelectedTileImage.Canvas.Pixels[i,j]:=ImageThumbBase.GetPixelTColor(item.Index,i,j); - end; - end; - *) LoadTile(item.Index); UpdateCurrentTile; end; @@ -647,61 +775,32 @@ procedure TMapEdit.TileZoomChange(Sender: TObject); TileWidth:=MapCoreBase.GetZoomMapTileWidth(CurrentMap); TileHeight:=MapCoreBase.GetZoomMapTileHeight(CurrentMap); UpdatePageSize; - UpdateMapView; + //UpdateMapView; + LoadTilesToTileImageList; + MapPaintBox.Invalidate; end; + procedure TMapEdit.UpdateMapView; var i,j : integer; T : TileRec; - LastTile : TileRec; - STile : integer; - FIndex : integer; begin - STile:=CTile.ImageIndex; - LastTile.ImageIndex:=-255; for j:=0 to MapCoreBase.GetMapWidth(CurrentMap)-1 do begin for i:=0 to MapCoreBase.GetMapHeight(CurrentMap)-1 do begin MapCoreBase.GetMapTile(CurrentMap,i,j,T); - if T.ImageIndex > -1 then - begin - //(LastTile.ImageIndex<>T.ImageIndex) and IsEqualGUID(LastTile.ImageUID,T.ImageUID)=false then //skip reloading if the same time - if IsEqualGUID(LastTile.ImageUID,T.ImageUID)=false then //skip reloading if the same time - begin - FIndex:=ImageThumbBase.FindUID(T.ImageUID); - if FIndex > -1 then // check if image exist - it might have been deleted - begin - T.ImageIndex:=FIndex; - LoadTile(T.ImageIndex); - PlotTile(i,j,T); - LastTile.ImageIndex:=T.ImageIndex; - LastTile.ImageUID:=T.ImageUID; - end - else - begin - PlotMissingTile(i,j); - end; - end - else - begin - PlotTile(i,j,T); - end; - end; + if T.ImageIndex = TileMissing then PlotMissingTile(i,j) + else if T.ImageIndex <> TileClear then ImageListPlotTile(i,j,T); end; end; - LoadTile(STile); //load the tile that is currently selected end; procedure TMapEdit.UpdateTileView; var i,count : integer; begin - (* - ImageList1.Clear; - ImageThumbBase.UpdateAllThumbImages(imagelist1); - *) count:=ImageThumbBase.GetCount; TileListView.items.Clear; @@ -732,39 +831,32 @@ procedure TMapEdit.UpdateTileView; For i:=0 to MapListView.Items.Count-1 do begin MapListView.Items[i].Caption:='Map '+IntToStr(i+1); - // MapListView.Items[i].ImageIndex:=i; end; end; procedure TMapEdit.UpdatePageSize; begin - MapImage.AutoSize:=true; - MapImage.Picture.Bitmap.SetSize(1,1); - MapImage.Picture.Bitmap.SetSize(MapCoreBase.GetZoomMapPageWidth(CurrentMap),MapCoreBase.GetZoomMapPageHeight(CurrentMap)); - MapImage.AutoSize:=false; + MapPaintBox.Width:=0; + MapPaintBox.height:=0; + MapPaintBox.Invalidate; + MapPaintBox.Width:=MapCoreBase.GetZoomMapPageWidth(CurrentMap); + MapPaintBox.height:=MapCoreBase.GetZoomMapPageHeight(CurrentMap); + MapPaintBox.Invalidate; end; procedure TMapEdit.UpdateCurrentTile; begin SelectedTileImage.Picture.Bitmap.SetSize(CTileBitMap.Width, CTileBitMap.Height); SelectedTileImage.canvas.CopyRect(Rect(0, 0, CTileBitMap.Width, CTileBitMap.Height), CTileBitMap.Canvas, Rect(0, 0,CTileBitMap.Width, CTileBitMap.Height)); - (* For j:=0 to aheight-1 do - begin - For i:=0 to awidth-1 do - begin - SelectedTileImage.Canvas.Pixels[i,j]:=ImageThumbBase.GetPixelTColor(item.Index,i,j); - end; - end; - *) end; procedure TMapEdit.UpdateMapInfo(x,y : integer); var mx,my : integer; begin - mx:=x div TileWidth; - my:=y div TileHeight; - MapInfoLabel.Caption:='X = '+IntToStr(mx)+' Y = '+IntToStr(my); + mx:=x div TileWidth; + my:=y div TileHeight; + MapInfoLabel.Caption:='X = '+IntToStr(mx)+' Y = '+IntToStr(my); end; end. diff --git a/rmabout.pas b/rmabout.pas index 3e90411..84d2931 100644 --- a/rmabout.pas +++ b/rmabout.pas @@ -8,7 +8,7 @@ interface Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf; Const - ProgramName ='Raster Master v1.4 R81'; + ProgramName ='Raster Master v1.5 R82'; ProgramLicense = 'Released under MIT License'; type diff --git a/rmmain.lfm b/rmmain.lfm index 468002b..6009713 100644 --- a/rmmain.lfm +++ b/rmmain.lfm @@ -1,7 +1,7 @@ object RMMainForm: TRMMainForm - Left = 33 + Left = 38 Height = 1027 - Top = 66 + Top = 43 Width = 1828 Anchors = [akTop, akLeft, akRight, akBottom] Caption = 'Raster Master' diff --git a/rmmain.pas b/rmmain.pas index d5313c1..6c7c8c6 100644 --- a/rmmain.pas +++ b/rmmain.pas @@ -3577,9 +3577,11 @@ procedure TRMMainForm.MapEditMenuClick(Sender: TObject); begin ImageThumbBase.CopyCoreToIndexImage(ImageThumbBase.GetCurrent); MapEdit.UpdateTileView; - if MapEdit.ShowModal = mrOK then - begin - end; +// if MapEdit.ShowModal = mrOK then +// begin +// end; + MapEdit.Show; + MapEdit.WindowState:=wsNormal; end; procedure TRMMainForm.RayLibExportClick(Sender: TObject); diff --git a/rwpal.pas b/rwpal.pas index 3805ef2..bbf42d8 100644 --- a/rwpal.pas +++ b/rwpal.pas @@ -4,7 +4,7 @@ interface uses - SysUtils,FileUtil,RMCore,rmxgfcore,rwxgf,gwbasic; + SysUtils,LazFileUtils,RMCore,rmxgfcore,rwxgf,gwbasic; Const ColorIndexFormat = 1; @@ -231,15 +231,15 @@ function WritePalConstants(filename : string; Lan,rgbFormat : integer) : word; palettenamestr:=filenametoPalettename(filename); if rgbformat =ColorIndexFormat then begin - arraysize:=NColors-1; + arraysize:=NColors; end else begin - arraysize:=Ncolors*3-1; + arraysize:=Ncolors*3; end; If (Lan=TPlan) OR (Lan =FPLan) OR (Lan=QPlan) OR (Lan = APLan) then begin - Writeln(F,palettenamestr, ' : array[0..',arraysize,'] of byte = ('); + Writeln(F,palettenamestr, ' : array[0..',arraysize-1,'] of byte = ('); end Else if (Lan = QCLan) or (Lan = TCLan) or (Lan = OWLan) then begin @@ -636,15 +636,15 @@ function WritePalBasicBuffer(var data : BufferRec; imagename : string; Lan,rgbFo palettenamestr:=imagename; if rgbformat =ColorIndexFormat then begin - arraysize:=NColors-1; + arraysize:=NColors; end else begin - arraysize:=Ncolors*3-1; + arraysize:=Ncolors*3; end; If (Lan = TPlan) OR (Lan = QPlan) OR (Lan =FPLan) OR (Lan = APLan) then begin - Writeln(data.fText,palettenamestr, ' : array[0..',arraysize,'] of byte = ('); + Writeln(data.fText,palettenamestr, ' : array[0..',arraysize-1,'] of byte = ('); end Else if (Lan = QCLan) or (Lan = TCLan) or (Lan = OWLan) then begin