|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 sakihadrimi 于 2023-5-12 02:21 编辑
[RenPy] 纯文本查看 复制代码 default synclP_vpy_adj = ui.adjustment()
define NcyclNaviStackList = []
default StackPlacementTmp = []
default curentryid = ""
screen synclP():
frame:
xpos +300
area(200,80,1600,420)
viewport id "vp_synclPup": #词条viewport
area(0,0,1600,420)
draggable True
mousewheel True
xinitial 0.0
yinitial 0.0
yadjustment synclP_vpy_adj
vbox:
spacing 0
textbutton _("返回1"):
id "inNcyclreturn"
xysize(200,100)
xalign 1.0
background Solid("#0ff5")
text_color "#000"
action Hide()
$ NcyclSubEntryList.sort(key=lambda x:(int(x.subentrylv.split(".")[0]), int(x.subentrylv.split(".")[1]), int(x.subentrylv.split(".")[2].split("-")[0]), int(x.subentrylv.split(".")[2].split("-")[1]))) #词条内容多级排序
for idxSNtrys in range(0, len(NcyclSubEntryList)):
if NcyclSubEntryList[idxSNtrys].parentcnt==1 or NcyclSubEntryList[idxSNtrys].parentcnt==2:
if int(NcyclSubEntryList[idxSNtrys].subentrylv.split(".")[0]) != 0 and int(NcyclSubEntryList[idxSNtrys].subentrylv.split(".")[1]) != 0 and int(NcyclSubEntryList[idxSNtrys].subentrylv.split(".")[2].split("-")[0]) != 0:
text NcyclSubEntryList[idxSNtrys].desc:
xpos +60
id "NCStackContent"+str(idxSNtrys)
$ curentryid = "NCStackContent"+str(idxSNtrys)
#或者,$ StackPlacementTmp = renpy.get_widget_properties("curentryid")["xpos"]
$ StackPlacementTmp = renpy.get_displayable_properties("curentryid")['ypos'] #尝试获取ypos参数
$ NcyclSubEntryList[idxSNtrys].stackseq = StackPlacementTmp #用获取的ypos参数更新类词条实例的.stackseq $ NcyclNaviStackList.append(NcyclSubEntryList[idxSNtrys])
#... ... (省略若干elif,与前面的if操作并无显著区别,只是将不同内容是否加入导航栏待显示列表NcyclNaviStackList中(比如说,正文就不会加入,只需要加入各级标题))
else:
text NcyclSubEntryList[idxSNtrys].desc:
id "NCStackContent"+"idxSNtrys"
vbar:
id "introbar"
value YScrollValue("vp_synclPup")
xalign 1.0
#adjustment synclP_vpy_adj
viewport id "vp_synclPup_navi": #侧边导航栏viewport
area(1200,40,600,300)
draggable True
mousewheel True
xinitial 1.0
yinitial 0.0
vbox:
$ NcyclNaviStackList.sort(key=lambda x:(int(x.subentrylv.split(".")[0]), int(x.subentrylv.split(".")[1]), int(x.subentrylv.split(".")[2].split("-")[0]), int(x.subentrylv.split(".")[2].split("-")[1]))) #标题多级排序
for idxSNtrys in range(0, len(NcyclNaviStackList)):
textbutton NcyclNaviStackList[idxSNtrys].desc:
xysize(200,100)
xalign 1.0
background Solid("#0ff5")
text_color "#000"
action SetVariable("synclP_vpy_adj.value", int(NcyclNaviStackList[idxSNtrys].stackseq))
#action SetVariable(synclP_vpy_adj.value, NcyclNaviStackList[idxSNtrys].stackseq)
vbar:
id "navibar"
value YScrollValue("vp_synclPup_navi") xalign 0.9
目的:在viewport中使用vbox堆叠数目不定的词条,并在生成时就记录对应词条的位置(主要是ypos),以供后续的跳转(用做侧边栏导航);
- 每个词条是写在词条类的实例里面的,词条的位置是在生成时记录在对应词条实例的属性中。
遇到的问题有两个,
- 一个就是get_widget_properties("id")或get_displayable_properties("id")返回的是一个空的字典,自然就没有对应的键-值对(程序中的['ypos']),想问一下为什么/如何解决?
- 第二个是,action SetVariable("synclP_vpy_adj.value", int(NcyclNaviStackList[idxSNtrys].stackseq))无法按照预想的,通过给到其中与vp_synclPup的yadjustment挂钩的synclP_vpy_adj.value中,表现为点击textbutton没有变化
- 同时还有另外一个更奇怪的事情就是,每点击一次,导航栏词条数目就会扩增一次,疑似又进行了一次for循环明着是为什么/如何避免?
词条类是这么写的(由于是python读取有一定格式的.md(txt)文本自动批量生成的,所以就选择存到类里):
[RenPy] 纯文本查看 复制代码 init -1 python:
class NcyclSubEntry(object):
def __init__(self, infer = [], parentcnt="0", subentrylv = "-1.0.0-0", version = "-1.0", desc = ""):
self.seen = False
self.collected = False
self.hidden = True
self.infer = infer
self.parentcnt = parentcnt
self.subentrylv = subentrylv
self.stackseq = -1
self.hashseq = -1
self.version = version # 用于调整不同版本表述,注意对应的
self.read = False
self.desc = desc
define NcyclSubEntry0 = NcyclSubEntry(infer = [], parentcnt= 1, subentrylv = '-1.0.0-0', version = '4.5.6', desc = '词条化,你说的\n')
define NcyclSubEntry1 = NcyclSubEntry(infer = [], parentcnt= 1, subentrylv = '3.0.0-0', version = '1', desc = '第一行文字\n')
define NcyclSubEntry2 = NcyclSubEntry(infer = [], parentcnt= 1, subentrylv = '4.1.0-3', version = '5.2', desc = '能不能=写点别“是索引的问题”的看看能不能显示?写长一点看看能不能自动换行。\n')
define NcyclSubEntry3 = NcyclSubEntry(infer = [], parentcnt= 1, subentrylv = '4.1.1-0', version = '5.2', desc = '虚拟\n')
define NcyclSubEntry4 = NcyclSubEntry(infer = [], parentcnt= 2, subentrylv = '0.0.0-1', version = '0', desc = '- 因此除了自称,国际上一般还称\n\n')
define NcyclSubEntry5 = NcyclSubEntry(infer = [], parentcnt= 2, subentrylv = '-1.0.0-0', version = '0', desc = '写上标题,请\n')
define NcyclSubEntry6 = NcyclSubEntry(infer = [], parentcnt= 2, subentrylv = '1.2.3-2', version = '5.3', desc = '\n')
define NcyclSubEntry7 = NcyclSubEntry(infer = [], parentcnt= 2, subentrylv = '1.2.3-1', version = '5.3', desc = '正常点\n')
define NcyclSubEntry8 = NcyclSubEntry(infer = [], parentcnt= 2, subentrylv = '2.1.0-2', version = '4\n', desc = '第一学期\n第二学期\n\n')
define NcyclSubEntryList = [NcyclSubEntry0, NcyclSubEntry1, NcyclSubEntry2, NcyclSubEntry3, NcyclSubEntry4, NcyclSubEntry5, NcyclSubEntry6, NcyclSubEntry7, NcyclSubEntry8]
报错信息如下:
关于lemmasoft上类似的问题解答,但并没能解决:
- https://lemmasoft.renai.us/forums/viewtopic.php?f=8&t=45263&p=462841&hilit=get_widget_properties#p462841
补充想法:
- 我实际只是需要当前页面中经过vbox堆叠后的相对位置(实际大概是Multibox经Wrapper的结果,不确定这个过程是否使得它的properties背书俺也或者消去),所以选择了在一开始for生成的时候就获取对应组建的位置
- 虽说文档中指出了经过transform之后,它的位置属性可能变化了,但这应该不影响我一开始(当for循环结束、组件堆叠完毕)获得的值。
请求论坛大佬帮助。关于词条有什么好建议也请留下,多谢!
|
|