Import current DEMON v0.19 source, assets and development handoff
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
extends RefCounted
|
||||
var w
|
||||
var g
|
||||
var index=-1
|
||||
var elapsed=0.0
|
||||
var anchor=Vector2.ZERO
|
||||
var active=false
|
||||
var left_down=false
|
||||
var strip: Control
|
||||
var label: Label
|
||||
var thickness=38.0
|
||||
var hold_ring: Control
|
||||
func setup(workshop):
|
||||
w=workshop;g=w.g
|
||||
hold_ring=preload("res://hold_indicator.gd").new();g.hud.add_child(hold_ring);hold_ring.name="HoldToMoveProgress";hold_ring.mouse_filter=Control.MOUSE_FILTER_IGNORE;hold_ring.z_index=101;hold_ring.hide()
|
||||
strip=Control.new();strip.name="DragDeleteStrip";g.hud.add_child(strip);strip.mouse_filter=Control.MOUSE_FILTER_IGNORE;strip.z_index=100
|
||||
var background=TextureRect.new();strip.add_child(background);background.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT);background.mouse_filter=Control.MOUSE_FILTER_IGNORE
|
||||
var gradient=Gradient.new();gradient.set_color(0,Color(.85,.015,.01,0));gradient.set_color(1,Color(.85,.015,.01,.94))
|
||||
var texture=GradientTexture2D.new();texture.gradient=gradient;texture.fill_from=Vector2(0,0);texture.fill_to=Vector2(0,1);background.texture=texture
|
||||
label=g.label("",16,Color.WHITE);strip.add_child(label);label.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT);label.horizontal_alignment=HORIZONTAL_ALIGNMENT_CENTER;label.vertical_alignment=VERTICAL_ALIGNMENT_CENTER
|
||||
strip.hide()
|
||||
func arm(station,point):
|
||||
if not w.build_mode or not w.is_free(w.stations[station]):return
|
||||
index=station;elapsed=0;anchor=point
|
||||
hold_ring.position=point+Vector2(23,-23);hold_ring.progress=0;hold_ring.show()
|
||||
func cancel():
|
||||
index=-1;elapsed=0;active=false
|
||||
if is_instance_valid(strip):strip.hide()
|
||||
if is_instance_valid(hold_ring):hold_ring.hide()
|
||||
func hover_delete(point):return point.y>=g.get_viewport().get_visible_rect().size.y-thickness
|
||||
func update(dt):
|
||||
var size=g.get_viewport().get_visible_rect().size
|
||||
thickness=clampf(DisplayServer.screen_get_dpi()/2.54*size.y/maxf(1,DisplayServer.window_get_size().y),28,64)*1.5625
|
||||
strip.position=Vector2(0,size.y-thickness);strip.size=Vector2(size.x,thickness)
|
||||
if not w.build_mode:cancel();return
|
||||
if active:
|
||||
label.text="Перетащи сюда для удаления · возврат %d золота"%int(w.PRICES[w.pending]/2)
|
||||
return
|
||||
if index<0:return
|
||||
if not left_down or w.pointer_position.distance_to(anchor)>18:cancel();return
|
||||
elapsed+=dt
|
||||
hold_ring.position=w.pointer_position+Vector2(23,-23);hold_ring.progress=elapsed
|
||||
if elapsed>=1:
|
||||
var picked=index;w.selected=picked;w.begin_move()
|
||||
if w.moving==picked:active=true;strip.show()
|
||||
hold_ring.hide()
|
||||
func release(point):
|
||||
# Releasing the pickup hold leaves the device attached to the cursor.
|
||||
if active:
|
||||
if hover_delete(point):confirm(point)
|
||||
return true
|
||||
cancel();return false
|
||||
func confirm(point):
|
||||
if not active:return false
|
||||
var station=w.moving;var trash=hover_delete(point)
|
||||
if trash:
|
||||
w.cancel_placement(false);w.selected=station;w.delete_selected();w.catalogue.visible=w.build_mode
|
||||
else:
|
||||
if g.get_viewport().gui_get_hovered_control()!=null:return true
|
||||
w.place(w.snap_to_grid(w.ground_point(point),w.pending,w.pending_turns))
|
||||
return true
|
||||
Reference in New Issue
Block a user