All pastes #217849 Raw Edit

Robin

public text v1 · immutable
#217849 ·published 2006-10-23 21:12 UTC
rendered paste body

`User Interface Setup Code
`===========================================
`Call createUI() to setup the user interface
`-------------------------------------------
sync on
sync rate 60
startBlue "..",".."


`Settings
make camera 1 : position camera 1,0,30,0
backdrop on : color backdrop 1,RGB(0,128,255)
set window title "GameGeeks LevelEditor"

`load lua config file
Err = load lua("config.lua")
if Err>1
   Status$ = "Lua config file failed to load"
else
   Status$ = "Lua config file loaded perfect"
endif
cls

`Global Variable Declarations for Gadgets
`----------------------------------------

global StatusBar
global ToolBar
global ObjPanel
global ObjXPosEdit
global ObjXPosLabel
global ObjYPosLabel
global ObjYPosEdit
global ObjToolBarTabs
global ObjZPosLabel
global ObjZPosEdit
global ObjXScaleLabel
global ObjXScaleEdit
global ObYScaleLabel
global ObjYScaleEdit
global ObjZScaleLabel
global ObjZScaleEdit
global ObjXRotateLabel
global ObjXRotateEdit
global ObjYRotateLabel
global ObjYRotateEdit
global ObjZRotateEdit
global ObjZRotateLabel

global newMap
global newmapMapname
global newmapMaplabel
global newmapHeightdirlabel
global newmapHeightdir
global newmapHeightdirbrowse
global newmapTexturedirlabel
global newmapTexturedir
global newmapTexturedirbrowse
global newmapDetaildirlabel
global newmapDetaildir
global newmapDetaildirbrowse
global newmapTerrainscalelabel
global newmapTerrainscaleA
global newmapTerrainscaleB
global newmapTerrainscaleC
global newmapTerrainsplitlabel
global newmapTerrainsplit
global newmapTerraintilinglabel
global newmapTerraintiling
global newmapTerrainlightlabel
global newmapTerrainlightA
global newmapTerrainlightB
global newmapTerrainlightC
global newmapTerrainlightD
global newmapTerrainlightE
global newmapTerrainlightF
global newmapTerrainlightG
global newmapCreatemap

global ObjectBrowser
global OBList
global OBFolders
global OBLoad


`Menu Gloals
`-----------
    global menu

    #constant MENU_FILE 0
    global menuFile
    #constant MENU_NEWMAP 1
    #constant MENU_LOADMAP 2
    #constant MENU_SAVEMAP 3
    #constant MENU_EXIT 4


    #constant MENU_OBJECT 5
    global menuObject
    #constant MENU_INSERTAGAINF6 6
    #constant MENU_OBJECTBROWSERF8 7
    #constant MENU_SHOWHIDEOBJECTOPTIONS 8


    #constant MENU_HELP 9
    global menuHelp
    #constant MENU_HELPCONTENTF1 10
    #constant MENU_ABOUT 11

`Prepare and create GUI
createUI()
createMainMenu()
gosub presetNewMapValues
gosub prepareObjectBrowser

`Variables
newMapKey as boolean : newMapKey = 0
loadObjectKey as boolean : loadObjectKey = 0
FreeFlyMode as boolean : FreeFlyMode = 0
TbKeyState as boolean
CurrentObject as integer

