diff options
| author | dam <dam@gudinoff> | 2022-03-30 16:37:28 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-03-30 16:37:28 +0000 |
| commit | e04f33a614e2723db47f69a7f3146b030ee5e326 (patch) | |
| tree | 999dd486901a363e4f1b427117de0e120eb465b4 | |
| parent | 8d4db7d2c92aa719da8ce218df9490283754d20b (diff) | |
| download | surgery-log-e04f33a614e2723db47f69a7f3146b030ee5e326.tar.zst surgery-log-e04f33a614e2723db47f69a7f3146b030ee5e326.zip | |
Add dismiss button logic on popup.
| -rw-r--r-- | logic/popup.gd | 34 | ||||
| -rw-r--r-- | main.tscn | 2 | ||||
| -rw-r--r-- | option_set/option_set.gd | 24 | ||||
| -rw-r--r-- | readme.md | 5 |
4 files changed, 38 insertions, 27 deletions
diff --git a/logic/popup.gd b/logic/popup.gd index 5a1c2a5..2ff91fe 100644 --- a/logic/popup.gd +++ b/logic/popup.gd @@ -1,7 +1,10 @@ extends Control class_name ModalPopup +signal dismissed # () + var control : Control +var control_parent : Node onready var title := get_node("title") as Label onready var background := get_node("background") as Panel @@ -13,13 +16,20 @@ func _init(): func _ready(): - get_node("back").connect("pressed", self, "hide") + get_node("dismiss").connect("pressed", self, "dismiss") -func popup_control(title: String, item: Control): +func open_popup(title: String, item: Control): + if visible == true: + return + self.title.text = title + control = item - control.connect("visibility_changed", self, "closed") + control_parent = control.get_parent() + control_parent.remove_child(control) + self.add_child(control) + control.anchor_left = background.anchor_left control.anchor_top = background.anchor_top control.anchor_right = background.anchor_right @@ -29,16 +39,22 @@ func popup_control(title: String, item: Control): control.margin_right = -20 control.margin_bottom = -20 add_child(control) - show() + + self.show() control.show() -# self.visible = true -func closed(): - if control.visible == true: +func dismiss(): + emit_signal("dismissed") + + +func close_popup(): + if visible == false: return - control.disconnect("visibility_changed", self, "closed") - remove_child(control) self.hide() + control.hide() + remove_child(control) + control_parent.add_child(control) + control_parent = null @@ -278,7 +278,7 @@ align = 1 valign = 1 autowrap = true -[node name="back" type="Button" parent="popup"] +[node name="dismiss" type="Button" parent="popup"] anchor_left = 0.05 anchor_top = 0.025 anchor_right = 0.95 diff --git a/option_set/option_set.gd b/option_set/option_set.gd index 2ac1475..637d033 100644 --- a/option_set/option_set.gd +++ b/option_set/option_set.gd @@ -28,30 +28,24 @@ func _ready(): func show_options(options_array: Array): options.clear_items() - var main = get_node("/root/main") - main.remove_child(options) options.add_items(options_array) if options_array[selected_idx] == input.text: options.select(selected_idx) else: options.unselect() - options.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT) - popup.popup_control(input.placeholder_text, options) -# popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT) -# popup.clear_items() -# popup_opt.visible = true -# get_node("/root/main/popup/blur") -# popup.add_items(options) + options.connect("item_selected", self, "popup_result", []) + options.connect("nothing_selected", self, "popup_result", [-1, ""]) + popup.connect("dismissed", self, "popup_result", [selected_idx, input.text]) + popup.open_popup(input.placeholder_text, options) -func option_selected(index: int, text: String): +func popup_result(index: int, text: String): + options.disconnect("item_selected", self, "popup_result") + options.disconnect("nothing_selected", self, "popup_result") + popup.disconnect("dismissed", self, "popup_result") selected_idx = index input.text = text input.caret_position = input.max_length - button.release_focus() - options.visible = false - var main = get_node("/root/main") - main.add_child(options) - + popup.close_popup() @@ -51,9 +51,10 @@ Surgery Log - [x] Maybe replace fonts with non-mono version; - [x] Fix option sets GUI element to provide word-wrap, otherwise long texts will be hidden; - [x] After save and load, entries opened on stage always detect changes (even when no change occurs); -- [ ] Add to popup: +- [x] Add to popup: - [x] title; - - [ ] back/close button; + - [x] dismiss button; +- [ ] What to do when the optionset has no options available? - [ ] Use popup to display confirmation messages; - [ ] Theming: - [ ] Make all buttons with same style; |
