PDA

View Full Version : Seperating a listbox



Spkka
Jul 16 2009, 11:56
Hey, this part opens up a build menu on which players can choose whatever structure they want to build ingame from a listbox in crcti warfare.07
I have a feeling loading the whole list at once is a bit heavy so i thought to seperate Primary, defense, rural and sign structures. I have no idea how to show only Primary structures when the button primary is being pressed. Guess i need to hold what button got pressed last and display these. Do i need to set types or something for each structure then?

; args: [object, type, si, distance]

_object = _this select 0
_unit = player
_si = playerSideIndex
_distMax = _this select 3

_isMHQ = (_object == mhqWest || _object == mhqEast)

buttonPressedBuild = false
buttonPressedPlaceBuild = false
buttonPressedBuy = false

buttonPressedPrimary = false
buttonPressedDefense = false
buttonPressedRural = false
buttonPressedSigns = false

_delay = 0.2

#Init

openBuildMenu = false
_menuOpen = true

;Create the build menu.
_buildMenu = CreateDialog "BuildMenu"
[IDD_BuildMenu]call funcFixDialogTitleColor

ctrlSetText [IDC_TEXT_MENU_NAME, "Build Structures"]

ctrlShow [IDC_BTN_ALIGN, false]
ctrlShow [IDC_BTN_FLOAT, false]

? !(_isMHQ): ctrlShow [IDC_BTN_BUY_BG, false]; ctrlShow [IDC_BTN_BUY, false]

_index = 0
_count = count structDefs
_money = (groupMoneyMatrix select _si) select playerGroupIndex

;Add an entry onto the structure selection combobox.
#AddStructures

_desc = structDefs select _index
_name = _desc select sdName
_cost = _desc select sdCost
_sides = _desc select sdSides
_onlyCO = _desc select sdOnlyCO
_onlyMHQ = _desc select sdOnlyMHQ

?(playerSideIndex == siwest):_model = sdObjectsWest
?(playerSideIndex == sieast):_model = sdObjectsEast

_spacer = ""
? (_cost < 10): _spacer = " "
? (_cost < 100): _spacer = " "
? (_cost < 1000): _spacer = " "
? (_cost < 10000): _spacer = " "

_text = Format["$%1 %2%3", _cost, _spacer, _name]

? (_si != _sides && _sides != siBoth): goto "Skip"

? (_onlyMHQ && !_isMHQ): goto "Skip"
? (_onlyCO && playerGroup != (groupCommander select _si)): goto "Skip"
? (_type == 1 ): goto "Skip"

_id = lbAdd[IDC_LB_LIST1, _text]
lbSetValue [IDC_LB_LIST1, _id, _index]
? (_id > 8): lbSetColor [IDC_LB_LIST1, _id, [0,0,.3,1]]
? (_cost > _money): lbSetColor [IDC_LB_LIST1, _id, [.5,0,0,1]]
? (lastSelectedStructType == _index): lbSetCurSel [IDC_LB_LIST1, _id]

#Skip

_index = _index + 1
? (_index < _count):goto "AddStructures"

_type = -1

#Update
? !(alive _object): goto "CloseDialog"
? !(alive _unit): goto "CloseDialog"
? (_unit distance _object > _distMax): goto "CloseDialog"
? (_isMHQ && playerGroup != (groupCommander select _si)): goto "CloseDialog"

;If the value is not 1 then the menu was closed with the ESC key.
? !(dialog): goto "CloseDialog"

_selected = lbCurSel IDC_LB_LIST1
? (_selected == -1): _type == -1; goto "NoStructSelected"
_type = lbValue[IDC_LB_LIST1, _selected]

_image = getText (configFile >> "CfgVehicles" >> ((((structDefs select _type) select _model)select 0) select 0) >> "picture")
?(_image == "PICTURESTATICOBJECT"): _image = "\CA\UI\DATA\marker_x_ca.paa"
?(_image == "\CA\UI\DATA\ICON_WF_BUILDING_REPAIR_CA.PAA"):_image = "\CA\UI\DATA\iconship_ca.paa"
ctrlSetText [IDC_Build_Picture, _image]

