def _init_widget(self): current_y_diff = 27 self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=23, y=42) self.character_selector.bind('<Return>', lambda event: self.max_atk.focus_set()) current_y = 10 current_x = 171 Label(self, width=7, text='MaxAtk', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_atk = IntEntry(self, width=5, font=(SCP, 12)) self.max_atk.place(x=current_x + 10, y=current_y + current_y_diff) self.max_atk.bind('<Return>', lambda event: self.max_critical.focus_set()) current_x += 87 Label(self, width=8, text='MaxCrit.', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_critical = IntEntry(self, width=5, font=(SCP, 12)) self.max_critical.place(x=current_x + 16, y=current_y + current_y_diff) self.max_critical.bind('<Return>', lambda event: self.max_armor.focus_set()) current_x += 92 Label(self, width=8, text='MaxArmor', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_armor = IntEntry(self, width=5, font=(SCP, 12)) self.max_armor.place(x=current_x + 16, y=current_y + current_y_diff) self.max_armor.bind('<Return>', lambda event: self.current_atk.focus_set()) self.max_armor.bind('<Control-Return>', lambda event: self.auto_fill()) current_y += 65 current_x = 171 Label(self, width=7, text='CurAtk', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_atk = IntEntry(self, width=5, font=(SCP, 12)) self.current_atk.place(x=current_x + 10, y=current_y + current_y_diff) self.current_atk.bind('<Return>', lambda event: self.current_critical.focus_set()) current_x += 87 Label(self, width=8, text='CurCrit.', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_critical = IntEntry(self, width=5, font=(SCP, 12)) self.current_critical.place(x=current_x + 16, y=current_y + current_y_diff) self.current_critical.bind('<Return>', lambda event: self.current_armor.focus_set()) current_x += 92 Label(self, width=8, text='CurArmor', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_armor = IntEntry(self, width=5, font=(SCP, 12)) self.current_armor.place(x=current_x + 16, y=current_y + current_y_diff) self.current_armor.bind('<Return>', lambda event: self.submitting()) # 送出、取消的按鈕 current_y += 81 Button(self, text="Submit", command=self.submitting, width=25, relief=RIDGE, font=(SCP, 11)).place( x=34, y=current_y) Button(self, text="Cancel", command=self.destroy, width=12, relief=RIDGE, font=(SCP, 11)).place( x=297, y=current_y)
def _init_widgets(self, events): # 筆數 current_y = 15 Label(self, text='Order', width=6, font=("", 12)).place(x=4, y=current_y) self.order = IntVar() # 下一次的筆數 Label(self, textvariable=self.order, width=6, font=("", 12)).place(x=4, y=current_y + 27) # 酒廠 Label(self, text='Event', width=14, font=("", 12)).place(x=57, y=current_y) self.event_selector = ObjectCombobox(self, setter=lambda obj: obj.name, width=14, justify=CENTER) self.event_selector.set_objects(events) self.event_selector.place(x=64, y=current_y + 27) # 角色 self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=201, y=current_y - 4) # 花費 Label(self, text='Cost', width=9, font=("", 12)).place(x=338, y=current_y) self.cost_selector = ttk.Combobox(self, state='readonly', width=8, justify=CENTER) self.cost_selector['values'] = DRAW_LOTS_COST self.cost_selector.place(x=346, y=current_y + 27) # 時間欄位,送交、取消並關閉的按鈕 current_y = 90 self.date_time = StringVar() self.date_time_entry = Entry(self, textvariable=self.date_time, width=11, font=(SCP, 10), justify=CENTER) self.date_time_entry.place(x=14, y=current_y + 5) button = Button(self, text="送出此記錄", width=30, borderwidth=3) button.place(x=117, y=current_y) button["command"] = self.submitting button = Button(self, text="關閉視窗", width=10, borderwidth=3) button.place(x=348, y=current_y) button["command"] = self.destroy
def _init_widget(self): Label(self, width=12, text="UsedNames :", font=(SCP, 12)).place(x=15, y=8) self.used_names = StringVar() Label(self, width=22, textvariable=self.used_names, font=(MS_JH, 12), anchor=W).place(x=47, y=32) self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=8, y=68) self.character_selector.bind("<Return>", lambda x: character_level_entry.focus_set()) current_y = 71 Label(self, width=7, text="C.Level", font=(SCP, 12)).place(x=146, y=current_y) self.character_level_var = IntVar() character_level_entry = Entry( self, width=6, textvariable=self.character_level_var, font=(SCP, 12), justify=CENTER ) character_level_entry.place(x=153, y=current_y + 28) character_level_entry.bind("<Return>", lambda x: rank_entry.focus_set()) Label(self, width=6, text="Rank", font=(SCP, 12)).place(x=229, y=current_y) self.rank_var = IntVar() rank_entry = Entry(self, width=6, textvariable=self.rank_var, font=(SCP, 12), justify=CENTER) rank_entry.place(x=232, y=current_y + 27) rank_entry.bind("<Return>", lambda x: self.submitting()) # 取消的按鈕 Button(self, text="Cancel", command=self.destroy, width=28, borderwidth=2, font=(SCP, 11)).place(x=23, y=150)
def _init_widget(self): Label(self, width=12, text='UsedNames :', font=(SCP, 12)).place(x=15, y=8) self.used_names = StringVar() Label(self, width=22, textvariable=self.used_names, font=(MS_JH, 12), anchor=W).place(x=47, y=32) self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=8, y=68) self.character_selector.bind( '<Return>', lambda x: character_level_entry.focus_set()) current_y = 71 Label(self, width=7, text='C.Level', font=(SCP, 12)).place(x=146, y=current_y) self.character_level_var = IntVar() character_level_entry = Entry(self, width=6, textvariable=self.character_level_var, font=(SCP, 12), justify=CENTER) character_level_entry.place(x=153, y=current_y + 28) character_level_entry.bind('<Return>', lambda x: rank_entry.focus_set()) Label(self, width=6, text='Rank', font=(SCP, 12)).place(x=229, y=current_y) self.rank_var = IntVar() rank_entry = Entry(self, width=6, textvariable=self.rank_var, font=(SCP, 12), justify=CENTER) rank_entry.place(x=232, y=current_y + 27) rank_entry.bind('<Return>', lambda x: self.submitting()) # 取消的按鈕 Button(self, text="Cancel", command=self.destroy, width=28, borderwidth=2, font=(SCP, 11)).place(x=23, y=150)
class RecordWindow(BasicWindow): def __init__(self, master, record, events, callback, width=445, height=133, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.callback = callback self._init_widgets(events) self._init_context(record) # 註冊 Enter 確認送出 self.bind('<Return>', lambda event: self.submitting()) # 註冊編輯 DateTime 熱鍵 self.bind('<Control-d>', lambda event: ( self.date_time_entry.focus_set(), self.date_time_entry.selection_range(0, END))) def _init_widgets(self, events): # 筆數 current_y = 15 Label(self, text='Order', width=6, font=("", 12)).place(x=4, y=current_y) self.order = IntVar() # 下一次的筆數 Label(self, textvariable=self.order, width=6, font=("", 12)).place(x=4, y=current_y + 27) # 酒廠 Label(self, text='Event', width=14, font=("", 12)).place(x=57, y=current_y) self.event_selector = ObjectCombobox(self, setter=lambda obj: obj.name, width=14, justify=CENTER) self.event_selector.set_objects(events) self.event_selector.place(x=64, y=current_y + 27) # 角色 self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=201, y=current_y - 4) # 花費 Label(self, text='Cost', width=9, font=("", 12)).place(x=338, y=current_y) self.cost_selector = ttk.Combobox(self, state='readonly', width=8, justify=CENTER) self.cost_selector['values'] = DRAW_LOTS_COST self.cost_selector.place(x=346, y=current_y + 27) # 時間欄位,送交、取消並關閉的按鈕 current_y = 90 self.date_time = StringVar() self.date_time_entry = Entry(self, textvariable=self.date_time, width=11, font=(SCP, 10), justify=CENTER) self.date_time_entry.place(x=14, y=current_y + 5) button = Button(self, text="送出此記錄", width=30, borderwidth=3) button.place(x=117, y=current_y) button["command"] = self.submitting button = Button(self, text="關閉視窗", width=10, borderwidth=3) button.place(x=348, y=current_y) button["command"] = self.destroy # noinspection PyUnusedLocal def _init_context(self, record): if isinstance(record, RecordOfDrawLots): self.record = record self.order.set(record.order) self.event_selector.set(record.event) self.character_selector.set(record.character) self.cost_selector.set(record.cost) self.date_time.set(record.date_time) else: raise TypeError('In RecordWindow, arg: \"record\"') # 合法的選擇情況下才繼續進行,否則彈出錯誤視窗 def submitting(self): if self.event_selector.get() is None: tkMessageBox.showwarning("Event haven't selected", '\"Event\" 未選\n', parent=self) if self.character_selector.get() is None: tkMessageBox.showwarning("Character haven't selected", '\"Character\" 未選\n', parent=self) else: self.record.order = self.order.get() self.record.event = self.event_selector.get() self.record.character = self.character_selector.get() self.record.cost = self.cost_selector.get() self.record.date_time = self.date_time.get() self._post_submitting() # Template method def _post_submitting(self): pass
def _init_widget(self): current_y_diff = 28 current_y = 20 current_x = 23 self.character_selector = CharacterSelectorCanvas(self, self.character_power.character) self.character_selector.place(x=current_x, y=current_y - 3) callback_after_selection = lambda event: (self.filling_in_entries_by_character(), level_entry.focus_set()) self.character_selector.bind("<Return>", callback_after_selection) self.character_selector.bind("-", callback_after_selection) current_x += 145 Label(self, width=5, text="Level", font=(SCP, 12)).place(x=current_x, y=current_y) self.level = StringVar() level_entry = Entry(self, width=5, textvariable=self.level, font=(SCP, 12), justify=CENTER) level_entry.place(x=current_x + 2, y=current_y + current_y_diff) level_entry.bind("<Return>", lambda x: (self.filling_in_atk_by_level(), atk_entry.focus_set())) current_x += 62 Label(self, width=5, text="Atk", font=(SCP, 12)).place(x=current_x, y=current_y) self.atk = StringVar() atk_entry = Entry(self, width=5, textvariable=self.atk, font=(SCP, 12), justify=CENTER) atk_entry.place(x=current_x + 3, y=current_y + current_y_diff) atk_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 70 Label(self, width=25, text="Addition", font=(SCP, 12)).place(x=current_x, y=current_y) self.addition = StringVar() addition_entry = Entry(self, width=25, textvariable=self.addition, font=(MS_JH, 12), justify=CENTER) addition_entry.place(x=current_x + 3, y=current_y + current_y_diff) addition_entry.bind("<Return>", lambda x: self.presently.focus_set()) current_y += 14 + current_y_diff * 2 current_x = 27 Label(self, width=8, text="AtkRaised", font=(SCP, 10)).place(x=current_x + 1, y=current_y + 3) self.atk_raised = StringVar() atk_raised_entry = Entry(self, width=7, textvariable=self.atk_raised, font=(SCP, 12), justify=CENTER) atk_raised_entry.place(x=current_x, y=current_y + current_y_diff) atk_raised_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 90 Label(self, width=7, text="HitRate", font=(SCP, 11)).place(x=current_x, y=current_y) self.hit_rate = StringVar() hit_rate_entry = Entry(self, width=6, textvariable=self.hit_rate, font=(SCP, 12), justify=CENTER) hit_rate_entry.place(x=current_x + 2, y=current_y + current_y_diff) hit_rate_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 83 Label(self, width=8, text="Cri.Ratio", font=(SCP, 10)).place(x=current_x, y=current_y + 3) self.critical_ratio = StringVar() critical_ratio_entry = Entry(self, width=6, textvariable=self.critical_ratio, font=(SCP, 12), justify=CENTER) critical_ratio_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_ratio_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 85 Label(self, width=9, text="Cri.Factor", font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.critical_factor = StringVar() critical_factor_entry = Entry(self, width=6, textvariable=self.critical_factor, font=(SCP, 12), justify=CENTER) critical_factor_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_factor_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 84 Label(self, width=9, text="Act.Factor", font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.active_factor = StringVar() active_factor_entry = Entry(self, width=6, textvariable=self.active_factor, font=(SCP, 12), justify=CENTER) active_factor_entry.place(x=current_x + 4, y=current_y + current_y_diff) active_factor_entry.bind("<Return>", lambda x: addition_entry.focus_set()) current_x += 86 Label(self, width=8, text="Act.Cost", font=(SCP, 11)).place(x=current_x, y=current_y + 3) self.active_cost = StringVar() active_cost_entry = Entry(self, width=6, textvariable=self.active_cost, font=(SCP, 12), justify=CENTER) active_cost_entry.place(x=current_x + 5, y=current_y + current_y_diff) active_cost_entry.bind("<Return>", lambda x: addition_entry.focus_set()) # 送出、取消的按鈕 current_y += 23 + current_y_diff * 2 self.presently = ToggleButton(self, text="Presently", width=9, font=(SCP, 11), relief=RIDGE) self.presently.place(x=22, y=current_y) self.presently.bind("<space>", lambda event: self.presently.toggling()) self.presently.bind("<Return>", lambda x: self.submitting()) Button(self, text="Submit", command=self.submitting, width=28, relief=RIDGE, font=(SCP, 11)).place( x=131, y=current_y ) Button(self, text="Cancel", command=self.destroy, width=13, relief=RIDGE, font=(SCP, 11)).place( x=405, y=current_y )
class CharacterPowerWindow(BasicWindow): def __init__(self, master, character_power, callback, width=558, height=222, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title("CharacterPower") self.character_power = character_power self.callback = callback self._init_widget() self._init_content() # 事件註冊,設定為更改角色詳細資訊 self.bind("-", lambda event: self.open_updating_character_window()) def _init_widget(self): current_y_diff = 28 current_y = 20 current_x = 23 self.character_selector = CharacterSelectorCanvas(self, self.character_power.character) self.character_selector.place(x=current_x, y=current_y - 3) callback_after_selection = lambda event: (self.filling_in_entries_by_character(), level_entry.focus_set()) self.character_selector.bind("<Return>", callback_after_selection) self.character_selector.bind("-", callback_after_selection) current_x += 145 Label(self, width=5, text="Level", font=(SCP, 12)).place(x=current_x, y=current_y) self.level = StringVar() level_entry = Entry(self, width=5, textvariable=self.level, font=(SCP, 12), justify=CENTER) level_entry.place(x=current_x + 2, y=current_y + current_y_diff) level_entry.bind("<Return>", lambda x: (self.filling_in_atk_by_level(), atk_entry.focus_set())) current_x += 62 Label(self, width=5, text="Atk", font=(SCP, 12)).place(x=current_x, y=current_y) self.atk = StringVar() atk_entry = Entry(self, width=5, textvariable=self.atk, font=(SCP, 12), justify=CENTER) atk_entry.place(x=current_x + 3, y=current_y + current_y_diff) atk_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 70 Label(self, width=25, text="Addition", font=(SCP, 12)).place(x=current_x, y=current_y) self.addition = StringVar() addition_entry = Entry(self, width=25, textvariable=self.addition, font=(MS_JH, 12), justify=CENTER) addition_entry.place(x=current_x + 3, y=current_y + current_y_diff) addition_entry.bind("<Return>", lambda x: self.presently.focus_set()) current_y += 14 + current_y_diff * 2 current_x = 27 Label(self, width=8, text="AtkRaised", font=(SCP, 10)).place(x=current_x + 1, y=current_y + 3) self.atk_raised = StringVar() atk_raised_entry = Entry(self, width=7, textvariable=self.atk_raised, font=(SCP, 12), justify=CENTER) atk_raised_entry.place(x=current_x, y=current_y + current_y_diff) atk_raised_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 90 Label(self, width=7, text="HitRate", font=(SCP, 11)).place(x=current_x, y=current_y) self.hit_rate = StringVar() hit_rate_entry = Entry(self, width=6, textvariable=self.hit_rate, font=(SCP, 12), justify=CENTER) hit_rate_entry.place(x=current_x + 2, y=current_y + current_y_diff) hit_rate_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 83 Label(self, width=8, text="Cri.Ratio", font=(SCP, 10)).place(x=current_x, y=current_y + 3) self.critical_ratio = StringVar() critical_ratio_entry = Entry(self, width=6, textvariable=self.critical_ratio, font=(SCP, 12), justify=CENTER) critical_ratio_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_ratio_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 85 Label(self, width=9, text="Cri.Factor", font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.critical_factor = StringVar() critical_factor_entry = Entry(self, width=6, textvariable=self.critical_factor, font=(SCP, 12), justify=CENTER) critical_factor_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_factor_entry.bind("<Return>", lambda x: active_factor_entry.focus_set()) current_x += 84 Label(self, width=9, text="Act.Factor", font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.active_factor = StringVar() active_factor_entry = Entry(self, width=6, textvariable=self.active_factor, font=(SCP, 12), justify=CENTER) active_factor_entry.place(x=current_x + 4, y=current_y + current_y_diff) active_factor_entry.bind("<Return>", lambda x: addition_entry.focus_set()) current_x += 86 Label(self, width=8, text="Act.Cost", font=(SCP, 11)).place(x=current_x, y=current_y + 3) self.active_cost = StringVar() active_cost_entry = Entry(self, width=6, textvariable=self.active_cost, font=(SCP, 12), justify=CENTER) active_cost_entry.place(x=current_x + 5, y=current_y + current_y_diff) active_cost_entry.bind("<Return>", lambda x: addition_entry.focus_set()) # 送出、取消的按鈕 current_y += 23 + current_y_diff * 2 self.presently = ToggleButton(self, text="Presently", width=9, font=(SCP, 11), relief=RIDGE) self.presently.place(x=22, y=current_y) self.presently.bind("<space>", lambda event: self.presently.toggling()) self.presently.bind("<Return>", lambda x: self.submitting()) Button(self, text="Submit", command=self.submitting, width=28, relief=RIDGE, font=(SCP, 11)).place( x=131, y=current_y ) Button(self, text="Cancel", command=self.destroy, width=13, relief=RIDGE, font=(SCP, 11)).place( x=405, y=current_y ) def _init_content(self): self.atk.set(self.character_power.atk) self.level.set(self.character_power.level) self.atk_raised.set(self.character_power.atk_raised) self.hit_rate.set(self.character_power.hit_rate) self.critical_ratio.set(self.character_power.critical_ratio) self.critical_factor.set(self.character_power.critical_factor) self.active_factor.set(self.character_power.active_factor) self.active_cost.set(self.character_power.active_cost) self.addition.set(self.character_power.addition) self.presently.set_is_selected(self.character_power.presently) def submitting(self): self.character_power.character = self.character_selector.get() self.character_power.atk = int(self.atk.get()) self.character_power.level = int(self.level.get()) self.character_power.atk_raised = float(self.atk_raised.get()) self.character_power.hit_rate = float(self.hit_rate.get()) self.character_power.critical_ratio = float(self.critical_ratio.get()) self.character_power.critical_factor = float(self.critical_factor.get()) self.character_power.active_factor = float(self.active_factor.get()) self.character_power.active_cost = int(self.active_cost.get()) self.character_power.addition = self.addition.get() self.character_power.presently = self.presently.is_selected self.callback() self.destroy() def filling_in_entries_by_character(self): character = self.character_selector.get() self.atk_raised.set(1.0) self.hit_rate.set(character.atk_speed) self.critical_ratio.set(character.critical_rate) self.critical_factor.set(1.5) self.active_cost.set(character.active_cost) def filling_in_atk_by_level(self): atk = self.character_selector.get().estimate_atk_by_level(int(self.level.get())) if atk: self.atk.set(atk) def open_updating_character_window(self): open_updating_character_window(self.master, self.character_selector.get(), position_y_shift=-300)
class RecordWindow(BasicWindow): def __init__(self, master, record, events, callback, width=445, height=133, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.callback = callback self._init_widgets(events) self._init_context(record) # 註冊 Enter 確認送出 self.bind('<Return>', lambda event: self.submitting()) # 註冊編輯 DateTime 熱鍵 self.bind( '<Control-d>', lambda event: (self.date_time_entry.focus_set(), self.date_time_entry.selection_range(0, END))) def _init_widgets(self, events): # 筆數 current_y = 15 Label(self, text='Order', width=6, font=("", 12)).place(x=4, y=current_y) self.order = IntVar() # 下一次的筆數 Label(self, textvariable=self.order, width=6, font=("", 12)).place(x=4, y=current_y + 27) # 酒廠 Label(self, text='Event', width=14, font=("", 12)).place(x=57, y=current_y) self.event_selector = ObjectCombobox(self, setter=lambda obj: obj.name, width=14, justify=CENTER) self.event_selector.set_objects(events) self.event_selector.place(x=64, y=current_y + 27) # 角色 self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=201, y=current_y - 4) # 花費 Label(self, text='Cost', width=9, font=("", 12)).place(x=338, y=current_y) self.cost_selector = ttk.Combobox(self, state='readonly', width=8, justify=CENTER) self.cost_selector['values'] = DRAW_LOTS_COST self.cost_selector.place(x=346, y=current_y + 27) # 時間欄位,送交、取消並關閉的按鈕 current_y = 90 self.date_time = StringVar() self.date_time_entry = Entry(self, textvariable=self.date_time, width=11, font=(SCP, 10), justify=CENTER) self.date_time_entry.place(x=14, y=current_y + 5) button = Button(self, text="送出此記錄", width=30, borderwidth=3) button.place(x=117, y=current_y) button["command"] = self.submitting button = Button(self, text="關閉視窗", width=10, borderwidth=3) button.place(x=348, y=current_y) button["command"] = self.destroy # noinspection PyUnusedLocal def _init_context(self, record): if isinstance(record, RecordOfDrawLots): self.record = record self.order.set(record.order) self.event_selector.set(record.event) self.character_selector.set(record.character) self.cost_selector.set(record.cost) self.date_time.set(record.date_time) else: raise TypeError('In RecordWindow, arg: \"record\"') # 合法的選擇情況下才繼續進行,否則彈出錯誤視窗 def submitting(self): if self.event_selector.get() is None: tkMessageBox.showwarning("Event haven't selected", '\"Event\" 未選\n', parent=self) if self.character_selector.get() is None: tkMessageBox.showwarning("Character haven't selected", '\"Character\" 未選\n', parent=self) else: self.record.order = self.order.get() self.record.event = self.event_selector.get() self.record.character = self.character_selector.get() self.record.cost = self.cost_selector.get() self.record.date_time = self.date_time.get() self._post_submitting() # Template method def _post_submitting(self): pass
def _init_widget(self): current_y_diff = 28 current_y = 20 current_x = 23 self.character_selector = CharacterSelectorCanvas( self, self.character_power.character) self.character_selector.place(x=current_x, y=current_y - 3) callback_after_selection = lambda event: ( self.filling_in_entries_by_character(), level_entry.focus_set()) self.character_selector.bind('<Return>', callback_after_selection) self.character_selector.bind('-', callback_after_selection) current_x += 145 Label(self, width=5, text='Level', font=(SCP, 12)).place(x=current_x, y=current_y) self.level = StringVar() level_entry = Entry(self, width=5, textvariable=self.level, font=(SCP, 12), justify=CENTER) level_entry.place(x=current_x + 2, y=current_y + current_y_diff) level_entry.bind( '<Return>', lambda x: (self.filling_in_atk_by_level(), atk_entry.focus_set())) current_x += 62 Label(self, width=5, text='Atk', font=(SCP, 12)).place(x=current_x, y=current_y) self.atk = StringVar() atk_entry = Entry(self, width=5, textvariable=self.atk, font=(SCP, 12), justify=CENTER) atk_entry.place(x=current_x + 3, y=current_y + current_y_diff) atk_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 70 Label(self, width=25, text='Addition', font=(SCP, 12)).place(x=current_x, y=current_y) self.addition = StringVar() addition_entry = Entry(self, width=25, textvariable=self.addition, font=(MS_JH, 12), justify=CENTER) addition_entry.place(x=current_x + 3, y=current_y + current_y_diff) addition_entry.bind('<Return>', lambda x: self.presently.focus_set()) current_y += 14 + current_y_diff * 2 current_x = 27 Label(self, width=8, text='AtkRaised', font=(SCP, 10)).place(x=current_x + 1, y=current_y + 3) self.atk_raised = StringVar() atk_raised_entry = Entry(self, width=7, textvariable=self.atk_raised, font=(SCP, 12), justify=CENTER) atk_raised_entry.place(x=current_x, y=current_y + current_y_diff) atk_raised_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 90 Label(self, width=7, text='HitRate', font=(SCP, 11)).place(x=current_x, y=current_y) self.hit_rate = StringVar() hit_rate_entry = Entry(self, width=6, textvariable=self.hit_rate, font=(SCP, 12), justify=CENTER) hit_rate_entry.place(x=current_x + 2, y=current_y + current_y_diff) hit_rate_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 83 Label(self, width=8, text='Cri.Ratio', font=(SCP, 10)).place(x=current_x, y=current_y + 3) self.critical_ratio = StringVar() critical_ratio_entry = Entry(self, width=6, textvariable=self.critical_ratio, font=(SCP, 12), justify=CENTER) critical_ratio_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_ratio_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 85 Label(self, width=9, text='Cri.Factor', font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.critical_factor = StringVar() critical_factor_entry = Entry(self, width=6, textvariable=self.critical_factor, font=(SCP, 12), justify=CENTER) critical_factor_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_factor_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 84 Label(self, width=9, text='Act.Factor', font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.active_factor = StringVar() active_factor_entry = Entry(self, width=6, textvariable=self.active_factor, font=(SCP, 12), justify=CENTER) active_factor_entry.place(x=current_x + 4, y=current_y + current_y_diff) active_factor_entry.bind('<Return>', lambda x: addition_entry.focus_set()) current_x += 86 Label(self, width=8, text='Act.Cost', font=(SCP, 11)).place(x=current_x, y=current_y + 3) self.active_cost = StringVar() active_cost_entry = Entry(self, width=6, textvariable=self.active_cost, font=(SCP, 12), justify=CENTER) active_cost_entry.place(x=current_x + 5, y=current_y + current_y_diff) active_cost_entry.bind('<Return>', lambda x: addition_entry.focus_set()) # 送出、取消的按鈕 current_y += 23 + current_y_diff * 2 self.presently = ToggleButton(self, text='Presently', width=9, font=(SCP, 11), relief=RIDGE) self.presently.place(x=22, y=current_y) self.presently.bind('<space>', lambda event: self.presently.toggling()) self.presently.bind('<Return>', lambda x: self.submitting()) Button(self, text="Submit", command=self.submitting, width=28, relief=RIDGE, font=(SCP, 11)).place(x=131, y=current_y) Button(self, text="Cancel", command=self.destroy, width=13, relief=RIDGE, font=(SCP, 11)).place(x=405, y=current_y)
class CharacterPowerWindow(BasicWindow): def __init__(self, master, character_power, callback, width=558, height=222, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title('CharacterPower') self.character_power = character_power self.callback = callback self._init_widget() self._init_content() # 事件註冊,設定為更改角色詳細資訊 self.bind("-", lambda event: self.open_updating_character_window()) def _init_widget(self): current_y_diff = 28 current_y = 20 current_x = 23 self.character_selector = CharacterSelectorCanvas( self, self.character_power.character) self.character_selector.place(x=current_x, y=current_y - 3) callback_after_selection = lambda event: ( self.filling_in_entries_by_character(), level_entry.focus_set()) self.character_selector.bind('<Return>', callback_after_selection) self.character_selector.bind('-', callback_after_selection) current_x += 145 Label(self, width=5, text='Level', font=(SCP, 12)).place(x=current_x, y=current_y) self.level = StringVar() level_entry = Entry(self, width=5, textvariable=self.level, font=(SCP, 12), justify=CENTER) level_entry.place(x=current_x + 2, y=current_y + current_y_diff) level_entry.bind( '<Return>', lambda x: (self.filling_in_atk_by_level(), atk_entry.focus_set())) current_x += 62 Label(self, width=5, text='Atk', font=(SCP, 12)).place(x=current_x, y=current_y) self.atk = StringVar() atk_entry = Entry(self, width=5, textvariable=self.atk, font=(SCP, 12), justify=CENTER) atk_entry.place(x=current_x + 3, y=current_y + current_y_diff) atk_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 70 Label(self, width=25, text='Addition', font=(SCP, 12)).place(x=current_x, y=current_y) self.addition = StringVar() addition_entry = Entry(self, width=25, textvariable=self.addition, font=(MS_JH, 12), justify=CENTER) addition_entry.place(x=current_x + 3, y=current_y + current_y_diff) addition_entry.bind('<Return>', lambda x: self.presently.focus_set()) current_y += 14 + current_y_diff * 2 current_x = 27 Label(self, width=8, text='AtkRaised', font=(SCP, 10)).place(x=current_x + 1, y=current_y + 3) self.atk_raised = StringVar() atk_raised_entry = Entry(self, width=7, textvariable=self.atk_raised, font=(SCP, 12), justify=CENTER) atk_raised_entry.place(x=current_x, y=current_y + current_y_diff) atk_raised_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 90 Label(self, width=7, text='HitRate', font=(SCP, 11)).place(x=current_x, y=current_y) self.hit_rate = StringVar() hit_rate_entry = Entry(self, width=6, textvariable=self.hit_rate, font=(SCP, 12), justify=CENTER) hit_rate_entry.place(x=current_x + 2, y=current_y + current_y_diff) hit_rate_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 83 Label(self, width=8, text='Cri.Ratio', font=(SCP, 10)).place(x=current_x, y=current_y + 3) self.critical_ratio = StringVar() critical_ratio_entry = Entry(self, width=6, textvariable=self.critical_ratio, font=(SCP, 12), justify=CENTER) critical_ratio_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_ratio_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 85 Label(self, width=9, text='Cri.Factor', font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.critical_factor = StringVar() critical_factor_entry = Entry(self, width=6, textvariable=self.critical_factor, font=(SCP, 12), justify=CENTER) critical_factor_entry.place(x=current_x + 3, y=current_y + current_y_diff) critical_factor_entry.bind('<Return>', lambda x: active_factor_entry.focus_set()) current_x += 84 Label(self, width=9, text='Act.Factor', font=(SCP, 9)).place(x=current_x, y=current_y + 4) self.active_factor = StringVar() active_factor_entry = Entry(self, width=6, textvariable=self.active_factor, font=(SCP, 12), justify=CENTER) active_factor_entry.place(x=current_x + 4, y=current_y + current_y_diff) active_factor_entry.bind('<Return>', lambda x: addition_entry.focus_set()) current_x += 86 Label(self, width=8, text='Act.Cost', font=(SCP, 11)).place(x=current_x, y=current_y + 3) self.active_cost = StringVar() active_cost_entry = Entry(self, width=6, textvariable=self.active_cost, font=(SCP, 12), justify=CENTER) active_cost_entry.place(x=current_x + 5, y=current_y + current_y_diff) active_cost_entry.bind('<Return>', lambda x: addition_entry.focus_set()) # 送出、取消的按鈕 current_y += 23 + current_y_diff * 2 self.presently = ToggleButton(self, text='Presently', width=9, font=(SCP, 11), relief=RIDGE) self.presently.place(x=22, y=current_y) self.presently.bind('<space>', lambda event: self.presently.toggling()) self.presently.bind('<Return>', lambda x: self.submitting()) Button(self, text="Submit", command=self.submitting, width=28, relief=RIDGE, font=(SCP, 11)).place(x=131, y=current_y) Button(self, text="Cancel", command=self.destroy, width=13, relief=RIDGE, font=(SCP, 11)).place(x=405, y=current_y) def _init_content(self): self.atk.set(self.character_power.atk) self.level.set(self.character_power.level) self.atk_raised.set(self.character_power.atk_raised) self.hit_rate.set(self.character_power.hit_rate) self.critical_ratio.set(self.character_power.critical_ratio) self.critical_factor.set(self.character_power.critical_factor) self.active_factor.set(self.character_power.active_factor) self.active_cost.set(self.character_power.active_cost) self.addition.set(self.character_power.addition) self.presently.set_is_selected(self.character_power.presently) def submitting(self): self.character_power.character = self.character_selector.get() self.character_power.atk = int(self.atk.get()) self.character_power.level = int(self.level.get()) self.character_power.atk_raised = float(self.atk_raised.get()) self.character_power.hit_rate = float(self.hit_rate.get()) self.character_power.critical_ratio = float(self.critical_ratio.get()) self.character_power.critical_factor = float( self.critical_factor.get()) self.character_power.active_factor = float(self.active_factor.get()) self.character_power.active_cost = int(self.active_cost.get()) self.character_power.addition = self.addition.get() self.character_power.presently = self.presently.is_selected self.callback() self.destroy() def filling_in_entries_by_character(self): character = self.character_selector.get() self.atk_raised.set(1.0) self.hit_rate.set(character.atk_speed) self.critical_ratio.set(character.critical_rate) self.critical_factor.set(1.5) self.active_cost.set(character.active_cost) def filling_in_atk_by_level(self): atk = self.character_selector.get().estimate_atk_by_level( int(self.level.get())) if atk: self.atk.set(atk) def open_updating_character_window(self): open_updating_character_window(self.master, self.character_selector.get(), position_y_shift=-300)
class FriendRecordWindow(BasicWindow): def __init__(self, master, record, callback, width=309, height=198, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title("Friend Record") self._init_widget() self._init_record(record) self.callback = callback def _init_widget(self): Label(self, width=12, text="UsedNames :", font=(SCP, 12)).place(x=15, y=8) self.used_names = StringVar() Label(self, width=22, textvariable=self.used_names, font=(MS_JH, 12), anchor=W).place(x=47, y=32) self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=8, y=68) self.character_selector.bind("<Return>", lambda x: character_level_entry.focus_set()) current_y = 71 Label(self, width=7, text="C.Level", font=(SCP, 12)).place(x=146, y=current_y) self.character_level_var = IntVar() character_level_entry = Entry( self, width=6, textvariable=self.character_level_var, font=(SCP, 12), justify=CENTER ) character_level_entry.place(x=153, y=current_y + 28) character_level_entry.bind("<Return>", lambda x: rank_entry.focus_set()) Label(self, width=6, text="Rank", font=(SCP, 12)).place(x=229, y=current_y) self.rank_var = IntVar() rank_entry = Entry(self, width=6, textvariable=self.rank_var, font=(SCP, 12), justify=CENTER) rank_entry.place(x=232, y=current_y + 27) rank_entry.bind("<Return>", lambda x: self.submitting()) # 取消的按鈕 Button(self, text="Cancel", command=self.destroy, width=28, borderwidth=2, font=(SCP, 11)).place(x=23, y=150) def _init_record(self, record): if isinstance(record, FriendRecord): self.record = record self.used_names.set(record.used_names) self.character_selector.set( CharacterModel.select_character_by_specific_column("Nickname", record.current_character) if record.current_character != "" else None ) self.character_level_var.set(record.current_character_level) self.rank_var.set(record.current_rank) else: raise TypeError('In FriendRecordWindow, arg: "record"') def submitting(self): # 確認 rank 沒有異常 if self.record.is_unusual_rank(self.rank_var.get()): message = "Friend {0} has rank {1} with previous rank {2}.\nSure to continue?".format( self.used_names.get().encode("utf-8"), self.rank_var.get(), self.record.last_rank ) if not tkMessageBox.askyesno("Unusual rank", message, parent=self): return self.record.record(self.character_selector.get().nickname, self.character_level_var.get(), self.rank_var.get()) self.destroy() self.callback()
class CharacterWeaponWindow(BasicWindow): def __init__(self, master, character_weapon, callback, width=454, height=209, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title('CharacterWeapon') self.character_weapon = character_weapon self.callback = callback self._init_widget() self._init_content() def _init_widget(self): current_y_diff = 27 self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=23, y=42) self.character_selector.bind('<Return>', lambda event: self.max_atk.focus_set()) current_y = 10 current_x = 171 Label(self, width=7, text='MaxAtk', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_atk = IntEntry(self, width=5, font=(SCP, 12)) self.max_atk.place(x=current_x + 10, y=current_y + current_y_diff) self.max_atk.bind('<Return>', lambda event: self.max_critical.focus_set()) current_x += 87 Label(self, width=8, text='MaxCrit.', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_critical = IntEntry(self, width=5, font=(SCP, 12)) self.max_critical.place(x=current_x + 16, y=current_y + current_y_diff) self.max_critical.bind('<Return>', lambda event: self.max_armor.focus_set()) current_x += 92 Label(self, width=8, text='MaxArmor', font=(SCP, 12)).place(x=current_x, y=current_y) self.max_armor = IntEntry(self, width=5, font=(SCP, 12)) self.max_armor.place(x=current_x + 16, y=current_y + current_y_diff) self.max_armor.bind('<Return>', lambda event: self.current_atk.focus_set()) self.max_armor.bind('<Control-Return>', lambda event: self.auto_fill()) current_y += 65 current_x = 171 Label(self, width=7, text='CurAtk', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_atk = IntEntry(self, width=5, font=(SCP, 12)) self.current_atk.place(x=current_x + 10, y=current_y + current_y_diff) self.current_atk.bind('<Return>', lambda event: self.current_critical.focus_set()) current_x += 87 Label(self, width=8, text='CurCrit.', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_critical = IntEntry(self, width=5, font=(SCP, 12)) self.current_critical.place(x=current_x + 16, y=current_y + current_y_diff) self.current_critical.bind('<Return>', lambda event: self.current_armor.focus_set()) current_x += 92 Label(self, width=8, text='CurArmor', font=(SCP, 12)).place(x=current_x, y=current_y) self.current_armor = IntEntry(self, width=5, font=(SCP, 12)) self.current_armor.place(x=current_x + 16, y=current_y + current_y_diff) self.current_armor.bind('<Return>', lambda event: self.submitting()) # 送出、取消的按鈕 current_y += 81 Button(self, text="Submit", command=self.submitting, width=25, relief=RIDGE, font=(SCP, 11)).place( x=34, y=current_y) Button(self, text="Cancel", command=self.destroy, width=12, relief=RIDGE, font=(SCP, 11)).place( x=297, y=current_y) def _init_content(self): self.character_selector.set(self.character_weapon.character) self.max_atk.set(self.character_weapon.max_atk) self.max_critical.set(self.character_weapon.max_critical) self.max_armor.set(self.character_weapon.max_armor) self.current_atk.set(self.character_weapon.current_atk) self.current_critical.set(self.character_weapon.current_critical) self.current_armor.set(self.character_weapon.current_armor) def submitting(self): if self.current_atk.get() > self.max_atk.get() or self.current_critical.get() > self.max_critical.get() or \ self.current_armor.get() > self.max_armor.get(): raise ValueError('Current value over then max value.') self.character_weapon.character = self.character_selector.get() self.character_weapon.max_atk = self.max_atk.get() self.character_weapon.max_critical = self.max_critical.get() self.character_weapon.max_armor = self.max_armor.get() self.character_weapon.current_atk = self.current_atk.get() self.character_weapon.current_critical = self.current_critical.get() self.character_weapon.current_armor = self.current_armor.get() self.callback() self.destroy() def auto_fill(self): self.current_atk.set(self.max_atk.get()) self.current_critical.set(self.max_critical.get()) self.current_armor.set(self.max_armor.get()) self.current_armor.focus_set()
class FriendRecordWindow(BasicWindow): def __init__(self, master, record, callback, width=309, height=198, **kwargs): BasicWindow.__init__(self, master, width=width, height=height, **kwargs) self.title('Friend Record') self._init_widget() self._init_record(record) self.callback = callback def _init_widget(self): Label(self, width=12, text='UsedNames :', font=(SCP, 12)).place(x=15, y=8) self.used_names = StringVar() Label(self, width=22, textvariable=self.used_names, font=(MS_JH, 12), anchor=W).place(x=47, y=32) self.character_selector = CharacterSelectorCanvas(self) self.character_selector.place(x=8, y=68) self.character_selector.bind( '<Return>', lambda x: character_level_entry.focus_set()) current_y = 71 Label(self, width=7, text='C.Level', font=(SCP, 12)).place(x=146, y=current_y) self.character_level_var = IntVar() character_level_entry = Entry(self, width=6, textvariable=self.character_level_var, font=(SCP, 12), justify=CENTER) character_level_entry.place(x=153, y=current_y + 28) character_level_entry.bind('<Return>', lambda x: rank_entry.focus_set()) Label(self, width=6, text='Rank', font=(SCP, 12)).place(x=229, y=current_y) self.rank_var = IntVar() rank_entry = Entry(self, width=6, textvariable=self.rank_var, font=(SCP, 12), justify=CENTER) rank_entry.place(x=232, y=current_y + 27) rank_entry.bind('<Return>', lambda x: self.submitting()) # 取消的按鈕 Button(self, text="Cancel", command=self.destroy, width=28, borderwidth=2, font=(SCP, 11)).place(x=23, y=150) def _init_record(self, record): if isinstance(record, FriendRecord): self.record = record self.used_names.set(record.used_names) self.character_selector.set( CharacterModel.select_character_by_specific_column( 'Nickname', record.current_character ) if record.current_character != '' else None) self.character_level_var.set(record.current_character_level) self.rank_var.set(record.current_rank) else: raise TypeError('In FriendRecordWindow, arg: \"record\"') def submitting(self): # 確認 rank 沒有異常 if self.record.is_unusual_rank(self.rank_var.get()): message = 'Friend {0} has rank {1} with previous rank {2}.\nSure to continue?'.format( self.used_names.get().encode('utf-8'), self.rank_var.get(), self.record.last_rank) if not tkMessageBox.askyesno('Unusual rank', message, parent=self): return self.record.record(self.character_selector.get().nickname, self.character_level_var.get(), self.rank_var.get()) self.destroy() self.callback()