do

  getEvent

     setStatusText StatusBar,0,"Status: "+Status$
   `Menu and submenus
   if eventType()=MENU_CLICK
      select eventData()
         case 1 : newMapKey = 1 : endcase
         `case 2 : loadMap() : endcase
         `case 3 : saveMap() : endcase
         case 4 : end : endcase
         case 7 : loadObjectKey = 1 : endcase
      endselect
   endif
   `Quickbuttons
   if eventType()=MOUSE_CLICK and eventSource()=toolbar
      select getToolbarItem(toolbar)
         case 0 : newMapKey = 1 : endcase
         `case 1 : loadMap() : endcase
         case 15
            TbKeyState=getToolBarButtonState (toolbar,15)
            if TbKeyState = 1
               FreeFlyMode = 1
            else
               FreeFlyMode = 0
            endif
         endcase
      endselect
   endif

   gosub WindowsStatus

   gosub FlyMode

sync : loop


`Create User Interface
`---------------------
function createUI()
    If Not GUI_CONSTANTS Then errorMessage "GUI Constants not defined.  Please include gui.dba when you compile" : end

    StatusBar=createStatusBar(0)
    ToolBar=createToolbar(0)
      addToolbarButton ToolBar,"data/gfx/ico_new.bmp",0
      addToolbarButton ToolBar,"data/gfx/ico_load.bmp",0
      addToolbarButton ToolBar,"data/gfx/ico_save.bmp",0
      addToolbarSplitter Toolbar
      addToolbarButton ToolBar,"data/gfx/ico_objbrowse.bmp",0
      addToolbarButton ToolBar,"data/gfx/ico_objoptions.bmp",1
      addToolbarSplitter Toolbar
      addToolbarButton ToolBar,"data/gfx/ico_x_rotate.bmp",1
      addToolbarButton ToolBar,"data/gfx/ico_y_rotate.bmp",1
      addToolbarButton ToolBar,"data/gfx/ico_z_rotate.bmp",1
      addToolbarSplitter Toolbar
      addToolbarButton Toolbar,"data/gfx/ico_x_move.bmp",1
      addToolbarButton Toolbar,"data/gfx/ico_y_move.bmp",1
      addToolbarButton Toolbar,"data/gfx/ico_z_move.bmp",1
      addToolbarSplitter Toolbar
      addToolbarButton Toolbar,"data/gfx/ico_free_fly.bmp",1
    ObjPanel=createPanel(382,0,250,426,0)
    setPanelBorderStyle ObjPanel,2
    setGadgetAlign ObjPanel,4

    ObjXPosEdit=createEdit(12,67,220,20,0,ObjPanel)
    ObjXPosLabel=createLabel(12,47,50,20,"Obj X Pos",ObjPanel)
    ObjYPosLabel=createLabel(12,92,50,20,"Obj Y Pos",ObjPanel)
    ObjYPosEdit=createEdit(12,112,220,20,0,ObjPanel)
    ObjZPosLabel=createLabel(12,137,50,20,"Obj Z Pos",ObjPanel)
    ObjZPosEdit=createEdit(12,157,220,20,0,ObjPanel)
    ObjXScaleLabel=createLabel(12,207,60,20,"Obj X Scale",ObjPanel)
    ObjXScaleEdit=createEdit(12,227,55,20,0,ObjPanel)
    ObYScaleLabel=createLabel(87,207,60,20,"Obj Y Scale",ObjPanel)
    ObjYScaleEdit=createEdit(87,227,50,20,0,ObjPanel)
    ObjZScaleLabel=createLabel(162,207,60,20,"Obj Z Scale",ObjPanel)
    ObjZScaleEdit=createEdit(162,227,50,20,0,ObjPanel)
    ObjXRotateLabel=createLabel(12,272,65,20,"Obj X Rotate",ObjPanel)
    ObjXRotateEdit=createEdit(12,292,55,20,0,ObjPanel)
    ObjYRotateLabel=createLabel(87,272,65,20,"Obj Y Rotate",ObjPanel)
    ObjYRotateEdit=createEdit(87,292,55,20,0,ObjPanel)
    ObjZRotateEdit=createEdit(162,292,55,20,0,ObjPanel)
    ObjZRotateLabel=createLabel(162,272,65,20,"Obj Z Rotate",ObjPanel)
    ObjToolBarTabs=createTabs(2,2,240,360,ObjPanel)
      addTab ObjToolBarTabs,"Basic"
      addTab ObjToolBarTabs,"Advanced"

    newMap=createWindow(95,214,345,503,"New Map",WINDOW_FIXED,0,0,0)
    newmapMapname=createEdit(5,5,165,20,0,newMap)
    newmapMaplabel=createLabel(175,10,50,20,".ggm",newMap)
    newmapHeightdirlabel=createLabel(5,40,95,20,"Heightmap directory",newMap)
    newmapHeightdir=createEdit(5,60,320,20,0,newMap)
    newmapHeightdirbrowse=createButton(250,85,75,25,"Browse",0,newMap)
    newmapTexturedirlabel=createLabel(5,100,95,20,"Texture directory",newMap)
    newmapTexturedir=createEdit(5,120,320,20,0,newMap)
    newmapTexturedirbrowse=createButton(250,145,75,25,"Browse",0,newMap)
    newmapDetaildirlabel=createLabel(5,160,95,20,"Detailmap directory",newMap)
    newmapDetaildir=createEdit(5,180,320,20,0,newMap)
    newmapDetaildirbrowse=createButton(250,205,75,25,"Browse",0,newMap)
    newmapTerrainscalelabel=createLabel(5,230,65,20,"Terrain scale",newMap)
    newmapTerrainscaleA=createEdit(5,250,60,20,0,newMap)
    newmapTerrainscaleB=createEdit(70,250,60,20,0,newMap)
    newmapTerrainscaleC=createEdit(135,250,60,20,0,newMap)
    newmapTerrainsplitlabel=createLabel(5,285,65,20,"Terrain split",newMap)
    newmapTerrainsplit=createEdit(5,305,60,20,0,newMap)
    newmapTerraintilinglabel=createLabel(5,340,65,20,"Terrain tiling",newMap)
    newmapTerraintiling=createEdit(5,360,60,20,0,newMap)
    newmapTerrainlightlabel=createLabel(5,395,65,20,"Terrain light",newMap)
    newmapTerrainlightA=createEdit(5,415,42,20,0,newMap)
    newmapTerrainlightB=createEdit(50,415,42,20,0,newMap)
    newmapTerrainlightC=createEdit(95,415,42,20,0,newMap)
    newmapTerrainlightD=createEdit(140,415,42,20,0,newMap)
    newmapTerrainlightE=createEdit(185,415,42,20,0,newMap)
    newmapTerrainlightF=createEdit(230,415,42,20,0,newMap)
    newmapTerrainlightG=createEdit(275,415,42,20,0,newMap)
    newmapCreatemap=createButton(255,440,75,25,"Create Map",0,newMap)

    ObjectBrowser=createWindow(100,210,533,616,"Object Browser",WINDOW_NORMAL,0,0,0)
    OBList=createListView(5,5,420,570,ObjectBrowser)
    OBFolders=createComboBox(435,5,80,100,ObjectBrowser)
    OBLoad=createButton(435,550,80,25,"Load Object",0,ObjectBrowser)

    createHotKey 15,0,0,1,asc("f")

endfunction

`Create Main Menu
`----------------
function createMainMenu()
menu=createMenu(0)
    addMenuItem menu,"File",0

    menuFile=createSubMenu(menu,0)
    addMenuItem menuFile,"New Map",1
    addMenuItem menuFile,"Load Map",2
    addMenuItem menuFile,"Save Map",3
    addMenuItem menuFile,"Exit",4


    addMenuItem menu,"Object",5

    menuObject=createSubMenu(menu,5)
    addMenuItem menuObject,"Insert Again [F6]",6
    addMenuItem menuObject,"Object Browser [F8]",7
    addMenuItem menuObject,"Show/Hide Object Options",8


    addMenuItem menu,"Help",9

    menuHelp=createSubMenu(menu,9)
    addMenuItem menuHelp,"Help Content [F1]",10
    addMenuItem menuHelp,"About",11
endfunction

WindowsStatus:
   if newMapKey = 1
      setgadgetvisible NewMap,1
      setgadgetenabled 0,0

      MapName$ = getGadgetText(newmapMapname)
      HeightMapLoc$ = getGadgetText(newmapHeightdir)
      TextureLoc$ = getGadgetText(newmapTexturedir)
      DetailLoc$ = getGadgetText(newmapDetaildir)
      TScaleA$ = getGadgetText(newmapTerrainscaleA)
      TScaleB$ = getGadgetText(newmapTerrainscaleB)
      TScaleC$ = getGadgetText(newmapTerrainscaleC)
      TSplit$ = getGadgetText(newmapTerrainsplit)
      TTiling$ = getGadgetText(newmapTerraintiling)
      TLightA$ = getGadgetText(newmapTerrainlightA)
      TLightB$ = getGadgetText(newmapTerrainlightB)
      TLightC$ = getGadgetText(newmapTerrainlightC)
      TLightD$ = getGadgetText(newmapTerrainlightD)
      TLightE$ = getGadgetText(newmapTerrainlightE)
      TLightF$ = getGadgetText(newmapTerrainlightF)
      TLightG$ = getGadgetText(newmapTerrainlightG)

      if eventSource()=newmapHeightdirbrowse and eventType()=MOUSE_CLICK
         HeightMapLoc$ = openDialog("Load HeightMap File","jpeg format(*.jpeg)|*.jpeg|png format (*.png)|*.png|bmp format (*.bmp)|*.bmp|tga format (*.tga)|*.tga")
         setGadgetText newmapHeightdir,HeightMapLoc$
      endif
      if eventSource()=newmapTexturedirbrowse and eventType()=MOUSE_CLICK
         TextureLoc$ = openDialog("Load Texture File","jpeg format(*.jpeg)|*.jpeg|png format (*.png)|*.png|bmp format (*.bmp)|*.bmp|tga format (*.tga)|*.tga")
         setGadgetText newmapTexturedir,TextureLoc$
      endif
      if eventSource()=newmapDetaildirbrowse and eventType()=MOUSE_CLICK
         DetailLoc$ = openDialog("Load DetailMap File","jpeg format(*.jpeg)|*.jpeg|png format (*.png)|*.png|bmp format (*.bmp)|*.bmp|tga format (*.tga)|*.tga")
         setGadgetText newmapDetaildir,DetailLoc$
      endif

      if eventSource()=newmapCreatemap and eventType()=MOUSE_CLICK
         load image TextureLoc$, 1001
         load image DetailLoc$, 1002
         make object terrain 1000                              ` create the terrain object
         set terrain heightmap 1000, HeightMapLoc$             ` set the heightmap
         set terrain scale 1000, val(TScaleA$), val(TScaleB$), val(TScaleC$)   ` set the scale
         set terrain split 1000, val(TSplit$)                      ` split value by 16 * 16
         set terrain tiling 1000, val(TTiling$)                    ` detail map tiling
         set terrain light 1000, val(TLightA$), val(TLightB$), val(TLightC$), val(TLightD$), val(TLightE$), val(TLightF$), val(TLightG$)  ` light - xdir, ydir, zdir, red, green, blue, intensity
         set terrain texture 1000, 1001, 1002                        ` base and detail texture
         build terrain 1000                                    ` finally build the terrain
         position object 1000,0,0,0
         CurrentObject = 1
         newMapKey = 0
      endif
   else
      setgadgetvisible NewMap,0
   endif

   if loadObjectKey = 1
      setgadgetvisible ObjectBrowser,1
   else
      setgadgetvisible ObjectBrowser,0
   endif
return

`Sets the vaules in the editboxes so it got deafault values
presetNewMapValues:

   TScaleA$ = lua array string("Settings->TScaleA")
      setGadgetText newmapTerrainscaleA, TScaleA$
   TScaleB$ = lua array string("Settings->TScaleB")
      setGadgetText newmapTerrainscaleB, TScaleB$
   TScaleC$ = lua array string("Settings->TScaleC")
      setGadgetText newmapTerrainscaleC, TScaleC$
   TSplit$ = lua array string("Settings->TSplit")
      setGadgetText newmapTerrainsplit, TSplit$
   TTiling$ = lua array string("Settings->TTiling")
      setGadgetText newmapTerraintiling, TTiling$
   TLightA$ = lua array string("Settings->TLightA")
      setGadgetText newmapTerrainlightA, TLightA$
   TLightB$ = lua array string("Settings->TLightB")
      setGadgetText newmapTerrainlightB, TLightB$
   TLightC$ = lua array string("Settings->TLightC")
      setGadgetText newmapTerrainlightC, TLightC$
   TLightD$ = lua array string("Settings->TLightD")
      setGadgetText newmapTerrainlightD, TLightD$
   TLightE$ = lua array string("Settings->TLightE")
      setGadgetText newmapTerrainlightE, TLightE$
   TLightF$ = lua array string("Settings->TLightF")
      setGadgetText newmapTerrainlightF, TLightF$
   TLightG$ = lua array string("Settings->TLightG")
      setGadgetText newmapTerrainlightG, TLightG$

return

FlyMode:
if FreeFlyMode=1
   If keystate(17)=1 then move camera 1,3
   if keystate(31)=1 then move camera 1,-3
   rotatex=wrapvalue(mousemovex()+rotatex)
   rotatey=wrapvalue(mousemovey()+rotatey)
   rotate camera 1,rotatey,rotatex,0
endif
return

prepareObjectBrowser:
   type ListObjSettings
      path as string
      object as string
      texture as string
      icon as string
   endtype
   dim ObjList(1000) as ListObjSettings
   CurrentListItem as integer : CurrentListItem = 1

   type ListFolderSettings
      name as string
   endtype
   dim FolderList(30) as ListFolderSettings
   CurrentFolderItem as integer : CurrentFolderItem = 1

   `ImageList = createImageList(120,120)
   `Sets the dir for media
   set dir "media/"
   find First
   while Get File Type() <> -1
      if Get File Type() = 1 then CurrentDir$ = Get File Name$()
      FolderList(CurrentFolderItem).name =  CurrentDir$
      CurrentFolderItem = CurrentFolderItem + 1
      find Next
   endWhile

   sets current found dir
   for folder = 1 to 50
            find first
      if FolderList(folder).name <> "" and Get File Type() = 1
         set dir FolderList(folder).name
            while Get File Type() <> -1
               if Get File Type() = 0 and right$(CurrentFile$,3)="dbo"
                  ObjList(CurrentListItem).path = "media/"+FolderList(folder).name
                  ObjList(CurrentListItem).object = CurrentFile$
                  for i = 1 to (len(CurrentFile$)-4)
                     tempFileName$ = tempFileName$ +  mid$(CurrentFile$,i)
                  next i
                  ObjList(CurrentListItem).texture = tempFileName$ + "_texture.png"
                  ObjList(CurrentListItem).icon = tempFileName$ + "_icon.png"
               endif
            endWhile
      endif
            find Next
   next folder
return