Skip to content

Commit

Permalink
fix: fix health bar overflowing if max health is higher than 100
Browse files Browse the repository at this point in the history
  • Loading branch information
Notexe committed Mar 3, 2024
1 parent 4d38518 commit 31d0da8
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 97 deletions.
21 changes: 18 additions & 3 deletions content/chunk0/gameessentialbase.entity.patch.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"Height": { "type": "float32", "value": 1 },
"Width": { "type": "float32", "value": 1 }
},
"events": { "RequestColours": { "GetData": ["cafea8f9b3707ba1", "cafe6e40d206cd7a"] } }
"events": { "RequestData": { "GetData": ["cafea8f9b3707ba1", "cafe6e40d206cd7a"] } }
}
]
},
Expand All @@ -103,8 +103,11 @@
"factory": "[modules:/zhm5healthsoundcontroller.class].pc_entitytype",
"blueprint": "[modules:/zhm5healthsoundcontroller.class].pc_entityblueprint",
"events": {
"CurrentHealth": { "SetHealth": ["cafef77f80f5f691"] },
"Died": { "SetHealth": [{ "ref": "cafef77f80f5f691", "value": { "type": "float32", "value": 0 } }] }
"CurrentHealth": { "SetTextHealth": ["cafef77f80f5f691"], "GetHealth": ["cafea104c0198b1a"] },
"Died": {
"SetTextHealth": [{ "ref": "cafef77f80f5f691", "value": { "type": "float32", "value": 0 } }],
"SetBarHealth": [{ "ref": "cafef77f80f5f691", "value": { "type": "float32", "value": 0 } }]
}
}
}
]
Expand Down Expand Up @@ -227,6 +230,18 @@
"events": { "EventOccurred": { "GetData": ["cafea8f9b3707ba1", "cafe6e40d206cd7a"] } }
}
]
},
{
"AddEntity": [
"cafea104c0198b1a",
{
"parent": "cafeba446945a84b",
"name": "HitmanHealthModifier",
"factory": "[modules:/zhm5hitmanhealthmodifier.class].pc_entitytype",
"blueprint": "[modules:/zhm5hitmanhealthmodifier.class].pc_entityblueprint",
"events": { "OnGetHealth": { "SetBarHealth": ["cafef77f80f5f691"] } }
}
]
}
],
"patchVersion": 6
Expand Down
Binary file modified content/chunk0/scaleform/001D0947392E2DD6.GFXF
Binary file not shown.
Binary file modified content/chunk0/scaleform/003F45DD25EEE393.UICB
Binary file not shown.
13 changes: 6 additions & 7 deletions source/animate/HealthBar/DOMDocument.xml

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions source/animate/HealthBar/LIBRARY/DebugTextView.xml

This file was deleted.

2 changes: 1 addition & 1 deletion source/animate/HealthBar/LIBRARY/HealthBarBorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</FillStyle>
</fills>
<edges>
<Edge fillStyle1="1" edges="!532 0|532 3602!532 3602|0 3602!0 3602|0 0!0 0|532 0!512 20|20 20!20 20|20 3582!20 3582|512 3582!512 3582|512 20"/>
<Edge fillStyle1="1" edges="!512 20|20 20!20 20|20 3582!20 3582|512 3582!512 3582|512 20!532 0|532 3602!532 3602|0 3602!0 3602|0 0!0 0|532 0"/>
<Edge cubics="!512 20(;512,20 20,20 20,20q512 20 20 20);"/>
<Edge cubics="!20 20(;20,20 20,3582 20,3582q20 20 20 3582);"/>
<Edge cubics="!20 3582(;20,3582 512,3582 512,3582q20 3582 512 3582);"/>
Expand Down
2 changes: 1 addition & 1 deletion source/animate/HealthBar/LIBRARY/HealthBarTextBorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</FillStyle>
</fills>
<edges>
<Edge fillStyle1="1" edges="!512 20S2|20 20!20 20|20 513!20 513|512 513!512 513|512 20!0 0|532 0!532 0|532 533!532 533|0 533!0 533|0 0"/>
<Edge fillStyle1="1" edges="!0 0S2|532 0!532 0|532 533!532 533|0 533!0 533|0 0!512 20|20 20!20 20|20 513!20 513|512 513!512 513|512 20"/>
<Edge cubics="!0 0(;0,0 532,0 532,0q0 0 532 0);"/>
<Edge cubics="!532 0(;532,0 532,533 532,533q532 0 532 533);"/>
<Edge cubics="!532 533(;532,533 0,533 0,533q532 533 0 533);"/>
Expand Down
Binary file modified source/animate/HealthBar/bin/SymDepend.cache
Binary file not shown.
Binary file modified source/bin/HealthBar.swf
Binary file not shown.
Binary file modified source/lib/HealthBar.swc
Binary file not shown.
92 changes: 36 additions & 56 deletions source/src/healthbar/HealthBar.as
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import common.BaseControl;

import flash.events.Event;
import flash.events.TimerEvent;

import flash.geom.ColorTransform;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.utils.Timer;

import scaleform.gfx.Extensions;

