Skip to content

Commit

Permalink
wip terrain.cfg loading, wip compare creature stats window
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed May 22, 2024
1 parent 4fc48f6 commit 5714cd1
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 15 deletions.
14 changes: 6 additions & 8 deletions Autoload/Slabs.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ enum {
GEMS = 52,
GUARD_POST = 53,
PURPLE_PATH = 54,
# PURPLE_PATH2 = 55,
# PURPLE_PATH3 = 56,
# PURPLE_PATH4 = 57,
# 58 doesn't exist within 1304 entries
WALL_AUTOMATIC = 999,
}
Expand Down Expand Up @@ -263,11 +260,6 @@ IRON_DOOR_2,
MAGIC_DOOR_2,
PORTAL,
DUNGEON_HEART,

#PURPLE_PATH2,
#PURPLE_PATH3,
#PURPLE_PATH4,

EARTH_WITH_TORCH,
WALL_WITH_TORCH,
WALL_WITH_BANNER,
Expand Down Expand Up @@ -303,3 +295,9 @@ func is_door(slabID):
if data[slabID][BITMASK_TYPE] == BITMASK_DOOR1 or data[slabID][BITMASK_TYPE] == BITMASK_DOOR2:
return true
return false

var NAME_MAPPINGS = {
"DOOR_SECRET" : "Secret Door",
"DOOR_SECRET2" : "Secret Door",
"HARD_FLOOR" : "Hard Floor",
}
50 changes: 44 additions & 6 deletions Scenes/CfgLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,53 @@ func load_objects_data(path):
var id = int(section)
if id == 0: continue
if id >= 136 or id in [100, 101, 102, 103, 104, 105]: # Dummy Boxes should be overwritten
var data = objects_cfg[section]
var newName = data["Name"]
var animID = data["AnimationID"]
var objSection = objects_cfg[section]
var newName = objSection["Name"]
var animID = objSection["AnimationID"]
var newSprite = get_sprite(animID, newName)
var newGenre = data.get("Genre", null)
var newGenre = objSection.get("Genre", null)
var newEditorTab = Things.GENRE_TO_TAB[newGenre]
Things.DATA_OBJECT[id] = [newName, newSprite, newEditorTab]

func load_terrain_data(path):
var terrain_cfg = Utils.read_dkcfg_file(path)
for section in terrain_cfg:
if section.begins_with("slab"):
var id = int(section)
if id >= 55: # Beyond Slabs.PURPLE_PATH
var slabSection = terrain_cfg[section]

var setName = slabSection.get("Name", "Unknown")
if setName != "Unknown":
setName = Slabs.NAME_MAPPINGS.get(setName, setName.capitalize())

# BlockFlagsHeight
# BlockHealthIndex
# BlockFlags
# NoBlockFlags #; Possible (no)block flags are: VALUABLE, IS_ROOM, UNEXPLORED, DIGGABLE, FILLED, IS_DOOR, and TAGGED_VALUABLE.
# FillStyle # ; The type of terrain this slab fills adjacent slabs with if possible. 1 = Lava. 2 = Water.
# Category # ; 0 = Unclaimed. 1 = Diggable dirt. 2 = Claimed path. 3 = Fortified wall. 4 = Room interior. 5 = Obstacle.
# SlbID
# Indestructible # ; If set to 1 the slab cannot be dug, is immune to vandalizing and eruption effect.
# Wibble # ; The amount of distortion the slab has in normal view. The higher the value, the less distortion there is.
# Animated
# IsSafeLand
# IsDiggable
# IsOwnable
# WlbType

Slabs.data[id] = [
setName,
Slabs.BLOCK_SLAB,
Slabs.BITMASK_BLOCK,
Slabs.PANEL_TOP_VIEW,
0,
Slabs.TAB_MAINSLAB,
Slabs.WIBBLE_ON,
Slabs.REMEMBER_PATH,
Slabs.NOT_OWNABLE,
]


func load_creatures_data(path):
var creature_cfg = Utils.read_dkcfg_file(path)
Expand Down Expand Up @@ -101,8 +140,7 @@ func load_trapdoor_data(path):
Things.DATA_TRAP[id] = [newName, newSprite, Things.TAB_TRAP]
Things.LIST_OF_BOXES[crateName] = [trapOrDoor, id]

func load_terrain_data(path):
var terrain_cfg = Utils.read_dkcfg_file(path)



func get_sprite(first_priority, second_priority):
Expand Down
141 changes: 141 additions & 0 deletions Scenes/CompareCreatureStats.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
extends WindowDialog
onready var oGame = Nodelist.list["oGame"]
onready var oSortCreaStatsGrid = Nodelist.list["oSortCreaStatsGrid"]
onready var oStatsOptionButton = Nodelist.list["oStatsOptionButton"]


var all_creature_data = {}

var list_data = []
var selected_labels = []

func _ready():
for i in 10:
yield(get_tree(),'idle_frame')

var CODETIME_START = OS.get_ticks_msec()
var listOfCfgs = Utils.get_filetype_in_directory(oGame.GAME_DIRECTORY.plus_file("creatrs"), "CFG")
for path in listOfCfgs:
var aaa = Utils.read_dkcfg_file(path)
all_creature_data[path.get_file()] = aaa
#print(creature_data)

print('Codetime: ' + str(OS.get_ticks_msec() - CODETIME_START) + 'ms')

populate_optionbutton()


# Default selection
oStatsOptionButton.select(2)
_on_StatsOptionButton_item_selected(2)

Utils.popup_centered(self)

func _on_StatsOptionButton_item_selected(index):
update_list()

func update_list():
for file in all_creature_data:
for section in all_creature_data[file]:
if section == "attributes":
var getName = all_creature_data[file][section].get("Name")
var getHealth = all_creature_data[file][section].get("Health")

list_data.append([getName, getHealth])

list_data.sort_custom(self, "sort_list")

for i in list_data:
add_entry(i[0], i[1], Color(0.5,0.5,0.5))


func sort_list(a, b):
return int(a[1]) < int(b[1])

func add_entry(string1, value, fontColor):
var addLabel1 = Label.new()
addLabel1.text = string1
oSortCreaStatsGrid.add_child(addLabel1)
addLabel1.set("custom_colors/font_color", fontColor)
addLabel1.mouse_filter = Control.MOUSE_FILTER_PASS

var addLabel2 = Label.new()
addLabel2.text = str(value)
oSortCreaStatsGrid.add_child(addLabel2)
addLabel2.set("custom_colors/font_color", fontColor)
addLabel2.mouse_filter = Control.MOUSE_FILTER_PASS

addLabel1.size_flags_horizontal = Control.SIZE_EXPAND_FILL
addLabel2.size_flags_horizontal = Control.SIZE_EXPAND_FILL

addLabel1.connect("mouse_entered", self, "_on_label_mouse_entered", [addLabel1, addLabel2])
addLabel2.connect("mouse_entered", self, "_on_label_mouse_entered", [addLabel1, addLabel2])

addLabel1.connect("mouse_exited", self, "_on_label_mouse_exited", [addLabel1, addLabel2])
addLabel2.connect("mouse_exited", self, "_on_label_mouse_exited", [addLabel1, addLabel2])

addLabel1.connect("gui_input", self, "_on_label_gui_input", [addLabel1, addLabel2])
addLabel2.connect("gui_input", self, "_on_label_gui_input", [addLabel1, addLabel2])

func _on_label_mouse_entered(l1,l2):
if [l1, l2] in selected_labels:
pass
else:
l1.set("custom_colors/font_color", Color(1,1,1))
l2.set("custom_colors/font_color", Color(1,1,1))

func _on_label_mouse_exited(l1,l2):
if [l1, l2] in selected_labels:
pass
else:
l1.set("custom_colors/font_color", Color(0.5,0.5,0.5))
l2.set("custom_colors/font_color", Color(0.5,0.5,0.5))

func _on_label_gui_input(event, l1, l2):
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT:
if [l1, l2] in selected_labels:
selected_labels.erase([l1, l2])
l1.set("custom_colors/font_color", Color(0.5, 0.5, 0.5))
l2.set("custom_colors/font_color", Color(0.5, 0.5, 0.5))
else:
selected_labels.append([l1, l2])
l1.set("custom_colors/font_color", Color(1, 1, 1))
l2.set("custom_colors/font_color", Color(1, 1, 1))

func _on_NameStatsButton_pressed():
pass # Replace with function body.





func _on_RightStatsButton_pressed():
var next_index = oStatsOptionButton.selected + 1
while next_index < oStatsOptionButton.get_item_count() and oStatsOptionButton.get_item_text(next_index) == "":
next_index += 1
if next_index >= oStatsOptionButton.get_item_count():
next_index = 0
while next_index < oStatsOptionButton.selected and oStatsOptionButton.get_item_text(next_index) == "":
next_index += 1
oStatsOptionButton.selected = next_index

