alright,
heres the whole code:
Global CursorX, CursorY, CursorHit, ID_Number=1
;-----------------------------------------------------------------------------------------------------
; ScanCode Type
;-----------------------------------------------------------------------------------------------------
Type TKeyDown
Field s.ScanCode
End Type
;type to hold scancodes
Type ScanCode
Field code
Field key$
Field upkey$
Field isdown
End Type
Type DropDown
Field drawdrop
Field scrolly
Field shown
Field x,y
Field words$
Field Accepts
Field DropDown_ID
End Type
;-----------------------------------------------------------------------------------------------------
; InitGetKey()
;-----------------------------------------------------------------------------------------------------
;reads all scancodes into ScanCode type
Function InitGetKey()
;read scancodes
tel = 1
Restore scancodez
Repeat
Read scanc
If scanc = -1 Then Exit
s.ScanCode = New ScanCode
s\code = scanc
s\key$ = Lower$(Mid$("1234567890-=QWERTYUIOP[]ASDFGHJKL;'\ZXCVBNM,./* 789-456+1230.,/" + Chr$(8) + Chr$(13) + Chr$(13), tel, 1))
s\upkey$ = Mid$("!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:" + Chr$(34) + "|ZXCVBNM<>?* 789-456+1230.,/" + Chr$(8) + Chr$(13) + Chr$(13), tel, 1)
tel = tel + 1
Forever
End Function
Global oldkdown
;-----------------------------------------------------------------------------------------------------
; iGetKey()
;-----------------------------------------------------------------------------------------------------
;imitates GetKey() using scancodes
Function iGetKey()
;read scancodes
For s.ScanCode = Each ScanCode
down = KeyDown(s\code)
If down And (Not s\isdown) Then
tk.TKeyDown = New TKeyDown
tk\s = s
End If
s\isdown = down
Next
tk.TKeyDown = First TKeyDown
If tk = Null Then Return
sel.ScanCode = tk\s
If sel = Null Then Return
oldkdown = sel\code
Delete tk
;shift for uppercase
If KeyDown(42) Or KeyDown(54) Then
sc$ = sel\upkey$
Else
sc$ = sel\key$
End If
;return ascii value of key
Return Asc(sc$)
End Function
;"1234567890-=QWERTYUIOP[]ASDFGHJKL;'\ZXCVBNM,./* 789-456+7890.,/" (no shift)
;"!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:"|ZXCVBNM<>?* 789-456+7890.,/" (shift)
.scancodez
Data 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
Data 12, 13, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Data 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38
Data 39, 40, 43, 44, 45, 46, 47, 48, 49, 50, 51
Data 52, 53, 55, 57, 71, 72, 73, 74, 75, 76, 77
Data 78, 79, 80, 81, 82, 83, 179, 181
Data 14, 28, 156
Data -1
;-------------------------------------------------------------------------------------------------------
; CreateInputBox()
;-------------------------------------------------------------------------------------------------------
Function CreateInputBox$(box_x,box_y,box_w,useable,returnstr$,letters)
Rect box_x, box_y, box_w,20, False
If useable=True
key=iGetKey()
If MilliSecs() > blinky+500
Rect box_x+3+Len(returnstr$)*9,box_y+2,1,17,1
End If
If MilliSecs() > blinky+1000 blinky=MilliSecs()
If letters=True
If (key=>48 And key=<57) Or (key>=65 And key<=90) Or (key>=97 And key<=122)
If(Len(returnstr$)<box_w/10)
returnstr$ = returnstr$ + Chr(key)
End If
End If
End If
If letters=False
If (key=>48 And key=<57)
If(Len(returnstr$)<box_w/10)
returnstr$ = returnstr$ + Chr(key)
End If
End If
End If
End If
If useable=True
If KeyHit(14)
If Len(returnstr$)>0 returnstr$=Left(returnstr$,Len(returnstr$)-1)
End If
If KeyHit(57)
returnstr$=returnstr$+" "
End If
End If
Text box_x+3,box_y, returnstr$
Return(returnstr$)
End Function
;-------------------------------------------------------------------
; lvlCreateInputBox
;-------------------------------------------------------------------
Function lvlCreateInputBox$(box_x,box_y,box_w,useable,returnstr$,startnum,lastnum)
Rect box_x, box_y, box_w,20, False
If useable=True
key=iGetKey()
If MilliSecs() > blinky+500
Rect box_x+3+Len(returnstr$)*9,box_y+2,1,17,1
End If
If MilliSecs() > blinky+1000 blinky=MilliSecs()
End If
If (key=>startnum And key=<lastnum)
If (Len(returnstr$)<1)
returnstr$ = returnstr$ + Chr(key)
End If
End If
If useable=True
If KeyHit(14)
If Len(returnstr$)>0 returnstr$=Left(returnstr$,Len(returnstr$)-1)
End If
If KeyHit(57)
returnstr$=returnstr$+" "
End If
End If
Text box_x+3,box_y, returnstr$
Return(returnstr$)
End Function
;Function InitDropDown()
;drawdrop=False
;scrolly=70
;shown=50
;End Function
;-----------------------------------------------------------------
; CreateDropDown()
;-----------------------------------------------------------------
Function CreateDropDown(x,y,Accepted)
NewDD.DropDown = New DropDown
NewDD\x=x
NewDD\y=y
NewDD\drawdrop=False
NewDD\scrolly=y+20
NewDD\shown=y
NewDD\DropDown_ID=ID_Number
NewDD\Accepts=Accepted
ID_Number=ID_Number+1
End Function
;----------------------------------------------------------------
; DrawDropDowns()
;----------------------------------------------------------------
Function DrawDropDowns(Creation_Info.DropDown)
drawdrop = Creation_Info\drawdrop
scrolly = Creation_Info\scrolly
shown = Creation_Info\shown
x = Creation_Info\x
y = Creation_Info\y
words$ = Creation_Info\words$
number = Creation_Info\Accepts
;If you click on the button, dropdown=True
If RectsOverlap(x+100,y,25,20,CursorX,CursorY,5,5) And CursorHit
If drawdrop=False
drawdrop=True
Else
drawdrop=False
End If
End If
If drawdrop=True
Rect x,y,125,200,0
;For...Each ... should get the name of all the objects.
i=0
For checklist.list = Each list
If checklist\ID=number
i=i+1
;Made this For i...2 loop so the Text can loop itself...
Viewport x,y+20,125,180
Text x,shown+(i*20),checklist\name
Viewport 0,0,GraphicsWidth(),GraphicsHeight()
;If you click on one of the names it will put it up top.
If RectsOverlap(x,shown+(i*20),100,20,CursorX,CursorY,5,5) And CursorX > x And CursorX< x+125 And CursorY > y+20 And CursorY < y+200 And MouseDown(1)
words$=checklist\name
drawdrop=False
shown=y
scrolly=y+20
End If
End If
Next
Rect x+100,y+20,25,180,False
If i>9
Rect x+100,scrolly,25,20,True
If RectsOverlap(x+100,y+20,25,180,CursorX,CursorY,5,5) And MouseDown(1)
scrolly=MouseY()
End If
If scrolly<y+20 scrolly=y+20
If scrolly>y+180 scrolly=y+180
;The more things in the Text the faster it scrolls To compensate..
ScrollbarPos = ScrollY - y-20
ScrollbarMax = y+180- y-20
ListSize = (i - 9) * 20
shown = y - (scrollbarpos * listsize / scrollbarmax)
End If
End If
;Draws the 3 main parts of the dropdown, with all the math from above: Main box, DD button,
Rect x,y,125,20,0
Rect x+100,y,25,20,0
Text x,y,words
;Takes the Creation info and Equals it to the messed with dropdown info.
Creation_Info\scrolly = scrolly
Creation_Info\drawdrop = drawdrop
Creation_Info\shown = shown
Creation_Info\words$ = words$
End Function
;-------------------------------------------------------------------------
; DeleteDropDown(DropDown_ID)
;-------------------------------------------------------------------------
Function DeleteDropDown(ID)
For FindDD.DropDown = Each DropDown
If FindDD\DropDown_ID=ID Delete FindDD
Next
End Function
;Sets the apptitle.
AppTitle "Fitting Calculator","Exit Fitting calculator?"
;Includes my function libary
;Sets the graphics modes
Graphics 500,400,16,2
SetBuffer BackBuffer()
Type ship
Field powergrid
Field cpu
Field name$
Field h,m,l
End Type
Type list
Field name$
Field ID
End Type
testship.ship = New ship
testship\powergrid=750
testship\cpu=400
testship\name="Test"
test3.list = New list
test3\name="Test"
test3\ID=1
test1.list = New list
test1\name="Test2"
test1\ID=1
test.list = New list
test\name="Test"
test\ID=2
test2.list =New list
test2\name="Test2"
test2\ID=3
Global doOnce=0
;Current PG/CPU
C_POWER=0
C_CPU=0
;Added CPU/PG to add with Current CPU/PG
ADD_CPU$=""
ADD_POWER$=""
NO_OFMODS$=""
SLOTOFMOD$=""
F_HS=0
F_MS=0
F_LS=0
C_SLOT=0
C_SLOT2=0
;Sets the current textbox veriable this keeps track of the current textbox in use
c_textbox=1
c_textbox2=1
;menus True/False Veriables For the textboxs To work
TF1=False
TF2=False
TF3=False
TF4=False
TF5=False
TF6=False
TF7=False
;Special function that makes the special iGetKey() function work
InitGetKey()
;Sets the timer veriable
Global blinky=MilliSecs()
;Answer=1 so the first loop can start
answer=1
;The picked ship string
PickedShip$=""
Engineering$=""
Electronics$=""
;Creates the DropDowns
CreateDropDown(10,120,1) ;ID=1
CreateDropDown(350,120,2) ;ID=2
.start
;-------------------------------------------------------------------------------
;- Startup loop
;-------------------------------------------------------------------------------
While answer=1
Cls
CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)
;If you click on a text box make it the active one
If RectsOverlap(0,0,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=1
End If
If RectsOverlap(0,30,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=2
End If
If RectsOverlap(0,60,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
c_textbox2=3
End If
;Looks at the c_textbox2 ver. and turns the textboxs on/off
Select c_textbox2
Case 1
TF5=True
TF4=False
TF6=False
Case 2
TF4=True
TF5=False
TF6=False
Case 3
TF6=True
TF4=False
TF5=False
End Select
;Makes the first letter in the ship input always uppercase
If Pickedship=Lower(Left(PickedShip,1)) Pickedship=Upper(Left(PickedShip,1))
;Creates a input boxs
PickedShip=CreateInputBox$(0,0,100,TF5,PickedShip,True)
Engineering=lvlCreateInputBox$(0,30,100,TF4,Engineering$,49,53)
Electronics=lvlCreateInputBox$(0,60,100,TF6,Electronics$,49,53)
Text 100,0,":What ship are you in? Full name."
Text 100,30,":Whats your Engineering at?"
Text 100,60,":Whats your Electronics at?"
;Turns a string into a interger
F_Engineering%=Engineering$
F_Electronics%=Electronics$
;Percentage maths depending on what you typed in
Select F_Engineering
Case 1
Engineering_percentage#=1.05
Case 2
Engineering_percentage#=1.1
Case 3
Engineering_percentage#=1.15
Case 4
Engineering_percentage#=1.2
Case 5
Engineering_percentage#=1.25
End Select
;Percentage maths depending on what you typed in
Select F_Electronics
Case 1
Electronics_percentage#=1.05
Case 2
Electronics_percentage#=1.1
Case 3
Electronics_percentage#=1.15
Case 4
Electronics_percentage#=1.2
Case 5
Electronics_percentage#=1.25
End Select
;Creates the "NEXT" button
Rect 200,350,60,25,True
Color 0,0,0
Text 210,354,"Next"
Color 255,255,255
;If ESC is pressed end the program
If KeyHit(1)
End
End If
;if you didnt type anything in, add nothing
If F_Engineering=0 Then Engineering_percentage=1.0
If F_Electronics=0 Then Electronics_percentage=1.0
;did you find anything?
found=0
;Does what you typed in match up with anything in the database?
For shipname.ship=Each ship
If shipname\name=PickedShip$
shipCPU$=shipname\cpu*Electronics_percentage
shippower$=shipname\powergrid*Engineering_percentage
HS=shipname\h
MS=shipname\m
LS=shipname\l
found=1
End If
Next
;Turns a string into a int.
ship_CPU%=shipCPU$
ship_power%=shippower$
;Yay it matchs up continue with the program
If found=1
If RectsOverlap(200,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1) Or KeyHit(28)
answer=2
End If
End If
;Boo you didnt type it in right print a error and try again!
If found=0
If RectsOverlap(200,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1) Or KeyHit(28)
PickedShip$=""
Text 40,130,"This ship is not in the database"
End If
End If
;Delay flip wend..
Delay 5
Flip
Wend
;---------------------------------------------------------------------------------------
;- MAIN LOOP -
;---------------------------------------------------------------------------------------
While Not KeyHit(1)
Cls
CursorX = MouseX()
CursorY = MouseY()
CursorHit = MouseHit(1)
;colors PG depending on if its over PG or not
If C_POWER>ship_power
Color 255,0,0
Else
Color 0,255,0
End If
Text 0,0,"PG: ("+C_POWER+"/"+ship_power+")"
;Same as above but for CPU
If C_CPU>ship_CPU
Color 255,0,0
Else
Color 0,255,0
End If
Text 0,15,"CPU: ("+C_CPU+"/"+ship_CPU+")"
;Sets color to white
Color 255,255,255
;Draws the Add module text at the top
; Text 180,80,"Add module:"
;Draws the Power of mod Textbox
;Text 0,120,"Power of mod:"
;Draws the CPU of mod textbox
;
;Draws the number of mods textbox
;Text 0,180,"How many of these?:"
;Draws the slot text
;Text 0,210,"What slot? (1-3):"
;Text 0,230,"H=1, M=2, L=3"
;Draws the Update button
Rect 300,350,60,25,True
Color 0,0,0
Text 302,354,"Update"
Color 255,255,255
;Draws the Clear button
Rect 220,350,60,25,True
Color 0,0,0
Text 224,354,"Clear"
Color 255,255,255
Rect 135,350,60,25,True
Color 0,0,0
Text 146,355,"New"
Color 255,255,255
;Creates 4 input boxs, with their own veriables to feed the info to
;ADD_POWER$=CreateInputBox$(180,120,100,TF1,ADD_POWER$,False)
;ADD_CPU$=CreateInputBox$(180,150,100,TF2,ADD_CPU$,False)
;NO_OFMODS$=CreateInputBox$(180,180,100,TF3,NO_OFMODS$,False)
;SLOTOFMOD$=lvlCreateInputBox$(180,210,100,TF7,SLOTOFMOD$,49,51)
;If you click on another text box change the selection
;If RectsOverlap(180,120,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
; c_textbox=1
;End If
;If RectsOverlap(180,150,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
; c_textbox=2
;End If
;If RectsOverlap(180,180,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
; c_textbox=3
;End If
;If RectsOverlap(180,210,100,20,MouseX(),MouseY(),10,10) And MouseDown(1)
; c_textbox=4
;End If
;If the Currect Textbox changes ... Change the current active textbox
;Select c_textbox
;Case 1
;TF1=True
;TF2=False
;TF3=False
;TF7=False
;Case 2
;TF2=True
;TF1=False
;TF3=False
;TF7=False
;Case 3
;TF3=True
;TF2=False
;TF1=False
;TF7=False
;Case 4
;TF7=True
;TF3=False
;TF1=False
;TF2=False
;End Select
;Few maths to translate a String into a pure number easyer to do math with this new number
;F_POWER%=ADD_POWER
;F_CPU%=ADD_CPU
;F_MODS%=NO_OFMODS
;if you type in somthing it turns into its slot
;If SLOTOFMOD="1" C_SLOT=F_HS C_SLOT2=HS
;If SLOTOFMOD="2" C_SLOT=F_MS C_SLOT2=MS
;If SLOTOFMOD="3" C_SLOT=F_LS C_SLOT2=LS
;If C_SLOT<C_SLOT2
;Makes the "Clear" and "Update" buttons work
If RectsOverlap(300,350,60,25,MouseX(),MouseY(),10,10) And MouseHit(1) Or KeyHit(28)
;If F_MODS=0 F_MODS=1
;If SLOTOFMOD="1" F_HS=F_HS+F_MODS
;If SLOTOFMOD="2" F_MS=F_MS+F_MODS
;If SLOTOFMOD="3" F_LS=F_LS+F_MODS
; C_POWER=C_POWER+F_POWER*F_MODS
; C_CPU=C_CPU+F_CPU*F_MODS
; NO_OFMODS=""
;ADD_CPU=""
;ADD_POWER=""
;End If
End If
If RectsOverlap(220,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1)
; C_CPU=0
; ; C_POWER=0
; NO_OFMODS=""
; ADD_CPU=""
; ADD_POWER=""
End If
If RectsOverlap(135,350,60,25,MouseX(),MouseY(),10,10) And MouseDown(1)
answer=1
Goto start
End If
Catagory=0
For CheckDD.DropDown = Each DropDown
If CheckDD\DropDown_ID=1 And CheckDD\words="HybridTurrs" Catagory=1
If CheckDD\DropDown_ID=1 And CheckDD\words="EnergyTurrs" Catagory=2
Next
;If Catagory <> Catagory doOnce=0
;If doOnce=0
Select Catagory
Case 1
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,2)
Case 2
DeleteDropDown(2)
DeleteDropDown(3)
CreateDropDown(350,120,3)
End Select
;doOnce=1
;End If
For DrawDrops.DropDown = Each DropDown
DrawDropDowns(DrawDrops.DropDown)
Next
;Draws the Highs the mediums and the lows, and draws them filled if they have somthing in em
For i=1 To HS
Oval 280+(i*18),0,15,15,False
Next
For i=1 To MS
Oval 280+(i*18),20,15,15,False
Next
For i=1 To LS
Oval 280+(i*18),40,15,15,False
Next
If F_HS>HS F_HS=HS
If F_MS>MS F_MS=MS
If F_LS>LS F_LS=LS
For i=1 To F_HS
Oval 280+(i*18),0,15,15,True
Next
For i=1 To F_MS
Oval 280+(i*18),20,15,15,True
Next
For i=1 To F_LS
Oval 280+(i*18),40,15,15,True
Next
Text 220,0,"Highs:"
Text 220,20,"Mediums:"
Text 220,40,"Lows:"
;Delay to use less CPU on computer, flips the buffer and if the main loop ends, terminate the process
Delay 5
Flip
Wend
End
When it prompts you for what "ship" your in type in "test" then click next, you'll see the dropdowns :D
sorry bout the messy code, didnt have time to coment it or make it look pretty