Skip to content

Commit

Permalink
Improved LOF fields in Map Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 3, 2024
1 parent 742c93d commit a16ffc9
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Scenes/GamePaths.gd
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func set_keeperfx_version():
var script = ""
script += "cd " + EXECUTABLE_PATH.get_base_dir() + ";"
script += "exiftool -ProductVersion -n keeperfx.exe | awk -F ': ' '{print $2}'"
var exit_code = OS.execute("bash", ["-c", script], true, output, true)
var _exit_code = OS.execute("bash", ["-c", script], true, output, true)
#print("Exit code: ", exit_code)
#print("Output: ", output)
#print(script)
Expand Down
3 changes: 0 additions & 3 deletions Scenes/ImageAsMapDialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ func _on_slab_button_pressed(buttonID):
oMessage.quick("Must first click on a pixel within the image.")
return


var slabID = buttonID.get_meta("slabID")



# Many colours can be assigned to one Button.
# Many buttons CANNOT be assigned to one colour.

Expand Down
148 changes: 144 additions & 4 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=180 format=2]
[gd_scene load_steps=183 format=2]

[ext_resource path="res://Scenes/SlabStyle.gd" type="Script" id=1]
[ext_resource path="res://Scenes/SlabPlacement.gd" type="Script" id=2]
Expand Down Expand Up @@ -158,6 +158,9 @@
[ext_resource path="res://Art/HelpIcon.png" type="Texture" id=156]
[ext_resource path="res://Scenes/AddCustomSlabWindow.gd" type="Script" id=157]
[ext_resource path="res://Scenes/ConstructedVariations.gd" type="Script" id=158]
[ext_resource path="res://dk_images/landviews/rgmap00.png" type="Texture" id=159]
[ext_resource path="res://Scenes/MapCoordinatesWindow.gd" type="Script" id=160]
[ext_resource path="res://dk_images/landviews/ensign_lvl5.png" type="Texture" id=161]

[sub_resource type="TileSet" id=1]
0/name = "Wibble_0.png 0"
Expand Down Expand Up @@ -4268,15 +4271,51 @@ size_flags_vertical = 1
text = "Flag position"
valign = 1

[node name="EnsignPositionLineEdit" type="LineEdit" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition"]
[node name="HBoxContainer2" type="HBoxContainer" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition"]
margin_left = 305.0
margin_right = 607.0
margin_bottom = 31.0
size_flags_horizontal = 3

[node name="Spacing" type="Control" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2"]
margin_right = 79.0
margin_bottom = 31.0
size_flags_horizontal = 3

[node name="EnsignPositionX" type="LineEdit" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2"]
margin_left = 83.0
margin_right = 141.0
margin_bottom = 31.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 7
size_flags_horizontal = 5
text = "0"
align = 1

[node name="Label" type="Label" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2"]
margin_left = 145.0
margin_top = 5.0
margin_right = 156.0
margin_bottom = 26.0
text = "x"

[node name="EnsignPositionY" type="LineEdit" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2"]
margin_left = 160.0
margin_right = 218.0
margin_bottom = 31.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 5
text = "0"
align = 1

[node name="OpenMapCoordButton" type="Button" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2"]
margin_left = 222.0
margin_right = 302.0
margin_bottom = 31.0
size_flags_horizontal = 3
text = "Map"

[node name="HBoxEnsignZoom" type="HBoxContainer" parent="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer"]
visible = false
margin_top = 291.0
Expand Down Expand Up @@ -6688,6 +6727,99 @@ margin_bottom = 227.0
group = ExtResource( 155 )
text = "Fake Slabs (.une)"

[node name="MapCoordinatesWindow" type="WindowDialog" parent="Ui/UiSystem"]
visible = true
margin_left = -1480.0
margin_top = -1560.0
margin_right = -235.0
margin_bottom = -697.0
mouse_filter = 1
window_title = "Map Coordinates"
resizable = true
script = ExtResource( 160 )

[node name="MarginContainer" type="MarginContainer" parent="Ui/UiSystem/MapCoordinatesWindow"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
custom_constants/margin_right = 10
custom_constants/margin_top = 10
custom_constants/margin_left = 10
custom_constants/margin_bottom = 10

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer"]
margin_left = 10.0
margin_top = 10.0
margin_right = 1235.0
margin_bottom = 853.0
mouse_filter = 2

[node name="LandviewAspectRatioContainer" type="AspectRatioContainer" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer"]
margin_right = 1225.0
margin_bottom = 812.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="LandviewImage" type="TextureRect" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/LandviewAspectRatioContainer"]
margin_left = 206.5
margin_right = 1018.5
margin_bottom = 812.0
size_flags_horizontal = 3
size_flags_vertical = 3
texture = ExtResource( 159 )
expand = true
stretch_mode = 1

[node name="EnsignFlagImg" type="TextureRect" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/LandviewAspectRatioContainer/LandviewImage"]
margin_right = 31.0
margin_bottom = 63.0
rect_pivot_offset = Vector2( 16, 62 )
mouse_filter = 2
texture = ExtResource( 161 )
stretch_mode = 1

[node name="HBoxContainer" type="HBoxContainer" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer"]
margin_top = 816.0
margin_right = 1225.0
margin_bottom = 843.0
alignment = 1

[node name="ChangeImageCoordButton" type="Button" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 470.0
margin_right = 570.0
margin_bottom = 27.0
rect_min_size = Vector2( 100, 0 )
size_flags_horizontal = 4
text = "Image"

[node name="LandViewFlagPosLabel" type="Label" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 574.0
margin_top = 3.0
margin_right = 650.0
margin_bottom = 24.0
text = "640, 480"

[node name="CloseMapCoordButton" type="Button" parent="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 654.0
margin_right = 754.0
margin_bottom = 27.0
rect_min_size = Vector2( 100, 0 )
size_flags_horizontal = 4
text = "Close"

[node name="ChooseLandviewImageFileDialog" type="FileDialog" parent="Ui/UiSystem"]
margin_right = 638.0
margin_bottom = 538.0
rect_min_size = Vector2( 300, 105 )
window_title = "Select a .png image"
resizable = true
dialog_hide_on_ok = true
mode_overrides_title = false
mode = 0
access = 2
filters = PoolStringArray( "*.png" )
show_hidden_files = true

[node name="UiMessages" type="Control" parent="Ui"]
anchor_right = 1.0
anchor_bottom = 1.0
Expand Down Expand Up @@ -7256,7 +7388,9 @@ script = SubResource( 20 )
[connection signal="value_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxPlayers/PlayersSpinBox" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_PlayersSpinBox_value_changed"]
[connection signal="text_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxSpeech/SpeechLineEdit" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_SpeechLineEdit_text_changed"]
[connection signal="text_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxLandView/LandViewLineEdit" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_LandViewLineEdit_text_changed"]
[connection signal="text_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/EnsignPositionLineEdit" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_EnsignPositionLineEdit_text_changed"]
[connection signal="focus_exited" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2/EnsignPositionX" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_EnsignPositionX_focus_exited"]
[connection signal="focus_exited" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2/EnsignPositionY" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_EnsignPositionY_focus_exited"]
[connection signal="pressed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignPosition/HBoxContainer2/OpenMapCoordButton" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_OpenMapCoordButton_pressed"]
[connection signal="text_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxEnsignZoom/EnsignZoomLineEdit" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_EnsignZoomLineEdit_text_changed"]
[connection signal="item_selected" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxOptions/OptionsOptionButton" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_OptionsOptionButton_item_selected"]
[connection signal="text_changed" from="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties/VBoxContainer/AdvancedMapProperties/VBoxContainer/HBoxNameID/NameIDLineEdit" to="Ui/UiSystem/MapSettingsWindow/MapSettingsTabs/MapProperties" method="_on_NameIDLineEdit_text_changed"]
Expand Down Expand Up @@ -7348,6 +7482,12 @@ script = SubResource( 20 )
[connection signal="value_changed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/HBoxContainer2/VBoxContainer/ResizeFillWithID" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeFillWithID_value_changed"]
[connection signal="pressed" from="Ui/UiSystem/ResizeCurrentMapSize/MarginContainer/VBoxContainer/ResizeApplyButton" to="Ui/UiSystem/ResizeCurrentMapSize" method="_on_ResizeApplyButton_pressed"]
[connection signal="visibility_changed" from="Ui/UiSystem/GridDataWindow" to="Game2D/AnalyzeGrids" method="_on_GridDataWindow_visibility_changed"]
[connection signal="visibility_changed" from="Ui/UiSystem/MapCoordinatesWindow" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_MapCoordinatesWindow_visibility_changed"]
[connection signal="gui_input" from="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/LandviewAspectRatioContainer/LandviewImage" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_LandviewImage_gui_input"]
[connection signal="resized" from="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/LandviewAspectRatioContainer/LandviewImage" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_LandviewImage_resized"]
[connection signal="pressed" from="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/HBoxContainer/ChangeImageCoordButton" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_ChangeImageCoordButton_pressed"]
[connection signal="pressed" from="Ui/UiSystem/MapCoordinatesWindow/MarginContainer/VBoxContainer/HBoxContainer/CloseMapCoordButton" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_CloseMapCoordButton_pressed"]
[connection signal="file_selected" from="Ui/UiSystem/ChooseLandviewImageFileDialog" to="Ui/UiSystem/MapCoordinatesWindow" method="_on_ChooseLandviewImageFileDialog_file_selected"]
[connection signal="timeout" from="Ui/UiMessages/FPScounter/Timer" to="Ui/UiMessages/FPScounter" method="_on_Wait_timeout"]
[connection signal="about_to_show" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_about_to_show"]
[connection signal="hide" from="Ui/UiPreviewExporter/ExportPreview" to="Ui/UiPreviewExporter/ExportPreview" method="_on_ExportPreview_hide"]
Expand Down
104 changes: 104 additions & 0 deletions Scenes/MapCoordinatesWindow.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
extends WindowDialog

onready var oMapProperties = Nodelist.list["oMapProperties"]
onready var oEnsignFlagImg = Nodelist.list["oEnsignFlagImg"]
onready var oLandviewAspectRatioContainer = Nodelist.list["oLandviewAspectRatioContainer"]
onready var oLandviewImage = Nodelist.list["oLandviewImage"]
onready var oEnsignPositionX = Nodelist.list["oEnsignPositionX"]
onready var oEnsignPositionY = Nodelist.list["oEnsignPositionY"]
onready var oMessage = Nodelist.list["oMessage"]
onready var oChooseLandviewImageFileDialog = Nodelist.list["oChooseLandviewImageFileDialog"]
onready var oLandViewFlagPosLabel = Nodelist.list["oLandViewFlagPosLabel"]

var imageData = Image.new()
var textureData = ImageTexture.new()

var image_resolution = Vector2()
var holding_left_click = false
var normalized_flag_position = Vector2(0.5, 0.5) # Default to center


func _ready():
update_image_resolution()
update_aspect_ratio()
update_flag_position()


func _on_LandviewImage_resized():
update_flag_size()
update_flag_position()


func update_image_resolution():
image_resolution = oLandviewImage.texture.get_data().get_size()


func update_aspect_ratio():
oLandviewAspectRatioContainer.ratio = image_resolution.x / image_resolution.y


func update_flag_size():
var adjustScale = oLandviewImage.rect_size / image_resolution
oEnsignFlagImg.rect_scale = Vector2(adjustScale.x, adjustScale.x)


func update_flag_position():
var flag_position = normalized_flag_position * oLandviewImage.rect_size
oEnsignFlagImg.rect_position = flag_position - oEnsignFlagImg.rect_pivot_offset

var new_set_pos = image_resolution * normalized_flag_position
new_set_pos.x = int(new_set_pos.x)
new_set_pos.y = int(new_set_pos.y)

oMapProperties.set_flag_pos_by_landview_img(new_set_pos)
oLandViewFlagPosLabel.text = "(" + str(new_set_pos.x) + ", " + str(new_set_pos.y) + ")"

func _on_CloseMapCoordButton_pressed():
visible = false


func _on_LandviewImage_gui_input(event):
if visible == false: return

if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
holding_left_click = true
else:
holding_left_click = false

if event is InputEventMouseMotion:
if holding_left_click == true:
var clamped_position = Vector2()
clamped_position.x = clamp(event.position.x, 0, oLandviewImage.rect_size.x)
clamped_position.y = clamp(event.position.y, 0, oLandviewImage.rect_size.y)

normalized_flag_position = clamped_position / oLandviewImage.rect_size
update_flag_position()


func _on_ChangeImageCoordButton_pressed():
Utils.popup_centered(oChooseLandviewImageFileDialog)


func _on_MapCoordinatesWindow_visibility_changed():
if visible == true:
var flag_position_x = int(oEnsignPositionX.text)
var flag_position_y = int(oEnsignPositionY.text)
var flag_position = Vector2(flag_position_x, flag_position_y)
normalized_flag_position = flag_position / image_resolution
update_flag_position()
else:
if oMessage == null: return

func _on_ChooseLandviewImageFileDialog_file_selected(path):
var err = imageData.load(path)
if err != OK:
oMessage.quick("Error loading file.")
return
textureData = ImageTexture.new()
textureData.create_from_image(imageData, 0) # flags off
oLandviewImage.texture = textureData

update_image_resolution()
update_aspect_ratio()
update_flag_position()
Loading

0 comments on commit a16ffc9

Please sign in to comment.