func _on_LeftStatsButton_pressed():
var prev_index = oStatsOptionButton.selected - 1
while prev_index >= 0 and oStatsOptionButton.get_item_text(prev_index) == "":
prev_index -= 1
if prev_index < 0:
prev_index = oStatsOptionButton.get_item_count() - 1
while prev_index > oStatsOptionButton.selected and oStatsOptionButton.get_item_text(prev_index) == "":
prev_index -= 1
oStatsOptionButton.selected = prev_index


func populate_optionbutton():
var items_checked = 0
for file in all_creature_data:
items_checked+=1
for section in all_creature_data[file]:
if items_checked == 1:
for blah in all_creature_data[file][section].keys():
oStatsOptionButton.add_item(blah)
oStatsOptionButton.add_separator()
90 changes: 89 additions & 1 deletion Scenes/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=190 format=2]
[gd_scene load_steps=191 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 @@ -169,6 +169,7 @@
[ext_resource path="res://Scenes/ThreadedSaveUndo.gd" type="Script" id=167]
[ext_resource path="res://Scenes/Guidelines.gd" type="Script" id=168]
[ext_resource path="res://Scenes/CfgLoader.gd" type="Script" id=169]
[ext_resource path="res://Scenes/CompareCreatureStats.gd" type="Script" id=170]

[sub_resource type="CubeMesh" id=2]
size = Vector3( 1, 1, 1 )
Expand Down Expand Up @@ -6800,6 +6801,89 @@ allow_reselect = true
auto_height = true
script = ExtResource( 65 )

[node name="SortCreatureStats" type="WindowDialog" parent="Ui/UiSystem"]
visible = true
margin_left = 1704.0
margin_top = -1832.0
margin_right = 2053.0
margin_bottom = -886.0
rect_min_size = Vector2( 281, 296 )
mouse_filter = 1
window_title = "Compare Creature Stats"
resizable = true
script = ExtResource( 170 )

[node name="MarginContainer" type="MarginContainer" parent="Ui/UiSystem/SortCreatureStats"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 1
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/margin_right = 20
custom_constants/margin_top = 20
custom_constants/margin_left = 20
custom_constants/margin_bottom = 20

[node name="VBoxContainer" type="VBoxContainer" parent="Ui/UiSystem/SortCreatureStats/MarginContainer"]
margin_left = 20.0
margin_top = 20.0
margin_right = 329.0
margin_bottom = 926.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="HBoxContainer" type="HBoxContainer" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer"]
margin_right = 309.0
margin_bottom = 27.0

[node name="LeftStatsButton" type="Button" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
margin_right = 27.0
margin_bottom = 27.0
rect_min_size = Vector2( 27, 27 )
size_flags_horizontal = 0
text = "<"

[node name="StatsOptionButton" type="OptionButton" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 31.0
margin_right = 278.0
margin_bottom = 27.0
size_flags_horizontal = 3
text = "Sections"

[node name="RightStatsButton" type="Button" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 282.0
margin_right = 309.0
margin_bottom = 27.0
rect_min_size = Vector2( 27, 27 )
size_flags_horizontal = 0
text = ">"

[node name="ScrollContainer" type="ScrollContainer" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="SortCreaStatsGrid" type="GridContainer" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/ScrollContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/hseparation = 20
columns = 2

[node name="HBoxContainer2" type="HBoxContainer" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer"]
margin_top = 879.0
margin_right = 309.0
margin_bottom = 906.0

[node name="NameStatsButton" type="Button" parent="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer2"]
margin_right = 100.0
margin_bottom = 27.0
rect_min_size = Vector2( 100, 0 )
size_flags_horizontal = 2
text = "Name"

[node name="MapCoordinatesWindow" type="WindowDialog" parent="Ui/UiSystem"]
visible = true
margin_left = -1480.0
Expand Down Expand Up @@ -7556,6 +7640,10 @@ script = SubResource( 20 )
[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/ActionPointListWindow" to="Ui/UiSystem/ActionPointListWindow/MarginContainer/VBoxContainer/ScrollContainer/ActionPointList" method="_on_ActionPointListWindow_visibility_changed"]
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/LeftStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_LeftStatsButton_pressed"]
[connection signal="item_selected" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/StatsOptionButton" to="Ui/UiSystem/SortCreatureStats" method="_on_StatsOptionButton_item_selected"]
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer/RightStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_RightStatsButton_pressed"]
[connection signal="pressed" from="Ui/UiSystem/SortCreatureStats/MarginContainer/VBoxContainer/HBoxContainer2/NameStatsButton" to="Ui/UiSystem/SortCreatureStats" method="_on_NameStatsButton_pressed"]
[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"]
Expand Down

0 comments on commit 5714cd1

Please sign in to comment.