OSDN Git Service

add alchemy simulator
[amulettoolsmh4/main.git] / view / notebookskill1view.py
1 # -*- coding: utf-8 -*-
2
3 # GUIのメインフレームにおけるSkill2一覧Notebookのview
4 # 2013/12/15 written by kei9
5 import wx
6 from wx import xrc
7 import wx.grid
8
9 import constnumbers
10
11 class NoteBookSkill1View():
12     u""" メインのフレームのスキル1一覧タブ """
13     SEPARATER = u"/"
14     def __init__(self, frame):
15         self.frame = frame
16         self._init_view()
17         self._init_event()
18         self._seed1, self._table_no, self._no = None, None, None
19
20     def _init_view(self):
21         # initialize view
22         self.radiobox_tenun = xrc.XRCCTRL(self.frame, "RadioBoxSkill1Tenun")
23         self.grid_skill1 = xrc.XRCCTRL(self.frame, "GridFirstSkill")
24         self.ID_SKILL1_GRID = xrc.XRCID("GridFirstSkill")
25
26         self.button_skill1_search = xrc.XRCCTRL(self.frame, "ButtonSeed1Skill1Search")
27         self.button_skill1_clear = xrc.XRCCTRL(self.frame, "ButtonSeed1Skill1Clear")
28         self.ID_BUTTON_SKILL1_SEARCH = xrc.XRCID("ButtonSeedSkill1Search")
29         self.ID_BUTTON_SKILL1_CLEAR = xrc.XRCID("ButtonSeedSkill1Clear")
30
31         # load skill1 grid value
32         u"""Tableを結果TextCtrlで示し、No.をrowラベル、行にはseed1, 天運個数、
33         1-7枠目の値を表示する。1-7枠目をお守りの種類とスキル名で分けると面倒なので
34         合体させて1つの行で表示した方がいいかもしれない。この場合は行数は9となる"""
35         self.grid_skill1.CreateGrid(constnumbers.NUM_SKILL1_GRID_ROW, constnumbers.NUM_SKILL1_GRID_COL)
36         self.grid_skill1.SetColLabelValue(0, constnumbers.LABEL_FORMAT_SKILL1_GRID_COL1)
37         self.grid_skill1.SetColLabelValue(1, constnumbers.LABEL_FORMAT_SKILL1_GRID_COL2)
38         for i in range(2, constnumbers.NUM_SKILL1_GRID_COL):
39             self.grid_skill1.SetColLabelValue(i, 
40                     constnumbers.LABEL_FORMAT_SKILL1_GRID_COL_AFTER2.format(i-1))
41         self.grid_skill1.DisableDragGridSize()
42         self.grid_skill1.EnableEditing(False)
43
44         # text ctrl
45         self.text_ctrl_seed1_select = xrc.XRCCTRL(self.frame, "TextCtrlSeed1Select")
46         self.text_ctrl_result = xrc.XRCCTRL(self.frame, "TextCtrlSkill1Result")
47
48     def _init_event(self):
49         u""" イベントの登録 """
50         self.grid_skill1.Bind(wx.EVT_SIZE, self.OnGridSizeChanged)
51
52     def OnGridSizeChanged(self, event):
53         u""" Gridサイズの変更時 """
54         width, height = self.grid_skill1.GetParent().GetSize()
55         each_width = (width - 60) / (constnumbers.NUM_SKILL1_GRID_COL) # consider margin size
56         self.grid_skill1.SetRowLabelSize(45)
57         for col in range(constnumbers.NUM_SKILL1_GRID_COL):
58             self.grid_skill1.SetColSize(col, each_width) 
59
60     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
61         u""" 検索ボタンへのイベント登録 """
62         self.button_skill1_search.Bind(evt, event_func)
63
64     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
65         u""" クリアボタンへのイベント登録 """
66         self.button_skill1_clear.Bind(evt, event_func)
67
68     def set_result_text(self, value):
69         u""" 結果の表示TextCtrlのセット """
70         self.text_ctrl_result.SetValue(value)
71         self._seed1, self._table_no, self._no = None, None, None
72
73     def clear_result_text(self):
74         u""" 結果の表示TextCtrlのクリア """
75         self.text_ctrl_result.SetValue(u"")
76         self._seed1, self._table_no, self._no = None, None, None
77
78     def set_text_result_by_seed1(self, seed1, table_no, no):
79         u""" 結果を示すTextCtrlへの値のセット """
80         if seed1 is not None and table_no is not None and no is not None:
81             self.text_ctrl_result.SetValue(
82                     u"Seed1: {0}, テーブルNo: {1}, 通し番号: {2}".format(seed1, table_no, no))
83             self._seed1, self._table_no, self._no = seed1, table_no, no
84         else:
85             self.clear_text_result()
86
87     def set_seed1_value(self, value):
88         u""" TextCtrlに与えられた値をセットする"""
89         self.text_ctrl_seed1_select.SetValue(u"{0}".format(value))
90
91     def get_seed1_value(self):
92         u""" TextCtrlから入力されたSeed1の値を得る。数値に変換できない時はNoneを返す"""
93         seed = self.text_ctrl_seed1_select.GetValue()
94         if seed.isdigit():
95             return int(seed)
96         else:
97             return None
98
99     def get_tenun_radio_key(self):
100         u""" 天運の錬金で使用したお守りの種類を示すkeyを返す """
101         idx = self.radiobox_tenun.GetSelection()
102         if idx == 0:
103             return constnumbers.KEY_TENUN555
104         elif idx == 1:
105             return constnumbers.KEY_TENUN888
106         else:
107             return None
108
109     def set_tenun_radio_key(self, alchemy_key):
110         u""" 天運の錬金で使用したお守りの種類を示すkeyにより、ラジオボックスの選択状態を変更 """
111         if alchemy_key == constnumbers.KEY_TENUN555:
112             self.radiobox_tenun.SetSelection(0)
113         elif alchemy_key == constnumbers.KEY_TENUN888:
114             self.radiobox_tenun.SetSelection(1)
115         else:
116             pass
117
118     def clear_highlight(self):
119         u""" セルの強調表示をクリアする """
120         for row in range(self.grid_skill1.GetNumberRows()):
121             for col in range(self.grid_skill1.GetNumberCols()):
122                 self.grid_skill1.SetCellBackgroundColour(row, col, wx.NullColor)
123
124     def update_highlight(self, skill_names, color=u"Yellow"):
125         u""" 指定されたスキル名に一致するセルを強調表示する """
126         for row in range(self.grid_skill1.GetNumberRows()):
127             for col in range(2, self.grid_skill1.GetNumberCols()):
128                 val = self.grid_skill1.GetCellValue(row, col)
129                 try:
130                     amu_name, skill_name = val.split(self.SEPARATER)
131                     if skill_name in skill_names:
132                         self.grid_skill1.SetCellBackgroundColour(row, col, color)
133                     else:
134                         self.grid_skill1.SetCellBackgroundColour(row, col, wx.NullColor)
135                 except ValueError as e:
136                     #cannot unpack
137                     self.grid_skill1.SetCellBackgroundColour(row, col, wx.NullColor)
138
139
140     def set_no2seed1s_dict(self, no2seed1s_dict, select_no=None):
141         u""" 通し番号から(seed1, result_num, amulet_names, skill_names)への辞書を元に、
142         noを列ラベルとする表を作成する
143         select_noがNoneでなければ、対応する行を選択状態とする"""
144         row_num = len(no2seed1s_dict)
145         diff = row_num - self.grid_skill1.GetNumberRows()
146         if diff > 0:
147             self.grid_skill1.AppendRows(diff, False)
148         elif diff < 0:
149             self.grid_skill1.DeleteRows(0, -diff, False)
150
151         for row, no in enumerate(sorted(no2seed1s_dict.keys())): # order by no
152             seed1, result_num, amu_names, skill_names = no2seed1s_dict[no]
153             self.grid_skill1.SetRowLabelValue(row, u"{0}".format(no))
154             self.grid_skill1.SetCellValue(row, 0, "{0}".format(seed1))
155             self.grid_skill1.SetCellValue(row, 1, "{0}".format(result_num))
156             for col, amu_name, skill_name in zip(
157                     range(2, constnumbers.NUM_SKILL1_GRID_COL), amu_names, skill_names):
158                 if ((amu_name is not None and amu_name is not u"") and 
159                     (skill_name is not None and skill_name is not u"")):
160                     val = u"{0}{1}{2}".format(
161                         constnumbers.AMULET_NAME_TO_SHORT_NAME_DICT[amu_name], self.SEPARATER, skill_name)
162                     self.grid_skill1.SetCellValue(row, col, val)
163                 else:
164                     self.grid_skill1.SetCellValue(row, col, u"")
165             if no == select_no:
166                 self.grid_skill1.MakeCellVisible(row, 0)
167                 self.grid_skill1.SelectRow(row)
168
169     def clear_skill1_grid(self):
170         u""" セルの内容をクリアする """
171         for row in range(self.grid_skill1.GetNumberRows()):
172             self.grid_skill1.SetRowLabelValue(row, u"")
173             for col in range(self.grid_skill1.GetNumberCols()):
174                self.grid_skill1.SetCellValue(row, col, u"")