Create a "like" button, which only counts up once
Posted: Fri May 15, 2020 9:21 am
Hi all,
I want to create a button which displays at the side of a chat post which acts as a "like" button i.e. it can only be pushed once and adds 1 to the number shown.
My code so far... Screens:
How the chat works in script:
Not only am I unsure how to create the button and change the text on it, but each post will have a different amount of likes as well (which I'd like to set with $ fflog.add_chat). So, without making a different like button for every post, I'm unsure how to go about this, too.
Here's the rest of the chat code for reference:
Does anyone have any ideas?
I want to create a button which displays at the side of a chat post which acts as a "like" button i.e. it can only be pushed once and adds 1 to the number shown.
My code so far... Screens:
Code: Select all
screen chat_picture(pic=None, nick=None, avatar=None, posttime=None):
hbox:
spacing 10
if avatar != None:
add avatar
vbox:
hbox:
if nick != None:
text nick
if posttime != None:
text " - "
text posttime
if nick != None and pic != None:
null height 10
if pic != None:
add pic
vbox:
yalign 1.0
spacing 8
button:
background "images/button_likes.png"
text "{color=#000}1{/color}" xpos 54 ypos -5 ### this is the button I want to change. So far, it doesn't have an action.
Code: Select all
$ fflog.add_chat(msg="This is a message I want to like.", nick="Wolfie", avatar="images/avatars/wolfie.png", posttime="< 1 hour ago")
Here's the rest of the chat code for reference:
Code: Select all
screen chat_log(log):
viewport id "chatlog":
xpos 332
ypos 144
ysize 900
yadjustment log.adjustment()
mousewheel True
draggable True
yinitial 1.0
python:
# Thanks to mangoduck at
# https://lemmasoft.renai.us/forums/viewtopic.php?t=32584 for this
# flash of insight for auto scrolling
log.adjustment().value = chat_infinity_float
vbox:
spacing 20
for type, kwargs in log.history():
use expression type pass (**kwargs)
#...
define chat_infinity_float = float("inf")
init python:
class ChatLog:
"""
Thanks to milkymalk at
https://lemmasoft.renai.us/forums/viewtopic.php?t=44711
for the idea here. I refined the implementation a bunch, but it's their
core suggestion that helped.
"""
def __init__(self):
# Create a blank list for the chats.
self._chats = []
# And make the adjustment for our screen.
self._adj = ui.adjustment()
def add_chat(self, type="chat_entry", **kwargs):
"""
Adds a new chat entry.
type - selects the name of the screen that will display this line
of chat.
Additional named arguments will need to be provided based on the
arguments the screen that displays the line. For the default
chat_entry screen, this will be msg, nick, and avatar.
For example:
mychat.add_chat(type="chat_entry", msg="Hello world",
nick="darkflamemaster", avatar="dfm chat avatar")
"""
self._chats.append((type, kwargs))
return len(self._chats)-1
def history(self):
""" Returns the list of chat lines. """
return self._chats
def adjustment(self):
""" Returns the adjustment. Needed by the chat log screen """
return self._adj;