OSDN Git Service

add alchemy simulator
[amulettoolsmh4/main.git] / view / notebookalchemysimulatorview.py
1
2 # -*- coding: utf-8 -*-
3
4 # GUIのメインフレームにおける錬金シミュレーターNotebookのview
5 # 2013/12/15 written by kei9
6 import wx
7 from wx import xrc
8 import wx.grid
9
10 import constnumbers
11
12 class NoteBookAlchemySimulatorView():
13     u""" メインのフレームの錬金シミュレータータブ """
14     def __init__(self, frame):
15         self.frame = frame
16         self._init_view()
17
18     def _init_view(self):
19         # initialize view
20         self.grid_sim = xrc.XRCCTRL(self.frame, "GridSimulator")
21         self.grid_sim.Bind(wx.EVT_SIZE, self.OnGridSizeChanged)
22
23         self.button_search = xrc.XRCCTRL(self.frame, "ButtonSimulatorSearch")
24         self.button_clear = xrc.XRCCTRL(self.frame, "ButtonSimulatorClear")
25
26         self.radiobox_tenun = xrc.XRCCTRL(self.frame, "RadioBoxSimulatorTenun")
27
28         # load simulator grid value
29         self.grid_sim.CreateGrid(constnumbers.NUM_SIMULATOR_GRID_ROW, constnumbers.NUM_SIMULATOR_GRID_COL)
30         self.grid_sim.SetColLabelValue(0, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL1)
31         self.grid_sim.SetColLabelValue(1, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL2)
32         self.grid_sim.SetColLabelValue(2, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL3)
33         self.grid_sim.SetColLabelValue(3, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL4)
34         self.grid_sim.SetColLabelValue(4, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL5)
35         self.grid_sim.SetColLabelValue(5, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_COL6)
36
37         self.grid_sim.SetRowLabelValue(0, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW1)
38         self.grid_sim.SetRowLabelValue(1, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW2)
39         self.grid_sim.SetRowLabelValue(2, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW3)
40         self.grid_sim.SetRowLabelValue(3, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW4)
41         self.grid_sim.SetRowLabelValue(4, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW5)
42         self.grid_sim.SetRowLabelValue(5, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW6)
43         self.grid_sim.SetRowLabelValue(6, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW7)
44         self.grid_sim.SetRowLabelValue(7, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW8)
45         self.grid_sim.SetRowLabelValue(8, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW9)
46         self.grid_sim.SetRowLabelValue(9, constnumbers.LABEL_FORMAT_SIMULATOR_GRID_ROW10)
47         self.grid_sim.DisableDragGridSize()
48         self.grid_sim.EnableEditing(False)
49
50         # text ctrl
51         self.text_ctrl_seed1 = xrc.XRCCTRL(self.frame, "TextCtrlSimulatorSeed1")
52         self.text_ctrl_seed2 = xrc.XRCCTRL(self.frame, "TextCtrlSimulatorSeed2")
53
54
55     def OnGridSizeChanged(self, event):
56         u""" Gridリサイズ時に親パネルのwidthに応じて自動で横に伸長する """
57         width, height = self.grid_sim.GetParent().GetSize()
58         each_width = (width - 130) / (constnumbers.NUM_SIMULATOR_GRID_COL) # consider margin size
59         self.grid_sim.SetRowLabelSize(120)
60         for col in range(constnumbers.NUM_SIMULATOR_GRID_COL):
61             self.grid_sim.SetColSize(col, each_width)
62
63     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
64         u""" 検索ボタンへのイベント登録 """
65         self.button_search.Bind(evt, event_func)
66
67     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
68         u""" クリアボタンへのイベント登録 """
69         self.button_clear.Bind(evt, event_func)
70
71     def update_highlight(self, skill_names, color="Yellow"):
72         u""" スキル名が一致するセルをハイライトする """
73         for row in range(self.grid_sim.GetNumberRows()):
74             for col in constnumbers.SIMULATOR_GRID_SKILL_NAME_COLS:
75                 skill_name = self.grid_sim.GetCellValue(row, col)
76                 if skill_name in skill_names:
77                     self.grid_sim.SetCellBackgroundColour(row, col, color)
78                 else:
79                     self.grid_sim.SetCellBackgroundColour(row, col, wx.NullColor)
80
81     def clear_highlight(self):
82         u""" セルの強調表示をクリアする """
83         for row in range(self.grid_sim.GetNumberRows()):
84             for col in range(self.grid_sim.GetNumberCols()):
85                 self.grid_sim.SetCellBackgroundColour(row, col, wx.NullColor)
86
87     def clear_grid(self):
88         u""" セルの内容をクリアする """
89         for row in range(self.grid_sim.GetNumberRows()):
90             for col in range(self.grid_sim.GetNumberCols()):
91                self.grid_sim.SetCellValue(row, col, u"")
92
93     def set_seed_values(self, seed1, seed2):
94         u""" TextCtrlに与えられた値をセットする"""
95         self.text_ctrl_seed1.SetValue(u"{0}".format(seed1))
96         self.text_ctrl_seed2.SetValue(u"{0}".format(seed2))
97
98     def clear_seed_values(self):
99         u""" TextCtrlに与えられた値をセットする"""
100         self.text_ctrl_seed1.SetValue(u"")
101         self.text_ctrl_seed2.SetValue(u"")
102
103     def get_seed_values(self):
104         u""" TextCtrlから入力されたSeed1, Seed2の値を得る。数値に変換できない時はNoneを返す"""
105         seed1 = self.text_ctrl_seed1.GetValue()
106         seed2 = self.text_ctrl_seed2.GetValue()
107         if seed1.isdigit() and seed2.isdigit():
108             return int(seed1), int(seed2)
109         else:
110             return None
111
112     def get_tenun_radio_key(self):
113         u""" 天運の錬金で使用したお守りの種類を示すkeyを返す """
114         idx = self.radiobox_tenun.GetSelection()
115         if idx == 0:
116             return constnumbers.KEY_TENUN555
117         elif idx == 1:
118             return constnumbers.KEY_TENUN888
119         else:
120             return None
121
122     def set_tenun_radio_key(self, alchemy_key):
123         u""" 天運の錬金で使用したお守りの種類を示すkeyにより、ラジオボックスの選択状態を変更 """
124         if alchemy_key == constnumbers.KEY_TENUN555:
125             self.radiobox_tenun.SetSelection(0)
126         elif alchemy_key == constnumbers.KEY_TENUN888:
127             self.radiobox_tenun.SetSelection(1)
128         else:
129             pass
130
131     def set_tenun_values(self, values):
132         u""" values: list of (skill_name1, skill_val1, skill_name2, skill_val2, slot_num, amulet_name)
133         天運の錬金の対応する値のセット """
134         rows = constnumbers.SIMULATOR_GRID_ROW_DICT[constnumbers.KEY_TENUN]
135
136         for row in rows:
137             for col in range(self.grid_sim.GetNumberCols()):
138                 self.grid_sim.SetCellValue(row, col, u"")
139
140         for row, (skill1_name, skill1_val, skill2_name, skill2_val, slot_num, amulet_name) in zip(rows, values):
141             self.grid_sim.SetCellValue(row, 0, amulet_name)
142             self.grid_sim.SetCellValue(row, 1, skill1_name)
143             self.grid_sim.SetCellValue(row, 2, u"{0}".format(skill1_val))
144             if skill2_name != u"":
145                 self.grid_sim.SetCellValue(row, 3, skill2_name)
146                 self.grid_sim.SetCellValue(row, 4, u"{0}".format(skill2_val))
147             else:
148                 self.grid_sim.SetCellValue(row, 3, u"")
149                 self.grid_sim.SetCellValue(row, 4, u"")
150             self.grid_sim.SetCellValue(row, 5, u"{0}".format(slot_num))
151
152     def set_values(self, alchemy_type, 
153             skill1_name, skill1_val, skill2_name, skill2_val, slot_num, amulet_name):
154         u""" なぞ・光明・いにしえの錬金の対応する値のセット """
155         row = constnumbers.SIMULATOR_GRID_ROW_DICT[alchemy_type]
156         self.grid_sim.SetCellValue(row, 0, amulet_name)
157         self.grid_sim.SetCellValue(row, 1, skill1_name)
158         self.grid_sim.SetCellValue(row, 2, u"{0}".format(skill1_val))
159         if skill2_name != u"":
160             self.grid_sim.SetCellValue(row, 3, skill2_name)
161             self.grid_sim.SetCellValue(row, 4, u"{0}".format(skill2_val))
162         else:
163             self.grid_sim.SetCellValue(row, 3, u"")
164             self.grid_sim.SetCellValue(row, 4, u"")
165         self.grid_sim.SetCellValue(row, 5, u"{0}".format(slot_num))