Crafting v2
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
extends Node
|
||||
|
||||
## DragManager - handles drag and drop between UI elements
|
||||
|
||||
signal drag_started(data: Dictionary)
|
||||
signal drag_ended
|
||||
signal item_dropped(data: Dictionary, target_type: String, target_slot: int)
|
||||
|
||||
var is_dragging: bool = false
|
||||
var drag_data: Dictionary = {}
|
||||
var drag_preview: Control = null
|
||||
|
||||
func _ready():
|
||||
_create_drag_preview()
|
||||
|
||||
func _create_drag_preview():
|
||||
drag_preview = PanelContainer.new()
|
||||
drag_preview.name = "DragPreview"
|
||||
drag_preview.visible = false
|
||||
drag_preview.z_index = 1000
|
||||
drag_preview.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
var style = StyleBoxFlat.new()
|
||||
style.bg_color = Color(0.2, 0.2, 0.25, 0.9)
|
||||
style.set_corner_radius_all(4)
|
||||
drag_preview.add_theme_stylebox_override("panel", style)
|
||||
|
||||
var label = Label.new()
|
||||
label.name = "Label"
|
||||
label.add_theme_font_size_override("font_size", 12)
|
||||
drag_preview.add_child(label)
|
||||
|
||||
# Add to scene tree when ready
|
||||
call_deferred("_add_preview_to_tree")
|
||||
|
||||
func _add_preview_to_tree():
|
||||
var root = get_tree().root
|
||||
if root:
|
||||
root.add_child(drag_preview)
|
||||
|
||||
func start_drag(item: Dictionary, source_type: String, source_slot: int):
|
||||
is_dragging = true
|
||||
drag_data = {
|
||||
"item": item.duplicate(),
|
||||
"source_type": source_type,
|
||||
"source_slot": source_slot
|
||||
}
|
||||
|
||||
if drag_preview:
|
||||
var label = drag_preview.get_node_or_null("Label")
|
||||
if label:
|
||||
label.text = item.get("name", "Item")
|
||||
drag_preview.visible = true
|
||||
|
||||
drag_started.emit(drag_data)
|
||||
|
||||
func end_drag():
|
||||
is_dragging = false
|
||||
drag_data = {}
|
||||
if drag_preview:
|
||||
drag_preview.visible = false
|
||||
drag_ended.emit()
|
||||
|
||||
func drop_on(target_type: String, target_slot: int):
|
||||
if not is_dragging:
|
||||
return
|
||||
|
||||
item_dropped.emit(drag_data, target_type, target_slot)
|
||||
end_drag()
|
||||
|
||||
func get_drag_item() -> Dictionary:
|
||||
return drag_data.get("item", {})
|
||||
|
||||
func _process(_delta):
|
||||
if is_dragging and drag_preview:
|
||||
drag_preview.global_position = get_viewport().get_mouse_position() + Vector2(15, 10)
|
||||
|
||||
func _input(event):
|
||||
# Cancel drag on right click or escape
|
||||
if is_dragging:
|
||||
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
end_drag()
|
||||
elif event.is_action_pressed("ui_cancel"):
|
||||
end_drag()
|
||||
@@ -14,6 +14,10 @@ signal loot_chest_spawned(chest_data: Dictionary)
|
||||
signal loot_chest_state_received(chest_data: Dictionary)
|
||||
signal death_loot_lost(data: Dictionary)
|
||||
signal dungeon_list_received(data: Dictionary)
|
||||
signal crafting_skills_updated(skills: Dictionary)
|
||||
signal crafting_recipes_updated(recipes: Array)
|
||||
signal crafting_result_received(result: Dictionary)
|
||||
signal recipe_discovered(recipe: Dictionary)
|
||||
|
||||
# Use constants instead of enum to avoid type issues
|
||||
const STATE_AUTH = 0
|
||||
@@ -138,6 +142,16 @@ func _on_message_received(opcode: int, data: Dictionary):
|
||||
_handle_dungeon_list(data)
|
||||
OpCodes.ASSET_MANIFEST_RESPONSE:
|
||||
_handle_asset_manifest(data)
|
||||
OpCodes.CRAFTING_SKILLS_STATE:
|
||||
_handle_crafting_skills(data)
|
||||
OpCodes.CRAFTING_RECIPES_STATE:
|
||||
_handle_crafting_recipes(data)
|
||||
OpCodes.CRAFTING_RESULT:
|
||||
_handle_crafting_result(data)
|
||||
OpCodes.RECIPE_DISCOVERED:
|
||||
_handle_recipe_discovered(data)
|
||||
OpCodes.CRAFTING_SKILL_LEVELUP:
|
||||
_handle_crafting_skill_levelup(data)
|
||||
_:
|
||||
print("[GameState] Unhandled opcode: ", opcode)
|
||||
|
||||
@@ -534,3 +548,64 @@ func create_dungeon(tier: int):
|
||||
|
||||
func join_dungeon(dungeon_id: String):
|
||||
Network.send_message(OpCodes.DUNGEON_JOIN, {"DungeonId": dungeon_id})
|
||||
|
||||
# ===== CRAFTING SYSTEM =====
|
||||
|
||||
var crafting_skills: Dictionary = {} # skillType -> {level, xp, xpForNext}
|
||||
var known_recipes: Array = []
|
||||
|
||||
func _handle_crafting_skills(data: Dictionary):
|
||||
print("[GameState] Received crafting skills")
|
||||
crafting_skills = data.get("skills", {})
|
||||
crafting_skills_updated.emit(crafting_skills)
|
||||
|
||||
func _handle_crafting_recipes(data: Dictionary):
|
||||
print("[GameState] Received crafting recipes")
|
||||
known_recipes = data.get("recipes", [])
|
||||
crafting_recipes_updated.emit(known_recipes)
|
||||
|
||||
func _handle_crafting_result(data: Dictionary):
|
||||
print("[GameState] Received crafting result: %s" % str(data))
|
||||
crafting_result_received.emit(data)
|
||||
|
||||
# Refresh inventory if successful
|
||||
if data.get("success", false):
|
||||
request_inventory()
|
||||
|
||||
func _handle_recipe_discovered(data: Dictionary):
|
||||
print("[GameState] Discovered new recipe: %s" % data.get("name", "Unknown"))
|
||||
recipe_discovered.emit(data)
|
||||
# Refresh recipes
|
||||
request_crafting_recipes()
|
||||
|
||||
func _handle_crafting_skill_levelup(data: Dictionary):
|
||||
print("[GameState] Crafting skill level up: %s to level %d" % [
|
||||
data.get("skillName", "Unknown"),
|
||||
data.get("newLevel", 1)
|
||||
])
|
||||
# Refresh skills
|
||||
request_crafting_skills()
|
||||
|
||||
func request_crafting_skills():
|
||||
Network.send_message(OpCodes.CRAFTING_SKILLS_REQUEST, {})
|
||||
|
||||
func request_crafting_recipes():
|
||||
Network.send_message(OpCodes.CRAFTING_RECIPES_REQUEST, {})
|
||||
|
||||
func request_inventory():
|
||||
Network.send_message(OpCodes.INVENTORY_REQUEST, {})
|
||||
|
||||
func send_craft_request(recipe_id: int):
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {"RecipeId": recipe_id})
|
||||
|
||||
func send_discover_recipe(ingredients: Array):
|
||||
# ingredients is an array of {itemDefinitionId, quantity}
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {"Ingredients": ingredients, "Discover": true})
|
||||
|
||||
func send_discover_recipe_with_skill(ingredients: Array, skill_type: int):
|
||||
# Discovery with specific skill type
|
||||
Network.send_message(OpCodes.CRAFTING_ATTEMPT, {
|
||||
"Ingredients": ingredients,
|
||||
"Discover": true,
|
||||
"SkillType": skill_type
|
||||
})
|
||||
|
||||
@@ -34,6 +34,17 @@ const LOOT_CHEST_SPAWNED = 275
|
||||
# Player Death
|
||||
const PLAYER_DEATH_LOOT_LOST = 280
|
||||
|
||||
# Crafting
|
||||
const CRAFTING_SKILLS_REQUEST = 330
|
||||
const CRAFTING_SKILLS_STATE = 331
|
||||
const CRAFTING_RECIPES_REQUEST = 332
|
||||
const CRAFTING_RECIPES_STATE = 333
|
||||
const CRAFTING_ATTEMPT = 334
|
||||
const CRAFTING_RESULT = 335
|
||||
const CRAFTING_SKILL_LEVELUP = 336
|
||||
const RECIPE_DISCOVERED = 337
|
||||
const RECIPE_SCROLL_USE = 338
|
||||
|
||||
# Dungeon
|
||||
const DUNGEON_ENTER = 300
|
||||
const DUNGEON_ENTER_RESULT = 301
|
||||
|
||||
Reference in New Issue
Block a user