TGC Codebase Backup



Browser system by Lukas W

1st Sep 2004 7:09
Summary

This is my Browser system v1.0 It was my first attempt on a browser.



Description

This is my Browser system v1.0
It was my first attempt on a browser.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This Browser system works in 3D and 2D
` if you want Pure 2D then Remove all commands that has with 3D to do :)
` =====================================
` written by: Lukas Wadenhof a.k.a n0id
` =====================================

` First of all We need two variables to store the files in.
Dim Files$(999)
Dim EntryY(999)
` We used 'Files$(999)' to store the FileName of 999 files
` And we have 'EntryY(999)' to store the Y position inside the browser of each file.

` Now we load the Browser Image.
`(This image is from my Level Editor to a game I am working on)
load image "load_save.png",9

` setup screen. (You can change the screen resolution too if you want.. just remove the 'REM')
sync on : sync rate 0
REM set display mode 1024,768,32

` Now get the Start Directory
deafultDIR$=get dir$()
` and the Current Directory
currentDIR$=get dir$()

` Get screen width and height
sw=screen width()
sh=screen height()

` change the camera view so we do not ruin the browser (this is for 3D use).
` If you want pure 2D then Remove this Line or put a 'REM' command in front of it :)
set camera view 250,30,sw,sh

` turn on 3D mode
` If you want pure 2D then Remove this Line or put a 'REM' command in front of it :)
backdrop on

` Get Image X and Y position.
` Instead of using numbers, we use these variables.
` This way, if you want to reposition the browser, you only need to change these two numbers,
` Instead of maybe a hundred!
imgx=35: imgy=100
` Paste the Image at the X and Y position
paste image 9,imgX,imgY,1

` Get Files in current Dir
gosub GETDIR
` Print All Files that is visible
gosub REFRESH


` Start the Main Loop
do
   ` Color the Backdrop to a blue color!
   ` If you want pure 2D then Remove this Line or put a 'REM' command in front of it :)
   color backdrop rgb(0,78,128)

   ` start a timer
   timer=timer+1
   ` get mouse x,y position and check if mouse is clicked
   mx=mousex():my=mousey():mc=mouseclick()

   ` Select a File
   for x = First_File to Last_File
      ` If mouse is inside the browser
      if mx>=imgx+3 and mx<=imgx+156
         ` and inside a file Item
         if my>=EntryY(x) and my<=EntryY(x)+15
            ` And mouse is  clicked
            if mc=1
               ` Store the File name into a Variable we call 'FileName$'
               FileName$=files$(x)
               ` get the File Intem Number
               selected=x
               ` print all files (clear the screen)
               gosub REFRESH
               ` and give the selected file a box and a new color
               ink rgb(225,225,225),0:box imgX+3,EntryY(selected)+1,imgX+155,EntryY(selected)+15
               ink rgb(128,128,128),0:text imgX+5,EntryY(selected),FileName$
            endif
         endif
      endif
   next x
   ` Go Down
   if Last_File<file
      if mx>=imgX+158 and mx<=imgX+173 and my>=imgY+152 and my<=imgY+163 and mc=1
         Last_File=Last_File+1
         First_File=First_File+1
         gosub REFRESH
         ` check if the selected file is inside the browser.
         ` If it is outside then do not draw the box and the new Item color
         if selected>First_File and selected<Last_File
            ink rgb(225,225,225),0:box imgX+3,EntryY(selected)+1,imgX+155,EntryY(selected)+15
            ink rgb(128,128,128),0:text imgX+5,EntryY(selected),FileName$
         endif
      endif
   endif
   ` Go Up
   if First_File>2
      if mx>=imgX+158 and mx<=imgX+173 and my>=imgY+45 and my<=imgY+60 and mc=1
         Last_File=Last_File-1
         First_File=First_File-1
         gosub REFRESH
         ` check if the selected file is inside the browser.
         ` If it is outside then do not draw the box and the new Item color
         if selected>First_File and selected<Last_File
            ink rgb(225,225,225),0:box imgX+3,EntryY(selected)+1,imgX+155,EntryY(selected)+15
            ink rgb(128,128,128),0:text imgX+5,EntryY(selected),FileName$
         endif
      endif
   endif
   ` print selected file
   ink rgb(0,0,0),0
   text imgX+3,imgY+169,FileName$
   ` print Current Directory
   text imgX+3,imgY+27,CurrentDIR$
   ` Check if OK or CANCEL button is pressed.
   if timer>9
   if mc=1
      timer=0
      ` This is the 'OK' button
      if my>=imgY+189 and my<=imgY+205
         if mx>=imgX+2 and mx<=imgX+51
            ` If file is a folder then Remove the '[ ]' and Enter that folder
            if left$(FileName$,1)="["
               letters=len(FileName$)
               poop1$=right$(FileName$,letters-1)
               letters=len(poop1$)
               poop2$=left$(poop1$,letters-1)
               FileName$=poop2$
               set dir CurrentDIR$+"/"+FileName$
               CurrentDIR$=get dir$()
               Gosub GETDIR
               Gosub REFRESH
               FileName$=""
            else
            ` else if it is a file then goto Ending
               goto ENDING
            endif
         endif
      endif
   endif
   endif
sync:loop

GETDIR:
   ` changer directory to current directory
   cd CurrentDIR$
   ` check how many files is inside this directory
   perform checklist for files
   ` variable 'file' is total amount of files inside this browser
   file=checklist quantity()
   ` variable 'First_File' is 2, because if it is 1 then an Item we do not use appears
   ` you can change this to 1 if you want... nothing will actually happen
   First_File=2
   ` variable 'Last_File' is total amount of Files
   Last_File=file
   ` If The variable is larger than 9, then it is 9 files
   ` because if we have more than 9 files they will be printed outside the browser!
   if Last_File>9 then Last_File=9
return

REFRESH:
   ` Get the same color as the browser
   ink rgb(192,192,192),0
      ` clear the browser from all files
      box imgX+3,imgY+46,imgX+155,imgY+166
      box imgX+3,imgY+170,imgX+172,imgY+184
      box imgX+3,imgY+28,imgX+172,imgY+42
   ` Y position of first file = Image position Y + 45
   EntryY(First_File)=(imgY+45)
   ` print all files that is visible
   for x =First_File to Last_File
      ` file$ is file name
      file$=checklist string$(x)
      ` if file$ is a folder then make two '[ ]' to show that it is a folder
      ` files$(current file) gets the foldername of the current folder + '[ ]'
      if checklist value a(x)=1
         files$(x)="["+file$+"]"
         ` and change the color to DarkGreen
         Ink RGB(0,100,0),0
      else
         ` if the file IS a file then files$(current file) gets the filename of the current file
         files$(x)=file$
         ` change text color to black
         Ink RGB(0,0,0),0
      endif
      ` print the file item at its position
      text imgX+5,EntryY(x),files$(x)
      ` change Y position of files to Increase by 15..
      EntryY(x+1)=EntryY(x)+15
   next x
return


ENDING:
   backdrop off
   cls 0
do:cls

   ink rgb(0,225,0),0

   print "Hello there!"
   print "This is where the demo ends"
   print "check out for more demos at"
   print "www.n0id.tk"
   print
   print "By the Way:"
   print "Dir: "+CurrentDIR$
   print "File: "+FileName$
   print "Path: "+CurrentDIR$+"\"+FileName$
   print
   print "Press a Key To Exit Demo"
   print
   print "  -Lukas Wadenhof"

   if mouseclick()>0 then end
   if scancode()>0 then end

sync:loop