- Dec 18, 2019
- 21
- 1
Hi,
I have found a quite nice script on the internet for social media.
I tried to change the code as followed
Thanks a lot
I have found a quite nice script on the internet for social media.
You must be registered to see the links
I tried to change the code as followed
- When the user posts sth /Likes as post its stays and wil not be reset.
- When you click somewhere it shouldnt continoue the story, i.e. it shouldnt jump back to the main menu
- How can i change the code to make it easier to have this social media for different characters.
Thanks a lot
Code:
# vk.rpy module simulates a simplified copy of the social network vk_
# colors and pictures are customizable, you can simulate another similar social network
# author: 7DOTS license: creative commons with attribution
init python:
# auto-declaration of images
config.automatic_images_minimum_components = 1
config.automatic_images = [' ', '_', '/']
config.automatic_images_strip = ["images"]
init -999 python:
# background colors can be replaced with constructs like Frame ("imagename", 0, 0)
# the ability to comment is enabled by default
vk_can_comment = True
# post and comment
vk_font = "fonts/Tahoma.ttf"
# stripe imitating the header of the social network
vk_header = "vk header"
# header height
vk_headerheight = 60
# picture for avade by default
vk_avadefault = "vk avadefault"
# mask for cropping avatars
vk_ava_mask = "vk avamask"
# ava side size
vk_avasize = 72
# picture for the clicked like
vk_likeon = "vk likeon"
# picture for
vk_likeoff = "vk likeoff"
# suffix for reduced likes
vk_zoom = "2"
# picture for the comment
vk_comment = "vk comment"
# username color in header
vk_usercolor = "#fff"
# color for title text
vk_nickcolor = "#175490"
# color for the likes and comments
vk_countcolor = "#96A0B4"
# color for the like counter when the like is
vk_likecolor = "#CB272F"
# text color
vk_textcolor = "#000"
# screen color outside the post
vk_screencolor = "images/facebook/page/vk_morrison_page.png"
# screen color inside the post
vk_postcolor = "#fff"
# post width
vk_postwidth = 1080
# post height
vk_screenheight = 840
# padding from the edge of the post to the content
# (1080 - 28 - 28 = 1024 - the optimal width for the image in the post)
vk_postpadding = 28
# indent from avatar to comment content
vk_commpadding = 14
# user ava
vk_ava = vk_avadefault
# username
vk_nickname = _("Анон Аноныч")
# Likes text size
vk_likesize = 24
# heading text size
vk_nicksize = 22
# size of other text
vk_textsize = 20
# a list of autocorrect text of smiles to their images
vk_smiles = {":)": "vk smile smile", ":(": "vk smile sad", "xD": "vk smile rofl", ":D": "vk smile rofl", "*up*": "vk smile up", "↑": "vk smile up"}
# class for the post
class VKpost:
def __init__(self, nick=_("Анон Аноныч"), text="", ava=vk_avadefault, likes=0, user=False, comments=[]):
# avatar cropped by mask (in a circle)
self.ava = AlphaMask(ava, renpy.easy.displayable(vk_ava_mask))
self.nick = nick # author name
self.text = text # post text
self.likes = likes # post likes
self.comments = comments ## comments (list of VKpost instances)
self.count = len(comments) # number of comments for this post
self.user = user # did the user like
# get the number of comments for this post
def get_com_count(self):
return len(self.comments)
# put / remove the user's like if user == True
# or just add a bunch of left likes
def add_likes(self, count=1, user=True):
if user:
if self.user:
self.likes -= 1
else:
self.likes += 1
self.user = not self.user
else:
self.likes += count
# list of posts in the feed
vk_posts = []
# set user avatar
def vk_set_ava(ava):
global vk_ava
vk_ava = AlphaMask(ava, renpy.easy.displayable(vk_ava_mask))
# post likes
def vk_post_add_like(i, count=1, user=True):
global vk_posts
if i >= 0 and i < len(vk_posts):
vk_posts[i].add_likes(count, user)
VKPostAddLike = renpy.curry(vk_post_add_like)
# like comments
def vk_comm_add_like(i, ii, count=1, user=True):
global vk_posts
if i >= 0 and i < len(vk_posts):
if ii >= 0 and ii < len(vk_posts[i].comments):
vk_posts[i].comments[ii].add_likes(count, user)
VKCommAddLike = renpy.curry(vk_comm_add_like)
# refresh screens
def repaint():
renpy.restart_interaction()
Repaint = renpy.curry(repaint)
# add one post (but you can immediately list)
def vk_add_post(post=[]):
global vk_posts
if not isinstance(post, (list, tuple)):
post = [post]
for i in post:
vk_posts.append(i)
# to scroll
yadj.value = yadjValue
renpy.restart_interaction()
VKAddPost = renpy.curry(vk_add_post)
# add a comment (or more in the [list])
def vk_add_comm(comm, index=0):
global vk_posts
if not isinstance(comm, list):
comm = [comm]
for i in comm:
# remove spaces around text
i.text = i.text.strip()
# remove double spaces
while i.text.find(" ") >= 0:
i.text = i.text.replace(" ", " ")
# replace smiles with pictures of smiles
keys = vk_smiles.keys()
for k in keys:
i.text = i.text.replace(k, "{image=" + vk_smiles[k] + "}")
# add comments
vk_posts[index].comments = vk_posts[index].comments + comm
# define the style (color) of the like
def vk_like_style(user):
if user:
return "vk_like_on"
return "vk_like_off"
# define the picture of the comment
def vk_comm_text(comments):
count = len(comments)
text = "{image=" + vk_comment + "}"
if count > 0:
text = text + " " + str(count)
else:
text = text + " "
return text
# define the like picture
def vk_like_text(user, count=0, zoom=""):
text = "{image=" + vk_likeoff + zoom + "}"
if user:
text = "{image=" + vk_likeon + zoom + "}"
if count > 0:
text = text + " " + str(count)
else:
text = text + " "
return text
# scroll to the very top
def vk_scroll0():
yadj.value = 0
renpy.restart_interaction()
# to scroll down when adding posts
yadjValue = float("inf")
yadj = ui.adjustment()
# call the comment input routine
def vk_input(i):
renpy.call_in_new_context("vkinput", i)
VKinput = renpy.curry(vk_input)
init 999:
# style for the frame without indentation
style vk_empty is frame:
# without indents
xpadding 0 ypadding 0
xmargin 0 ymargin 0
# top center
align (.5, .0)
# background
background vk_screencolor
# style for the screen
style vk_screen is vk_empty:
# full screen
xminimum config.screen_width
xmaximum config.screen_width
# hardcoded height
yminimum vk_screenheight ymaximum vk_screenheight
# The center of
align(.5, .0)
# background
background vk_screencolor
# post
style vk_post is vk_empty:
# hardcoded width
xminimum vk_postwidth
xmaximum vk_postwidth
# padding from post border to content
xpadding vk_postpadding
ypadding vk_postpadding
# space between posts (and comments)
ymargin vk_commpadding
# The center of
align(.5, .0)
# background
background vk_postcolor
# style for the like bar
style vk_likes is vk_empty:
# hardcoded width
xminimum vk_postwidth
xmaximum vk_postwidth
# padding from post border to content
xpadding 0 ypadding 0
# vertical padding
ymargin vk_commpadding
# The center of
align(.5, .0)
# background
background vk_postcolor
# comment
style vk_comm is vk_empty:
# left
xalign .0
# less
ymargin 0
# background
background None
# Avytarok style for
style vk_avatar is vk_empty:
# center left,
align(.0, .0)
# size
xminimum vk_avasize xmaximum vk_avasize
yminimum vk_avasize ymaximum vk_avasize
# background
background None
# text
style vk_text is text:
size vk_textsize
color vk_textcolor
font vk_font
# style of the title / name text
style vk_nick is text:
size vk_nicksize
color vk_nickcolor
bold True
font vk_font
# social network screen
screen vk:
# screen
frame:
style "vk_screen"
#vbox:
# frame:
# style "vk_empty"
# yminimum vk_headerheight
# ymaximum vk_headerheight
# xfill True
# cap
# add vk_header align (.5, .0)
hbox:
xpos 0
ypos 100
spacing vk_commpadding
text vk_nickname style "vk_nick" color vk_usercolor yalign .5
add vk_ava:
zoom .75
yalign .5
# viewport for scrolling posts
viewport:
id "id vk"
xinitial 1.0
yfill False
xfill False
mousewheel True
draggable True
side_xfill False
transclude
yadjustment yadj
xalign .5
# all posts
vbox:
for i in range(len(vk_posts)):
# post background
frame:
style "vk_post"
vbox:
spacing vk_commpadding # text indent from ava
# post title
hbox:
spacing vk_postpadding # spacing between ava and title
# avatar of the author
frame:
style "vk_avatar"
add vk_posts[i].ava
# author name
text vk_posts[i].nick style "vk_nick"
# post
text vk_posts[i].text style "vk_text"
# likes
frame:
style "vk_likes"
xpadding 0
hbox:
xalign .0
# likes and quantity
textbutton vk_like_text(vk_posts[i].user, vk_posts[i].likes):
action [VKPostAddLike(i), Repaint()]
style "vk_text"
if vk_posts[i].user:
text_color vk_likecolor
else:
text_color vk_countcolor
text_size vk_likesize
text_bold True
xminimum 96
yoffset 10
# number of comments
textbutton vk_comm_text(vk_posts[i].comments):
if vk_can_comment:
action VKinput(i)
else:
action []
style "vk_text"
text_color vk_countcolor
text_size vk_likesize
text_bold True
yoffset 10
xminimum 96
# comments
if len(vk_posts[i].comments) > 0:
# all comments window
frame:
style "vk_comm"
xpadding 0
vbox:
# iterating over comments
for ii in range(len(vk_posts[i].comments)):
# next comment window
frame:
style "vk_comm"
hbox:
spacing vk_commpadding
#commenter avatar
frame:
style "vk_avatar"
add vk_posts[i].comments[ii].ava
vbox:
# commentator name
text vk_posts[i].comments[ii].nick style "vk_nick"
# comment text
text vk_posts[i].comments[ii].text style "vk_text"
# comment likes
frame:
style "vk_likes"
xpadding 0
hbox:
spacing vk_commpadding
xpos .8
# likes and quantity
textbutton vk_like_text(vk_posts[i].comments[ii].user, vk_posts[i].comments[ii].likes, vk_zoom):
action [VKCommAddLike(i, ii), Repaint()]
style "vk_text"
if vk_posts[i].comments[ii].user:
text_color vk_likecolor
else:
text_color vk_countcolor
text_size vk_likesize * 3 / 4
text_bold True
yoffset 10
# subroutine for user input comment
label vkinput(post_index):
scene black
$ text = renpy.input(_("Введите текст комментария:"))
if text.strip():
$ vk_add_comm(VKpost(vk_nickname, text, vk_ava), 0)
return
# EXAMPLE OF USE:
# on the feed screen, in addition to likes, the comment button next to it works
label vk_test:
scene bg win
# add post (s)
python:
# user avatar
vk_set_ava("7dots")
# username
vk_nickname = _("«7DOTS» визуальные новеллы")
# reset all posts
vk_posts = []
# add posts
vk_add_post(VKpost(vk_nickname, "This is the maxim was born when discussing the acidity of the ruvn))\n\n{a=call_in_new_context:img1_label}{image=post}{/a}", vk_ava, 8))
# adding a comment to post number 0
vk_add_comm(VKpost(_("Anonymous Anonistych"), "Your games are shit!", vk_avadefault, 1), 0)
# adding a comment to post number 0
vk_add_comm(VKpost("Vovan Petrov", "Ахахах xD", "ava vovan", 1, True), 0)
# adding a comment to post number 0
vk_add_comm(VKpost(vk_nickname, "* up * And these comments confirm my words :)", vk_ava, 3), 0)
# rewind to the very top of the tape
$ vk_scroll0()
# show screen vk
show screen vk
with dissolve
pause
## waiting for a click past the feed
"An example of how a simplified Vkontakte feed simulates. You can like posts and comments. It is also possible to leave comments by entering them from the keyboard."
return
label img1_label:
window hide
show black
show post at truecenter
pause
return