//ADD: invisible destructables (range, interval, image type)
scope Multiboard initializer Init
globals
private constant real KEY_INTERVAL = .2 //Almost 3 times a sec
private constant real KEY_LOOP_WAIT = .5
private constant string POINTER = ">>>"
private multiboard array Multiboard
private integer array Menu
private integer array Position
private boolean array KeyPress[12][4] //false=off; true=on
private boolean array KeyLoopOn[12]
endglobals
struct Data
static integer menusize //Title doesn't count
static integer array row [10] //Title doesn't count
static integer array col [10] //Title doesn't count
static string array title [10] //Title of menu
static string array name [10][10] //What to display in the menu
static real array inc [10][10] //How much to increase/decrease by
//static real array min [10][10]
//static real array max [10][10]
static method onInit takes nothing returns nothing
set .menusize = 3
//Main menu
set .row [1] = 1
set .col [1] = 2
set .title [1] = "Main Menu"
set .name [1][1] = "Use the arrow keys to navagate"
//Camera Menu
set .row [2] = 6
set .col [2] = 3
set .title [2] = "Camera Settings"
set .name [2][1] = "Rotation Speed"
set .inc [2][1] = .1
set .name [2][2] = "Angle of Attack"
set .inc [2][2] = 2
set .name [2][3] = "Field of View"
set .inc [2][3] = 2
set .name [2][4] = "Target Distance"
set .inc [2][4] = 20
set .name [2][5] = "Z Offset"
set .inc [2][5] = 2
set .name [2][6] = "Far Z"
set .inc [2][6] = 50
//Invisible Destructables
set .row [3] = 2
set .col [3] = 3
set .title [3] = "Invisible Trees"
set .name [3][1] = "Radius"
set .inc [3][1] = 10
set .name [3][2] = "Image"
set .inc [3][2] = 1
endmethod
//Can this be moved into the original function itself?
static method Set takes integer id, integer k returns nothing
local integer p = Position[id] //+1
if Menu[id] == 2 then
if p == 0 then
set Camera_Data.D[id].rotationspeed = Camera_Data.D[id].rotationspeed + .inc[2][1]*k
elseif p == 1 then
set Camera_Data.D[id].aoa = Camera_Data.D[id].aoa + .inc[2][2]*k
elseif p == 2 then
set Camera_Data.D[id].fov = Camera_Data.D[id].fov + .inc[2][3]*k
elseif p == 3 then
set Camera_Data.D[id].targetdistance = Camera_Data.D[id].targetdistance + .inc[2][4]*k
elseif p == 4 then
set Camera_Data.D[id].zoffset = Camera_Data.D[id].zoffset + .inc[2][5]*k
elseif p == 5 then
set Camera_Data.D[id].farz = Camera_Data.D[id].farz + .inc[2][6]*k
endif
elseif Menu[id] == 3 then
if p == 0 then
set InvisibleDestructables_Radius[id] = InvisibleDestructables_Radius[id] + .inc[3][1]*k
elseif p == 1 then
set InvisibleDestructables_WhichImage[id] = InvisibleDestructables_WhichImage[id] + k
endif
endif
endmethod
//A seperate function because the values (reals) can change and need to be updated
static method Get takes integer id, integer m, integer p returns string
local real r
if m == 2 then
if p == 1 then
set r = Camera_Data.D[id].rotationspeed
elseif p == 2 then
set r = Camera_Data.D[id].aoa
elseif p == 3 then
set r = Camera_Data.D[id].fov
elseif p == 4 then
set r = Camera_Data.D[id].targetdistance
elseif p == 5 then
set r = Camera_Data.D[id].zoffset
elseif p == 6 then
set r = Camera_Data.D[id].farz
endif
elseif m == 3 then
if p == 1 then
set r = InvisibleDestructables_Radius[id]
elseif p == 2 then
set r = InvisibleDestructables_WhichImage[id]
endif
endif
if r != null then
return R2S(r)
else
return "null"
endif
endmethod
//Updates everything on the board
static method FullUpdate takes integer id returns nothing
local integer row = 0 //Top/Bottom
local multiboard mb = Multiboard[id]
local multiboarditem mi1
local multiboarditem mi2
local multiboarditem mi3
//Resize multiboard
call MultiboardSetRowCount(mb, .row[Menu[id]])
call MultiboardSetColumnCount(mb, .col[Menu[id]])
//The board
if .col[Menu[id]] == 2 then
loop
set mi1 = MultiboardGetItem(mb, row, 0)
call MultiboardSetItemStyle(mi1, true, false)
call MultiboardSetItemValue(mi1, "")
call MultiboardSetItemWidth(mi1, 0.01)
set mi2 = MultiboardGetItem(mb, row, 1)
call MultiboardSetItemStyle(mi2, true, false)
call MultiboardSetItemValue(mi2, .name[Menu[id]][row+1])
call MultiboardSetItemWidth(mi2, 0.17)
set mi3 = MultiboardGetItem(mb, row, 2)
call MultiboardSetItemStyle(mi3, false, false)
call MultiboardSetItemValue(mi3, "")
call MultiboardSetItemWidth(mi3, 0)
set row = row + 1
exitwhen row == .row[Menu[id]]
endloop
elseif .col[Menu[id]] == 3 then
loop
set mi1 = MultiboardGetItem(mb, row, 0)
set mi2 = MultiboardGetItem(mb, row, 1)
set mi3 = MultiboardGetItem(mb, row, 2)
call MultiboardSetItemWidth(mi1, 0.03)
call MultiboardSetItemWidth(mi2, 0.10)
call MultiboardSetItemWidth(mi3, 0.05)
call MultiboardSetItemStyle(mi1, true, false)
call MultiboardSetItemStyle(mi2, true, false)
call MultiboardSetItemStyle(mi3, true, false)
call MultiboardSetItemValue(mi1, "")
call MultiboardSetItemValue(mi2, .name[Menu[id]][row+1])
call MultiboardSetItemValue(mi3, .Get(id, Menu[id], row+1))
set row = row + 1
exitwhen row == .row[Menu[id]]
endloop
endif
//The title and Pointer
if Position[id] == -1 then
if Menu[id] == 1 then
call MultiboardSetTitleText(mb, " " + .title[Menu[id]] + " >>>")
elseif Menu[id] == .menusize then
call MultiboardSetTitleText(mb, "<<< " + .title[Menu[id]] + " ")
else
call MultiboardSetTitleText(mb, "<<< " + .title[Menu[id]] + " >>>")
endif
else
call MultiboardSetTitleText(mb, " " + .title[Menu[id]] + " ")
call MultiboardSetItemValue(MultiboardGetItem(mb, Position[id], 0), POINTER)
endif
endmethod
endstruct
//========================================================================================
//Arrow keys
//========================================================================================
//For holding down the key (There has to be a better way to do this)
private function KeyLoop takes nothing returns nothing
local integer id = 0
local integer i
loop
set i = 0
if KeyPress[id][1] then
set i = i + 1
endif
if KeyPress[id][2] then
set i = i + 1
endif
if KeyPress[id][3] then
set i = i + 1
endif
if KeyPress[id][4] then
set i = i + 1
endif
if i >= 2 then
//Do Nothing
else
if KeyPress[id][1] then
if Menu[id] == 1 and Position[id] == -1 then
//Do nothing
elseif Menu[id] > 1 and Position[id] == -1 then
set Menu[id] = Menu[id] - 1
call Data.FullUpdate(id)
else
call Data.Set(id, -1)
call Data.FullUpdate(id)
endif
endif
if KeyPress[id][2] then
if Menu[id] == Data.menusize and Position[id] == -1 then
//Do nothing
elseif Menu[id] < Data.menusize and Position[id] == -1 then
set Menu[id] = Menu[id] + 1
call Data.FullUpdate(id)
else
call Data.Set(id, 1)
call Data.FullUpdate(id)
endif
endif
if KeyPress[id][3] then
if Position[id] == Data.row[Menu[id]]-1 then
//Do nothing
else
set Position[id] = Position[id] + 1
call Data.FullUpdate(id)
endif
endif
if KeyPress[id][4] then
if Position[id] == -1 then
//Do nothing
else
set Position[id] = Position[id] - 1
call Data.FullUpdate(id)
endif
endif
endif
set id = id + 1
exitwhen id == 12
endloop
endfunction
//For pressing the key fast
private function QuickKey takes integer id, integer key returns nothing
local integer i = 0
if KeyPress[id][1] then
set i = i + 1
endif
if KeyPress[id][2] then
set i = i + 1
endif
if KeyPress[id][3] then
set i = i + 1
endif
if KeyPress[id][4] then
set i = i + 1
endif
if not (i >= 2) then
if key == 1 then
if Menu[id] == 1 and Position[id] == -1 then
//Do nothing
elseif Menu[id] > 1 and Position[id] == -1 then
set Menu[id] = Menu[id] - 1
call Data.FullUpdate(id)
else
call Data.Set(id, -1)
call Data.FullUpdate(id)
endif
endif
if key == 2 then
if Menu[id] == Data.menusize and Position[id] == -1 then
//Do nothing
elseif Menu[id] < Data.menusize and Position[id] == -1 then
set Menu[id] = Menu[id] + 1
call Data.FullUpdate(id)
else
call Data.Set(id, 1)
call Data.FullUpdate(id)
endif
endif
if key == 3 then
if Position[id] == Data.row[Menu[id]]-1 then
//Do nothing
else
set Position[id] = Position[id] + 1
call Data.FullUpdate(id)
endif
endif
if key == 4 then
if Position[id] == -1 then
//Do nothing
else
set Position[id] = Position[id] - 1
call Data.FullUpdate(id)
endif
endif
endif
endfunction
private function Down_Left takes nothing returns nothing
call QuickKey(GetPlayerId(GetTriggerPlayer()), 1)
set KeyPress[GetPlayerId(GetTriggerPlayer())][1] = true
endfunction
private function Down_Right takes nothing returns nothing
call QuickKey(GetPlayerId(GetTriggerPlayer()), 2)
set KeyPress[GetPlayerId(GetTriggerPlayer())][2] = true
endfunction
private function Down_Down takes nothing returns nothing
call QuickKey(GetPlayerId(GetTriggerPlayer()), 3)
set KeyPress[GetPlayerId(GetTriggerPlayer())][3] = true
endfunction
private function Down_Up takes nothing returns nothing
call QuickKey(GetPlayerId(GetTriggerPlayer()), 4)
set KeyPress[GetPlayerId(GetTriggerPlayer())][4] = true
endfunction
private function Up_Left takes nothing returns nothing
set KeyPress[GetPlayerId(GetTriggerPlayer())][1] = false
endfunction
private function Up_Right takes nothing returns nothing
set KeyPress[GetPlayerId(GetTriggerPlayer())][2] = false
endfunction
private function Up_Down takes nothing returns nothing
set KeyPress[GetPlayerId(GetTriggerPlayer())][3] = false
endfunction
private function Up_Up takes nothing returns nothing
set KeyPress[GetPlayerId(GetTriggerPlayer())][4] = false
endfunction
//========================================================================================
//Setup
//========================================================================================
private function BoardOn takes nothing returns nothing
local integer id = 0
loop
set Multiboard[id] = CreateMultiboard()
set Menu[id] = 1
set Position[id] = -1
set KeyLoopOn[id] = false
call Data.FullUpdate(id)
//Different people, different boards
if GetLocalPlayer() == Player(id) then
call MultiboardMinimize(Multiboard[id], false)
call MultiboardDisplay(Multiboard[id], true)
endif
set id = id + 1
exitwhen id == 12
endloop
endfunction
private function Init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local trigger t4 = CreateTrigger()
local trigger t5 = CreateTrigger()
local trigger t6 = CreateTrigger()
local trigger t7 = CreateTrigger()
local trigger t8 = CreateTrigger()
local trigger t9 = CreateTrigger()
local integer id = 0
loop
if GetPlayerController(Player(id)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(id)) == PLAYER_SLOT_STATE_PLAYING then
//Pressing the key down
call TriggerRegisterPlayerEvent(t1, Player(id), EVENT_PLAYER_ARROW_LEFT_DOWN)
call TriggerRegisterPlayerEvent(t2, Player(id), EVENT_PLAYER_ARROW_RIGHT_DOWN)
call TriggerRegisterPlayerEvent(t3, Player(id), EVENT_PLAYER_ARROW_DOWN_DOWN)
call TriggerRegisterPlayerEvent(t4, Player(id), EVENT_PLAYER_ARROW_UP_DOWN)
//Letting go of the key
call TriggerRegisterPlayerEvent(t5, Player(id), EVENT_PLAYER_ARROW_LEFT_UP)
call TriggerRegisterPlayerEvent(t6, Player(id), EVENT_PLAYER_ARROW_RIGHT_UP)
call TriggerRegisterPlayerEvent(t7, Player(id), EVENT_PLAYER_ARROW_DOWN_UP)
call TriggerRegisterPlayerEvent(t8, Player(id), EVENT_PLAYER_ARROW_UP_UP)
endif
set KeyPress[id][1] = false
set KeyPress[id][2] = false
set KeyPress[id][3] = false
set KeyPress[id][4] = false
set id = id + 1
exitwhen id == 12
endloop
call TriggerAddAction(t1, function Down_Left)
call TriggerAddAction(t2, function Down_Right)
call TriggerAddAction(t3, function Down_Down)
call TriggerAddAction(t4, function Down_Up)
call TriggerAddAction(t5, function Up_Left)
call TriggerAddAction(t6, function Up_Right)
call TriggerAddAction(t7, function Up_Down)
call TriggerAddAction(t8, function Up_Up)
call TriggerRegisterTimerEvent(t9, .01, false)
call TriggerAddAction(t9, function BoardOn)
call TimerStart(CreateTimer(), KEY_INTERVAL, true, function KeyLoop)
endfunction
endscope