This commit is contained in:
恍兮惚兮 2024-07-01 02:07:46 +08:00
parent 3a7135a1bd
commit 192df621bb
4 changed files with 74 additions and 33 deletions

View File

@ -18,7 +18,7 @@ from myutils.utils import (
minmaxmoveobservefunc, minmaxmoveobservefunc,
parsemayberegexreplace, parsemayberegexreplace,
kanjitrans, kanjitrans,
checkifnewgame, find_or_create_uid,
checkpostusing, checkpostusing,
stringfyerror, stringfyerror,
) )
@ -483,9 +483,16 @@ class MAINUI:
return return
if not title: if not title:
title = windows.GetWindowText(hwnd) title = windows.GetWindowText(hwnd)
checkifnewgame(savehook_new_list, pexe, title)
if globalconfig["sourcestatus2"]["texthook"]["use"]: if not globalconfig["sourcestatus2"]["texthook"]["use"]:
gameuid = findgameuidofpath(pexe, savehook_new_list) return
gameuid = find_or_create_uid(savehook_new_list, pexe, title)
if gameuid not in savehook_new_list:
savehook_new_list.insert(0, gameuid)
else:
if globalconfig["startgamenototop"] == False:
idx = savehook_new_list.index(gameuid)
savehook_new_list.insert(0, savehook_new_list.pop(idx))
self.textsource = texthook(pids, hwnd, pexe, gameuid) self.textsource = texthook(pids, hwnd, pexe, gameuid)
self.textsource.start() self.textsource.start()

View File