lastSelectedStructType = _type
_cost = (structDefs select _type) select sdCost
if (_type in alignTypes) then { ctrlShow [IDC_BTN_ALIGN, true] } else { ctrlShow [IDC_BTN_ALIGN, false] }
if (_type in structsFloat) then { ctrlShow [IDC_BTN_FLOAT, true] } else { ctrlShow [IDC_BTN_FLOAT, false] }
#NoStructSelected

_money = (groupMoneyMatrix select _si) select playerGroupIndex
_text = format ["$%1", _money]
ctrlSetText [IDC_TEXT_PLAYER_MONEY, _text]

? (_si == siWest): _text = format ["Buy Worker $%1 (%2/%3)", costWorker, pvWorkersWest, maxWorkers]
? (_si == siEast): _text = format ["Buy Worker $%1 (%2/%3)", costWorker, pvWorkersEast, maxWorkers]
ctrlSetText[IDC_BTN_BUY, _text]

if (alignWalls) then { ctrlSetText [IDC_BTN_ALIGN, "Align Walls: ON"] } else { ctrlSetText [IDC_BTN_ALIGN, "Align Walls: OFF"] }
if (SQU_FloatObj) then { ctrlSetText [IDC_BTN_FLOAT, "Float Object: ON"] } else { ctrlSetText [IDC_BTN_FLOAT, "Float Object: OFF"] }

ctrlShow [IDC_BTN_PRI, true]
ctrlShow [IDC_BTN_DEF, true]
ctrlShow [IDC_BTN_RUR, true]
ctrlShow [IDC_BTN_SIG, true]

? (buttonPressedBuild):goto "BuildStructure"
? (buttonPressedPlaceBuild):goto "PlaceBuildStructure"
? (buttonPressedBuy):goto "BuyWorker"

? (buttonPressedPrimary):goto "UpdatePrimary"
? (buttonPressedDefense):goto "UpdateDefense"
? (buttonPressedRural):goto "UpdateRural"
? (buttonPressedSigns):goto "UpdateSigns"

~_delay
goto "Update"

#UpdatePrimary
buttonPressedPrimary = false
lastSelectedStructType = 1;
goto "Update"

#UpdateDefense
buttonPressedDefense = false
lastSelectedStructType = 2;
goto "Update"

#UpdateRural
buttonPressedRural = false
goto "Update"

#UpdateSigns
buttonPressedSigns = false
goto "Update"

#BuyWorker
buttonPressedBuy = false
? (_money < costWorker): hint "Not enough Money"; goto "Update"
[_unit] exec "Player\AddWorker.sqs"
goto "Update"

#BuildStructure
buttonPressedBuild = false
? (_type == -1): hint "No structure selected"; goto "Update"
? (_money < _cost): hint "Not enough Money"; goto "Update"
[_unit, _type, [], 0, alignWalls && ctrlVisible IDC_BTN_ALIGN, SQU_FloatObj && ctrlVisible IDC_BTN_FLOAT] exec "Player\BuildStructure.sqs"
goto "CloseDialog"

#PlaceBuildStructure
buttonPressedPlaceBuild = false
? (_type == -1): hint "No structure selected"; goto "Update"
? (_money < _cost): hint "Not enough Money"; goto "Update"
[_object, _unit, _type, alignWalls && ctrlVisible IDC_BTN_ALIGN, SQU_FloatObj && ctrlVisible IDC_BTN_FLOAT, _distMax] exec "Player\PlaceAndBuildStructure.sqs"
goto "CloseDialog"

#CloseDialog
buttonPressedBuild = false
buttonPressedPlaceBuild = false
buttonPressedBuy = false
buttonPressedPrimary = false
buttonPressedDefense = false
buttonPressedRural = false
buttonPressedSigns = false
? (dialog): closeDialog 0
Exit