/////////////////////////////////////////////////////
// Letterbox Choose System //
// by: McThyzer //
// //
// v1.3 //
// //
// Give Credits if you use! //
// If you have ideas or found buggs... //
// inWc: vol-lol //
// Hive: McDoNaLdGaNgStA //
// //
/////////////////////////////////////////////////////
library LCS initializer init
globals
private boolean repeating = true //when you've selected the last option and press "down", do you want to return to the start?
private string highlighting = "|cffff9900" //the highlighting color of the selected option
private boolean autoclose = false //When the user has choosen an option the LCS-Mode is turned off?
private boolean exitwhenesc = true //Exits the LCS when pressing Escape?
private sound updownsound = CreateSound("Sound\\Interface\\MouseClick1.wav", false, false, false, 10, 10, "") //just a "click" sound :)
private sound rightsound = CreateSound("Sound\\Interface\\BigButtonClick.wav", false, false, false, 10, 10, "") //just a "click" sound :)
private real delay = 0.5 //in what time does the interface fadein/out
private hashtable HTstr = InitHashtable() //Saves the Strings and Messages for each player
private hashtable HTfun = InitHashtable() // Saves the Functions which are executed.
private hashtable HTex = InitHashtable() // For extra stuff (like "Which String is marked?")
private hashtable HTfun2 = InitHashtable() //Saves the Functions for the "left" key.
public integer LCSLastPickedOptionId = 0
endglobals
private function LCSString takes integer whichplayer returns string
local string str = ""
local integer i = 1
if LoadInteger(HTex, whichplayer, 0) > 4 then
set i = LoadInteger(HTex, whichplayer, 0) - 4
endif
loop
exitwhen i > LoadInteger(HTstr, whichplayer, 0)
if i == LoadInteger(HTex, whichplayer, 0) then
set str = str + highlighting
endif
set str = str + LoadStr(HTstr, whichplayer, i)
if i == LoadInteger(HTex, whichplayer, 0) then
set str = str + "|r"
endif
set str = str + "|n"
set i = i + 1
endloop
return str
endfunction
private function LCSOn takes nothing returns boolean
return LoadBoolean(HTex, GetPlayerId(GetTriggerPlayer()), 3)
endfunction
function LCSClear takes integer whichplayer, boolean all returns nothing
local integer i = 1
loop
exitwhen i > LoadInteger(HTstr, whichplayer, 0)
call SaveStr(HTstr, whichplayer, i, "")
call SaveStr(HTfun, whichplayer, i, "")
set i = i + 1
endloop
call SaveInteger(HTstr, whichplayer, 0, 0)
call SaveInteger(HTex, whichplayer, 0, 1)
if all == true then
call SaveUnitHandle(HTex, whichplayer, 1, null)
call SaveStr(HTex, whichplayer, 2, "")
endif
endfunction
private function LCSTextReset takes integer whichplayer returns nothing
local string str = LCSString(whichplayer)
call TransmissionFromUnitWithNameBJ( bj_FORCE_PLAYER[whichplayer], LoadUnitHandle(HTex, whichplayer, 1), LoadStr(HTex, whichplayer, 2), null, str, bj_TIMETYPE_SET, 9999, false)
loop
exitwhen LoadStr(HTfun, whichplayer, LoadInteger(HTex, whichplayer, 0)) != "lcsfake"
call SaveInteger(HTex, whichplayer, 0, LoadInteger(HTex, whichplayer, 0) + 1)
endloop
endfunction
function LCSOptionChange takes integer whichplayer, integer option, string newtext, boolean exefunc, string newfunc1, string newfunc2 returns nothing
if newtext != "" then
call SaveStr(HTstr, whichplayer, option, newtext)
endif
if exefunc == false then
call SaveStr(HTfun, whichplayer, option, null)
else
if newfunc1 != "" then
call SaveStr(HTfun, whichplayer, option, newfunc1)
endif
if newfunc2 != "" then
call SaveStr(HTfun2, whichplayer, option, newfunc2)
endif
endif
call LCSTextReset(whichplayer)
endfunction
function LCSOptionClear takes integer whichplayer, integer option returns nothing
local integer i = option
local integer amount = LoadInteger(HTstr, whichplayer, 0) - 1
loop
exitwhen i > amount
call SaveStr(HTstr, whichplayer, i, LoadStr(HTstr, whichplayer, i + 1))
call SaveStr(HTfun, whichplayer, i, LoadStr(HTfun, whichplayer, i + 1))
call SaveStr(HTfun2, whichplayer, i, LoadStr(HTfun2, whichplayer, i + 1))
set i = i + 1
endloop
call SaveInteger(HTstr, whichplayer, 0, amount)
call LCSTextReset(whichplayer)
endfunction
function LCSRem takes integer whichplayer returns nothing
call LCSClear(whichplayer, true)
if GetLocalPlayer() == Player(whichplayer) then
call ShowInterface(true, delay)
call PanCameraTo(GetUnitX(LoadUnitHandle(HTex, whichplayer, 1)),GetUnitY(LoadUnitHandle(HTex, whichplayer, 1)))
endif
call SaveBoolean(HTex, whichplayer, 3, false)
endfunction
function LCSShow takes integer whichplayer, unit hero, string name returns nothing
call LCSClear(whichplayer, true)
if GetLocalPlayer() == Player(whichplayer) then
call ClearTextMessages()
call ShowInterface(false, delay)
call EnableUserControl(true)
endif
call SetCameraTargetControllerNoZForPlayer(Player(whichplayer), hero, 0, 0, false)
call SaveUnitHandle(HTex, whichplayer, 1, hero)
call SaveStr(HTex, whichplayer, 2, name)
call SaveBoolean(HTex, whichplayer, 3, true)
call LCSTextReset(whichplayer)
set hero = null
endfunction
function lcsfake takes nothing returns nothing
endfunction
function LCSOptionAdd takes integer whichplayer, string text, string funcName, string leftfunc returns nothing
local integer i = LoadInteger(HTstr, whichplayer, 0) + 1
call SaveStr(HTstr, whichplayer, i, text)
call SaveStr(HTfun, whichplayer, i, funcName)
call SaveStr(HTfun2, whichplayer, i, leftfunc)
if leftfunc == "" then
call SaveStr(HTfun2, whichplayer, i, null)
endif
call SaveInteger(HTstr, whichplayer, 0, i)
if LCSOn() == true then
call LCSTextReset(whichplayer)
endif
endfunction
function LCSFakeAdd takes integer whichplayer, string text returns nothing
local integer i = LoadInteger(HTstr, whichplayer, 0) + 1
call SaveStr(HTstr, whichplayer, i, text)
call SaveStr(HTfun, whichplayer, i, "lcsfake")
call SaveInteger(HTstr, whichplayer, 0, i)
if LCSOn() == true then
call LCSTextReset(whichplayer)
endif
endfunction
private function up takes nothing returns nothing
local integer i = LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)
if (GetLocalPlayer() == GetTriggerPlayer()) then
call StartSound( updownsound )
endif
if i == 1 and repeating == true then
set i = LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0)
elseif i == 1 and repeating == false then
set i = i
elseif i > 1 then
set i = i - 1
endif
if LoadStr(HTfun, GetPlayerId(GetTriggerPlayer()), i) == "lcsfake" then
set i = i - 1
if i == 0 and repeating == true then
set i = LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0)
endif
endif
call SaveInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0, i)
call LCSTextReset(GetPlayerId(GetTriggerPlayer()))
endfunction
private function down takes nothing returns nothing
local integer i = LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)
if (GetLocalPlayer() == GetTriggerPlayer()) then
call StartSound( updownsound )
endif
if i == LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0) and repeating == true then
set i = 1
elseif i == LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0) and repeating == false then
set i = i
elseif i < LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0) then
set i = i + 1
endif
if LoadStr(HTfun, GetPlayerId(GetTriggerPlayer()), i) == "lcsfake" then
set i = i + 1
if i == LoadInteger(HTstr, GetPlayerId(GetTriggerPlayer()), 0) and repeating == true then
set i = 1
endif
endif
call SaveInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0, i)
call LCSTextReset(GetPlayerId(GetTriggerPlayer()))
endfunction
function LCSGetPicked takes nothing returns integer
return LCSLastPickedOptionId
endfunction
private function right takes nothing returns nothing
set LCSLastPickedOptionId = LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)
if LoadStr(HTfun, GetPlayerId(GetTriggerPlayer()), LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)) != null then
call ExecuteFunc(LoadStr(HTfun, GetPlayerId(GetTriggerPlayer()), LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)))
endif
if (GetLocalPlayer() == GetTriggerPlayer()) then
call StartSound( rightsound )
endif
if autoclose == true then
call LCSRem(GetPlayerId(GetTriggerPlayer()))
endif
endfunction
private function left takes nothing returns nothing
if LoadStr(HTfun2, GetPlayerId(GetTriggerPlayer()), LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)) != null then
set LCSLastPickedOptionId = LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)
call ExecuteFunc(LoadStr(HTfun2, GetPlayerId(GetTriggerPlayer()), LoadInteger(HTex, GetPlayerId(GetTriggerPlayer()), 0)))
if (GetLocalPlayer() == GetTriggerPlayer()) then
call StartSound( rightsound )
endif
if autoclose == true then
call LCSRem(GetPlayerId(GetTriggerPlayer()))
endif
endif
endfunction
private function esc takes nothing returns nothing
local integer id = GetPlayerId(GetTriggerPlayer())
if exitwhenesc == true then
call LCSRem(id)
else
call PolledWait(0.01)
call LCSTextReset(id)
endif
endfunction
private function init takes nothing returns nothing
local trigger LCSup = CreateTrigger()
local trigger LCSdown = CreateTrigger()
local trigger LCSright = CreateTrigger()
local trigger LCSleft = CreateTrigger()
local trigger LCSEsc = CreateTrigger()
local integer i = 0
loop
exitwhen i > 12
call TriggerRegisterPlayerKeyEventBJ( LCSup, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
call TriggerRegisterPlayerKeyEventBJ( LCSdown, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
call TriggerRegisterPlayerKeyEventBJ( LCSright, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT )
call TriggerRegisterPlayerKeyEventBJ( LCSleft, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
call TriggerRegisterPlayerEvent(LCSEsc, Player(i), EVENT_PLAYER_END_CINEMATIC)
call SaveBoolean(HTex, i, 3, false)
set i = i + 1
endloop
call TriggerAddCondition(LCSup, Condition(function LCSOn))
call TriggerAddCondition(LCSdown, Condition(function LCSOn))
call TriggerAddCondition(LCSright, Condition(function LCSOn))
call TriggerAddCondition(LCSleft, Condition(function LCSOn))
call TriggerAddCondition(LCSEsc, Condition(function LCSOn))
call TriggerAddAction(LCSup, function up)
call TriggerAddAction(LCSdown, function down)
call TriggerAddAction(LCSright, function right)
call TriggerAddAction(LCSleft, function left)
call TriggerAddAction(LCSEsc, function esc)
endfunction
endlibrary