@ -23,7 +23,7 @@ from myutils.wrapper import (
Singleton_close, Singleton_close,
) )
from myutils.utils import ( from myutils.utils import (
checkifnewgame, find_or_create_uid,
str2rgba, str2rgba,
gamdidchangedtask, gamdidchangedtask,
titlechangedtask, titlechangedtask,
@ -1769,8 +1769,13 @@ def addgamesingle(callback, targetlist):
if res == "": if res == "":
return return
res = os.path.normpath(res) res = os.path.normpath(res)
uid = checkifnewgame(targetlist, res) uid = find_or_create_uid(targetlist, res)
if uid: if uid in targetlist:
idx = targetlist.index(uid)
if idx == 0:
return
targetlist.pop(idx)
targetlist.insert(0, uid)
callback(uid) callback(uid)
@ -1785,8 +1790,10 @@ def addgamebatch(callback, targetlist):
path = os.path.normpath(os.path.abspath(os.path.join(_dir, _f))) path = os.path.normpath(os.path.abspath(os.path.join(_dir, _f)))
if path.lower().endswith(".exe") == False: if path.lower().endswith(".exe") == False:
continue continue
uid = checkifnewgame(targetlist, path) uid = find_or_create_uid(targetlist, path)
if uid: if uid in targetlist:
targetlist.pop(targetlist.index(uid))
targetlist.insert(0, uid)
callback(uid) callback(uid)
@ -1917,11 +1924,20 @@ class dialog_savedgame_new(QWidget):
def clicked4(self): def clicked4(self):
opendirforgameuid(self.currentfocusuid) opendirforgameuid(self.currentfocusuid)
def addgame(self, uid):
if uid not in self.idxsave:
self.newline(uid, first=True)
else:
idx = self.idxsave.index(uid)
self.idxsave.pop(idx)
self.idxsave.insert(0, uid)
self.flow.totop1(idx)
def clicked3_batch(self): def clicked3_batch(self):
addgamebatch(lambda uid: self.newline(uid, True), self.reflist) addgamebatch(self.addgame, self.reflist)
def clicked3(self): def clicked3(self):
addgamesingle(lambda uid: self.newline(uid, True), self.reflist) addgamesingle(self.addgame, self.reflist)
def tagschanged(self, tags): def tagschanged(self, tags):
self.currtags = tags self.currtags = tags
@ -2318,7 +2334,7 @@ class LazyLoadTableView(QTableView):
for i in range(len(self.widgetfunction)): for i in range(len(self.widgetfunction)):
if self.widgetfunction[i][0] >= start: if self.widgetfunction[i][0] >= start:
self.widgetfunction[i][0] += off self.widgetfunction[i][0] += off
print(self.widgetfunction[i]) # print(self.widgetfunction[i])
self.loadVisibleRows() self.loadVisibleRows()
@ -2367,16 +2383,21 @@ class dialog_savedgame_lagacy(QWidget):
idx = self.table.currentIndex().row() idx = self.table.currentIndex().row()
savehook_new_list.pop(idx) savehook_new_list.pop(idx)
self.savelist.pop(idx)
self.model.removeRow(self.table.currentIndex().row()) self.model.removeRow(self.table.currentIndex().row())
except: except:
pass pass
def clicked3(self): def clicked3(self):
def call(uid): def call(uid):
if uid in self.savelist:
idx = self.savelist.index(uid)
self.savelist.pop(idx)
self.model.removeRow(idx)
self.newline(0, uid) self.newline(0, uid)
self.table.setCurrentIndex(self.model.index(0, 0)) self.table.setCurrentIndex(self.model.index(0, 0))
addgamesingle(call) addgamesingle(call, savehook_new_list)
def clicked(self): def clicked(self):
startgamecheck( startgamecheck(
@ -2440,8 +2461,10 @@ class dialog_savedgame_lagacy(QWidget):
table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection)) table.setSelectionMode((QAbstractItemView.SelectionMode.SingleSelection))
table.setWordWrap(False) table.setWordWrap(False)
self.table = table self.table = table
self.savelist = []
for row, k in enumerate(savehook_new_list): # 2 for row, k in enumerate(savehook_new_list): # 2
self.newline(row, k) self.newline(row, k)
self.savelist.append(k)
self.table.starttraceir() self.table.starttraceir()
bottom = QHBoxLayout() bottom = QHBoxLayout()
@ -3107,11 +3130,20 @@ class dialog_savedgame_v3(QWidget):
def clicked4(self): def clicked4(self):
opendirforgameuid(self.currentfocusuid) opendirforgameuid(self.currentfocusuid)
def addgame(self, uid):
if uid not in self.reallist[self.reftagid]:
self.newline(uid)
else:
idx = self.reallist[self.reftagid].index(uid)
self.reallist[self.reftagid].pop(idx)
self.reallist[self.reftagid].insert(0, uid)
self.stack.w(calculatetagidx(self.reftagid)).torank1(idx)
def clicked3_batch(self): def clicked3_batch(self):
addgamebatch(lambda uid: self.newline(uid), getreflist(self.reftagid)) addgamebatch(self.addgame, getreflist(self.reftagid))
def clicked3(self): def clicked3(self):
addgamesingle(lambda uid: self.newline(uid), getreflist(self.reftagid)) addgamesingle(self.addgame, getreflist(self.reftagid))
def clicked(self): def clicked(self):
startgamecheck(self, self.currentfocusuid) startgamecheck(self, self.currentfocusuid)

View File

@ -389,6 +389,15 @@ class lazyscrollflow(ScrollArea):
if refresh: if refresh:
self.resizeandshow() self.resizeandshow()
@trypass
def totop1(self, idx):
if idx == 0:
return
with self.lock:
self.widgets.insert(0, self.widgets.pop(idx))
self.fakegeos.insert(0, self.fakegeos.pop(idx))
self.resizeandshow()
@trypass @trypass
def removeidx(self, idx): def removeidx(self, idx):
with self.lock: with self.lock:
@ -548,6 +557,8 @@ class delayloadvbox(QWidget):
self._dovisinternal(False, self.nowvisregion) self._dovisinternal(False, self.nowvisregion)
def torank1(self, i): def torank1(self, i):
if i == 0:
return
with self.lock: with self.lock:
self.internal_widgets.insert(0, self.internal_widgets.pop(i)) self.internal_widgets.insert(0, self.internal_widgets.pop(i))
self.internal_itemH.insert(0, self.internal_itemH.pop(i)) self.internal_itemH.insert(0, self.internal_itemH.pop(i))

View File

@ -242,10 +242,8 @@ def initanewitem(title):
return uid return uid
def checkifnewgame(targetlist, gamepath, title=None): def find_or_create_uid(targetlist, gamepath, title=None):
# 用于添加游戏时,全局查找是否有过历史记录
uids = findgameuidofpath(gamepath, findall=True) uids = findgameuidofpath(gamepath, findall=True)
print(uids)
if len(uids) == 0: if len(uids) == 0:
uid = initanewitem(title) uid = initanewitem(title)
if title is None: if title is None:
@ -256,19 +254,12 @@ def checkifnewgame(targetlist, gamepath, title=None):
) )
uid2gamepath[uid] = gamepath uid2gamepath[uid] = gamepath
trysearchforid(uid, [title] + guessmaybetitle(gamepath, title)) trysearchforid(uid, [title] + guessmaybetitle(gamepath, title))
isnew = True
else:
isnew = True
for uid in uids:
if uid in targetlist:
isnew = False
break
if isnew:
targetlist.insert(0, uid)
return uid return uid
else: else:
return None for uid in uids:
if uid in targetlist:
return uid
return uids[0]
kanjichs2ja = str.maketrans(static_data["kanjichs2ja"]) kanjichs2ja = str.maketrans(static_data["kanjichs2ja"])