OSDN Git Service

add alchemy simulator
[amulettoolsmh4/main.git] / view / notebookskill2view.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 NoteBookSkill2View():
12     u""" メインのフレームのスキル2一覧タブ """
13     def __init__(self, frame):
14         self.frame = frame
15         self._init_view()
16
17     def _init_view(self):
18         # initialize view
19         self.skill2_grid = xrc.XRCCTRL(self.frame, "GridSecondSkill")
20         self.ID_SKILL2_GRID = xrc.XRCID("GridSecondSkill")
21         self.skill2_grid.Bind(wx.EVT_SIZE, self.OnSkill2GridSize)
22
23         self.button_skill2_search = xrc.XRCCTRL(self.frame, "ButtonSeedSkillSearch")
24         self.button_skill2_clear = xrc.XRCCTRL(self.frame, "ButtonSeedSkillClear")
25         self.ID_BUTTON_SKILL2_SEARCH = xrc.XRCID("ButtonSeedSkillSearch")
26         self.ID_BUTTON_SKILL2_CLEAR = xrc.XRCID("ButtonSeedSkillClear")
27
28         # load skill2 grid value
29         self.skill2_grid.CreateGrid(constnumbers.NUM_SKILL2_GRID_ROW, constnumbers.NUM_SKILL2_GRID_COL)
30         self.skill2_grid.SetColLabelValue(0, constnumbers.NAME_AMULET1)
31         self.skill2_grid.SetColLabelValue(1, constnumbers.NAME_AMULET2)
32         self.skill2_grid.SetColLabelValue(2, constnumbers.NAME_AMULET3)
33         self.skill2_grid.SetColLabelValue(3, constnumbers.NAME_THRESHOLD1)
34         self.skill2_grid.SetColLabelValue(4, constnumbers.NAME_THRESHOLD2)
35         for i in range(constnumbers.NUM_SKILL2_GRID_ROW):
36             self.skill2_grid.SetRowLabelValue(i, constnumbers.LABEL_FORMAT_SKILL2_GRID_ROW.format(i+1))
37         self.skill2_grid.DisableDragGridSize()
38         self.skill2_grid.EnableEditing(False)
39
40         # text ctrl
41         self.text_ctrl_seed2_select = xrc.XRCCTRL(self.frame, "TextCtrlSeedSelect")
42         self.text_ctrl_result = xrc.XRCCTRL(self.frame, "TextCtrlSkillResult")
43         self.text_ctrl_inishie_skill2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieSkill")
44         self.text_ctrl_inishie_threshold1 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold1")
45         self.text_ctrl_inishie_threshold2 = xrc.XRCCTRL(self.frame, "TextCtrlInishieThreshold2")
46
47     def OnSkill2GridSize(self, event):
48         u""" Gridリサイズ時に親パネルのwidthに応じて自動で横に伸長する """
49         width, height = self.skill2_grid.GetParent().GetSize()
50         each_width = (width - 50) / (constnumbers.NUM_SKILL2_GRID_COL) # consider margin size
51         self.skill2_grid.SetRowLabelSize(40)
52         for col in range(constnumbers.NUM_SKILL2_GRID_COL):
53             self.skill2_grid.SetColSize(col, each_width)
54
55     def bind_button_search(self, event_func, evt=wx.EVT_BUTTON):
56         u""" 検索ボタンへのイベント登録 """
57         self.button_skill2_search.Bind(evt, event_func)
58
59     def bind_button_clear(self, event_func, evt=wx.EVT_BUTTON):
60         u""" クリアボタンへのイベント登録 """
61         self.button_skill2_clear.Bind(evt, event_func)
62
63     def set_skill2_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
64         u""" スキル名、判定値1,2での条件を満たすセルをハイライトする """
65         skill_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
66                 for x in [constnumbers.KEY_AMULET1, constnumbers.KEY_AMULET2, constnumbers.KEY_AMULET3]]
67         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
68             for col in skill_cols:
69                 val = self.skill2_grid.GetCellValue(row, col)
70                 if val in skill_names:
71                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
72                 else:
73                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
74
75         # threshold
76         th_cols = [constnumbers.DICT_SKILL2_GRID_COL[x]
77                 for x in [constnumbers.KEY_THRESHOLD1, constnumbers.KEY_THRESHOLD2]]
78         th_vals = [threshold1, threshold2]
79         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
80             for col, th_val in zip(th_cols, th_vals):
81                 val = self.skill2_grid.GetCellValue(row, col)
82                 if val.isdigit() and int(val) >= th_val:
83                     self.skill2_grid.SetCellBackgroundColour(row, col, color)
84                 else:
85                     self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
86         self._set_inishie_highlight(skill_names, threshold1, threshold2, color)
87
88     def _set_inishie_highlight(self, skill_names, threshold1, threshold2, color="Yellow"):
89         u"""いにしえの錬金結果のハイライト"""
90         val = self.text_ctrl_inishie_skill2.GetValue()
91         if val in skill_names:
92             self.text_ctrl_inishie_skill2.SetBackgroundColour(color)
93         else:
94             self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
95
96         for txt_ctrl, th_val in zip([self.text_ctrl_inishie_threshold1, self.text_ctrl_inishie_threshold2],
97                 [threshold1, threshold2]):
98             val = txt_ctrl.GetValue()
99             if val.isdigit() and int(val) >= th_val:
100                 txt_ctrl.SetBackgroundColour(color)
101             else:
102                 txt_ctrl.SetBackgroundColour(wx.NullColor)
103
104     def clear_skill2_highlight(self):
105         u""" 表のハイライトをクリアする """
106         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
107             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
108                self.skill2_grid.SetCellBackgroundColour(row, col, wx.NullColor)
109         self.text_ctrl_inishie_skill2.SetBackgroundColour(wx.NullColor)
110         self.text_ctrl_inishie_threshold1.SetBackgroundColour(wx.NullColor)
111         self.text_ctrl_inishie_threshold2.SetBackgroundColour(wx.NullColor)
112
113     def clear_skill2_grid(self):
114         u""" セルの内容をクリアする """
115         for row in range(constnumbers.NUM_SKILL2_GRID_ROW):
116             for col in range(constnumbers.NUM_SKILL2_GRID_COL):
117                self.skill2_grid.SetCellValue(row, col, u"")
118
119     def set_result_text(self, value):
120         u""" 結果の表示TextCtrlのセット """
121         self.text_ctrl_result.SetValue(value)
122
123     def clear_result_text(self):
124         u""" 結果の表示TextCtrlのクリア """
125         self.text_ctrl_result.SetValue(u"")
126
127     def set_skill2_by_col_key(self, column_key, values):
128         u""" キーに対応する行に値をまとめて登録する """
129         col = constnumbers.DICT_SKILL2_GRID_COL[column_key]
130         for row, val in zip( range(constnumbers.NUM_SKILL2_GRID_ROW), values):
131             self.skill2_grid.SetCellValue(row, col, val)
132
133     def set_seed2_value(self, value):
134         u""" TextCtrlに与えられた値をセットする"""
135         self.text_ctrl_seed2_select.SetValue(u"{0}".format(value))
136
137     def get_seed2_value(self):
138         u""" TextCtrlから入力されたSeed2の値を得る。数値に変換できない時はNoneを返す"""
139         seed = self.text_ctrl_seed2_select.GetValue()
140         if seed.isdigit():
141             return int(seed)
142         else:
143             return None
144
145     def clear_inishie(self):
146         u""" いにしえの錬金の結果のクリア """
147         self.text_ctrl_inishie_skill2.SetValue(u"")
148         self.text_ctrl_inishie_threshold1.SetValue(u"")
149         self.text_ctrl_inishie_threshold2.SetValue(u"")
150
151     def set_inishie(self, skill_name, threshold1, threshold2):
152         u""" いにしえの錬金の対応する値のセット """
153         self.text_ctrl_inishie_skill2.SetValue(u"{0}".format(skill_name))
154         self.text_ctrl_inishie_threshold1.SetValue(u"{0}".format(threshold1))
155         self.text_ctrl_inishie_threshold2.SetValue(u"{0}".format(threshold2))