public class HealthBar extends BaseControl {

private var m_healthBarView:HealthBarView = new HealthBarView();
private var m_debugTextView:DebugTextView = new DebugTextView();
private var m_healthBarColourTransform:ColorTransform = new ColorTransform();
private var m_infectedColourTransform:ColorTransform = new ColorTransform();
private var m_currentHealth:Number;
private var m_currentHealthBar:Number;
private var m_isInfected:Boolean = false;
private var m_lowHealthColour:uint;
private var m_mediumHealthColour:uint;
Expand All @@ -26,25 +26,33 @@ public class HealthBar extends BaseControl {
private var checkCallEntityTimer:Timer;

// Debug thing
private var healthUpdateTimer:Timer;
private var healthChangeDirection:int = 1;
private var mainColoursObjectDebug:Object;
private var secondaryColoursObjectDebug:Object;

private var m_debugTextField:TextField;

public function HealthBar() {
Extensions.setEdgeAAMode(m_healthBarView, Extensions.EDGEAA_OFF)

// Debug text setup
m_debugTextView.DebugText.visible = false;
m_debugTextView.scaleX = 1.5;
m_debugTextView.scaleY = 1.5;
m_debugTextView.x = 300;
m_debugTextView.y = -250;
m_debugTextField = new TextField();
m_debugTextField.visible = false;
m_debugTextField.wordWrap = true;
m_debugTextField.multiline = true;
m_debugTextField.width = 400;
m_debugTextField.height = 500;
m_debugTextField.x = 300;
m_debugTextField.y = -250;

var m_debugTextFieldFormat:TextFormat = new TextFormat();
m_debugTextFieldFormat.size = 18;
m_debugTextFieldFormat.font = "$medium";
m_debugTextFieldFormat.color = 0xffffff
m_debugTextField.defaultTextFormat = m_debugTextFieldFormat;

WaitForCallEntity();

addChild(m_healthBarView)
addChild(m_debugTextView);
addChild(m_healthBarView);
addChild(m_debugTextField);
}

private function WaitForCallEntity():void {
Expand All @@ -57,12 +65,12 @@ public class HealthBar extends BaseControl {
if (CallEntity != null) {
checkCallEntityTimer.stop();
checkCallEntityTimer.removeEventListener(TimerEvent.TIMER, checkCallEntity);
send_RequestColours();
send_RequestData();
}
}

public function send_RequestColours():void {
sendEvent("RequestColours");
public function send_RequestData():void {
sendEvent("RequestData");
}

public function MainColours(object:Object):void {
Expand All @@ -84,12 +92,15 @@ public class HealthBar extends BaseControl {
secondaryColoursObjectDebug = object.SecondaryColours;
}

public function SetHealth(health:Number):void {
m_currentHealth = health;
m_healthBarView.HealthBarText.text = String(Math.round(health));
public function SetBarHealth(health:Number):void {
m_currentHealthBar = health;
UpdateHealth()
}

public function SetTextHealth(health:Number):void {
m_healthBarView.HealthBarText.text = String(Math.round(health));
}

public function SetInfected(isInfected:Boolean):void {
m_isInfected = isInfected;

Expand All @@ -103,8 +114,7 @@ public class HealthBar extends BaseControl {
}

private function UpdateHealth():void {
var m_maxHealth:Number = 100;
m_healthBarView.HealthBarInner.scaleY = m_currentHealth / m_maxHealth;
m_healthBarView.HealthBarInner.scaleY = m_currentHealthBar;
UpdateHealthBarColour();
}

Expand All @@ -115,8 +125,7 @@ public class HealthBar extends BaseControl {
return;
}

var m_maxHealth:Number = 100;
var healthRatio:Number = m_currentHealth / m_maxHealth;
var healthRatio:Number = m_currentHealthBar;

var low:uint, medium:uint, full:uint;

Expand Down Expand Up @@ -203,18 +212,14 @@ public class HealthBar extends BaseControl {
m_infectedColour = colourValue;
}

public function set Debug(health:Number):void {
SetHealth(health);
}

public function set DebugMode(bool:Boolean):void {
if (bool) {
addEventListener(Event.ENTER_FRAME, UpdateDebugText);
m_debugTextView.DebugText.visible = true;
m_debugTextField.visible = true;
}
else {
removeEventListener(Event.ENTER_FRAME, UpdateDebugText);
m_debugTextView.DebugText.visible = false;
m_debugTextField.visible = false;
}
}

Expand All @@ -228,7 +233,7 @@ public class HealthBar extends BaseControl {

private function UpdateDebugText(e:Event):void {
var debugInfo:String = "";
debugInfo += "Current Health: " + Math.round(m_currentHealth) + "\n";
debugInfo += "Current Health: " + m_healthBarView.HealthBarText.text + "\n";
debugInfo += "Is Infected: " + m_isInfected + "\n";
if (mainColoursObjectDebug != null) {
debugInfo += "Main colours:\n";
Expand Down Expand Up @@ -261,32 +266,7 @@ public class HealthBar extends BaseControl {
debugInfo += "\tHealthBarBorderColour: \n";
}

m_debugTextView.DebugText.text = debugInfo;
m_debugTextView.DebugText.visible = true;
m_debugTextView.DebugText.wordWrap = true;
m_debugTextView.DebugText.multiline = true;
}

public function ToggleDebug():void {
if (healthUpdateTimer != null) {
healthUpdateTimer.stop();
healthUpdateTimer.removeEventListener(TimerEvent.TIMER, onDebugToggled);
healthUpdateTimer = null;
} else {
healthUpdateTimer = new Timer(10);
healthUpdateTimer.addEventListener(TimerEvent.TIMER, onDebugToggled);
healthUpdateTimer.start();
}
}

private function onDebugToggled(event:TimerEvent):void {
m_currentHealth += healthChangeDirection * 1;
m_currentHealth = Math.max(0, Math.min(100, m_currentHealth));
SetHealth(m_currentHealth);

if (m_currentHealth >= 100 || m_currentHealth <= 0) {
healthChangeDirection *= -1;
}
m_debugTextField.text = debugInfo;
}

}
Expand Down

0 comments on commit 31d0da8

Please sign in to comment.