Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/session.js
Show First 20 Lines • Show All 1,023 Lines • ▼ Show 20 Lines | for (let ent of panelEnts) | ||||
let template = GetTemplateData(panelEntState.template); | let template = GetTemplateData(panelEntState.template); | ||||
let panelEnt = g_PanelEntities.find(pEnt => ent == pEnt.ent); | let panelEnt = g_PanelEntities.find(pEnt => ent == pEnt.ent); | ||||
if (!panelEnt) | if (!panelEnt) | ||||
{ | { | ||||
panelEnt = { | panelEnt = { | ||||
"ent": ent, | "ent": ent, | ||||
"player": panelEntState.player, | |||||
"tooltip": undefined, | "tooltip": undefined, | ||||
"sprite": "stretched:session/portraits/" + template.icon, | "sprite": "stretched:session/portraits/" + template.icon | ||||
}; | |||||
if (panelEntState.hitpoints) | |||||
panelEnt.health = { | |||||
"maxHitpoints": undefined, | "maxHitpoints": undefined, | ||||
"currentHitpoints": panelEntState.hitpoints, | "currentHitpoints": panelEntState.hitpoints, | ||||
"previousHitpoints": undefined | "previousHitpoints": undefined | ||||
}; | }; | ||||
if (panelEntState.capturePoints) | |||||
panelEnt.capture = { | |||||
"maxCapturePoints": undefined, | |||||
"currentCapturePoints": panelEntState.capturePoints, | |||||
"previousCapturePoints": undefined | |||||
}; | |||||
g_PanelEntities.push(panelEnt); | g_PanelEntities.push(panelEnt); | ||||
} | } | ||||
panelEnt.tooltip = createPanelEntityTooltip(panelEntState, template); | panelEnt.tooltip = createPanelEntityTooltip(panelEntState, template); | ||||
panelEnt.previousHitpoints = panelEnt.currentHitpoints; | if (panelEnt.health) | ||||
panelEnt.currentHitpoints = panelEntState.hitpoints; | panelEnt.health = { | ||||
panelEnt.maxHitpoints = panelEntState.maxHitpoints; | "previousHitpoints": panelEnt.health.currentHitpoints, | ||||
"currentHitpoints": panelEntState.hitpoints, | |||||
"maxHitpoints": panelEntState.maxHitpoints | |||||
}; | |||||
if (panelEnt.capture) | |||||
panelEnt.capture = { | |||||
"previousCapturePoints": panelEnt.capture.currentCapturePoints, | |||||
"currentCapturePoints": panelEntState.capturePoints, | |||||
"maxCapturePoints": panelEntState.maxCapturePoints | |||||
}; | |||||
} | } | ||||
let panelEntIndex = ent => g_PanelEntityOrder.findIndex(entClass => | let panelEntIndex = ent => g_PanelEntityOrder.findIndex(entClass => | ||||
GetEntityState(ent).identity.classes.indexOf(entClass) != -1); | GetEntityState(ent).identity.classes.indexOf(entClass) != -1); | ||||
g_PanelEntities = g_PanelEntities.sort((panelEntA, panelEntB) => panelEntIndex(panelEntA.ent) - panelEntIndex(panelEntB.ent)); | g_PanelEntities = g_PanelEntities.sort((panelEntA, panelEntB) => panelEntIndex(panelEntA.ent) - panelEntIndex(panelEntB.ent)); | ||||
} | } | ||||
function createPanelEntityTooltip(panelEntState, template) | function createPanelEntityTooltip(panelEntState, template) | ||||
{ | { | ||||
let getPanelEntNameTooltip = panelEntState => "[font=\"sans-bold-16\"]" + template.name.specific + "[/font]"; | let getPanelEntNameTooltip = panelEntState => "[font=\"sans-bold-16\"]" + template.name.specific + "[/font]"; | ||||
return [ | return [ | ||||
getPanelEntNameTooltip, | getPanelEntNameTooltip, | ||||
getCurrentHealthTooltip, | getCurrentHealthTooltip, | ||||
getCurrentCaptureTooltip, | |||||
getAttackTooltip, | getAttackTooltip, | ||||
getArmorTooltip, | getArmorTooltip, | ||||
getEntityTooltip, | getEntityTooltip, | ||||
getAurasTooltip | getAurasTooltip | ||||
].map(tooltip => tooltip(panelEntState)).filter(tip => tip).join("\n"); | ].map(tooltip => tooltip(panelEntState)).filter(tip => tip).join("\n"); | ||||
} | } | ||||
function displayPanelEntities() | function displayPanelEntities() | ||||
Show All 17 Lines | for (let displayIndex = 0; displayIndex < Math.min(g_PanelEntities.length, buttons.length); ++displayIndex) | ||||
// Find the first unused slot if new, otherwise reuse previous. | // Find the first unused slot if new, otherwise reuse previous. | ||||
let slot = panelEnt.slot === undefined ? | let slot = panelEnt.slot === undefined ? | ||||
buttons.findIndex(button => button.hidden) : | buttons.findIndex(button => button.hidden) : | ||||
panelEnt.slot; | panelEnt.slot; | ||||
let panelEntButton = Engine.GetGUIObjectByName("panelEntityButton[" + slot + "]"); | let panelEntButton = Engine.GetGUIObjectByName("panelEntityButton[" + slot + "]"); | ||||
panelEntButton.tooltip = panelEnt.tooltip; | panelEntButton.tooltip = panelEnt.tooltip; | ||||
updateGUIStatusBar("panelEntityHealthBar[" + slot + "]", panelEnt.currentHitpoints, panelEnt.maxHitpoints); | if (panelEnt.health) | ||||
{ | |||||
Engine.GetGUIObjectByName("panelEntityHealthSection[" + slot + "]").hidden = false; | |||||
updateGUIStatusBar("panelEntityHealthBar[" + slot + "]", panelEnt.health.currentHitpoints, panelEnt.health.maxHitpoints); | |||||
} | |||||
if (panelEnt.capture) | |||||
{ | |||||
Engine.GetGUIObjectByName("panelEntityCaptureSection[" + slot + "]").hidden = false; | |||||
let setCaptureBarPart = function(playerID, startSize) { | |||||
let unitCaptureBar = Engine.GetGUIObjectByName("panelEntity[" + slot + "].CaptureBar[" + playerID + "]"); | |||||
let sizeObj = unitCaptureBar.size; | |||||
sizeObj.rleft = startSize; | |||||
let size = 100 * Math.max(0, Math.min(1, panelEnt.capture.currentCapturePoints[playerID] / panelEnt.capture.maxCapturePoints)); | |||||
sizeObj.rright = startSize + size; | |||||
unitCaptureBar.size = sizeObj; | |||||
unitCaptureBar.sprite = "color:" + rgbToGuiColor(g_DisplayedPlayerColors[playerID], 128); | |||||
unitCaptureBar.hidden = false; | |||||
return startSize + size; | |||||
}; | |||||
// first handle the owner's points, to keep those points on the left for clarity | |||||
let size = setCaptureBarPart(panelEnt.player, 0); | |||||
for (let i in panelEnt.capture.currentCapturePoints) | |||||
if (i != panelEnt.player) | |||||
size = setCaptureBarPart(i, size); | |||||
} | |||||
if (panelEnt.slot === undefined) | if (panelEnt.slot === undefined) | ||||
{ | { | ||||
let panelEntImage = Engine.GetGUIObjectByName("panelEntityImage[" + slot + "]"); | let panelEntImage = Engine.GetGUIObjectByName("panelEntityImage[" + slot + "]"); | ||||
panelEntImage.sprite = panelEnt.sprite; | panelEntImage.sprite = panelEnt.sprite; | ||||
panelEntButton.hidden = false; | panelEntButton.hidden = false; | ||||
panelEnt.slot = slot; | panelEnt.slot = slot; | ||||
} | } | ||||
// If the health of the panelEnt changed since the last update, trigger the animation. | // If the health of the panelEnt changed since the last update, trigger the animation. | ||||
if (panelEnt.previousHitpoints > panelEnt.currentHitpoints) | if (panelEnt.health && panelEnt.health.previousHitpoints > panelEnt.health.currentHitpoints) | ||||
startColorFade("panelEntityHitOverlay[" + slot + "]", 100, 0, | |||||
colorFade_attackUnit, true, smoothColorFadeRestart_attackUnit); | |||||
// If the capture points of the panelEnt changed since the last update, trigger the animation. | |||||
if (panelEnt.capture && panelEnt.capture.previousCapturePoints[panelEnt.player] > panelEnt.capture.currentCapturePoints[panelEnt.player]) | |||||
startColorFade("panelEntityHitOverlay[" + slot + "]", 100, 0, | startColorFade("panelEntityHitOverlay[" + slot + "]", 100, 0, | ||||
colorFade_attackUnit, true, smoothColorFadeRestart_attackUnit); | colorFade_attackUnit, true, smoothColorFadeRestart_attackUnit); | ||||
// TODO: Instead of instant position changes, animate button movement. | // TODO: Instead of instant position changes, animate button movement. | ||||
setPanelObjectPosition(panelEntButton, displayIndex, buttons.length); | setPanelObjectPosition(panelEntButton, displayIndex, buttons.length); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 589 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator