Grid-like gadget? (for map editors)

Everything else that doesn't fall into one of the other PB categories.
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Grid-like gadget? (for map editors)

Post by Kaiser »

Hey xD Happy New year Everyone ^^... what's up? :P ... anyhow! I've been trying to do some quick editor for a 3D game I'm working on (which is tile-based... internally) so I wanted to make the maps using an eagle-eye top view, 2D... like the old Final Fantasy's. Well... you all remember RPG Maker? or the 2D tiled map editors? I've been wondering if there's a gadget which can allow me to edit tiles and such (something like the grid gadget... but that allows pictures, at least) but without having to create a 2D windowed screen and flipbuffers and do all that heck... is there any possible way I can use a gadget.. that way? I've been thinking into using a containergadget and then adding lots of imagegadget but heeeeell that'd be a whole heck of a lot imagegadgets all around - and a pain to edit and handle... so... :P

^^ guess this can be a gadget request, if it isn't possible yet? ^^

Bye! :D
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

Nevermind. I just did it, lol!

It's a very rough draft... but I'm sure it's a good start... only thing is that the gadget drawing system seems to be a bit slow... oh well!

Code: Select all

;Scrolling test
;by Kaiser

#Cont=1
#Ts=10

Global WWidth
Global WHeight
Global TileSize
Global MapWidth
Global MapHeight

TileSize=24
WWidth=TileSize*20
WHeight=TileSize*20
MapWidth=39
MapHeight=39

Dim Map(MapWidth,MapHeight)

OpenWindow(1,0,0,WWidth,WHeight,#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget,"Scrolling Tiled Editor test by Kaiser")

CreateGadgetList(WindowID())
ScrollAreaGadget(#Cont, 0,0,WWidth,WHeight, TileSize*(MapWidth+1), TileSize*(MapHeight+1), 10)

For x=0 To MapWidth
  For y=0 To MapWidth
    ImageGadget(#Ts+count,x*TileSize,y*TileSize,TileSize,TileSize,0,#PB_Image_Border)
    count=count+1
  Next y
Next x 

CloseGadgetList()

Repeat
  Ev=WindowEvent()
  If Ev=#PB_Event_Gadget

    ;It's a tile?
    If EventGadgetID()>=#Ts And EventGadgetID()<=(#Ts+(MapWidth*MapHeight))
      G=EventGadgetID()
      Debug "Gadget #: "+Str(G)
      Debug "X: "+Str(GadgetX(G))
      Debug "Y: "+Str(GadgetY(G))
      Debug "Map X: "+Str(GadgetX(G)/TileSize)
      Debug "Map Y: "+Str(GadgetY(G)/TileSize)
    EndIf 
      
  EndIf 
  
ForEver 
Edit: Changed code a lil' bit ^_^
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

If it is for Windows then you can save a couple of hundred ms by turning updates off whilst the ImageGadgets are being created:

Code: Select all

SendMessage_(WindowID(), #WM_SETREDRAW, #False, 0)
For x=0 To MapWidth
  For y=0 To MapWidth
    ImageGadget(#Ts+count,x*TileSize,y*TileSize,TileSize,TileSize,0,#PB_Image_Border)
    count+1
  Next y
Next x
SendMessage_(WindowID(), #WM_SETREDRAW, #True, 0)
InvalidateRect_(WindowID(), 0, #True)
Mat
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Or just create the window with the #PB_Window_Invisible flag and unhide it when all init stuffs are done.
Kaiser
Enthusiast
Enthusiast
Posts: 118
Joined: Tue Jan 11, 2005 8:36 am

Post by Kaiser »

That's a good idea too Fred, thanks :)

MrMat, your code really worked... makes it fast, guess it doesn't has to redraw them so it gets faster... nice one :O and yeah, it's all for Windows :P
Post Reply