library CommandLineChat
globals
// These will be used with GetLocalPlayer
private boolean array cDisabled
private boolean array cSilenced
private boolean array cAutoTime
private integer array cDefaultTicks
private integer array cTicks
private player array cSender
private string array cPrefixTag
private string array cChatEntry
private string array cSuffixTag
private string array cChatLabel
private string array cChatFinal
private string array cChatClose
endglobals
///////////////////////////////////////////////////////////////////////////////////////////////
private function CLC_SendBlank takes player p returns nothing
local integer i = GetPlayerId( p )
if GetLocalPlayer() == p then
call BlzDisplayChatMessage( p, 0, cChatLabel[i] + cChatFinal[i] + cChatClose[i] )
endif
endfunction
private function CLC_SendString takes player sender, player p, string s returns nothing
local integer i = GetPlayerId( p )
if GetLocalPlayer() == p then
call BlzDisplayChatMessage( sender, 2, cChatLabel[i] + cChatFinal[i] + cChatClose[i] )
endif
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
function CLC_RefreshPlayerChat takes integer p returns nothing
local string s
if cDisabled[p] == true then
call CLC_SendBlank( Player( p ) )
else
set s = cChatLabel[p] + cChatFinal[p] + cChatClose[p]
call CLC_SendString( cSender[p], Player( p ), s )
endif
endfunction
function CLC_ClearPlayerChat takes integer p returns nothing
set cChatFinal[p] = ""
call CLC_RefreshPlayerChat( p )
endfunction
function CLC_RefreshAllChat takes nothing returns nothing
local integer i = 0
loop
call CLC_RefreshPlayerChat( i )
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
private function CLC_Tick takes nothing returns nothing
local integer i = 0
loop
set cTicks[i] = cTicks[i] - 1
if cTicks[i] <= 0 then
set cTicks[i] = 0
set cChatFinal[i] = ""
endif
call CLC_RefreshPlayerChat( i )
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
function CLC_PostString takes integer sender, integer target, string s returns nothing
if cAutoTime[target] == true then
set cTicks[target] = StringLength( s ) * 3 + 141
else
set cTicks[target] = cDefaultTicks[target]
endif
set cSender[target] = Player( sender )
set cChatEntry[target] = s
set cChatFinal[target] = cPrefixTag[target] + s + cSuffixTag[target]
call CLC_RefreshPlayerChat( target )
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
private function CLC_TagChat takes nothing returns nothing
local integer p = GetPlayerId( GetTriggerPlayer() )
local string s = GetEventPlayerChatString()
if cSilenced[p] == false then
call CLC_PostString( p, p, s )
else
set cChatEntry[p] = GetEventPlayerChatString()
endif
endfunction
function CLC_ResetPlayerChat takes integer p returns nothing
call CLC_PostString( p, p, "" )
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
function CLC_SetPlayerLabel takes integer p, string s returns nothing
set cChatLabel[p] = s
endfunction
function CLC_AddPlayerLabelLb takes integer p returns nothing
set cChatLabel[p] = cChatLabel[p] + "\n"
endfunction
function CLC_SetPlayerPrefixTag takes integer p, string s returns nothing
set cPrefixTag[p] = s
set cChatFinal[p] = cPrefixTag[p] + s + cSuffixTag[p]
endfunction
function CLC_SetPlayerSuffixTag takes integer p, string s returns nothing
set cSuffixTag[p] = s
set cChatFinal[p] = cPrefixTag[p] + s + cSuffixTag[p]
endfunction
function CLC_SetPlayerClose takes integer p, string s returns nothing
set cChatClose[p] = s
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
function CLC_DisablePlayer takes integer p, boolean b returns nothing
set cDisabled[p] = b
call CLC_RefreshAllChat()
endfunction
function CLC_SilencePlayer takes integer p, boolean b returns nothing
set cSilenced[p] = b
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
function CLC_EnablePlayerAutoTime takes integer p, boolean b returns nothing
set cAutoTime[p] = b
endfunction
function CLC_SetPlayerDefaultTicks takes integer p, integer t returns nothing
set cDefaultTicks[p] = t
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
// The top-left corner of screen is coordinate ( 0.00, 0.00 )
// The bottom-right corner of screen is coordinate ( 0.80, 0.60 )
// Only monitors with resolution wider than 8:6 will see the chat
// if xcoor < 0.00 or xcoor > 0.80
///////////////////////////////////////////////////////////////////////////////////////////
// player width is self explanatory.
//
// x and y represent the position of the window with the top-left corner
// of the single chat field being x and y and the top-left corner of the
// the minimum x and y.
// This uses the frame coordinate system where 0.0 x is left of standard
// resolution, for compatibility, stay within an x value of (0.00-0.80).
///////////////////////////////////////////////////////////////////////////////////////////
// To be fully visible:
// ( 0 <= |w| + |x| <= 0.800000000 ) \
// ( 0 <= |x| <= 0.800000000 ) ---> These values should not be more accurate
// ( 0 <= |y| <= 0.587625000 ) / than 9 decimal places or a crash may occur.
//
// If y = 0.6 it is off-screen, the exact buffer I have not tested
// the single chat line works better with a buffer below it anyway
// because a string that's more than one line will need some space.
///////////////////////////////////////////////////////////////////////////////////////////
// A width of < 0.005 will display "........" with each dot having its own line
// (this will include the text "> Player 1:" in the message).
//
// A width of 0 will be infinite width (one line that shows the whole entered text.
///////////////////////////////////////////////////////////////////////////////////////////
// x of 1.0 should safely be off screen and not visible
// ( 0.0 <= x <= 2.0 has been tested and is safe )
// x of 2.0 has proven safe to use in my testing
//
// y of 0.6 will be below the screen and not visible
// ( 0.0 <= y <= 0.6 has been tested and is safe )
//
// As long as none of these values are negative the game will not crash, so as a protective measure:
///////////////////////////////////////////////////////////////////////////////////////////
function CLC_SetPlayerChatWindow takes player p, real w, real x, real y returns nothing
if w < 0 then
set w = -w
endif
if x < 0 then
set x = -x
endif
if y < 0 then
set y = -y
endif
if GetLocalPlayer() == p then
call BlzFrameClearAllPoints( BlzGetOriginFrame( ORIGIN_FRAME_CHAT_MSG, 0 ) )
call BlzFrameSetAbsPoint( BlzGetOriginFrame( ORIGIN_FRAME_CHAT_MSG, 0 ), FRAMEPOINT_BOTTOMLEFT, 0.0 + x, 0.587000039 - y )
call BlzFrameSetAbsPoint( BlzGetOriginFrame( ORIGIN_FRAME_CHAT_MSG, 0 ), FRAMEPOINT_TOPRIGHT, 0.0 + x + w, 0.600000000 - y )
endif
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
// Can you tell I hate retyping events?
// Also makes sure that this will work
// whether the max players is 12 or 24.
//////////////////////////////////////////////////////////////////////
function TriggerRegisterGenericPlayerEvent takes trigger t, playerevent e returns nothing
local integer i = 0
loop
call TriggerRegisterPlayerEvent( t, Player( i ), e )
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
endfunction
function TriggerRegisterGenericChatEvent takes trigger t, string s, boolean b returns nothing
local integer i = 0
loop
call TriggerRegisterPlayerChatEvent( t, Player( i ), s, b )
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
endfunction
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////
// Fire away and forget, w is width; ( x, y ) are coordinates. All
// of them use Frame coordinate ranges ( 0.0, 0.0 ) to ( 0.8, 0.6 )
//
// chatLabel, chatPrefix, chatSuffix, and chatClose are not counted
// for the string length with auto timed messages.
//
// chatLabel and chatClose will persist when the message is blank
// chatPrefix and chat Suffix will disappear with the message.
//////////////////////////////////////////////////////////////////////
function CLC_Init takes real w, real x, real y, boolean autoTime, string chatLabel, string chatPrefix, string chatSuffix, string chatClose returns nothing
local integer i = 0
local timer T = CreateTimer( )
local trigger t = CreateTrigger( )
call TriggerRegisterGenericPlayerEvent( t, ConvertPlayerEvent( 16 ) )
call TriggerAddAction( t, function CLC_RefreshAllChat )
set t = CreateTrigger( )
call TriggerRegisterGenericChatEvent( t, "", true )
call TriggerAddAction( t, function CLC_TagChat )
call TimerStart( T, .02, true, function CLC_Tick )
loop
set cDisabled[i] = false
set cSilenced[i] = false
set cAutoTime[i] = autoTime
set cDefaultTicks[i] = 20
set cTicks[i] = 0
set cAutoTime[i] = autoTime
set cChatLabel[i] = chatLabel
set cPrefixTag[i] = chatPrefix
set cSuffixTag[i] = chatSuffix
set cChatClose[i] = chatClose
set cSender[i] = Player( i )
call CLC_SetPlayerChatWindow( Player ( i ), w, x, y )
set i = i + 1
exitwhen i == bj_MAX_PLAYERS
endloop
call CLC_Tick()
endfunction
endlibrary