Here is the Full Mod.
Module Pub.Console
ModuleInfo "Name: A Console Module for BMAX"
ModuleInfo "License : None(Credits would be nice)"
ModuleInfo "Copyright 2005 Benjamin 'Klepto2' Rössig"
ModuleInfo "Simple Console like in some Shooters or similar"
ModuleInfo "Version: 0.5"
Import BRL.GLMax2d
Import BRL.Max2D
Import BRL.Keycodes
Import BRL.Retro
Import BRL.LinkedList
Import BRL.Font
Import BRL.Basic
Global CText_List:Tlist
Global CSysItem_List:TList
Type CConsole
Field length:Int
Field height:Int
Field index:Int = 0
Field Alpha:Float
Field Status:Int
Field tc:Int
Field temp_Text:String
Field Return_Text:String = ""
Field Show_FPS:Byte = True
Field Dep_FPS:Byte = True
Field fc,ms,mn,fr
Field MAX_Chars:int
Field c_timer1:Int = 0
Field c_timer2:int = 0
Field c_ms:Int
Field c_pos:int = 0
Field list_index:int = 0
Field c_blink:Int = 500
Field Show_Statusbar:Byte = False
Field Dep_Statusbar:Byte = False
Field C_Length:Int = 200
Field tcr,tcb,tcg : int
Field bcr,bcb,bcg : Int
Field fcr,fcb,fcg : Int
Field frame:Byte
Field border:Int
Field BackImage:Timage
Function Create:CConsole(_length:Int,_height:int,_alpha:Float,_max_chars:Int,_Frame:Byte = True,_border:Int = 5,_Img:String = "")
local c:CConsole = New CConsole
c.length = _length
c.height = _height
c.Alpha = _Alpha
c.MAX_Chars = _max_chars
c.Frame = _Frame
if c.frame = True then
c.border = _border
else
c.border = 0
end if
c.tcr = 255
c.tcb = 255
c.tcg = 255
c.bcr = 25
c.bcb = 25
c.bcg = 25
c.fcr = c.tcr
c.fcb = c.tcb
c.fcg = c.tcg
' SetImageFont(Null)
Debuglog "" + _Img
Debuglog Appdir$
If filetype(_Img) = 1 then ' I have changed this part to control if the Imagepath is right
Debuglog "Loading Image"
c.BackImage = LoadImage(_Img)
endif
Return c
End Function
Method Update()
if status = 1 then
if Background = Null then
SetBlend Alphablend
SetAlpha alpha
if BackImage <> Null then
'DEbuglog "Drawing Backimage"
SetColor 255,255,255
Setscale width/ImageWidth(BackImage),height/Imageheight(Backimage)
DrawImage BackImage,0,0
SetScale 1,1
else
'DEbuglog "Backimage = Null"
SetColor bcr,bcb,bcg
Drawrect(0,0,length,height)
endif
SetColor tcr,tcb,tcg
Drawline border,height-(25+border),length-border,height-(25+border),0
local t_index:Int = 0
if Ctext_List <> Null then
For t_Text:CText = eachin Ctext_list
SetColor tcr,tcb,tcg
if height - ((40+border)+(t_index*20)) > border then
Drawtext(t_Text.Text,border,height-((40+border)+(t_index*20)))
t_index = t_index + 1
endif
next
Endif
endif
tc = Getchar()
SetColor tcr,tcb,tcg
SetAlpha alpha*2
if c_pos = temp_text.Length then
if tc <> 0 and temp_text.Length < max_chars and tc <> key_backspace and not keydown(key_alt) and tc <> key_enter then
Temp_Text = Temp_text + CHR(tc)
c_pos = c_pos + 1
Endif
if tc = key_backspace then
Temp_text = left(Temp_Text,Temp_text.length - 1)
if c_pos > 0 then c_pos = c_pos - 1
Endif
else
if tc <> 0 and temp_text.Length < max_chars and tc <> key_backspace and tc <> key_enter then
t_text1:String = left(temp_text,c_pos)
t_text2:String = right(temp_text,temp_text.length-c_pos)
T_Text2 = CHR(tc) + T_Text2
Temp_text = T_text1 + T_text2
Temp_Text = left(temp_text,temp_text.length)
c_pos = c_pos + 1
Endif
if tc = key_backspace then
t_text1:String = left(temp_text,c_pos-1)
t_text2:String = right(temp_text,temp_text.length-c_pos)
Temp_text = t_text1 + t_text2
Temp_Text = left(temp_text,temp_text.length)
if c_pos > 0 then c_pos = c_pos - 1
Endif
Endif
if keyhit(key_right) then
if c_pos < temp_text.length then
c_pos = c_pos + 1
Endif
endif
if keyhit(key_left) then
if c_pos > 0 then
c_pos = c_pos - 1
Endif
endif
if keyhit(key_up) then
if Ctext_List <> Null then
if list_index <= Ctext_list.Count() then list_index = list_index + 1
if list_index > Ctext_list.Count() then List_index = 1
local n = 0
For t_Text:CText = eachin Ctext_list
temp_text = t_text.Text
n = n + 1
if n = list_index then
n = 0
exit
endif
Next
Endif
c_pos = temp_text.Length
endif
if keyhit(key_Down) then
if Ctext_List <> Null then
if list_index >= 0 then list_index = list_index - 1
if list_index < 0 then List_index = Ctext_list.Count()-1
For t_Text:CText = eachin Ctext_list
temp_text = t_text.Text
n = n + 1
if n = list_index then
n = 0
exit
endif
Next
Endif
c_pos = temp_text.Length
endif
if tc = key_Enter then
'Temp_Text = left(temp_text,temp_text.length-1)
CText.Create(Temp_Text.Trim())
Return_Text = Temp_Text
Temp_Text = ""
c_pos = 0
list_index = 0
end if
DrawText(Temp_text,border,(height-border)-20)
'Draw Cursor
if c_timer1 = 0 then c_timer1 = millisecs()
if c_ms - c_timer1 > c_blink then
DrawText "_",border+c_pos*8,(height-border)-18
if c_timer2 = 0 then c_timer2 = millisecs()
if c_ms - c_timer2 > c_blink then
c_timer1 = 0
c_timer2 = 0
endif
endif
c_ms = millisecs()
' Debuglog temp_text.length
'End Cursor
SetBlend Alphablend
SetAlpha alpha
SetColor fcr,fcb,fcg
Drawrect(0,0,border,height)
Drawrect(border,0,length-border,border)
Drawrect(length-border,border,border,height-border)
Drawrect(border,height-border,length-(2*border),border)
SetColor tcr,tcb,tcg
endif
'End Console and Start of new added Items
if fc = 0 then ms = Millisecs()
mn = Millisecs() - ms
fc = fc + 1
if mn > 1000 then
fr = fc
fc = 0
endif
SetBlend Alphablend
SetAlpha alpha
' if Dep_FPS = False and Status = 1 then
' Dep_FPS = True
' elseif Dep_FPS = True and Status = 0
' Dep_FPS = False
' end if
if Show_FPS = True And Dep_Fps = True and Show_Statusbar = False then
SetColor bcr,bcb,bcg
Drawrect(length,0,30,15)
SetColor tcr,tcb,tcg
DrawText fr,length,0
end if
if Show_FPS = True And Dep_Fps = False and Show_Statusbar = False then
SetColor bcr,bcb,bcg
Drawrect(Graphicswidth()- Textwidth(fr),0,Textwidth(fr),Textheight(fr))
SetColor tcr,tcb,tcg
DrawText fr,Graphicswidth()- Textwidth(fr),0
endif
if Dep_Statusbar = False and Status = 1 then
Dep_Statusbar = True
Show_FPS = False
elseif Dep_Statusbar = True and Status = 0
Dep_Statusbar = False
Show_FPS = False
end if
if Show_Statusbar = True And Dep_Statusbar = True then
SetColor bcr,bcb,bcg
Drawrect (length,0,C_Length,45)
SetColor tcr,tcb,tcg
DrawText "FPS : "+fr,length,0
DrawText "Memalloced : "+Memalloced(),length,15
DrawText "MemUsage : "+MemUsage(),length,30
If CsysItem_List <> Null then
SetColor bcr,bcb,bcg
Drawrect (length,45,C_Length,CsysItem_list.Count() * 15)
SetColor tcr,tcb,tcg
Drawline C_Length+length,45,length,45,0
w_i = 0
For i_Item:IText = eachin CsysItem_list
DrawText i_Item.Text+ var I_item.w_PTR,length,45 + w_i * 15
w_i:+1
next
For S_Item:SText = eachin CsysItem_list
DrawText S_Item.Text+ var S_item.w_PTR,length,45 + w_i * 15
w_i:+1
next
For F_Item:FText = eachin CsysItem_list
DrawText F_Item.Text+ var F_item.w_PTR,length,45 + w_i * 15
w_i:+1
next
For D_Item:DText = eachin CsysItem_list
DrawText D_Item.Text+ var D_item.w_PTR,length,45 + w_i * 15
w_i :+1
next
For L_Item:LText = eachin CsysItem_list
DrawText L_Item.Text+ var L_item.w_PTR,Length,45 + w_i * 15
w_i:+1
next
For B_Item:BText = eachin CsysItem_list
DrawText B_Item.Text+ var B_item.w_PTR,Length,45 + w_i * 15
w_i:+1
next
Endif
end if
if Show_Statusbar = True And Dep_Statusbar = False then
SetColor bcr,bcb,bcg
Drawrect(Graphicswidth()- C_Length,0,C_Length,45)
SetColor tcr,tcb,tcg
DrawText "FPS : "+fr,Graphicswidth()- C_Length,0
DrawText "Memalloced : "+Memalloced(),Graphicswidth()- C_Length,15
DrawText "MemUsage : "+MemUsage(),Graphicswidth()- C_Length,30
If CsysItem_List <> Null then
SetColor bcr,bcb,bcg
Drawrect (Graphicswidth()- C_Length,45,C_Length,CsysItem_list.Count() * 15)
SetColor tcr,tcb,tcg
w_i = 0
Drawline c_Length+Graphicswidth()- C_Length,45,Graphicswidth()- C_Length,45,0
For I_Item:IText = eachin CsysItem_list
DrawText I_Item.Text+ var I_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i:+1
next
For S_Item:SText = eachin CsysItem_list
DrawText S_Item.Text+ var S_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i:+1
next
For F_Item:FText = eachin CsysItem_list
DrawText F_Item.Text+ var F_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i:+1
next
For D_Item:DText = eachin CsysItem_list
DrawText D_Item.Text+ var D_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i :+1
next
For L_Item:LText = eachin CsysItem_list
DrawText L_Item.Text+ var L_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i:+1
next
For B_Item:BText = eachin CsysItem_list
DrawText B_Item.Text+ var B_item.w_PTR,Graphicswidth()- C_Length,45 + w_i * 15
w_i:+1
next
Endif
end if
End Method
Method SetStatus(st:int)
Status = st
Flushkeys()
End Method
Method Set_Statusbar(b_st:Byte)
Show_Statusbar = b_st
End Method
Method Set_Alpha(_al:Float)
Alpha = _al
End Method
Method Return_Alpha:Float()
Return Alpha
End Method
Method Return_Status:Int()
Return Status
End Method
Method Return_last:String()
Return Return_text
End Method
Method SetFPS(f_ST:Byte,d_ST:Byte = True)
dep_FPS = d_st
Show_FPS = f_ST
End Method
Method Get_FPS:Int()
Return fr
End Method
Method Send_Text(txt:String)
CText.Create(txt)
End Method
Method Set_CursorSpeed(_blink:int)
c_blink = _blink
End Method
Method Set_CFont(_C_Font:String,_smooth:Int = 0)
c_Font = LoadImageFont(_C_Font,15,_smooth)
End Method
Method Set_BackColor(_r:Int,_b:Int,_g:int)
bcr = _r
bcb = _b
bcg = _g
End Method
Method Set_TextColor(_r:Int,_b:Int,_g:int)
tcr = _r
tcb = _b
tcg = _g
End Method
Method Set_FrameColor(_r:int,_b:int,_g:int)
fcr = _r
fcb = _b
fcg = _g
End Method
Method Set_Frame(_Frame:Byte)
if _frame = True then
frame = True
border = 5
else
frame = false
border = 0
endif
end Method
Method Set_Border(_border:Int)
if frame = True and _border >= 0 then
border = _border
if _border > height/3 then
border = height/3
endif
else
border = 0
endif
End Method
Method Add_IntWatch(Name:String,_ptr:Int Ptr)
Assert name.length < 11 else "Add_IntWatch : Name to long !! " +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
I_ITEM:IText = New IText
I_ITEM.Text = Name
I_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(I_Item)
endif
End Method
Method Add_StringWatch(Name:String,_ptr:String Ptr)
Assert name.length < 11 else "Add_StringWatch : Name to long !!" +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
S_ITEM:SText = New SText
S_ITEM.Text = Name
S_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(S_Item)
endif
End Method
Method Add_FloatWatch(Name:String,_ptr:Float Ptr)
Assert name.length < 11 else "Add_FloatWatch : Name to long !!" +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
F_ITEM:FText = New FText
F_ITEM.Text = Name
F_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(F_Item)
endif
End Method
Method Add_DoubleWatch(Name:String,_ptr:Double Ptr)
Assert name.length < 11 else "Add_DoubleWatch : Name to long !!" +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
D_ITEM:DText = New DText
D_ITEM.Text = Name
D_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(D_Item)
endif
End Method
Method Add_LongWatch(Name:String,_ptr:long Ptr)
Assert name.length < 11 else "Add_LongWatch : Name to long !!" +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
L_ITEM:LText = New LText
L_ITEM.Text = Name
L_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(L_Item)
endif
End Method
Method Add_ByteWatch(Name:String,_ptr:Byte Ptr)
Assert name.length < 11 else "Add_ByteWatch : Name to long !!" +Name+" (max. 10 chars)"
If name.length < 10 then
Repeat
Name = Name + " "
until Name.Length = 10
Endif
if Name.Length <= 10 then
Name = Name + " : "
if CsysItem_List = Null then CsysItem_List = New TList
B_ITEM:BText = New BText
B_ITEM.Text = Name
B_Item.w_ptr = _ptr
if TextWidth(name + var _PTR)> C_Length then C_Length = TextWidth(name + var _PTR)
CsysItem_List.AddLast(B_Item)
endif
End Method
End Type
Type CText
Field Text:String
Function Create(_Text:String)
if CText_List = Null then CText_list = New TList
t_Text:CText = New CText
t_Text.Text = _Text
CText_List.Addfirst(t_Text)
End Function
End type
' Types for Byte Short Int Long Float Double Object String
Type IText
Field Text:String
Field w_PTR:int PTR
End Type
Type SText
Field Text:String
Field w_PTR:String PTR
End Type
Type FText
Field Text:String
Field w_PTR:Float PTR
End Type
Type DText
Field Text:String
Field w_PTR:Double PTR
End Type
Type LText
Field Text:String
Field w_PTR:Long PTR
End Type
Type BText
Field Text:String
Field w_PTR:Byte PTR
End Type
And here is the Sample where I use it:
Framework pub.console
Graphics(800,600,32,-1)
TestF:Float = 0.0
TestS:String = "This is a String"
TestD:Double = 23
TestI:Int = 2
TestL:Long = 200
TestB:Byte = 1
Rem
At first the Init of the Console itself:
Normally it is very simple
console.create(witdth,height,alpha,length of the text you could enter)
At the Start the Colorvalues for the Console are set to 25,25,25 (Background)
and 255,255,255 (Text) by default.
EndREM
c:Cconsole = Cconsole.Create(600,300,.5,20,True,25,"back.bmp")
Rem
Two simple commands :
setFPS toogles a little FPS Window on and off
setStatus toogles the console itself on and off
Note:
if the console is turned off you're available of the SetFPS command.
But then the FPS is shown in the top right corner instead of glueing
on the console position.
Note 2:
setfps has also a second optional parameter which is set to true by default
by setting this parameter to false you can make the fps display unparented
and could show it as if the console is turned off.
end Rem
c.setFPS(False)
c.setstatus(1)
Rem
Now here comes one more feature of this Console:
It is a kind of Variable Watcher.
You can add Variables to a special Window of the Console(declared later)
Currently you can add Int,Long,Float,Double,Byte and Strings to the console
by using their own Function. I'm sorry for that different Functions but I haven't
found a way to do it in one Function.(If you have a solution,please tell me)
All these Function works the same.
Add_****Watch(Name of your Variable:String, VarPtr Your Variable you want to watch)
*Name maximum chars = 10
End Rem
c.Add_DoubleWatch("TestD",varPtr TestD)
c.Add_LongWatch("TestL",varPtr TestL)
c.Add_ByteWatch("TestB",varPtr TestB)
c.Add_Floatwatch("TestF",varPtr testF)
c.Add_intwatch("TestI",varPtr TestI)
c.Add_StringWatch("TestS",varPTR TestS)
While Not KeyHit(key_escape)
Cls
SetAlpha 1.0
Global A_st:Float = c.Return_Alpha()
Global B_st:Int = 25
TestF = RND(0.0,100000.0)
If KeyHit(key_space) And KeyDown(key_alt) Then
_st = 1 - _st
c.setstatus(_st)
End If
If KeyHit(key_F) And KeyDown(key_alt) Then
F_st = 1 - f_st
c.setFPS(F_st,F_st1)
End If
If KeyHit(key_G) And KeyDown(key_alt) Then
F_st1 = 1 - f_st1
c.setFPS(F_st,F_st1)
End If
If KeyDown(key_A) And KeyDown(key_alt) Then
A_st:Float = A_St + .001
End If
If KeyDown(key_Y) And KeyDown(key_alt) Then
A_st:Float = a_st - .001
End If
If KeyDown(key_S) And KeyDown(key_alt) Then
B_st = B_St + 1
End If
If KeyDown(key_X) And KeyDown(key_alt) Then
B_st = B_st - 1
End If
Rem
With this Method you can send Text directly to the Console like debugging infos or
maybe 'Cheat enabled'
Easy to use: Send_Text(Your Text:String)
End REM
If KeyHit(KEY_1) And KeyDown(key_alt) Then
c.send_Text("This is a Text,sended to the Console")
EndIf
REm
With this methods you can simply change the blinkrate of the cursor
higher = slower
lower = faster
End REM
if keyhit(KEY_2) and keydown(key_alt) then
c.set_CursorSpeed(500)
endif
if keyhit(KEY_3) and keydown(key_alt) then
c.set_CursorSpeed(50)
endif
Rem
The Statusbar is the thing your 'Watches' are shown.It has the same Options as
the FPS command. You can only show the FPS or the Statusbar but not both the same time.
Also with no added watches, the Statusbar will show some infos.
FPS
MemAlloc
MemUsage
End REM
if keyhit(KEY_4) and keydown(key_alt) then
F_st2 = 1 - f_st2
c.set_Statusbar(F_st2)
endif
Rem
With the following Methods you can change the Colors to your behaviour.
End Rem
if keyhit(KEY_5) and keydown(key_alt) then
col_t1 = RND(0,255)
col_t2 = RND(0,255)
col_t3 = RND(0,255)
col_b1 = col_t1/10
col_b2 = col_t2/10
col_b3 = col_t3/10
c.set_Backcolor(col_b1,col_b2,col_b3)
c.set_TextColor(col_t1,col_t2,col_t3)
endif
if keyhit(KEY_6) and keydown(key_alt) then
col_t1 = RND(0,255)
col_t2 = RND(0,255)
col_t3 = RND(0,255)
c.set_Framecolor(col_t1,col_t2,col_t3)
endif
Rem
One very importend Command is the 'Return_text'.With this command
you can read out the last entered Text in your console and let your App
react on it. i.e Console Text = 'GOD Mode 1' Reaction Send to Console
'Cheat enabled' and set God = 1
End REM
DrawText("This is the Return_Text : " + c.Return_text,320,240)
Rem
Set_Alpha allows you to change the Alpha value in runtime
With Return_Alpha you can get the current Alpha
End Rem
c.set_Alpha(A_st)
c.set_border(B_st)
Rem
Last but not least the main Method of this console
Importend: It always have to be at the end of the main loop like in this case
else there will be some issues with entering Text
End REM
c.Update()
SetAlpha (1.0)
SetColor 255,255,255
DrawText("Alt + Space toggles Console on and off",0,400)
DrawText("Alt + F toggles FPS ",0,420)
DrawText("Alt + G unparent FPS",0,440)
DrawText("Alt + A increase Alpha",0,460)
DrawText("Alt + Y decrease Alpha",0,480)
DrawText("Alt + 1 sends a text to the Console",0,500)
DrawText("Alt + 2 set Cursor BlinkSpeed to 500",0,520)
DrawText("Alt + 3 set Cursor BlinkSpeed to 50",0,540)
DrawText("Alt + 4 toggles the Statusbar",0,560)
Drawtext("Alt + 5 changes the Back and Text color",0,580)
FlushMem()
Flip
Wend
All pathes seems to be right.