I had renamed it to "ProgressBar", but the same thing
ProgressBar.agc
Type tProgressBar
id
spr_back
spr_front
spr_border
show_border
is_vertical
max_range
caption as string
caption_align
txt_caption
EndType
Global gProgressBar as tProgressBar[]
Function ProgressBar_Create(id, x, y, width, height, vertical, range, caption as string)
hb as tProgressBar
hb.id=id
hb.is_vertical=vertical
hb.max_range=range
hb.spr_border = CreateSprite(0)
SetSpritePosition(hb.spr_border, x-1, y-1)
SetSpriteSize(hb.spr_border, width+2, height+2)
SetSpriteColor(hb.spr_border, 0, 0, 0, 255)
FixSpriteToScreen(hb.spr_border, 1)
hb.spr_back = CreateSprite(0)
SetSpritePosition(hb.spr_back, x, y)
SetSpriteSize(hb.spr_back, width, height)
SetSpriteColor(hb.spr_back, 255, 255, 255, 125)
FixSpriteToScreen(hb.spr_back, 1)
hb.spr_front = CreateSprite(0)
SetSpritePosition(hb.spr_front, x, y)
SetSpriteSize(hb.spr_front, width, height)
SetSpriteColor(hb.spr_front, 255, 0, 0, 125)
FixSpriteToScreen(hb.spr_front, 1)
hb.txt_caption=CreateText(caption)
hb.caption=caption
hb.caption_align=1
SetTextAlignment(hb.txt_caption, 1)
FixTextToScreen(hb.txt_caption, 1)
SetTextColor(hb.txt_caption, 255, 255, 255, 255)
if vertical
SetTextPosition(hb.txt_caption, x-1, y+height/2)
SetTextSize(hb.txt_caption, width)
SetTextAngle(hb.txt_caption, -90)
else
SetTextPosition(hb.txt_caption, x+width/2, y-1)
SetTextSize(hb.txt_caption, height)
SetTextAngle(hb.txt_caption, 0)
endif
gProgressBar.insertSorted(hb)
ProgressBar_SetCaption(id, caption)
EndFunction gProgressBar.length
// Internal Functions
// Public Functions
Function ProgressBar_Delete(id)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) : DeleteSprite(gProgressBar[index].spr_border) : endif
if GetSpriteExists(gProgressBar[index].spr_back) : DeleteSprite(gProgressBar[index].spr_back) : endif
if GetSpriteExists(gProgressBar[index].spr_front) : DeleteSprite(gProgressBar[index].spr_front) : endif
endif
EndFunction
Function ProgressBar_Hide(id, hide)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) and GetSpriteExists(gProgressBar[index].spr_back) and GetSpriteExists(gProgressBar[index].spr_front)
SetSpriteVisible(gProgressBar[index].spr_border, abs(hide-1))
SetSpriteVisible(gProgressBar[index].spr_back, abs(hide-1))
SetSpriteVisible(gProgressBar[index].spr_front, abs(hide-1))
SetSpriteActive(gProgressBar[index].spr_border, abs(hide-1))
SetSpriteActive(gProgressBar[index].spr_back, abs(hide-1))
SetSpriteActive(gProgressBar[index].spr_front, abs(hide-1))
endif
endif
EndFunction
// State Functions
Function ProgressBar_SetState(id, pos)
index as integer
bar_width as integer
bar_height as integer
new_width as integer
new_height as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_back)
bar_x as integer
bar_y as integer
bar_width=GetSpriteWidth(gProgressBar[index].spr_back)
bar_height=GetSpriteHeight(gProgressBar[index].spr_back)
new_width=0
new_height=0
if gProgressBar[index].is_vertical = 1
new_width = bar_width
new_height = bar_height*pos/gProgressBar[index].max_range
bar_x = GetSpriteX(gProgressBar[index].spr_back)
bar_y = GetSpriteY(gProgressBar[index].spr_back)
SetSpritePosition(gProgressBar[index].spr_front, bar_x, bar_y+bar_height-new_height)
else
new_width = bar_width*pos/gProgressBar[index].max_range
new_height = bar_height
endif
SetSpriteSize(gProgressBar[index].spr_front, new_width, new_height)
ProgressBar_SetCaption(id, gProgressBar[index].caption)
endif
endif
EndFunction
Function ProgressBar_GetState(id)
index as integer
bar_width as integer
bar_height as integer
front_width as integer
front_height as integer
max_Y as integer
min_Y as integer
max_X as integer
min_X as integer
percent as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_back)
bar_width=GetSpriteWidth(gProgressBar[index].spr_back)
bar_height=GetSpriteHeight(gProgressBar[index].spr_back)
front_width=GetSpriteWidth(gProgressBar[index].spr_front)
front_height=GetSpriteHeight(gProgressBar[index].spr_front)
if gProgressBar[index].is_vertical = 1
max_Y=GetSpriteY(gProgressBar[index].spr_back)+GetSpriteHeight(gProgressBar[index].spr_back)
min_Y=GetSpriteY(gProgressBar[index].spr_back)
percent=(GetSpriteHeight(gProgressBar[index].spr_front) / (max_Y-min_Y)) * gProgressBar[index].max_range
else
max_X=GetSpriteX(gProgressBar[index].spr_back)+GetSpriteWidth(gProgressBar[index].spr_back)
min_X=GetSpriteX(gProgressBar[index].spr_back)
percent=(GetSpriteWidth(gProgressBar[index].spr_front) / (max_X-min_X)) * gProgressBar[index].max_range
endif
endif
endif
EndFunction percent
// Size/Position Functions
Function ProgressBar_SetPosition(id, x, y)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) : SetSpritePosition(gProgressBar[index].spr_border, x-1, y-1) : endif
if GetSpriteExists(gProgressBar[index].spr_back) : SetSpritePosition(gProgressBar[index].spr_back, x, y) : endif
if GetSpriteExists(gProgressBar[index].spr_front) : SetSpritePosition(gProgressBar[index].spr_front, x, y) : endif
ProgressBar_SetCaptionAlign(id, gProgressBar[index].caption_align)
endif
EndFunction
// TODO: add ProgressBar_GetPosition
Function ProgressBar_SetSize(id, width, height)
old_state as integer
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) and GetSpriteExists(gProgressBar[index].spr_back) and GetSpriteExists(gProgressBar[index].spr_front)
old_state=ProgressBar_GetState(id)
SetSpriteSize(gProgressBar[index].spr_border, width+2, height+2)
SetSpriteSize(gProgressBar[index].spr_back, width, height)
SetSpriteSize(gProgressBar[index].spr_front, width, height)
//x as integer
//y as integer
//x = GetSpriteX(gProgressBar[index].spr_back)
//y = GetSpriteY(gProgressBar[index].spr_back)
//SetTextPosition(gProgressBar[index].txt_caption, x+width/2, y-2)
SetTextSize(gProgressBar[index].txt_caption, height)
ProgressBar_SetCaptionAlign(id, gProgressBar[index].caption_align)
ProgressBar_SetState(id, old_state)
endif
endif
EndFunction
// TODO: add ProgressBar_GetSize
Function ProgressBar_SetMax(id, max)
old_state as integer
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) and GetSpriteExists(gProgressBar[index].spr_back) and GetSpriteExists(gProgressBar[index].spr_front)
old_state=ProgressBar_GetState(id)
gProgressBar[index].max_range=max
ProgressBar_SetState(id, old_state)
endif
endif
EndFunction
Function ProgressBar_GetMax(id)
index as integer
max as integer
index = gProgressBar.find(id)
if index<>-1
max=gProgressBar[index].max_range
endif
EndFunction max
Function ProgressBar_SetColor(id, border, back, front, alpha)
index as integer
r as integer
g as integer
b as integer
index = gProgressBar.find(id)
if index<>-1
if GetSpriteExists(gProgressBar[index].spr_border) and GetSpriteExists(gProgressBar[index].spr_back) and GetSpriteExists(gProgressBar[index].spr_front)
r=GetColorRed(border)
g=GetColorRed(border)
b=GetColorRed(border)
SetSpriteColor(gProgressBar[index].spr_border, r, g, b, alpha)
r=GetColorRed(back)
g=GetColorRed(back)
b=GetColorRed(back)
SetSpriteColor(gProgressBar[index].spr_back, r, g, b, alpha)
r=GetColorRed(front)
g=GetColorRed(front)
b=GetColorRed(front)
SetSpriteColor(gProgressBar[index].spr_front, r, g, b, alpha)
endif
endif
EndFunction
// Caption Functions
Function ProgressBar_SetCaption(id, caption as string)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetTextExists(gProgressBar[index].txt_caption)
gProgressBar[index].caption=caption
caption=ReplaceString(caption, "[c]", str(ProgressBar_GetState(id)), 1)
caption=ReplaceString(caption, "[m]", str(ProgressBar_GetMax(id)), 1)
SetTextString(gProgressBar[index].txt_caption, caption)
endif
endif
EndFunction
Function ProgressBar_SetCaptionColor(id, r, g, b, alpha)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetTextExists(gProgressBar[index].txt_caption)
SetTextColor(gProgressBar[index].txt_caption, r, g, b, alpha)
endif
endif
EndFunction
Function ProgressBar_SetCaptionSize(id, size)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetTextExists(gProgressBar[index].txt_caption)
SetTextSize(gProgressBar[index].txt_caption, size)
endif
endif
EndFunction
Function ProgressBar_SetCaptionAlign(id, align)
index as integer
index = gProgressBar.find(id)
if index<>-1
if GetTextExists(gProgressBar[index].txt_caption)
gProgressBar[index].caption_align=align
SetTextAlignment(gProgressBar[index].txt_caption, gProgressBar[index].caption_align)
width as integer
height as integer
x as integer
y as integer
width = GetSpriteWidth(gProgressBar[index].spr_back)
height = GetSpriteHeight(gProgressBar[index].spr_back)
x = GetSpriteX(gProgressBar[index].spr_back)
y = GetSpriteY(gProgressBar[index].spr_back)
if gProgressBar[index].is_vertical
SetTextSize(gProgressBar[index].txt_caption, width)
SetTextAngle(gProgressBar[index].txt_caption, -90)
Select gProgressBar[index].caption_align
Case 0
SetTextPosition(gProgressBar[index].txt_caption, x-1, y+height-5)
EndCase
Case 1
SetTextPosition(gProgressBar[index].txt_caption, x-1, y+height/2)
EndCase
Case 2
SetTextPosition(gProgressBar[index].txt_caption, x-1, y+5)
EndCase
EndSelect
else
SetTextSize(gProgressBar[index].txt_caption, height)
SetTextAngle(gProgressBar[index].txt_caption, 0)
Select gProgressBar[index].caption_align
Case 0
SetTextPosition(gProgressBar[index].txt_caption, x+5, y-1)
EndCase
Case 1
SetTextPosition(gProgressBar[index].txt_caption, x+width/2, y-1)
EndCase
Case 2
SetTextPosition(gProgressBar[index].txt_caption, x+width-5, y-1)
EndCase
EndSelect
endif
endif
endif
EndFunction
ProgressBar_Create(BAR_SHIP_HULL, (RES_WIDTH/2)-100, RES_HEIGHT-30, 200, 20, 0, 100, "Hull: [c]/[m]%")
ProgressBar_Create(BAR_SHIP_ARMOR, (RES_WIDTH/2)-100, RES_HEIGHT-55, 200, 20, 0, 100, "Armor: [c]/[m]%")
ProgressBar_Create(BAR_SHIP_SHIELD, (RES_WIDTH/2)-100, RES_HEIGHT-80, 200, 20, 0, 100, "Shield: [c]/[m]%")
ProgressBar_Create(BAR_SHIP_CARGO, (RES_WIDTH/2)-150, RES_HEIGHT-110, 20, 100, 1, 100, "Cargo Hold")
ProgressBar_Create(BAR_SHIP_ORE, (RES_WIDTH/2)-125, RES_HEIGHT-110, 20, 100, 1, 100, "Ore Hold")
ProgressBar_Create(BAR_SHIP_WARP, (RES_WIDTH/2)+105, RES_HEIGHT-110, 20, 100, 1, 100, "Warp")
ProgressBar_Create(BAR_SHIP_IMPULSE, (RES_WIDTH/2)+130, RES_HEIGHT-110, 20, 100, 1, 100, "Impulse")
Edit: [c]/[m] are placeholder to automatically insert "Current, Maximum" values
How that helps