feat: complete mobile UI implementation
This commit is contained in:
+34
-3
@@ -24,6 +24,7 @@ var _grid: GridContainer
|
||||
var _cells: Dictionary = {}
|
||||
var _page_label: Label
|
||||
var _page := 0
|
||||
var _mobile_mode := false
|
||||
|
||||
func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
client = m2client
|
||||
@@ -41,6 +42,12 @@ func setup(m2client: Node, parent: Node, proto_node: Node = null) -> void:
|
||||
func is_open() -> bool:
|
||||
return _root != null and _root.visible
|
||||
|
||||
func set_mobile_mode(enabled: bool) -> void:
|
||||
_mobile_mode = enabled
|
||||
|
||||
func get_mobile_window() -> Control:
|
||||
return _root
|
||||
|
||||
func close() -> void:
|
||||
if item_mouse and item_mouse.has_method("unregister_owner"):
|
||||
item_mouse.unregister_owner(self)
|
||||
@@ -136,6 +143,20 @@ func _on_grid_input(local_pos: int, event: InputEvent) -> void:
|
||||
item_mouse.attach_item(MALL_WINDOW, _page * MALL_PAGE_SLOTS + local_pos, vnum,
|
||||
int(cell.get_meta("count", 1)), null, "mall")
|
||||
|
||||
func _on_mobile_grid_tap(local_pos: int) -> void:
|
||||
if not _mobile_mode or client == null or not _cells.has(local_pos):
|
||||
return
|
||||
var cell: Button = _cells[local_pos]
|
||||
var vnum := int(cell.get_meta("vnum", 0))
|
||||
if vnum == 0 or not client.has_method("mall_checkout"):
|
||||
return
|
||||
var target := _first_free_inv()
|
||||
if target < 0:
|
||||
_status.text = "背包已满"
|
||||
return
|
||||
if not client.mall_checkout(_page * MALL_PAGE_SLOTS + local_pos, 1, target):
|
||||
_status.text = "取出请求发送失败"
|
||||
|
||||
func _change_page(delta: int) -> void:
|
||||
var pages := maxi(1, int(ceil(float(client.get_mall_size()) / float(MALL_PAGE_SLOTS))))
|
||||
_page = clampi(_page + delta, 0, pages - 1)
|
||||
@@ -153,7 +174,8 @@ func _ask_password() -> void:
|
||||
edit.secret = true
|
||||
edit.max_length = 6
|
||||
edit.placeholder_text = "密码"
|
||||
edit.custom_minimum_size = Vector2(220, 28)
|
||||
edit.virtual_keyboard_type = LineEdit.KEYBOARD_TYPE_NUMBER
|
||||
edit.custom_minimum_size = Vector2(360, 44) if _mobile_mode else Vector2(220, 28)
|
||||
_password_dialog.add_child(edit)
|
||||
_password_dialog.confirmed.connect(func() -> void:
|
||||
if not client.mall_password(edit.text) and is_instance_valid(_status):
|
||||
@@ -163,8 +185,16 @@ func _ask_password() -> void:
|
||||
_password_dialog.canceled.connect(func() -> void:
|
||||
_password_dialog.queue_free()
|
||||
_password_dialog = null)
|
||||
_root.get_parent().add_child(_password_dialog)
|
||||
_password_dialog.popup_centered()
|
||||
if _mobile_mode:
|
||||
_password_dialog.set_meta("mobile_modal", true)
|
||||
_password_dialog.set_meta("mobile_title", "商城密码")
|
||||
_password_dialog.min_size = Vector2i(460, 230)
|
||||
_password_dialog.size = Vector2i(460, 230)
|
||||
_root.add_child(_password_dialog)
|
||||
if _mobile_mode:
|
||||
_password_dialog.popup_centered(Vector2i(460, 230))
|
||||
else:
|
||||
_password_dialog.popup_centered()
|
||||
|
||||
func _row(it: Dictionary) -> Control:
|
||||
var row := HBoxContainer.new()
|
||||
@@ -252,6 +282,7 @@ func _build(parent: Node) -> void:
|
||||
cell.custom_minimum_size = Vector2(58, 30)
|
||||
cell.add_theme_font_size_override("font_size", 9)
|
||||
cell.gui_input.connect(func(e: InputEvent): _on_grid_input(pos, e))
|
||||
cell.pressed.connect(func(): _on_mobile_grid_tap(pos))
|
||||
_grid.add_child(cell)
|
||||
_cells[pos] = cell
|
||||
var close := Button.new()
|
||||
|
||||
Reference in New Issue
Block a user