Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symbols editor #761

Merged
merged 8 commits into from
Jul 19, 2024
Merged

Add symbols editor #761

merged 8 commits into from
Jul 19, 2024

Conversation

Frostbyte0x70
Copy link
Member

Adds a new screen that can be used to view and edit the value of data symbols defined in pmdsky-debug. Requires SkyTemple/skytemple-files#505.

The new screen supports editing values as text. Symbols of known enum types use dropdowns or autocomplete textboxes, so the user can check the list of valid values. Boolean values use checkboxes. If the user inputs an invalid or out of range value, an error message is displayed.

Now that this editor exists, I see little purpose for the view located under Patches > Symbols. Maybe we should consider removing / hiding it.

I also think that Lists > Misc. Settings is outdated now, and I wouldn't mind removing it, mainly because:

  • All the values listed there can already be edited in this new screen, which isn't much harder to navigate
  • The Misc. Settings view contains arbitrary fields
  • Any future changes to those symbols in pmdsky-debug will not be reflected on the Misc. Settings view unless manually updated
  • The input for belly lost per turn cannot handle negative values, unlike the one in the new symbols view
    But I don't have a strong opinion on the matter, it's just a suggestion.

@Frostbyte0x70 Frostbyte0x70 marked this pull request as draft June 19, 2024 23:35
@theCapypara theCapypara self-requested a review June 20, 2024 12:58
@Frostbyte0x70 Frostbyte0x70 force-pushed the symbols branch 2 times, most recently from 9c6dce9 to 38702b3 Compare June 28, 2024 21:35
@Frostbyte0x70
Copy link
Member Author

skytemple/module/symbols/model_getter.py:133:18: error: Missing positional argument "types" in call to "new" of "ListStore" [call-arg]
skytemple/module/symbols/model_getter.py:133:36: error: Argument 1 to "new" of "ListStore" has incompatible type "list[type]"; expected "int" [arg-type]

As stated in the code, the type hint Gtk.ListStore.new seems to be incorrect. It says the function takes two parameters, but https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ListStore.html#Gtk.ListStore.new says it takes one. How do I suppress this?

skytemple/module/symbols/model_getter.py:143:57: error: Argument 1 to "Gender" has incompatible type "u8"; expected "str" [arg-type]

I copied this from existing code. Not sure what to do here.

Error: skytemple/module/symbols/widget/main.py:89:38: W605 Invalid escape sequence: \(
Error: skytemple/module/symbols/widget/main.py:89:45: W605 Invalid escape sequence: \d
Error: skytemple/module/symbols/widget/main.py:89:49: W605 Invalid escape sequence: \)

???
The regex is valid. Do I just suppress this?

@theCapypara
Copy link
Member

theCapypara commented Jun 29, 2024

  1. ListStore.new should not be used, use the normal constructor instead:
    store: Gtk.ListStore = Gtk.ListStore(*[int, str] + [str] * num_types)
  2. That is a quirk of our custom Enums with metadata that mypy doesn't understand, you add a # type: ignore in that line
  3. Use raw strings for regexs: r"\([$#](\d+)\)$". If you don't, then Python will interpret the backslashes and they won't be in the regex.

@Frostbyte0x70 Frostbyte0x70 marked this pull request as ready for review July 3, 2024 17:59
@Frostbyte0x70
Copy link
Member Author

@theCapypara Not sure if you saw it, but this is ready for review now. Just wanted to make sure you didn't miss it.

Copy link
Member

@theCapypara theCapypara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!! I have some remarks, but nothing big.

skytemple/data/widget/symbols/main.ui Outdated Show resolved Hide resolved
<property name="shadow-type">in</property>
<property name="propagate-natural-height">True</property>
<child>
<object class="GtkTreeView" id="symbols_treeview">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tree view requires horizontal scrolling in a lot of cases which is not great. However we can fix this with the GTK 4 migration. We really need to care more about smaller screen sizes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it a bit more bearable however, please switch the value and description column around. If you can figure out if there is a good way to make it so that only a small portion of description is shown by default and there is a way to show more details that would be even better.

Copy link
Member Author

@Frostbyte0x70 Frostbyte0x70 Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tree view requires horizontal scrolling in a lot of cases

Does it? I've never had to scroll horizontally. My screen resolution is on the high end (1080p), but there's always some space available on the right side.

The easiest fix would be to reduce the width limit for the description column, but I want to make sure it's necessary first. It might look worse in bigger screens if we do.

skytemple/module/symbols/module.py Outdated Show resolved Hide resolved
skytemple/module/symbols/widget/main.py Outdated Show resolved Hide resolved
new_value_final = str(int(_id))
self.on_value_changed(path, new_value_final)

def on_value_changed(self, path: str, new_value: str, model_iter: Optional[Gtk.TreeIter] = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add visual feedback when any row is changed. There should be an asterisks for unsaved changes similiar to how it is done in the main item tree. Maybe make changed rows bold as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where exactly should the asterisk appear? I don't think I can access the individual cells to change the text.
Bolding should be doable though. Do I just bold the entire row?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
As for the asterisks, there are a few options, potentially the eaiest is to add a new cell renderer to the first column that renders a column in the store that either contains "" or "*", this is similiar to how it works in the main item store.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh... how do I know when the ROM has been saved so I can restore the normal text display?

Copy link
Member

@theCapypara theCapypara Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I don't remember if there is a hook for that, maybe not. But tbh I think it's also fine if you don't reset it while the symbol editor is still open for now.
I guess another issue is also that you don't know what changed when you re-open. But that is also fine.
I guess this way it's more like a "this is what you changed since you last opened the symbol editor". In that case just using bold is probably better, no asterisk, since the asterisk is assosiated with the ROM itself not being saved, that might confuse people.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then, just bold for now.

skytemple/module/symbols/module.py Outdated Show resolved Hide resolved
from skytemple_files.hardcoded.symbols.manual.enums import get_enum_values, get_all_enum_types
from skytemple_files.hardcoded.symbols.unsupported_type_error import UnsupportedTypeError

_instance: "ModelGetter | None" = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put from __future__ import annotations at the top of all source files and then use regular type annotations (not strings)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhh, so that's how you avoid ImportErrors when referencing a type before or during its declaration. The only workaround I knew was using a string to declare the type. Good to know.

I've changed it in all files that needed it. Why should it be included in the others?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just like to have it everywhere so Python parses the annotations consistently everywhere. Having that future enabled changes the runtime characteristics of annotations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be done

get() instead.
"""
if do_not_instantiate != self._instantiation_string:
raise ValueError("This class cannot be directly instantiated")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to use Python's __new__ for a singleton pattern, but this is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elaborate, please? This is the only way I know right now.

Copy link
Member

@theCapypara theCapypara Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

skytemple/module/symbols/model_getter.py Show resolved Hide resolved
@theCapypara theCapypara merged commit 948934e into SkyTemple:master Jul 19, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants