Skip to content

Commit

Permalink
v1.19.0
Browse files Browse the repository at this point in the history
* Add: SetScaledContents for pictures.
* Add: Picture downloading.
* Add: Export deck.
* Add: Able to rename card from newcard list.
* Add: Normal desp for spell/trap.
* Add: Pasting single operation even if not selected.
* Fix: Crash when opening file which has less operation than current selecting index.
* Fix: Focus problem.
* Fix: Operation paste order.
* Fix: Card's color in targeting list.
* Fix: Picture window's name when downloading picture.
  • Loading branch information
Wind2009-Louse committed Apr 2, 2021
1 parent a671077 commit a8a6c27
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__pycache__/
build/
dist/
pics/
main.spec
*.cdb
*.json
Expand Down
176 changes: 152 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
import pic_window

idx_represent_str = ["己方手卡", "己方魔陷_1", "己方魔陷_2", "己方魔陷_3", "己方魔陷_4", "己方魔陷_5", "己方场地", "己方灵摆_1", "己方灵摆_2", "己方怪兽_1", "己方怪兽_2", "己方怪兽_3", "己方怪兽_4", "己方怪兽_5", "己方墓地", "己方除外", "己方额外", "对方手卡", "对方魔陷_1", "对方魔陷_2", "对方魔陷_3", "对方魔陷_4", "对方魔陷_5", "对方场地", "对方灵摆_1", "对方灵摆_2", "对方怪兽_1", "对方怪兽_2", "对方怪兽_3", "对方怪兽_4", "对方怪兽_5", "对方墓地", "对方除外", "对方额外", "额外怪兽区_1", "额外怪兽区_2"]
idx_represent_controller = {"己方": 1, "对方": -1, "额外怪兽区": 0}
cardcolors_dict = {0x2: QColor(10,128,0), 0x4: QColor(235,30,128), 0x10: QColor(168,168,0), 0x40: QColor(108,34,108), 0x80: QColor(16,128,235), 0x2000: QColor(168,168,168), 0x800000: QColor(0,0,0), 0x4000: QColor(98,98,98), 0x4000000: QColor(3,62,116), 0xffffffff: QColor(178,68,0)}
init_field = {"locations":{}, "desp":{}, "LP":[8000,8000], "fields":[]}
for t in range(len(idx_represent_str)):
init_field["fields"].append([])
version_idx = 180
version_name = "v1.18.0"
version_idx = 190
version_name = "v1.19.0"

class Update_Thread(Thread):
def __init__(self, window):
Expand Down Expand Up @@ -344,6 +345,7 @@ def init_frame(self):
self.Target_detail_browser.setTextInteractionFlags(Qt.TextBrowserInteraction)
self.Target_effect_button = QPushButton(self.centralwidget)
self.Target_img_button = QPushButton(self.centralwidget)
self.Target_img_button.setFocusPolicy(Qt.NoFocus)

self.NewCard_line = QLineEdit(self.centralwidget)
self.NewCard_line.setPlaceholderText("输入卡片名称")
Expand All @@ -352,6 +354,7 @@ def init_frame(self):
self.Create_card_button = QPushButton(self.centralwidget)
self.Rename_button = QPushButton(self.centralwidget)
self.Rename_button.setEnabled(False)
self.Rename_button.setFocusPolicy(Qt.NoFocus)
self.Comment_Line = QLineEdit(self.centralwidget)
self.Comment_Line.setPlaceholderText("输入注释")
self.Comment_card_button = QPushButton(self.centralwidget)
Expand Down Expand Up @@ -435,6 +438,7 @@ def __init__(self):
cardtypes = {0x1: "怪兽", 0x2: "<font color='#0A8000'>魔法</font>", 0x4: "<font color='#EB1E80'>陷阱</font>", 0x10: "<font color='#A8A800'>通常</font>", 0x20: "<font color='#B24400'>效果</font>", 0x40: "<font color='#6C226C'>融合</font>", 0x80: "<font color='#1080EB'>仪式</font>", 0x200: "灵魂", 0x400: "同盟", 0x800: "二重", 0x1000: "调整", 0x2000: "<font color='#A8A8A8'>同调</font>", 0x4000: "<font color='#626262'>衍生物</font>", 0x10000: "速攻", 0x20000: "永续", 0x40000: "装备", 0x80000: "场地", 0x100000: "反击", 0x200000: "反转", 0x400000: "卡通", 0x800000: "<span style='background:black'><font color='#FFFFFF'>超量</font></span>", 0x1000000: "灵摆", 0x2000000: "特殊召唤", 0x4000000: "<font color='#033E74'>连接</font>"}
cardraces = {0x1: "战士族", 0x2: "魔法师族", 0x4: "天使族", 0x8: "恶魔族", 0x10: "不死族", 0x20: "机械族", 0x40: "水族", 0x80: "炎族", 0x100: "岩石族", 0x200: "鸟兽族", 0x400: "植物族", 0x800: "昆虫族", 0x1000: "雷族", 0x2000: "龙族", 0x4000: "兽族", 0x8000: "兽战士族", 0x10000: "恐龙族", 0x20000: "鱼族", 0x40000: "海龙族", 0x80000: "爬虫类族", 0x100000: "念动力族", 0x200000: "幻神兽族", 0x400000: "创造神族", 0x800000: "幻龙族", 0x1000000: "电子界族"}
cardattrs = {0x1: "<font color='#121516'>地</font>", 0x2: "<font color='#0993D3'>水</font>", 0x4: "<font color='red'>炎</font>", 0x8: "<font color='#1B5D33'>风</font>", 0x10: "<font color='#7F5D32'>光</font>", 0x20: "<font color='#9A2B89'>暗</font>", 0x40: "<font color='DarkGoldenRod'>神</font>"}
excardtypes = {0x40: "融合", 0x2000: "同调", 0x800000: "超量", 0x4000000: "连接"}
linkmarkers = {0x40:"[↖]", 0x80:"[↑]", 0x100:"[↗]", 0x8:"[←]", 0x20:"[→]", 0x1: "[↙]", 0x2:"[↓]", 0x4:"[↘]"}
cardcolors_list = [0x2, 0x4, 0x10, 0x40, 0x80, 0x2000, 0x800000, 0x4000000, 0x4000]

