-
Notifications
You must be signed in to change notification settings - Fork 0
/
SatisfactionMeter.gd
41 lines (33 loc) · 1.6 KB
/
SatisfactionMeter.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extends Control
var asteroid_orig_pos : Vector2
var overall_orig_pos : Vector2
func _ready():
asteroid_orig_pos = $AsteroidSatisfactionMeterSprite.position
overall_orig_pos = $SatisfactionMeterSprite.position
$AsteroidSatisfactionMeterSprite.set_region(true)
$SatisfactionMeterSprite.set_region(true)
func set_progress_meter():
var meter = $SatisfactionMeterSprite
var ts = meter.texture.get_size()
var gjc = GameState.good_journey_count()
var unlock_pct = float(gjc) / GameState.UNLOCK_THRESHOLD if gjc > 0 else 0.0
var new_height = ts.y * unlock_pct
var offset = ts.y - new_height
meter.set_region_rect(Rect2(0, offset, ts.x, new_height))
meter.position.y = overall_orig_pos.y + offset/2
$ProgressCount.text = '%d/%d' % [gjc, GameState.UNLOCK_THRESHOLD]
func set_asteroid_meter(asteroid):
var meter = $AsteroidSatisfactionMeterSprite
var ts = meter.texture.get_size()
var new_height = ts.y * (GameState.asteroid_satisfaction[asteroid.name] / 100)
var offset = ts.y - new_height
meter.set_region_rect(Rect2(0, offset, ts.x, new_height))
meter.position.y = asteroid_orig_pos.y + offset/2
$AsteroidMeterValue.text = "%.2f%%" % GameState.asteroid_satisfaction[asteroid.name]
$AsteroidMeterLabel.text = '%s Satisfaction' % asteroid.name.replace('Asteroid', '')
func on_asteroid_change(_from, _to):
set_asteroid_meter(GameState.current_asteroid)
func on_new_dropoff(dropoff, _travel_time, _travel_score):
# Should ensure the satisfaction value is in its final state
call_deferred('set_progress_meter')
call_deferred('set_asteroid_meter', dropoff.get_asteroid())