Fixed screen issues
parent
b12f3dd14c
commit
bd35e3171f
12
Globals.gd
12
Globals.gd
|
@ -47,8 +47,16 @@ func DebugLabelAdd(text):
|
||||||
|
|
||||||
|
|
||||||
func ScreenToWorld(pos: Vector2, camera: Camera2D):
|
func ScreenToWorld(pos: Vector2, camera: Camera2D):
|
||||||
pos = pos - OS.get_window_safe_area().size * 0.5
|
# pos = pos - OS.get_window_safe_area().size * 0.5
|
||||||
return camera.offset + pos * camera.zoom
|
# pos = pos - get_viewport().size * 0.5
|
||||||
|
var project_size = Vector2(
|
||||||
|
ProjectSettings.get_setting("display/window/size/width"),
|
||||||
|
ProjectSettings.get_setting("display/window/size/height")
|
||||||
|
)
|
||||||
|
var window_size = OS.get_window_safe_area().size
|
||||||
|
var zoom_scale = window_size.x / window_size.x
|
||||||
|
pos = pos
|
||||||
|
return pos
|
||||||
|
|
||||||
|
|
||||||
func ScreenToHex(pos: Vector2, camera: Camera2D):
|
func ScreenToHex(pos: Vector2, camera: Camera2D):
|
||||||
|
|
|
@ -91,6 +91,7 @@ script = ExtResource( 7 )
|
||||||
[node name="UI" type="CanvasLayer" parent="Editor"]
|
[node name="UI" type="CanvasLayer" parent="Editor"]
|
||||||
|
|
||||||
[node name="Editor" type="VBoxContainer" parent="Editor/UI"]
|
[node name="Editor" type="VBoxContainer" parent="Editor/UI"]
|
||||||
|
visible = false
|
||||||
margin_left = 12.0
|
margin_left = 12.0
|
||||||
margin_top = 53.0
|
margin_top = 53.0
|
||||||
margin_right = 94.0
|
margin_right = 94.0
|
||||||
|
@ -370,10 +371,24 @@ margin_right = 498.0
|
||||||
margin_bottom = 27.0
|
margin_bottom = 27.0
|
||||||
text = "(0,0)"
|
text = "(0,0)"
|
||||||
|
|
||||||
[node name="TileType" type="Label" parent="World/UI/DebugContainer"]
|
[node name="ScreenCoord" type="Label" parent="World/UI/DebugContainer"]
|
||||||
margin_left = 502.0
|
margin_left = 502.0
|
||||||
margin_top = 13.0
|
margin_top = 13.0
|
||||||
margin_right = 525.0
|
margin_right = 590.0
|
||||||
|
margin_bottom = 27.0
|
||||||
|
text = "ScreenCoord: "
|
||||||
|
|
||||||
|
[node name="ScreenCoordValue" type="Label" parent="World/UI/DebugContainer"]
|
||||||
|
margin_left = 594.0
|
||||||
|
margin_top = 13.0
|
||||||
|
margin_right = 622.0
|
||||||
|
margin_bottom = 27.0
|
||||||
|
text = "(0,0)"
|
||||||
|
|
||||||
|
[node name="TileType" type="Label" parent="World/UI/DebugContainer"]
|
||||||
|
margin_left = 626.0
|
||||||
|
margin_top = 13.0
|
||||||
|
margin_right = 649.0
|
||||||
margin_bottom = 27.0
|
margin_bottom = 27.0
|
||||||
text = "Tile"
|
text = "Tile"
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -381,9 +396,9 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="TileTypeValue" type="Label" parent="World/UI/DebugContainer"]
|
[node name="TileTypeValue" type="Label" parent="World/UI/DebugContainer"]
|
||||||
margin_left = 529.0
|
margin_left = 653.0
|
||||||
margin_top = 13.0
|
margin_top = 13.0
|
||||||
margin_right = 563.0
|
margin_right = 687.0
|
||||||
margin_bottom = 27.0
|
margin_bottom = 27.0
|
||||||
text = "None"
|
text = "None"
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -391,8 +406,8 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="VSeparator" type="VSeparator" parent="World/UI/DebugContainer"]
|
[node name="VSeparator" type="VSeparator" parent="World/UI/DebugContainer"]
|
||||||
margin_left = 567.0
|
margin_left = 691.0
|
||||||
margin_right = 770.0
|
margin_right = 832.0
|
||||||
margin_bottom = 40.0
|
margin_bottom = 40.0
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
@ -400,7 +415,7 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Label2" type="Label" parent="World/UI/DebugContainer"]
|
[node name="Label2" type="Label" parent="World/UI/DebugContainer"]
|
||||||
margin_left = 774.0
|
margin_left = 836.0
|
||||||
margin_top = 13.0
|
margin_top = 13.0
|
||||||
margin_right = 978.0
|
margin_right = 978.0
|
||||||
margin_bottom = 27.0
|
margin_bottom = 27.0
|
||||||
|
|
|
@ -101,6 +101,9 @@ func generate():
|
||||||
generate_random_walk(size)
|
generate_random_walk(size)
|
||||||
extrude_island()
|
extrude_island()
|
||||||
mark_grass()
|
mark_grass()
|
||||||
|
|
||||||
|
calc_bbox()
|
||||||
|
update()
|
||||||
|
|
||||||
|
|
||||||
func calc_bbox():
|
func calc_bbox():
|
||||||
|
|
|
@ -13,6 +13,7 @@ onready var OffsetValueLabel = get_node("UI/DebugContainer/OffsetValue")
|
||||||
onready var ZoomValueLabel = get_node("UI/DebugContainer/ZoomValue")
|
onready var ZoomValueLabel = get_node("UI/DebugContainer/ZoomValue")
|
||||||
onready var HexCoordValueLabel = get_node("UI/DebugContainer/HexCoordValue")
|
onready var HexCoordValueLabel = get_node("UI/DebugContainer/HexCoordValue")
|
||||||
onready var WorldCoordValueLabel = get_node("UI/DebugContainer/WorldCoordValue")
|
onready var WorldCoordValueLabel = get_node("UI/DebugContainer/WorldCoordValue")
|
||||||
|
onready var ScreenCoordValueLabel = get_node("UI/DebugContainer/ScreenCoordValue")
|
||||||
onready var TileTypeValueLabel = get_node("UI/DebugContainer/TileTypeValue")
|
onready var TileTypeValueLabel = get_node("UI/DebugContainer/TileTypeValue")
|
||||||
onready var RepeatButton = get_node("UI/HBoxContainer/RepeatButton")
|
onready var RepeatButton = get_node("UI/HBoxContainer/RepeatButton")
|
||||||
onready var SuccessMessage = get_node("UI/SuccessMessage")
|
onready var SuccessMessage = get_node("UI/SuccessMessage")
|
||||||
|
@ -232,7 +233,9 @@ func place_treasure():
|
||||||
if treasure_island.tiles[coord] == "Grass":
|
if treasure_island.tiles[coord] == "Grass":
|
||||||
grass_tiles.append(coord)
|
grass_tiles.append(coord)
|
||||||
|
|
||||||
treasure_island.treasure_local_coords = grass_tiles[randi() % len(grass_tiles)]
|
var treasure_tile_index = randi() % len(grass_tiles)
|
||||||
|
treasure_island.treasure_local_coords = grass_tiles[treasure_tile_index]
|
||||||
|
print ("treasure_tile_index: ", treasure_tile_index, " num tiles: ", len(grass_tiles))
|
||||||
|
|
||||||
if Globals.debug_nav:
|
if Globals.debug_nav:
|
||||||
treasure_island.highlight_treasure = true
|
treasure_island.highlight_treasure = true
|
||||||
|
@ -240,60 +243,18 @@ func place_treasure():
|
||||||
treasure_island.update()
|
treasure_island.update()
|
||||||
|
|
||||||
|
|
||||||
func prerender_island(island):
|
|
||||||
var render_island = Island.new()
|
|
||||||
render_island.tiles = island.tiles.duplicate()
|
|
||||||
render_island.treasure_local_coords = island.treasure_local_coords
|
|
||||||
render_island.name = "island"
|
|
||||||
render_island.prerender = true
|
|
||||||
|
|
||||||
var island_rect_local_center = island.rect_local.position + 0.5 * island.rect_local.size
|
|
||||||
|
|
||||||
var viewport = Viewport.new()
|
|
||||||
viewport.size = island.rect_local.size
|
|
||||||
viewport.own_world = true
|
|
||||||
viewport.global_canvas_transform.origin = -island_rect_local_center
|
|
||||||
add_child(viewport)
|
|
||||||
|
|
||||||
var camera = Camera2D.new()
|
|
||||||
viewport.add_child(camera)
|
|
||||||
viewport.add_child(render_island)
|
|
||||||
camera.make_current()
|
|
||||||
viewport.render_target_v_flip = true
|
|
||||||
viewport.render_target_update_mode = Viewport.UPDATE_ONCE
|
|
||||||
|
|
||||||
yield(get_tree(), "idle_frame")
|
|
||||||
yield(get_tree(), "idle_frame")
|
|
||||||
|
|
||||||
var img_tex = ImageTexture.new()
|
|
||||||
img_tex.create_from_image(viewport.get_texture().get_data(), 0)
|
|
||||||
island.render_sprite.texture = img_tex
|
|
||||||
island.render_sprite.centered = false
|
|
||||||
island.render_sprite.transform.origin = island.rect_world.position
|
|
||||||
|
|
||||||
for c in viewport.get_children():
|
|
||||||
viewport.remove_child(c)
|
|
||||||
c.queue_free()
|
|
||||||
|
|
||||||
remove_child(viewport)
|
|
||||||
viewport.queue_free()
|
|
||||||
viewport = null
|
|
||||||
|
|
||||||
island.update()
|
|
||||||
|
|
||||||
|
|
||||||
func render_treasure_map():
|
func render_treasure_map():
|
||||||
IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE
|
IslandMapRenderer.render_target_update_mode = Viewport.UPDATE_ONCE
|
||||||
IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME
|
IslandMapRenderer.render_target_clear_mode = Viewport.CLEAR_MODE_ONLY_NEXT_FRAME
|
||||||
var camera = IslandMapRenderer.get_node("Camera2D")
|
var camera = IslandMapRenderer.get_node("Camera2D")
|
||||||
camera.current = true
|
camera.current = true
|
||||||
camera.zoom = Vector2.ONE * 10.0
|
|
||||||
camera.offset = treasure_island.center_world_coord
|
camera.offset = treasure_island.center_world_coord
|
||||||
var island = Island.new()
|
var island = Island.new()
|
||||||
island.tiles = treasure_island.tiles.duplicate()
|
island.tiles = treasure_island.tiles.duplicate()
|
||||||
island.treasure_local_coords = treasure_island.treasure_local_coords
|
island.treasure_local_coords = treasure_island.treasure_local_coords
|
||||||
island.highlight_treasure = true
|
island.highlight_treasure = true
|
||||||
island.name = "island"
|
island.name = "island"
|
||||||
|
camera.zoom = Vector2.ONE * (treasure_island.radius_world / 100.0 + 3)
|
||||||
|
|
||||||
for child in IslandMapRenderer.get_children():
|
for child in IslandMapRenderer.get_children():
|
||||||
if child.name == "island":
|
if child.name == "island":
|
||||||
|
@ -343,8 +304,7 @@ func generate():
|
||||||
|
|
||||||
for i in range (num_islands):
|
for i in range (num_islands):
|
||||||
var island = Island.new()
|
var island = Island.new()
|
||||||
var file_name = island_files[i]
|
island.generate()
|
||||||
island.load_island(file_name)
|
|
||||||
|
|
||||||
var rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
|
var rand_coord = Vector2(rng.randi_range(-radius, radius), rng.randi_range(-radius, radius))
|
||||||
island.set_offset_world(Globals.WorldToHexCenter(rand_coord))
|
island.set_offset_world(Globals.WorldToHexCenter(rand_coord))
|
||||||
|
@ -465,12 +425,13 @@ func on_leave_island(island):
|
||||||
func on_dig_stopped():
|
func on_dig_stopped():
|
||||||
print ("Dig stopped!")
|
print ("Dig stopped!")
|
||||||
var dig_site = Sprite.new()
|
var dig_site = Sprite.new()
|
||||||
dig_site.transform.origin = Globals.HexToWorld(PlayerChar.cur_tile)
|
dig_site.transform.origin = Globals.HexToWorld(PlayerChar.cur_tile) + Vector2(0, 32.0)
|
||||||
|
|
||||||
if check_player_on_treasure():
|
if check_player_on_treasure():
|
||||||
emit_signal("treasure_found")
|
emit_signal("treasure_found")
|
||||||
on_treasure_found()
|
on_treasure_found()
|
||||||
dig_site.texture = DigSiteTreasureSprite
|
dig_site.texture = DigSiteTreasureSprite
|
||||||
|
dig_site.z_index = PlayerChar.z_index + 1
|
||||||
else:
|
else:
|
||||||
emit_signal("wrong_digsite")
|
emit_signal("wrong_digsite")
|
||||||
dig_site.texture = DigSiteSprite
|
dig_site.texture = DigSiteSprite
|
||||||
|
@ -619,7 +580,7 @@ func handle_game_event(event):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
# Move main character
|
# Move main character
|
||||||
if event.pressed and event.button_index == BUTTON_LEFT:
|
if event.pressed and event.button_index == BUTTON_LEFT:
|
||||||
update_player_navigation_target (Globals.HexGrid.get_hex_center(Globals.ScreenToHex(event.position, WorldCamera)))
|
update_player_navigation_target (Globals.HexGrid.get_hex_center(Globals.ScreenToHex(get_global_mouse_position(), WorldCamera)))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
@ -649,10 +610,10 @@ func _unhandled_input(event):
|
||||||
WorldCamera.zoom = WorldCamera.zoom * 0.8
|
WorldCamera.zoom = WorldCamera.zoom * 0.8
|
||||||
|
|
||||||
if 'position' in event:
|
if 'position' in event:
|
||||||
hex_hover = Globals.ScreenToHex(event.position, WorldCamera)
|
hex_hover = Globals.ScreenToHex(get_global_mouse_position(), WorldCamera)
|
||||||
GridHighlight.pos = hex_hover
|
GridHighlight.pos = hex_hover
|
||||||
HexCoordValueLabel.text = str(hex_hover)
|
HexCoordValueLabel.text = str(hex_hover)
|
||||||
var world_coord = Globals.ScreenToWorld(event.position, WorldCamera)
|
var world_coord = Globals.ScreenToWorld(get_global_mouse_position(), WorldCamera)
|
||||||
var tile_type = get_tile_type(world_coord)
|
var tile_type = get_tile_type(world_coord)
|
||||||
if tile_type != null:
|
if tile_type != null:
|
||||||
TileTypeValueLabel.text = tile_type
|
TileTypeValueLabel.text = tile_type
|
||||||
|
@ -660,6 +621,7 @@ func _unhandled_input(event):
|
||||||
TileTypeValueLabel.text = "None"
|
TileTypeValueLabel.text = "None"
|
||||||
|
|
||||||
WorldCoordValueLabel.text = str(world_coord)
|
WorldCoordValueLabel.text = str(world_coord)
|
||||||
|
ScreenCoordValueLabel.text = str(event.position)
|
||||||
|
|
||||||
update_hex_line_path(world_coord)
|
update_hex_line_path(world_coord)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue