- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- In Game Notifications
- Site Map >
- Modding and Creation >
- Sims 4 Creation >
- Modding Discussion >
- In Game Notifications
Replies: 11 (Who?), Viewed: 11369 times.
#1
28th Dec 2014 at 7:26 AM
Last edited by scumbumbo : 25th Jun 2015 at 4:15 PM.
Posts: 2,671
Thanks: 62741 in 190 Posts
In Game Notifications
I wanted to be able to do notifications in my Family Tree Add-On I'm working on without the cheat output window necessarily being open. A bit of playing around, with the hidden 'ui.dialog.notification_test' command yielded this working method:
Code:
import services from sims4.localization import LocalizationHelperTuning from ui.ui_dialog_notification import UiDialogNotification def ft_show_notification(text, title=None): client = services.client_manager().get_first_client() if title is None: title = "Family Tree Mod" notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=lambda **_: LocalizationHelperTuning.get_raw_text(text), title=lambda **_: LocalizationHelperTuning.get_raw_text(title)) notification.show_dialog(icon_override=(None, client.active_sim))
The hard part was getting the client set without being able to pass _connection to the function. Once I solved that, everything fell into place nicely. Be sure to fix the long line starting "notification ="
Advertisement
#2
25th Jun 2015 at 4:14 PM
Last edited by scumbumbo : 17th Nov 2018 at 6:43 PM.
Posts: 2,671
Thanks: 62741 in 190 Posts
This method changed with the November 13, 2018 game patch, see further below for a new working example
I was asked for a clarification on how this worked, so I whipped up this as a "working example". If people are interested, I can expand on this with some examples using STBL support and/or custom icons:
Code:
import services import sims4.commands from sims4.localization import LocalizationHelperTuning from ui.ui_dialog_notification import UiDialogNotification def example_show_notification(text, title=None): # We need the client to get the active sim for the icon client = services.client_manager().get_first_client() # If no title was given, use a default if title is None: title = "Example Title" # Convert the strings to raw_text localized strings localized_text = lambda **_: LocalizationHelperTuning.get_raw_text(text) localized_title = lambda **_: LocalizationHelperTuning.get_raw_text(title) # Prepare and show the notification notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title) notification.show_dialog(icon_override=(None, client.active_sim)) # An example via some cheat commands. Note you need to put quotes around the arguments # when typing the commands at the cheat console, e.g. # notification.example "this is the text of a notification" # notification.example "this is a notification with an optional title" "title of notification" @sims4.commands.Command('notification.example', command_type=sims4.commands.CommandType.Live) def show_example_notification(text, title=None, _connection=None): output = sims4.commands.CheatOutput(_connection) output('Showing notification:\n text="{}"\n title="{}"'.format(text, title)) if title is None: # With no title, we can leave off the title argument example_show_notification(text) else: # Otherwise we need to send that to the notification function example_show_notification(text, title=title)
Test Subject
#3
3rd Jan 2018 at 4:34 PM
Posts: 5
Potential Update to 2018 Sims 4?
Quote: Originally posted by scumbumbo
I was asked for a clarification on how this worked, so I whipped up this as a "working example". If people are interested, I can expand on this with some examples using STBL support and/or custom icons... |
Hello @scumbumbo! I have been looking over your recent mods to see if you have instituted a simple in-game notification with the newer patch versions of the Sims 4. I thank you for leaving the de-compiled .py files in your mods, it helps a lot!
Unfortunately. I have not found anything that has worked so far for me. I have a custom pie menu (thanks to your awesome tutorial) that I want one of it's functions to output some generated data in a notification. No buttons, nothing fancy, just text. I have it currently outputting 8 lines of text/numbers to the console, but it requires the console already open, which is a pain.
I have tested your above code with the most recent patch, and can verify that the console output at least still works when calling notification.example:
Code:
output('Showing notification:\n text="{}"\n title="{}"'.format(text, title))
However, no notification pops up. You know better than I do how much EA has changed under the hood since 2014/2015. It is not surprising if they broke this as well.
I have been downloading random recently-updated mods that look like they use notifications with the hopes of finding .py files to pore over. I have found nothing yet. I see MC Command Center (deaderpool) has notifications on boot with recent patch versions, but everything of his is compiled.
I also found a bit of your code elsewhere from 2015 that deals with notifications:
Code:
import services from sims4.localization import _create_localized_string from ui.ui_dialog_notification import UiDialogNotification def CCB_notification(str_id, sim): client = services.client_manager().get_first_client() localized_title = lambda **_: sims4.localization._create_localized_string(0xA99E59A7) localized_text = lambda **_: sims4.localization._create_localized_string(str_id) notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title) notification.show_dialog(icon_override=(None, sim.sim_info)) @sims4.commands.Command('sims.ui_change_career_branch', command_type=sims4.commands.CommandType.Live) def MTS_Scumbumbo_ui_change_career_track(opt_sim:OptionalTargetParam=None, _connection=None): """ blah blah blah, do some stuff """ if not did_work: CCB_notification(0x59640527, sim)
The unfortunate thing with the above code is that it generates no exceptions to debug with, so I am a bit lost, wondering the best way to go about printing a simple notification (in Python) in 2018.
P.S. I hate bumping old threads, but this thread is all over Google as the top hit for "Sims 4 Game Notifications." There is not much info out there on this at all.
Any help you can give would be much appreciated!
Thank you again scumbumbo!
#4
3rd Jan 2018 at 6:50 PM
Posts: 2,671
Thanks: 62741 in 190 Posts
Hi @verschijnsel - The code you're trying to use above appears to be from Change Career Branch and is used to display a notification with a string from a string table. You can use this method (although I would not use that mod as your source example as it's not been updated in two years or so), but would have to build an STBL with the strings you want to display in order for it to work. If you just want to use a normal Python string for the notification you need to use the method I posted in message #2 above. That still works fine (just tried it in game myself).
Other than a typo, the only reason I can think you may not be seeing the notification when using the example I posted would be if you have your game paused. Notifications are queued, not instantly displayed, so the game would have to be taken off pause before it will show that notification.
ETA - The core difference between the two methods (STBL vs. the example above) is the use of sims4.localization._create_localized_string to use a string from an STBL vs using LocalizationHelperTuning.get_raw_text for displaying just a raw text string.
Other than a typo, the only reason I can think you may not be seeing the notification when using the example I posted would be if you have your game paused. Notifications are queued, not instantly displayed, so the game would have to be taken off pause before it will show that notification.
ETA - The core difference between the two methods (STBL vs. the example above) is the use of sims4.localization._create_localized_string to use a string from an STBL vs using LocalizationHelperTuning.get_raw_text for displaying just a raw text string.
Test Subject
#5
4th Jan 2018 at 10:11 AM
Posts: 5
Quote: Originally posted by scumbumbo
Other than a typo, the only reason I can think you may not be seeing the notification when using the example I posted would be if you have your game paused. Notifications are queued, not instantly displayed, so the game would have to be taken off pause before it will show that notification. |
Aww, you got me. I can't believe I did not test it un-paused. What a dumb mistake. I guess the good news is that this does still work. Thank you for confirming!
Test Subject
#6
6th Jan 2018 at 4:05 PM
Posts: 5
Custom Icons using Obj_Id/Sim Argument
Quote: Originally posted by scumbumbo
I was asked for a clarification on how this worked, so I whipped up this as a "working example". If people are interested, I can expand on this with some examples using STBL support and/or custom icons: |
Okay, so I cobbled together a way to pull an icon from the selected Sim, thank's to Scumbumbo's help.
Using Scumbumbo's mailbox tutorial as a guide (this is one command for the "enable" testing cheats, just stripped down):
Code:
@sims4.commands.Command('mbox.tc_enable', command_type=sims4.commands.CommandType.Live) def mbox_tc_enable_command(obj_id:int, _connection=None): obj = services.object_manager().get(obj_id) if obj.is_sim: text = "Test Text" title = "Test Title" example_show_notification(text, obj, title=title) else: continue
The object_manager() line retrieves a sim object with the obj_id passed from the XML argument "participant". "obj" now contains that "participant" sim, i.e the sim you clicked on.
Here is the notification function, again Scumbumbo's example, this time from above, but modified (in bold) to accept a sim object:
Code:
def example_show_notification(text, sim, title=None): # We need the client to get the active sim for the icon client = services.client_manager().get_first_client() # If no title was given, use a default if title is None: title = "Example Title" # Convert the strings to raw_text localized strings localized_text = lambda **_: LocalizationHelperTuning.get_raw_text(text) localized_title = lambda **_: LocalizationHelperTuning.get_raw_text(title) # Prepare and show the notification notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title) notification.show_dialog(icon_override=(None, sim.sim_info))
The sim.sim_info line is able to pull an icon using the "obj" sim object passed to the notification function. The test in the first function makes sure you don't send an object to the notification that is not a sim.
I am guessing this would be the proper way to do this in this case, unless passing the obj_id and pulling the sim object in the notification would be more efficient? Either way, it does work.
Thank you again scumbumbo!
#7
7th Jan 2018 at 2:29 AM
Posts: 2,671
Thanks: 62741 in 190 Posts
Quote: Originally posted by verschijnsel
The sim.sim_info line is able to pull an icon using the "obj" sim object passed to the notification function. The test in the first function makes sure you don't send an object to the notification that is not a sim. I am guessing this would be the proper way to do this in this case, unless passing the obj_id and pulling the sim object in the notification would be more efficient? Either way, it does work. |
For a simple example like this one, either method could be applicable - however in most modding situations you're going to be doing something with the sim or sim_info object in the caller method, so you already have a reference to that sim object. Sending the ID and making the notification method get a fresh reference to the sim object would be less efficient. So yeah, probably 95 times out of 100 the way you have chosen to do that is likely to be the best way.
You could pass just the sim_info item itself if you wanted, or even just a reference to the icon itself. But since you're not really passing all that data, just a reference to an existing object, that would be mostly a choice of style. Die-hard OOP programmers would probably disagree with me on that, but I don't think many die-hard OOP programmers choose to use Python to begin with!
Test Subject
#8
17th Nov 2018 at 9:59 AM
Posts: 2
So, I am trying to update a mod that broke with the November 13th patch. It no longer shows notifications and throws errors on startup. Converted .py injector and script to .pyc using Python 3.7 and errors went away, though everything besides the notification popup works? I dumped the output to the console window, and THAT works perfect, but the " example_show_notification" line like you have above does not seem to do anything. No error either, just silence, even after a long while in game? As mentioned, this specific mod worked right before the November 13th patch, and the mod author is long gone, unfortunately. I know things are being called, as the text output in the console is identical to what the notification used to be when it worked?
A lot of the lines in their included .py file are identical to what scumbumbo posted in post #2, hence how I found this thread. Thank you Google.
Any ideas if this method is broken now? Was it just a syntax change?
A lot of the lines in their included .py file are identical to what scumbumbo posted in post #2, hence how I found this thread. Thank you Google.
Any ideas if this method is broken now? Was it just a syntax change?
#9
17th Nov 2018 at 5:51 PM
Posts: 2,671
Thanks: 62741 in 190 Posts
Yes, the method for passing the icon to the UI has changed slightly with the latest patch. Where before a simple tuple was used for the icon_override, now a named tuple is used. There is a method in the distributor package of the game that can be used to easily generate the required named tuple. Rewriting the example from that second post above should make things clear. The only changes are the import to identify the IconInfoData method, and the call to the notification.show_dialog which uses that new method.
If you want to use an icon by resource id, rather than one that is attached to an object instance, then you need to use an icon_resource argument to the IconInfoData, for instance to use the chess pawn icon for your notification:
Code:
import services import sims4.commands from sims4.localization import LocalizationHelperTuning from ui.ui_dialog_notification import UiDialogNotification from distributor.shared_messages import IconInfoData def example_show_notification(text, title=None): # We need the client to get the active sim for the icon client = services.client_manager().get_first_client() # If no title was given, use a default if title is None: title = "Example Title" # Convert the strings to raw_text localized strings localized_text = lambda **_: LocalizationHelperTuning.get_raw_text(text) localized_title = lambda **_: LocalizationHelperTuning.get_raw_text(title) # Prepare and show the notification notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title) notification.show_dialog(icon_override=IconInfoData(obj_instance=client.active_sim)) # An example via some cheat commands. Note you need to put quotes around the arguments # when typing the commands at the cheat console, e.g. # notification.example "this is the text of a notification" # notification.example "this is a notification with an optional title" "title of notification" @sims4.commands.Command('notification.example', command_type=sims4.commands.CommandType.Live) def show_example_notification(text, title=None, _connection=None): output = sims4.commands.CheatOutput(_connection) output('Showing notification:\n text="{}"\n title="{}"'.format(text, title)) if title is None: # With no title, we can leave off the title argument example_show_notification(text) else: # Otherwise we need to send that to the notification function example_show_notification(text, title=title)
If you want to use an icon by resource id, rather than one that is attached to an object instance, then you need to use an icon_resource argument to the IconInfoData, for instance to use the chess pawn icon for your notification:
Code:
# Add an import to top to get the resource from sims4.resources import Types, get_resource_key # Change the last few lines of the prepare and show section to get that resource key # and use it in the icon_override my_icon = get_resource_key(0x3ef446c8cc0cecfc, Types.PNG) notification = UiDialogNotification.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title) notification.show_dialog(icon_override=IconInfoData(icon_resource=my_icon))
Test Subject
#10
17th Nov 2018 at 10:58 PM
Posts: 2
Aha, that worked! Thank you. At least it was a pretty small change.
Now on to try fixing the 65000 other broken mods. You would think Sims 4 was a pre-alpha software seeing how much stuff broke with this patch!
Now on to try fixing the 65000 other broken mods. You would think Sims 4 was a pre-alpha software seeing how much stuff broke with this patch!
#11
7th Dec 2018 at 3:29 AM
Last edited by scumbumbo : 7th Dec 2018 at 3:41 AM.
Posts: 2,671
Thanks: 62741 in 190 Posts
After figuring out some new things with using notifications from scripts nearly a month ago I thought it would be good to get this updated with a new and more complete example. This covers the latest method for including icons in the notification, using STBL strings instead of raw strings, adding ui responses (clickable icons and buttons) and the use of HTML font tags for text.
It is rather long as it is heavily commented, so I'm attaching this as a zip file in compiled and source form.
As always, if there's any questions just shout 'em out.
It is rather long as it is heavily commented, so I'm attaching this as a zip file in compiled and source form.
As always, if there's any questions just shout 'em out.
Attached files:
notification_example.zip (6.0 KB, 212 downloads) - View custom content | ||
4268 2018-12-06 21:22 notification_example.pyc 10786 2018-12-06 15:44 notification_example.py --------- ------- 15054 2 files |
||
Description: Notification example for game patch 1.47.49 (Get Famous patch) or later |
#12
5th Jan 2019 at 6:15 AM
Posts: 2,671
Thanks: 62741 in 190 Posts
Then of course, there's the easy way to do all this stuff, using module tuning.
https://modthesims.info/showthread.php?t=622129
https://modthesims.info/showthread.php?t=622129
Who Posted
|