edit: I took out the u/n and pass for blue, forgot to do that...
Well it's fully-functional if you ignore the bugs, and realize I didn't add one feature I wanted to. Just been busy with work lately. Also I did not clean the comments yet, as I will when I add that feature. Hopefully soon. I use Blue GUI, but a convert to WinGUI would be beneficial, as my interface also needs a huge cleaning. However it does work, and save files even.
And loading isn't the thing I wanted to add, it's groups for the specific type of game I'm making. The squares indicate your position. Also one of the comments is an error, as I had two variables named the same thing and didn't realize it.
Controls: Mouse moves, spacebar switches between move mode. The numpad lets you change the size of the x, y, and z values of every object. They don't have a real size until you start to change them, I fixed that in the previous editor that I lost the code for...
The other keys are wasd-like, and I broke the input functions up so you could probably tell what's happening.
Note: scancode and better input-handling would do this editor good, and error-checking to prevent accessing nonexistant stuff. There's a bit, but it's not enough. (good enough for my game though, you could say I finished it for my purposes)
Rem Project: racesegments
Rem Created: 8/29/2007 2:02:15 AM
Rem ***** Main Source File *****
`input the segment spacing, and the bound
`use markers for where you are
`rotate x and z
REM DO NOT ASSIGN VARIABLES VALUES BEFORE SYNC ON!!!!!!!1
`User Interface Setup Code
`===========================================
`Call createUI() to setup the user interface
`-------------------------------------------
#include gui.dba
startBlue "EDITEDOUT", "EDITEDOUT"
remstart object number specifics
*spacers are 10 through 19
remend
REM CONSTANTS
#constant MENU_ADD_OBJECT 1
#constant MENU_DELETE_OBJECT 2
#constant MENU_UNSELECT_OBJECT 3
`Global Variable Declarations for Gadgets
`----------------------------------------
global Gadget1
global spacingEdit
global xbound
global ybound
global Gadget5
global Gadget6
global Gadget7
global ResetButt
global NewObjectButt
global UL
global UC
global UR
global DL
global DC
global RC
global LC
global DR
global CC
global RotateButt
global MoveButt
global XSelector
global YSelector
global ZSelector
global SaveButt
global OpenButt
global Gadget26
global Gadget27
global Gadget28
global Gadget29
global Gadget30
global currentobject
currentobject = 1000
global spacing as integer
`spacing is which spacer you're at
`spacers is the space between
global spacers as integer
global xbounds as integer
global ybounds as integer
`addMenuItem handle menu, str caption, int returnValue, [int insertBefore], [str image]
rightmenu = createPopupMenu()
addMenuItem rightmenu, "Add Object", MENU_ADD_OBJECT
addMenuItem rightmenu, "Unselect Object", MENU_UNSELECT_OBJECT
addMenuItem rightmenu, "Delete Object", MENU_DELETE_OBJECT
`int item=showPopupMenu(handle menu) This command returns the constant values of what is clicked.
`the default width and height, and placing of the triangles that let you know what you're working on.
xbounds=100
ybounds=100
`spacing is the particular section # you're on
`while spacers is the actual space between those sections.
global selectedobject = 0
global maxobjects = 0
`max objects is the maximum number of objects that exist in the map, to prevent editing of unknown objects
`this is not the max number, but it is the max of the number that currently exist
sync on
sync rate 33
createUI()
type mapobject
deleted as float
xpos as float
ypos as float
zpos as float
`the next set is for freeform moving
oldxpos as float
oldypos as float
oldzpos as float
xrot as float
yrot as float
zrot as float
oldrot as float
oldyrot as float
oldzrot as float
`for scaling
xsize as float
ysize as float
zsize as float
filename as string
aitype as integer
`ai type lets the computer know how to handle movement
objectnum as integer
endtype
`mouse vars
global oldmousex
global oldmousey
`the spacers
`triangles are objnumber, x1, y1, z1, x2, y2, z2, z3, y3, z3
`make object triangle 10, 0,0,spacing*spacers, spacers,0,spacing*spacers, spacers/2 ,0,spacing*spacers
`make object triangle 11, xbounds,0,spacing*spacers, spacers+xbounds,0,spacing*spacers, spacers/2 + xbounds ,0,spacing*spacers
make object cube 10, 10
make object cube 11, 10
make object cube 12, 10
make object cube 13, 10
position object 10, 0, 0, 0
position object 11, xbounds, 0,0
position object 12, 0, ybounds, 0
position object 13, xbounds, ybounds,0
global movemode = -1
`if this value is positive then movemode is on.
global dim obstacles(5000) as mapobject
`add a key delay to avoid mistakes
global keydelay as integer
keydelay = 0
autocam off
position camera 50, 100, 0
point camera 50, 0, 0
`set camera range 1, 50000
spacing=0
spacers=20
`MAIN LOOP````````````````````````````````````````````````
do
dec keydelay
if keydelay < 0 then keydelay = 0
`do input after delay
if keydelay <= 0
if spacekey()
movemode = movemode * -1
`these next lines keep the camera from jittering if you move the mouse when movemode is off for awhile then back on
oldmousex=mouseX()
oldmousey=mouseY()
endif
if inkey$()="n"
spacing= spacing + 1
changeSpacingLocations()
endif
if inkey$()="m"
spacing = spacing - 1
changeSpacingLocations()
endif
if obstacles(selectedobject).objectnum+1 > 999
if inkey$() = "b" then selectedobject = selectedobject+1
endif
if obstacles(selectedobject).objectnum-1 > 999
if inkey$() = "v" then selectedobject = selectedobject - 1
endif
if inkey$() = "x"
obstacles(selectedobject).deleted = 1
hide object selectedobject
endif
if inkey$() = "z"
obstacles(selectedobject).deleted = 0
show object selectedobject
endif
` if selectedobject > maxobjects then selectedobject = maxobjects+1000
`if selectedobject = 999 then selectedobject = 1000
keydelay = keydelay + 10
endif
text 400, 10, STR$(object position z(10)) + " " + STR$(object position z(11))
text 400, 30, STR$(spacing)
` if objselected > 0 then objectfunc
``raw code, ignore
`obstacles(currentobject).filename=openDialog("Open Model File","3DS (*.3ds)|*.3ds|All Files (*.*)|*.*")
`load object obstacles(currentobject).filename, currentobject
`currentobject = currentobject + 1
`endif
``end ignore raw code
`do keyboard shortcuts
if movemode > 0 then doinput()
if selectedobject > 999 then doSelectedInput()
eventinput()
sync
loop
`Menu Gloals
`-----------
`User Interface Setup Code
`===========================================
`Call createUI() to setup the user interface
`-------------------------------------------
`Global Variable Declarations for Gadgets
`----------------------------------------
`Menu Gloals
`-----------
`Create User Interface
`---------------------
function createUI()
If Not GUI_CONSTANTS Then errorMessage "GUI Constants not defined. Please include gui.dba when you compile" : end
Gadget1=createPanel(0,0,260,710,0)
setPanelBorderStyle Gadget1,2
spacingEdit=createEdit(42,62,75,20,0,Gadget1)
xbound=createEdit(42,92,75,20,0,Gadget1)
ybound=createEdit(42,122,75,20,0,Gadget1)
Gadget5=createLabel(122,62,90,20,"Segment Spacing",Gadget1)
Gadget6=createLabel(122,92,90,20,"Upper X bounds",Gadget1)
Gadget7=createLabel(122,122,78,15,"Upper Y bounds",Gadget1)
ResetButt=createButton(72,157,75,25,"Reset",0,Gadget1)
NewObjectButt=createButton(72,222,75,25,"New Object",0,Gadget1)
UL=createRadioButton(57,302,15,20,"",Gadget1)
UC=createRadioButton(87,302,14,20,"",Gadget1)
UR=createRadioButton(117,302,15,20,"",Gadget1)
RC=createRadioButton(117,337,15,20,"",Gadget1)
LC=createRadioButton(57,337,15,20,"",Gadget1)
CC=createRadioButton(87,337,15,20,"",Gadget1)
DL=createRadioButton(57,367,15,20,"",Gadget1)
DC=createRadioButton(87,367,17,20,"",Gadget1)
DR=createRadioButton(117,367,15,18,"Radio",Gadget1)
RotateButt=createButton(32,432,75,25,"Rotate",0,Gadget1)
MoveButt=createButton(32,492,75,25,"Move",0,Gadget1)
XSelector=createCheckBox(147,432,75,20," X",Gadget1)
YSelector=createCheckBox(147,462,75,20," Y",Gadget1)
ZSelector=createCheckBox(147,492,75,20," Z",Gadget1)
SaveButt=createButton(17,17,75,25,"Save",0,Gadget1)
OpenButt=createButton(112,17,75,25,"Open",0,Gadget1)
Gadget26=createButton(162,192,75,25,"Save As...",0,Gadget1)
Gadget27=createLabel(47,272,95,20,"Initial region placing",Gadget1)
Gadget28=createEdit(22,562,110,20,0,Gadget1)
Gadget29=createLabel(146,563,71,19,"Current Object",Gadget1)
Gadget30=createLabel(22,542,113,19,"Object Number Here",Gadget1)
setChecked CC, 1
`thought I'd check the middle radio butt
endfunction
`Create Main Menu
`----------------
function createMainMenu()
menu=createMenu(0)
endfunction
function doinput()
mousemove()
`oldselected = selectedobject
` if object exist(selectedobject) + 1
` if inkey$() = "b" then selectedobject = selectedobject+1
` endif
`if object exist(selectedobject) - 1
` if inkey$() = "v" then selectedobject = selectedobject - 1
`endif
endfunction
function changeSpacingLocations()
position object 10, 0, 0, spacing*spacers
position object 11, xbounds, 0, spacing*spacers
position object 12, 0, ybounds, spacing*spacers
position object 13, xbounds, ybounds, spacing*spacers
endfunction
function mousemove()
mousemoveval=3
mx=mousex()
my=mousey()
if mx > oldmousex then turn camera right mousemoveval
if mx < oldmousex then turn camera right -mousemoveval
if my > oldmousey then pitch camera down mousemoveval
if my < oldmousey then pitch camera up mousemoveval
mz = mousemovez()
if mz <> 0 then move camera mz
if rightkey() then roll camera right mousemoveval
if leftkey() then roll camera right -mousemoveval
oldmousex=mx
oldmousey=my
endfunction
function eventinput()
getEvent
if eventSource()=ResetButt
if eventType()=MOUSE_CLICK
spacers=VAL(getgadgettext(spacingEdit))
xbounds=VAL(getgadgettext(xbound))
ybounds=VAL(getgadgettext(ybound))
endif
` position object 10, -10, 0, spacing*spacers
` position object 11, xbounds+10, 0,spacing*spacers
` position camera xbounds/2, ybounds/2, spacing*spacers-70
` point camera xbounds/2, ybounds/2, spacing*spacers
endif
if eventSource()=SaveButt
if eventType()=MOUSE_CLICK
savefunc()
endif
endif
if eventSource()=NewObjectButt
if eventType()=MOUSE_CLICK
putMapObject()
endif
endif
endfunction
function putMapObject()
obstacles(currentobject).filename=openDialog("Open Model File","3DS (*.3ds)|*.3ds|All Files (*.*)|*.*")
if LEN(obstacles(currentobject).filename) > 2
load object obstacles(currentobject).filename, currentobject
`checked=getChecked(handle gadget)
if getChecked(UL) then position object currentobject, xbounds/4, ybounds-ybounds/4, spacing*spacers
if getChecked(UC) then position object currentobject, xbounds/2, ybounds-ybounds/4, spacing*spacers
if getChecked(UR) then position object currentobject, xbounds-xbounds/4, ybounds-ybounds/4, spacing*spacers
if getChecked(LC) then position object currentobject, xbounds/4, ybounds/2, spacing*spacers
if getChecked(CC) then position object currentobject, xbounds/2, ybounds/2, spacing*spacers
if getChecked(RC) then position object currentobject, xbounds-xbounds/4, ybounds/2, spacing*spacers
if getChecked(DL) then position object currentobject, xbounds/4, ybounds/4, spacing*spacers
if getChecked(DC) then position object currentobject, xbounds/2, ybounds/4, spacing*spacers
if getChecked(DR) then position object currentobject, xbounds-xbounds/4, ybounds/4, spacing*spacers
obstacles(currentobject).xsize = object size x( currentobject)
obstacles(currentobject).ysize = object size y( currentobject)
obstacles(currentobject).zsize = object size z( currentobject)
maxobjects= maxobjects + 1
selectedobject= currentobject
obstacles(currentobject).objectnum = currentobject
currentobject = currentobject + 1
obstacles(selectedobject).xsize = 20
obstacles(selectedobject).ysize = 20
obstacles(selectedobject).zsize = 20
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
`end the LEN test for filename
endfunction
function doSelectedInput()
`show what's selected
Circle Object Screen X(selectedobject), object screen y( selectedobject), 10
if inkey$() = "w" then position object selectedobject, object position X(selectedobject), object position y(selectedobject) + 5, object position z ( selectedobject)
if inkey$() = "a" then position object selectedobject, object position X(selectedobject) - 5, object position y(selectedobject) , object position z ( selectedobject)
if inkey$() = "s" then position object selectedobject, object position X(selectedobject) , object position y(selectedobject) - 5 , object position z ( selectedobject)
if inkey$() = "d" then position object selectedobject, object position X(selectedobject) + 5, object position y(selectedobject) , object position z ( selectedobject)
`these are for saving the position later in the file
obstacles(selectedobject).xpos = object position x(selectedobject)
obstacles(selectedobject).ypos = object position y(selectedobject)
obstacles(selectedobject).zpos = object position z(selectedobject)
`scaling
if inkey$() = "8"
`obstacles(selectedobject).xsize = obstacles(selectedobject).xsize+5
obstacles(selectedobject).ysize = obstacles(selectedobject).ysize+5
`obstacles(selectedobject).zsize = obstacles(selectedobject).zsize+5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "2"
`obstacles(selectedobject).xsize = obstacles(selectedobject).xsize-5
obstacles(selectedobject).ysize = obstacles(selectedobject).ysize-5
`obstacles(selectedobject).zsize = obstacles(selectedobject).zsize-5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "4"
obstacles(selectedobject).xsize = obstacles(selectedobject).xsize-5
`obstacles(selectedobject).ysize = obstacles(selectedobject).ysize-5
`obstacles(selectedobject).zsize = obstacles(selectedobject).zsize-5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "6"
obstacles(selectedobject).xsize = obstacles(selectedobject).xsize+5
` obstacles(selectedobject).ysize = obstacles(selectedobject).ysize-5
`obstacles(selectedobject).zsize = obstacles(selectedobject).zsize-5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "3"
`obstacles(selectedobject).xsize = obstacles(selectedobject).xsize-5
`obstacles(selectedobject).ysize = obstacles(selectedobject).ysize-5
obstacles(selectedobject).zsize = obstacles(selectedobject).zsize+5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "7"
`obstacles(selectedobject).xsize = obstacles(selectedobject).xsize-5
`obstacles(selectedobject).ysize = obstacles(selectedobject).ysize-5
obstacles(selectedobject).zsize = obstacles(selectedobject).zsize-5
scale object selectedobject, obstacles(selectedobject).xsize, obstacles(selectedobject).ysize, obstacles(selectedobject).zsize
endif
if inkey$() = "l"
obstacles(selectedobject).yrot = obstacles(selectedobject).yrot - 2
yrotate object selectedobject, obstacles(selectedobject).yrot
endif
if inkey$() = "k"
obstacles(selectedobject).yrot = obstacles(selectedobject).yrot + 2
yrotate object selectedobject, obstacles(selectedobject).yrot
endif
if inkey$() = "o"
obstacles(selectedobject).xrot = obstacles(selectedobject).xrot + 2
xrotate object selectedobject, obstacles(selectedobject).xrot
endif
if inkey$() = "p"
obstacles(selectedobject).xrot = obstacles(selectedobject).xrot - 2
xrotate object selectedobject, obstacles(selectedobject).xrot
endif
endfunction
function savefunc()
`file=openDialog("Open Text File","Text Files (*.txt)|*.txt|All Files (*.*)|*.*")
savefile$=openDialog("Save Map","Map File (*.rac)|*.rac|All Files (*.*)|*.*")
if file exist( savefile$)
delete file savefile$
endif
if len(savefile$) > 3
if maxobjects>0
` prevent from writing a map if nothing's there
for index = 1000 to maxobjects+999
open to write 1, savefile$
write string 1, obstacles(index).filename
write float 1, obstacles(selectedobject).deleted
`if an object is deleted, which should save on bugs but add to memory needed, it won't be shown or used during the race at all
write float 1, obstacles(index).xpos
write float 1, obstacles(index).ypos
write float 1, obstacles(index).zpos
write float 1, obstacles(index).xsize
write float 1, obstacles(index).ysize
write float 1, obstacles(index).zsize
write float 1, obstacles(index).xrot
write float 1, obstacles(index).yrot
write float 1, obstacles(index).zrot
next index
endif
`end the maxobjects if
close file 1
endif
remstart MAP OBJECT TYPE REFERENCE
type mapobject
xpos as float
ypos as float
zpos as float
`the next set is for freeform moving
oldxpos as float
oldypos as float
oldzpos as float
xrot as float
yrot as float
zrot as float
oldrot as float
oldyrot as float
oldzrot as float
`for scaling
xsize as float
ysize as float
zsize as float
filename as string
aitype as integer
`ai type lets the computer know how to handle movement
objectnum as integer
endtype
remend
endfunction
I am releasing this as free and open-source to help any newbie, also if you wish to convert it to a free WinGUI version and add some stuff, go ahead. This is probably a good example for a newbie, (of how not to code) but a very basic map editor/object placement editor to study.
Note: The load map code is practically the same as save map code, and would be a good thing to code and test out if you're new.
Not all of my planned code and variables are used, like that menu near the top.
That's about it. It's not a WIP, more like a Finished Mess In Progress.... lol.
Promised to release it by tuesday, sorry
LLRGT omglol