From e0a6d318be7570152eef053ad0dbc67608a981de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 10 Jul 2020 14:46:13 +0200 Subject: add check boxes --- Main.gd | 7 +++++++ Main.tscn | 21 +++++++++++++++++++++ Map.gd | 30 ++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Main.gd b/Main.gd index 36affaa..88af749 100644 --- a/Main.gd +++ b/Main.gd @@ -9,11 +9,18 @@ onready var Camera : Camera2D = $ViewportContainer/Viewport/Camera func _ready(): UI.get_node("rotate").connect("pressed", Map, "on_rotate") + UI.get_node("LOS").connect("pressed", self, "on_toggle") + UI.get_node("Move").connect("pressed", self, "on_toggle") Map.connect("configure", Camera, "on_configure") Map.connect("hex_touched", self, "on_hex_touched") Camera.window = $ViewportContainer/Viewport.size + on_toggle() Map.on_rotate() +func on_toggle() -> void: + Map.config(UI.get_node("LOS").pressed, UI.get_node("Move").pressed) + Map.update() + func on_hex_touched(pos : Vector2, hex : Hex, key : int) -> void: UI.get_node("Info").set_text("\n(%d;%d)\n -> %s\n -> %d" % [int(pos.x), int(pos.y), hex.inspect(), key]) diff --git a/Main.tscn b/Main.tscn index 74aed48..84a9a7c 100644 --- a/Main.tscn +++ b/Main.tscn @@ -31,6 +31,27 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="LOS" type="CheckBox" parent="UI"] +margin_left = 30.0 +margin_top = 90.0 +margin_right = 83.0 +margin_bottom = 114.0 +pressed = true +text = "LOS" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Move" type="CheckBox" parent="UI"] +margin_left = 30.0 +margin_top = 140.0 +margin_right = 93.0 +margin_bottom = 164.0 +text = "Move" +__meta__ = { +"_edit_use_anchors_": false +} + [node name="ViewportContainer" type="ViewportContainer" parent="."] margin_left = 141.0 margin_top = 19.0 diff --git a/Map.gd b/Map.gd index 157aaca..b1859d0 100644 --- a/Map.gd +++ b/Map.gd @@ -24,6 +24,8 @@ var p1 : Vector2 var los : Array var move : Array var unit : Unit +var show_los : bool +var show_move : bool func _ready(): board = HexBoard.new() @@ -47,6 +49,10 @@ func get_tile(coords : Vector2, k : int) -> Tile: $Hexes.add_child(hex) return hex +func config(l : bool, m : bool) -> void: + show_los = l + show_move = m + func on_rotate() -> void: texture = load(MAPH if board.v else MAPV) var ts : Vector2 = texture.get_size() @@ -74,7 +80,7 @@ func on_rotate() -> void: $Hexes.remove_child(hex) hex.queue_free() reset() - update_los() + update() func on_mouse_move() -> void: if drag != null: @@ -97,7 +103,7 @@ func on_mouse_1(pressed : bool) -> void: drag.position = board.center_of(coords) if drag == $Tank: p0 = coords else: p1 = coords - update_los() + update() else: drag.position = board.center_of(prev) drag = null @@ -109,18 +115,22 @@ func on_mouse_2(pressed : bool) -> void: var hex : Hex = board.get_tile(coords) hex.change() notify(hex, pos, coords) - update_los() + update() func notify(hex : Hex, pos : Vector2, coords : Vector2) -> void: if board.is_on_map(coords): emit_signal("hex_touched",pos, hex, board.key(coords)) else: emit_signal("hex_touched", pos, hex, -1) -func update_los() -> void: +func update() -> void: + $Los.visible = false for hex in los: hex.show_los(false) - var ct : Vector2 = board.line_of_sight(p0, p1, los) - $Los.setup($Tank.position, $Target.position, ct) - for hex in los: hex.show_los(true) + if show_los: + $Los.visible = true + var ct : Vector2 = board.line_of_sight(p0, p1, los) + $Los.setup($Tank.position, $Target.position, ct) + for hex in los: hex.show_los(true) for hex in move: hex.show_move(false) - # warning-ignore:return_value_discarded - board.possible_moves(unit, board.get_tile(p0), move) - for hex in move: hex.show_move(true) + if show_move: + # warning-ignore:return_value_discarded + board.possible_moves(unit, board.get_tile(p0), move) + for hex in move: hex.show_move(true) -- cgit v1.1-2-g2b99