-- Player Unit Actions -- -- Author: Dearthenon (Daniel Carruth) -- Revisions -- 11/15/08: Creation (DWC) -- Properties Define Properties() team_color = {red = 0, green = 200, blue = 255, alpha = 1} ui_color = {red = 255, green = 255, blue = 255, alpha = 1} -- ExposeProperty('channel_1_color', 'What color should the grey channel be tinted with?', 'color') -- UI data controlUI = { startx = 4, starty = 26, width = 34, heightSmall = 26, heightBig = 34, paddingx = 3, paddingy = 3, cols = 8, rows = 2, normal32 = '12071:448', hover32 = '0:713', press32 = '0:715', normal24 = '12071:448', hover24 = '0:714', press24 = '0:716', normal61 = '12071:448', hover61 = '0:712', press61 = '0:711'} controlWindow = { x = 100, y = 346 } unitButton = { button = 0, image = 0} controlButtons = { l_hand = { button = 0, image = 0}, r_hand = { button = 0, image = 0}, belt_1 = { button = 0, image = 0}, belt_2 = { button = 0, image = 0}, belt_3 = { button = 0, image = 0}, belt_4 = { button = 0, image = 0} } hpRect = 0 epRect = 0 apRect = 0 controlPanel = 0 selected_object_id = 0 selected_unit_index = 1 command_state = "enemyTurn" -- Finances funds = 1000 -- Team Members -- NAME SPRITE TEMPLATE HP EP AP teamTemplate = { {"Warrior", '0:687', 'warrior', 100, 100, 100}, {"Knight", '0:688', 'knight', 100, 100, 100}, {"Sorcerer", '0:689', 'sorcerer', 100, 100, 100} } team = {} locker = "_object_" lockerId = 0 PersistProperty("lockerId") -- User Interace teamPanel = 0 --unitPanel = 0 --commandPanel = 0 --testPanel = 0 -- script information script_description = 'Player Unit Actions' script_long_description = 'Player Controls Units' end -- OutputToUser( Define Commands() -- MakeCommand(name, description, [arg-name:arg-type, ...]) -- MakeInput(input-description, input-code, input-event, input-modifier, command-string) -- ** MAIN SCREEN COMMANDS ** -- handle click on terrain MakeCommand("handle_terrain", "request move", "x:float", "y:float", "z:float") MakeInput('Click on terrain.', 'mouse-terrain', 'click', 'none', 'handle_terrain') -- handle click on an object MakeCommand("pick", "pick an object", "target:object") MakeInput('pick','mouse-object', 'click', 'none', 'pick') -- test -- various test functions used to test functionality MakeCommand("test", "test") MakeInput('test', 'a', 'down', 'none', 'test') MakeCommand("test2", "test2") MakeInput('test2', 'x', 'down', 'none', 'test2') MakeCommand("test3", "test3", "val:int") MakeCommand("test4", "test4") MakeInput('test4', 'd', 'down', 'none', 'test4') -- ** TEAM PANEL COMMANDS ** -- select unit MakeCommand("selectUnit", "select the specified unit", "val:int") -- end turn MakeCommand("endTurn", "endTurn") -- ** UNIT PANEL COMMANDS ** -- hold unit MakeCommand("holdUnit", "Orders the selected unit to hold") MakeInput('order unit to hold until next turn', 'h', 'down', 'none', 'holdUnit') -- shift selection to next unit MakeCommand("nextUnit", "Selects the next unit with remaining AP") MakeInput('select next unit with available AP', 'n', 'down', 'none', 'nextUnit') -- display inventory MakeCommand("showUnitInventory", "Displays the unit inventory window", "flag:int") MakeInput('display inventory screen for current unit', 'i', 'down', 'none', 'showUnitInventory 1') -- display status MakeCommand("showUnitStatus", "Displays the unit stats window") MakeInput('display status screen for current unit', 's', 'down', 'none', 'showUnitStatus') -- hand MakeCommand("useInventoryItem", "Activates item from inventory", "location:string", "slot:int") MakeCommand("moveInventory", "Takes an item from inventory", "location:string", "i:int", "j:int") MakeCommand("dismissExternalUI", "Dismiss UI belonging to an object", "containerId:int", "UiID:int") MakeCommand("moveContainer", "move objects to and from container", "containerId:int", "i:int", "j:int") end -- **** COMMANDS **** -- ** MAIN SCREEN COMMANDS ** -- pick -- Click on an object - no SHFT, CTRL, ALT modifiers Command pick(target) local selectedObject = GetObjectById(self.selected_object_id) -- select unit objects on click if (target.owner == self.id) then selectUnit(self, target) end if (selectedObject.inHand ~= 0) then SendTo(target, "useWithObject", 0, user, self.selected_object_id, selectedObject.inHand) else if (target.pickable and target.pickable == 1) then Debug("Pick up object %d", target.pickable) SendTo(selectedObject, "pickupObject", 0, target, "backpack") else Debug("Use world object") SendTo(target, "useObject", 0, user, self.selected_object_id) end end end -- handle_terrain -- Click on the terrain - no SHFT, CTRL, ALT modifiers Command handle_terrain(x, y, z) local selectedObject = GetObjectById(self.selected_object_id) -- if selected object is one of our units, order it to move if (selectedObject.inHand ~= 0) then --Debug("%d %d", x, y) SendTo(selectedObject, "dropObjectInHand", 0, x, y) elseif (selectedObject.owner == self.id) then -- move the player with the unit self.speed = 2 PathToLocation(self, round(x), round(y)) -- request unit to move SendTo(GetObjectById(self.selected_object_id), "requestMove", 0, x, y) end end -- Test -- Reusable commands for testing new script(s) Command test() --createTeamUI(self) --createUnitUI(self) --createUnits(self) --SendTo(self, "setupUI", 0, self) --ui_createControlPanel(self) local object = CreateObject('bow1', self.x,self.y+1, 0, 0) PersistObject(object) --SendTo(GetObjectById(self.selected_object_id), "dismissInventory", 0) --deployUnits(self) end Command test2() --deployUnits(self) SendTo(GetObjectById(self.selected_object_id), "checkInventory", 0) --createTestPanel(self) -- destroyUI(self) -- UiDelete(self.commandPanel) -- self.commandPanel = 0 end Command test3(val) Debug("Test3") --selectUnit(self, GetObjectById(self.team[val].id)) end Command test4() --pickUpUnits(self) --dismissTestPanel(self) ui_dismissControlPanel(self) --SendTo(GetObjectById(self.selected_object_id), "dropObject", 0, GetObjectById(10130), self.x, self.y + 1, 0, 0) end -- ** TEAM PANEL COMMANDS ** -- selectUnit -- selects a specified unit Command selectUnit(val) selectUnit(self, GetObjectById(val)) end -- endTurn -- ends the user's current turn Command endTurn() self.command_state = "enemyTurn" SendToPlace("endedTurn", 0, self.id) SendTo(self, "startTurn", 0) end -- ** UNIT PANEL COMMANDS ** -- holdUnit -- orders the current unit to hold until the next turn -- effectively it makes the nextUnit command ignore it until the next turn Command holdUnit() AlertToUser(self, 1500, "Hold Unit!") SendTo(GetObjectById(self.team[self.selected_unit_index].id), "hold", 0) end -- nextUnit -- selects the next available unit with AP Command nextUnit() AlertToUser(self, 1500, "Next Unit!") -- local var for unit storage local unit = 0 -- store where we start the search local startIndex = self.selected_unit_index Debug("StartIndex: %d", startIndex) -- increment the index and create a local copy local selectIndex = self.selected_unit_index + 1 if selectIndex > #(self.team) then selectIndex = 1 end -- loop thru the team table until we return to the start index while selectIndex ~= startIndex do --Debug("%d - %d Unit: %d", selectIndex, startIndex, self.team[selectIndex].id) -- if the unit has available AP and is not on hold, select the unit unit = GetObjectById(self.team[selectIndex].id) if (unit.curActionPoints > 0 and unit.state ~= "hold") then selectUnit(self, GetObjectById(self.team[selectIndex].id)) return end selectIndex = selectIndex + 1 -- set the index to start of team table if we reach the end of the table if selectIndex > #(self.team) then --Debug("Out of range") selectIndex = 1 end end -- check the current unit unit = GetObjectById(self.team[startIndex].id) if (unit.actionPoints > 0 and unit.state ~= "hold") then AlertToUser(self, 1500, "Other Units Out of Action Points!") else AlertToUser(self, 1500, "All Units Out of Action Points!") end end -- showUnitInventory -- displays the inventory UI for the selected unit Command showUnitInventory(flag) SendTo(GetObjectById(self.selected_object_id), "showInventory", 0, self, flag) --AlertToUser(self, 1500, "Inventory!") end -- showUnitStatus -- displays the status UI for the selected unit Command showUnitStatus() AlertToUser(self, 1500, "Current Team Size: %d Container Size: %d", #self.team, GetContainerSize(self.locker)) end -- useInventoryItem -- use item from inventory -- Args: -- location - which inventory location is the item in (l_hand, r_hand, belt, or backpack) -- slot - which slot of the inventory location is the item in Command useInventoryItem(location, slot) SendTo(getCurrentUnit(self), "useInventoryItem", 0, self, location, slot) end Command moveInventory(location, i, j) SendTo(GetObjectById(self.selected_object_id), "moveInventory", 0, self, location, i, j) end Command moveContainer(containerId, i, j) Debug("MoveContainer!") unit = GetObjectById(self.selected_object_id) SendTo(GetObjectById(containerId), "moveContainer", 0, self, unit, i, j) end Command dismissExternalUI(containerId, UiID) Debug("Dismiss Object %d Ui %d", containerId, UiID) SendTo(GetObjectById(containerId), "closeUI", 0, self, UiID) end -- TRIGGERS Trigger ui_move(id, x, y) -- Debug("Something moved! %d %d %d : %d", id, x, y, self.unitPanel) end Trigger ui_refreshUnitPanel(unit) --Debug("Request ui refresh") refreshUnitPanel(self, unit) end Trigger ui_redrawAPRect(object) -- Debug("Object: %d Selected: %d", object.id, self.selected_object_id) if (object.id == self.selected_object_id) then UiSize(self.apRect, math.floor((object.curActionPoints/(object.maxActionPoints+5))*32), 2) end end Trigger ui_redrawHPRect(object) if (object.id == self.selected_object_id) then UiSize(self.hpRect, math.floor((object.curHealth/object.maxHealth)*32), 2) end end Trigger ui_redrawEPRect(object) if (object.id == self.selected_object_id) then UiSize(self.epRect, math.floor((object.curEnergy/object.maxEnergy)*32),2) end end -- attach -- System Trigger: sent when script is attached Trigger attach() -- set the user sprite to blank self.spriteId = '12071:448' end -- enter -- System Trigger: sent when user/object enters place Trigger enter(placeId) --Debug("Player's Locker Id: %d", self.lockerId) if (self.lockerId == 0) then local object = CreateObjectById('0:9', -100, -100, 0, 0) Debug("Creating locker: %d", object.id) self.lockerId = object.id PersistObject(object) end self.locker = GetObjectById(self.lockerId) -- if the user has no stored units, create default units if (GetContainerSize(self.locker) == 0) then Log(SEV_WARN, "Locker empty!") Debug("Locker %d empty!", self.locker.id) createUnits(self) end -- deploy the units to the place deployUnits(self) -- Create the control UI Debug("Create Control Panel") ui_createControlPanel(self) -- start the turn, TODO: register with the game manager SendTo(self, "startTurn", 0) end -- left -- System Trigger: sent when user/object leaves place Trigger left(placeId, logoutFlag) Debug("LEFT") -- store user's units in the locker pickUpUnits(self) -- cleanup user ui ui_dismissControlPanel(self) end -- destroyed Trigger destroyed() Debug("DESTROYED") Log(SEV_WARN, "Destroyed player") pickUpUnits(self) ui_dismissControlPanel(self) end -- startTurn Trigger startTurn() self.command_state = "your_turn" AlertToUser(self, 1500, "Your Turn!") for k, unit in pairs(self.team) do -- Debug("unit: %d %s", k, unit.name) SendTo(GetObjectById(unit.id), "resetUnit", 0) end end -- attachSelected -- Custom Trigger: sent from an object that has been selected -- sets the selected_object_id to the object's id -- TODO: no longer in use? Trigger attachSelected(object) Debug("attachSelected") self.selected_object_id = object.id end -- FUNCTIONS -- selectUnit -- selects the specified unit -- Args: -- self - user object -- target - unit object to select function selectUnit(self, target) Debug("%d", target.id) -- Move the user to the selected unit MoveObject(self, target.x, target.y, 1, 1) -- Send message to target object to handle selection SendTo(target, "selectUnit", 0, self) -- Send message to previously selected object to handle deselection if self.selected_object_id ~= 0 then SendTo(GetObjectById(self.selected_object_id), "unselectUnit", 0, self) end -- store id of selected object self.selected_object_id = target.id self.selected_unit_index = getUnitIndexById(self, target.id) -- TODO: Update user interface panels Debug("Refresh") refreshUnitPanel(self, target) end -- createTeamPanel -- creates the team panel components -- Args: -- user - user object function createTeamPanel(user) -- local vars for creation local count = 0 local button = 0 local y = 0 local rect = 0 local unitObject = 0 -- create the background rect of the panel local panel = UiRect(user.teamPanel, "teamPanel", 0, 0, 50, 250) UiColor(panel, 180, 128, 0, 1) -- loop over the units in the team and create unit data panels/buttons for k, unit in pairs(user.team) do unitObject = GetObjectById(unit.id) -- calculate the y location of the button y = 54*count + 9 -- create the outer rectangle rect = UiRect(panel, "rect", 8, y-1, 34, 34) UiColor(rect, 0, 0, 0, 1) -- create the inner rectangle rect = UiRect(panel, "rect", 9, y, 32, 32) UiColor(rect, 180, 148, 0, 1) count = count + 1 end end -- createUnits -- creates the objects representing the user's units -- Args: -- user - user object function createUnits(user) local object = 0 -- loop over the team units and create them for k, unit in pairs(user.teamTemplate) do --unit.name = unit[1] -- map value to a name key --unit.sprite = unit[2] -- map value to sprite key -- create the object from unit data, place near user's location if (user.locker) then Debug("Creating Default Unit Object") object = CreateInContainer(user.locker, unit[3]) PersistObject(object) -- set the object's name and sprite object.name = unit[1] object.sprite = unit[2] -- set the object's owner to the user's id object.owner = user.id else Debug("Error: User does not have a locker!") end end end function acquireUnit(user, templateName) Debug("Acquire Unit") -- add a unit to the user's staff local object = CreateInContainer(user.locker, templateName) object.name = templaceName object.rank = "rookie" end function deployUnits(user) -- Debug("Deploy Units! Container: %d", GetContainerSize(user.locker)) -- from current team, deploy the units for i, object in pairs(GetContained(user.locker)) do Debug("Deploy Object %d: %s", i, object.name) ContainerToPlace(user.locker, object, user.x, user.y+i, 0, 0) table.insert(user.team, object) SendTo(object, "deploy", 0, user) end selectUnit(user, user.team[1]) end function pickUpUnits(user) -- the current unit needs to dismiss its inventory window SendTo(GetObjectById(user.selected_object_id), "dismissInventory", 0) if (user.locker) then -- move units from the place to the locker for k, unit in pairs(user.team) do Debug("Pickup %s", unit.name) SendTo(unit, "pickup", 0) PlaceToContainer(user.locker, unit) end -- clear the team table repeat table.remove(user.team) until #user.team == 0 -- clear the selected_object_id user.selected_object_id = 0 else Debug("Error: User has no locker") end end function getCurrentUnit(user) return getUnitByIndex(user, user.selected_unit_index) end function getUnitIndexById(user, id) -- loop over the team units for k, unit in pairs(user.team) do if (unit.id == id) then --Debug("Found index: %d", k) return k end end Debug("getUnitIndexById: Unit Id: %d not found in team list", id) return nil end function getUnitByIndex(user, index) if(user.selected_unit_index ~= 0 and user.selected_unit_index < #(user.team)) then return GetObjectById(user.team[index].id) else return nil end end function refreshUnitPanel(user, unitObject) -- refresh unit sprite if (user.unitButton.button ~= 0) then UiDelete(user.unitButton.button) UiDelete(user.unitButton.image) user.unitButton.button = 0 user.unitButton.image = 0 end user.unitButton.image = UiImage(user.controlPanel, "unitButton", user.controlUI.startx+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, unitObject.spriteId) user.unitButton.button = UiImageButton(user.controlPanel, "unitButton", user.controlUI.startx+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, user.controlUI.normal32, user.controlUI.hover32, user.controlUI.press32, 'selectUnit ' .. unitObject.id) -- refresh unit ap rect UiSize(user.apRect, math.floor((unitObject.curActionPoints/(unitObject.maxActionPoints+5))*32), 2) -- refresh unit health rect UiSize(user.hpRect, math.floor((unitObject.curHealth/unitObject.maxHealth)*32), 2) -- refresh unit energy rect UiSize(user.epRect, math.floor((unitObject.curEnergy/unitObject.maxEnergy)*32), 2) -- l_hand drawInventoryImage(user, user.controlPanel, unitObject, "l_hand", user.controlUI.startx + (1 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall + user.controlUI.paddingy + user.controlUI.heightBig-1) -- r_hand drawInventoryImage(user, user.controlPanel, unitObject, "r_hand", user.controlUI.startx + (6 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty +1, user.controlUI.width-1, user.controlUI.heightSmall + user.controlUI.paddingy + user.controlUI.heightBig-1) -- belt_1 drawInventoryImage(user, user.controlPanel, unitObject, "belt_1", user.controlUI.startx + (2 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightBig-1) -- belt_2 drawInventoryImage(user, user.controlPanel, unitObject, "belt_2", user.controlUI.startx + (3 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightBig-1) -- belt_3 drawInventoryImage(user, user.controlPanel, unitObject, "belt_3", user.controlUI.startx + (4 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightBig-1) -- belt_4 drawInventoryImage(user, user.controlPanel, unitObject, "belt_4", user.controlUI.startx + (5 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightBig-1) end function drawFrame(windowId, x, y, w, h) local rect rect = UiRect(windowId, "frame", x, y, w, h) UiColor(rect, 0, 0, 0, 1) rect = UiRect(windowId, "rect", x + 1, y+1, w-2, h-2) UiColor(rect, 255, 200, 0, 1) end function ui_dismissControlPanel(user) if (user.controlPanel ~= 0) then UiDelete(user.controlPanel) user.controlPanel = 0 end end function ui_createControlPanel(user) --Debug("Create Control Panel") -- some local vars for handling creation of the UI local param = user.controlUI local rect = 0 -- be sure the unit UI doesn't already exist if (user.controlPanel ~= 0) then UiDelete(user.controlPanel) user.controlPanel = 0 end -- create the unit UI -- Create a window to hold the unit controls -- currently using default window style user.controlPanel = UiWindow(0, "unitTestWindow", user.controlWindow.x, user.controlWindow.y, param.startx + (param.cols * (param.width + param.paddingx)) + param.paddingx, param.starty + param.heightBig + param.paddingy + param.heightSmall + param.paddingy + param.paddingy, '13197:3') -- allow users to drag the window UiCapability(user.controlPanel, "drag") -- create the interior of the panel -- create the unit image local unitObject = GetObjectById(user.selected_object_id) --Debug("Got Unit: %d", unitObject.id) --Debug("** Draw Unit Panel") drawUnitPanel(user, unitObject) --Debug("** Draw Command Panel") -- create two rows of 4 button outlines -- first row: 48x24 drawCommandPanel(user) -- second row: 48x48 --Debug("** Draw Unit Inventory Panel") drawInventoryAccessPanel(user, unitObject) -- end turn drawFrame(user.controlPanel, user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightBig) UiImage(user.controlPanel, "endTurn", user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, '12071:430') UiImageButton(user.controlPanel, "endTurnButton", user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, user.controlUI.normal32, user.controlUI.hover32, user.controlUI.press32, 'endTurn ') -- quit mission drawFrame(user.controlPanel, user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty + user.controlUI.width + user.controlUI.paddingy, user.controlUI.width, user.controlUI.heightSmall) UiImage(user.controlPanel, "quit", user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightBig+user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightSmall-1, '0:706') UiImageButton(user.controlPanel, "quit", user.controlUI.startx + (7 * (user.controlUI.width + user.controlUI.paddingx))+1, user.controlUI.starty + user.controlUI.heightBig+user.controlUI.paddingy+1, user.controlUI.width-1, user.controlUI.heightSmall-1, user.controlUI.normal24, user.controlUI.hover24, user.controlUI.press24, 'quit') --Debug("Attach Control Panel") UiAttachUser(user,user.controlPanel) end function drawUnitPanel(user, unit) local rect = 0 --Debug("Drawing Unit Panel") -- unit image drawFrame(user.controlPanel, user.controlUI.startx, user.controlUI.starty, user.controlUI.width, user.controlUI.heightBig) user.unitButton.button = UiImage(user.controlPanel, "unitButton", user.controlUI.startx+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, unit.spriteId) user.unitButton.image = UiImageButton(user.controlPanel, "unitButton", user.controlUI.startx+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightBig-1, user.controlUI.normal32, user.controlUI.hover32, user.controlUI.press32, 'selectUnit ' .. unit.id) -- background rect rect = UiRect(user.controlPanel, "rect", user.controlUI.startx, user.controlUI.starty + user.controlUI.heightBig + user.controlUI.paddingx, user.controlUI.width, 12) UiColor(rect, 0, 0, 0, 1) --Debug("Health") -- health user.hpRect = UiRect(user.controlPanel, "HP", user.controlUI.startx+1, user.controlUI.starty + user.controlUI.heightBig + user.controlUI.paddingx + 1, user.controlUI.width-2, 2) Debug("Health Color") UiColor(user.hpRect, 255, 0, 0, 1) UiSize(user.hpRect, math.floor((unit.curHealth/(unit.maxHealth))*user.controlUI.width-2), 2) --Debug("Energy") -- energy user.epRect = UiRect(user.controlPanel, "EP", user.controlUI.startx+1, user.controlUI.starty + user.controlUI.heightBig + user.controlUI.paddingx + 5, user.controlUI.width-2, 2) UiColor(user.epRect, 0, 0, 255, 1) UiSize(user.epRect, math.floor((unit.curEnergy/(unit.maxEnergy+5))*user.controlUI.width-2), 2) --Debug("Action") -- AP user.apRect = UiRect(user.controlPanel, "AP", user.controlUI.startx+1, user.controlUI.starty + user.controlUI.heightBig + user.controlUI.paddingx+9, user.controlUI.width-2, 2) UiColor(user.apRect, 0, 255, 0, 1) UiSize(user.apRect, math.floor((unit.curActionPoints/(unit.maxActionPoints))*user.controlUI.width-2), 2) --Debug("Unit Panel done") end function drawCommandPanel(user) -- command panel --Debug("Hold") drawFrame(user.controlPanel, user.controlUI.startx+(2*(user.controlUI.width+user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall) UiImage(user.controlPanel, "image", user.controlUI.startx+(2*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, '0:720') UiImageButton(user.controlPanel, "holdButton", user.controlUI.startx+(2*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, user.controlUI.normal24, user.controlUI.hover24, user.controlUI.press24, "holdUnit") --Debug("Next") drawFrame(user.controlPanel, user.controlUI.startx+(3*(user.controlUI.width+user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall) UiImage(user.controlPanel, "image", user.controlUI.startx+(3*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, '0:704') UiImageButton(user.controlPanel, "nextButton", user.controlUI.startx+(3*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, user.controlUI.normal24, user.controlUI.hover24, user.controlUI.press24, "nextUnit") --Debug("Inv") drawFrame(user.controlPanel, user.controlUI.startx+(4*(user.controlUI.width+user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall) UiImage(user.controlPanel, "image", user.controlUI.startx+(4*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, '0:717') UiImageButton(user.controlPanel, "invButton", user.controlUI.startx+(4*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, user.controlUI.normal24, user.controlUI.hover24, user.controlUI.press24, "showUnitInventory 1") --Debug("Stats") drawFrame(user.controlPanel, user.controlUI.startx+(5*(user.controlUI.width+user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall) UiImage(user.controlPanel, "image", user.controlUI.startx+(5*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, '0:705') UiImageButton(user.controlPanel, "statsButton", user.controlUI.startx+(5*(user.controlUI.width+user.controlUI.paddingx))+1, user.controlUI.starty+1, user.controlUI.width-1, user.controlUI.heightSmall-1, user.controlUI.normal24, user.controlUI.hover24, user.controlUI.press24, "showUnitStatus") end function drawInventoryAccessPanel(user, unit) -- belt panel --Debug("Belt1") drawInventoryButton(user, user.controlPanel, unit, "belt_1", user.controlUI.startx + (2 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy, user.controlUI.width, user.controlUI.heightBig) --Debug("Belt2") drawInventoryButton(user, user.controlPanel, unit, "belt_2", user.controlUI.startx + (3 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy, user.controlUI.width, user.controlUI.heightBig) --Debug("Belt3") drawInventoryButton(user, user.controlPanel, unit, "belt_3", user.controlUI.startx + (4 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy, user.controlUI.width, user.controlUI.heightBig) --Debug("Belt4") drawInventoryButton(user, user.controlPanel, unit, "belt_4", user.controlUI.startx + (5 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty + user.controlUI.heightSmall + user.controlUI.paddingy, user.controlUI.width, user.controlUI.heightBig) --Debug("LHand") -- left hand drawInventoryButton(user, user.controlPanel, unit, "l_hand", user.controlUI.startx + user.controlUI.width + user.controlUI.paddingx, user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall + user.controlUI.paddingy + user.controlUI.heightBig) --Debug("RHand") -- right hand drawInventoryButton(user, user.controlPanel, unit, "r_hand", user.controlUI.startx + (6 * (user.controlUI.width + user.controlUI.paddingx)), user.controlUI.starty, user.controlUI.width, user.controlUI.heightSmall + user.controlUI.paddingy + user.controlUI.heightBig) end function drawInventoryButton(user, windowId, unit, location, x, y, w, h) drawFrame(windowId, x, y, w, h) drawInventoryImage(user, windowId, unit, location, x+1, y+1, w-1, h-1) end function drawInventoryImage(user, windowId, unit, location, x, y, w, h) local object local sprite --Debug ("Location: %s X,Y: %d, %d W,H: %d,%d", location, x, y, w, h) -- clear existing button if it exists if (user.controlButtons[location].button ~= 0) then UiDelete(user.controlButtons[location].button) UiDelete(user.controlButtons[location].image) user.controlButtons[location].button = 0 user.controlButtons[location].image = 0 end -- get the appropriate sprite if (unit.paperDoll[location] and unit.paperDoll[location] ~= 0) then Debug("%d: ", unit.paperDoll[location]) object = GetObjectById(unit.paperDoll[location]) if (object) then sprite = object.spriteId else Debug("Object %d lost from unit %d container", unit.paperDoll[location], unit.id) unit.paperDoll[location] = 0 end if (sprite == nil) then sprite = '12071:448' Debug("Nil Sprite") end else sprite = '12071:448' end user.controlButtons[location].image = UiImage(windowId, location.."_image", x+math.floor((w - user.controlUI.width) / 2), y+math.floor((h - user.controlUI.heightBig) / 2), user.controlUI.width-2, user.controlUI.heightBig-2, sprite) user.controlButtons[location].button = UiImageButton(windowId, location.."_button", x, y, w, h, user.controlUI["normal"..(h-1)], user.controlUI["hover"..(h-1)], user.controlUI["press"..(h-1)], "useInventoryItem "..location.." 0") end -- round -- rounds num -- Args: -- num - number to round -- idp - decimal places, 0 - whole number function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end