Expand Down Expand Up @@ -463,6 +467,9 @@ def __init__(self):
self.calculator_bar = QAction("计算器",self)
self.calculator_bar.triggered.connect(self.open_calculator)
self.menu_bar_list.addAction(self.calculator_bar)
self.export_deck_bar = QAction("导出卡组",self)
self.export_deck_bar.triggered.connect(self.export_deck)
self.menu_bar_list.addAction(self.export_deck_bar)
self.blur_search_bar = QAction("搜索效果文字",self,checkable=True)
self.blur_search_bar.setChecked(True)
self.blur_search_bar.triggered.connect(self.search_card)
Expand All @@ -488,6 +495,7 @@ def __init__(self):
self.monster_datas = {}
self.card_colors = {}
self.id_map_by_name = {}
self.ex_card_id_set = set()
card_sorted = {}
try:
if not os.path.exists("cards.cdb"):
Expand Down Expand Up @@ -521,9 +529,13 @@ def __init__(self):
# 种类
for types in cardtypes.keys():
if carddata[4] & types != 0:
if types in excardtypes.keys():
self.ex_card_id_set.add(row[0])
if desp != "":
desp += "/"
desp += cardtypes[types]
if carddata[4] in [0x2, 0x4]:
desp += "/通常"
# 怪兽信息
if carddata[4] & 0x1 != 0:
# 等阶/Link
Expand Down Expand Up @@ -580,6 +592,7 @@ def __init__(self):
card_sorted[row[1]] = card_sorted_index
sql_conn.close()
except Exception as e:
print(e)
self.Newcard_List.addItem("无数据库")
self.Newcard_List.setEnabled(False)
self.coloring_field_card.setEnabled(False)
Expand Down Expand Up @@ -760,7 +773,7 @@ def retranslateUi(self):
self.Delete_ope_button.setText("删除操作")
self.Copy_ope_button.setText("复制操作")
self.Paste_ope_button.setText("粘贴操作")
self.Delete_copy_button.setText("删除操作")
self.Delete_copy_button.setText("从剪切板删除")
self.LPTarget_Box.setItemText(0, "己方")
self.LPTarget_Box.setItemText(1, "对方")
self.AddLP_button.setText("增加基本分")
Expand Down Expand Up @@ -885,7 +898,7 @@ def make_fields(self, begin_at=0, end_at=None):
self.fields.clear()
lastest_field = deepcopy(init_field)
else:
lastest_field = deepcopy(self.fields[begin_at-1])
lastest_field = deepcopy(self.fields[min(begin_at-1, len(self.fields) - 1)])
# 遍历操作
if end_at is None:
end_at = len(self.operators["operations"])
Expand Down Expand Up @@ -1133,11 +1146,18 @@ def remove_operator(self):

def paste_operator(self):
'''粘贴操作'''
idx_list = self.CopyingOpe_list.selectedIndexes()
sel_idx_list = self.CopyingOpe_list.selectedIndexes()
idx_list = []
for sel_idx in sel_idx_list:
idx_list.append(sel_idx.row())
if len(idx_list) <= 0:
return
if len(self.copying_operation) == 1:
idx_list.append(0)
else:
return
idx_list.reverse()
for idx in idx_list:
operation = self.copying_operation[idx.row()]
operation = self.copying_operation[idx]
self.insert_operation(operation, idx == idx_list[len(idx_list)-1])
self.remove_from_copying(False)
self.update_copying()
Expand Down Expand Up @@ -1262,7 +1282,8 @@ def select_copying(self):

def remove_from_copying(self, asking=True):
idx_list = self.CopyingOpe_list.selectedIndexes()
if len(idx_list) <= 0:
copying_size = len(self.copying_operation)
if len(idx_list) <= 0 and copying_size != 1:
return
if asking:
# 确认提示
Expand All @@ -1271,6 +1292,8 @@ def remove_from_copying(self, asking=True):
return
idx_list = [item.row() for item in idx_list]
idx_list.sort(reverse=True)
if len(idx_list) == 0 and copying_size == 1:
idx_list.append(0)
self.CopyingOpe_list.setCurrentRow(0)
for idx in idx_list:
del self.copying_operation[idx]
Expand Down Expand Up @@ -1329,6 +1352,7 @@ def update_targetlist(self):
for name in possible_name:
if name in self.card_colors:
self.Target_list.item(self.Target_list.count()-1).setForeground(cardcolors_dict[self.card_colors[name]])
break

# 如果和搜索栏内容匹配则变为斜体
if len(searching_name) > 0 and searching_name in target_name:
Expand Down Expand Up @@ -1730,6 +1754,7 @@ def show_carddesp(self):
if cardname in self.card_datas:
text = self.card_datas[cardname]
self.Target_detail_browser.setHtml(text)
self.update_img_buttom()

def fix_cardname(self,qindex):
'''补全卡名'''
Expand All @@ -1743,24 +1768,34 @@ def update_rename_buttom(self):
if self.showing_card_id is None:
self.Rename_button.setEnabled(False)
self.Target_effect_button.setEnabled(False)
idx = self.Newcard_List.selectedIndexes()
if len(idx) < 1:
self.Target_img_button.setEnabled(False)
else:
self.Target_img_button.setEnabled(True)
self.Rename_button.setText("未选定卡")
else:
self.Rename_button.setEnabled(True)
self.Target_effect_button.setEnabled(True)
self.Target_img_button.setEnabled(True)
cardname = self.operators["cards"][self.showing_card_id]["Name"]
self.Rename_button.setText("重命名[%s]"%cardname)
self.update_img_buttom()

def update_img_buttom(self):
if self.Newcard_List.hasFocus():
idx = self.Newcard_List.selectedIndexes()
if len(idx) < 1:
return
self.Target_img_button.setEnabled(True)
elif self.showing_card_id is not None:
self.Target_img_button.setEnabled(True)
else:
self.Target_img_button.setEnabled(False)

def card_rename(self):
'''卡片重命名'''
if self.showing_card_id is None:
return
text = self.NewCard_line.text()
if self.Newcard_List.hasFocus():
idx = self.Newcard_List.selectedIndexes()
if len(idx) > 0:
text = self.Newcard_List.item(idx[0].row()).text()
if len(text) == 0:
return
# 提示
Expand Down Expand Up @@ -1798,7 +1833,7 @@ def update_hint(self, name):
box = QMessageBox(QMessageBox.Question, "检查更新", "检查到最新版本:%s,是否下载?"%name)
direct_download = box.addButton("直接下载", QMessageBox.YesRole)
page_download = box.addButton("打开页面", QMessageBox.YesRole)
cancel_download = box.addButton("取消", QMessageBox.NoRole)
box.addButton("取消", QMessageBox.NoRole)
box.exec_()
if box.clickedButton() == direct_download:
if not self.download_thread.is_alive():
Expand Down Expand Up @@ -1883,29 +1918,122 @@ def save_config(self):

def view_pic(self):
card_name = ""
if self.showing_card_id is not None and self.showing_card_id in self.operators["cards"]:
card_name = self.operators["cards"][self.showing_card_id]["Name"]
else:
if self.Newcard_List.hasFocus():
idx = self.Newcard_List.selectedIndexes()
if len(idx) < 1:
return
card_name = self.Newcard_List.item(idx[0].row()).text()
card_name = self.Newcard_List.item(idx[0].row()).text()
if card_name == "" and self.showing_card_id is not None and self.showing_card_id in self.operators["cards"]:
card_name = self.operators["cards"][self.showing_card_id]["Name"]

if len(card_name) == 0:
return
search_list = [card_name, card_name[:-1]]
show_card_key = 0
show_card_name = ""
for name in search_list:
if name in self.id_map_by_name:
card_id = self.id_map_by_name[name]
png_file_name = os.path.join(os.path.abspath('.'), "pics", "%d.png"%card_id)
jpg_file_name = os.path.join(os.path.abspath('.'), "pics", "%d.jpg"%card_id)
show_card_key = self.id_map_by_name[name]
show_card_name = name
png_file_name = os.path.join(os.path.abspath('.'), "pics", "%d.png"%show_card_key)
jpg_file_name = os.path.join(os.path.abspath('.'), "pics", "%d.jpg"%show_card_key)
if os.path.exists(png_file_name) or os.path.exists(jpg_file_name):
pic_window_ref = pic_window.UI_PIC(self, card_id, name)
pic_window_ref = pic_window.UI_PIC(self, show_card_key, name)
pic_window_ref.show()
self.img_window_list.append(pic_window_ref)
return

if show_card_key == 0:
QMessageBox.warning(self, "提示", "该卡片没有图片!", QMessageBox.Yes)
else:
reply = QMessageBox.warning(self, '提示', "找不到[%s]的卡图,是否下载?"%show_card_name, QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.Yes:
pic_window_ref = pic_window.UI_PIC(self, show_card_key, show_card_name)
pic_window_ref.show()
self.img_window_list.append(pic_window_ref)

def export_deck(self):
'''导出卡组'''
# 判断是否有deck文件夹
open_dir = os.path.abspath('.')
deck_dir = os.path.join(os.path.abspath('.'), "deck")
if os.path.exists(deck_dir):
open_dir = deck_dir

# 获取
self_filename = str(QFileDialog.getSaveFileName(self,'己方卡组', os.path.join(open_dir, "self.ydk"),"*.ydk")[0])
if len(self_filename) == 0:
return
open_dir = os.path.dirname(self_filename)
enemy_filename = str(QFileDialog.getSaveFileName(self,'对方卡组', os.path.join(open_dir, "opposite.ydk"),"*.ydk")[0])
if len(enemy_filename) == 0:
return

QMessageBox.warning(self, "提示", "找不到图片!", QMessageBox.Yes)
# 开始导出(0=main, 1=ex)
self_deck_list = [[], []]
enemy_deck_list = [[], []]
undefined_name = []

try:
operation_list = self.operators["operations"]
last_controller = -2
for ope_idx in range(len(operation_list)):
ope = operation_list[ope_idx]
if ope["type"] != "move":
continue
for card_idx in ope["args"]:
last_place = self.get_last_location(card_idx, ope_idx)
if last_place != "未知":
continue
card_name = self.operators["cards"][card_idx]["Name"]
card_pic_id = self.get_id_by_name(card_name)
if card_pic_id == -1:
card_pic_id = 48588176
undefined_name.append(card_name)
ex_idx = 1 if card_pic_id in self.ex_card_id_set else 0
goal_str = idx_represent_str[ope["dest"]]
controller = -2
for check_str in idx_represent_controller.keys():
if check_str in goal_str:
controller = idx_represent_controller[check_str]
break
if controller == 0:
controller = last_controller
if controller in [-2, 0]:
print("[%s]找不到所在地[%s]的控制者。"%(card_name, goal_str))
if controller == 1:
self_deck_list[ex_idx].append(str(card_pic_id))
if controller == -1:
enemy_deck_list[ex_idx].append(str(card_pic_id))
last_controller = controller
except Exception as e:
print(e)
QMessageBox.warning(self, "提示", "生成卡组失败:%s"%str(e), QMessageBox.Yes)
return
if self.generate_deck(self_deck_list, self_filename, "己方卡组") and self.generate_deck(enemy_deck_list, enemy_filename, "对方卡组"):
result_str = "导出成功!"
if len(undefined_name) > 0:
result_str += "\n以下卡片无法被识别,已被设为默认卡片:\n" + "\n".join(undefined_name)
QMessageBox.warning(self, "提示", result_str, QMessageBox.Yes)

def get_id_by_name(self, card_name):
'''根据卡片名称,获取卡片ID。查询不到的情况下,返回-1。'''
search_list = [card_name, card_name[:-1]]
for name in search_list:
if name in self.id_map_by_name:
return self.id_map_by_name[name]
return -1

def generate_deck(self, deck_list, file_name, fail_by):
'''根据export_deck生成的卡组数据,生成卡组'''
deck_str = "\n".join(("#created by DuelEditor\n#main", "\n".join(deck_list[0]), "#extra", "\n".join(deck_list[1])))
try:
with open(file_name,'w',encoding='utf-8') as f:
f.write(deck_str)
return True
except Exception as e:
QMessageBox.warning(self, "提示", "保存%s失败:%s"%(fail_by, str(e)), QMessageBox.Yes)
return False

def img_cache_clear(self, signal=None):
new_list = []
Expand Down
Loading

0 comments on commit a8a6c27

Please sign in to comment.