class UIChooseGirl(Panel, InputHandler): def __init__(self, trans, *a, **k): self.trans = trans g = Game.getgame() choices = trans.mapping[g.me] w, h = 500 + 1*160, 390 + 1*113 Panel.__init__(self, width=w, height=h, zindex=5, *a, **k) p = self.parent pw, ph = p.width, p.height self.x, self.y = (pw-w)/2, (ph-h)/2 self.inputlet = None choices = self.choices = [c for c in choices if c.char_cls and not getattr(c, 'chosen', False)] self.selectors = selectors = [] for i, c in enumerate(choices): y, x = divmod(i, 4) x, y = 15 + 160*x, 45 + 113*(3-y) gs = GirlSelector(c, selectors, parent=self, x=x, y=y) @gs.event def on_dblclick(gs=gs): c = gs.choice ilet = self.inputlet if not c.chosen and ilet: ilet.set_choice(c) ilet.done() self.end_selection() selectors.append(gs) def process_user_input(self, ilet): self.inputlet = ilet self.begin_selection() def on_girl_chosen(self, choice): for c in self.selectors: if c.choice is choice: c.disable() break self.parent.update_portraits() def begin_selection(self): self.pbar = BigProgressBar( parent=self, x=(self.width-250)//2, y=9, width=250, ) def on_done(*a): self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, ) def end_selection(self): self.inputlet = None self.pbar.delete()
def process_user_input(self, ilet): g = Game.getgame() me = g.me choices = ilet.mapping[me] for i, c in enumerate(choices): c._choice_index = i w, h = CharacterSorterControl.expected_size(1, ilet.num) w = 20 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, font_size=12, x=x, y=y, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 190), anchor_x='center', anchor_y='center', batch=self.lbls, ) lbl(u'请拖动调整角色的出场顺序', w // 2, h - 25) parent = self.parent self.x, self.y = (parent.width - w) // 2, (parent.height - h) // 2 self.width, self.height = w, h self.update() self.sorter = sorter = CharacterSorterControl(ilet.num, ilet.limit, parent=self, x=20, y=60) selectors = [] for i, c in enumerate(choices): selectors.append(GirlSelector(c, selectors, parent=sorter)) sorter.init() btn = Button(parent=self, caption=u'调整完成', x=w - 120, y=15, width=100, height=30) @btn.event def on_click(*a, **k): gslist, = self.sorter.get_result() index = [c.choice._choice_index for c in gslist] ilet.set_result(index) ilet.done() end_transaction(self.trans) b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def process_user_input(self, ilet): cards = ilet.cards w, h = RanProphetControl.expected_size() w = 100 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, x=x, y=y, font_size=12, anchor_x='center', anchor_y='center', color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), batch=self.lbls, ) lbl(u'牌堆底', 50, 122) lbl(u'牌堆顶', 50, 277) lbl(u'请拖动调整牌的位置', w // 2, h - 25) parent = self.parent self.x, self.y = (parent.width - w) // 2, (parent.height - h) // 2 self.width, self.height = w, h self.update() self.rpc = rpc = RanProphetControl(parent=self, x=100, y=60) for i, c in enumerate(cards): cs = CardSprite(c, parent=rpc) cs.associated_card = c rpc.init() btn = Button(parent=self, caption=u'调整完成', x=w - 120, y=15, width=100, height=30) @btn.event def on_click(*a): up, down = self.rpc.get_result() up = [c.associated_card for c in up] down = [c.associated_card for c in down] ilet.set_result(up, down) ilet.done() end_transaction(self.trans) b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def process_user_input(self, ilet): cards = ilet.cards w, h = KokoroHopeMaskControl.expected_size() w = 100 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, x=x, y=y, font_size=12, anchor_x='center', anchor_y='center', color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), batch=self.lbls, ) lbl(u'请拖动调整牌的位置,获得的牌必须是同花色的', w//2, h-25) lbl(u'牌堆顶', 50, 277) lbl(u'展示并获得', 50, 122) parent = self.parent self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 self.width, self.height = w, h self.update() self.ctrl = ctrl = KokoroHopeMaskControl(parent=self, x=100, y=60) for i, c in enumerate(cards): cs = CardSprite(c, parent=ctrl) cs.associated_card = c ctrl.init() btn = Button(parent=self, caption=u'完成', x=w-120, y=15, width=100, height=30) @btn.event def on_click(*a): putback, acquire = self.ctrl.get_result() putback = [c.associated_card for c in putback] acquire = [c.associated_card for c in acquire] ilet.set_result(putback, acquire) ilet.done() end_transaction(self.trans) @ctrl.event def on_update(): putback, acquire = self.ctrl.get_result() putback = [c.associated_card for c in putback] acquire = [c.associated_card for c in acquire] if ilet.is_valid(putback, acquire): btn.state = Button.NORMAL else: btn.state = Button.DISABLED b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def process_user_input(self, ilet): cards = ilet.cards w, h = KokoroHopeMaskControl.expected_size() w = 100 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, x=x, y=y, font_size=12, anchor_x='center', anchor_y='center', color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), batch=self.lbls, ) lbl(u'请拖动调整牌的位置', w // 2, h - 25) lbl(u'牌堆顶', 50, 277) lbl(u'展示并获得', 50, 122) parent = self.parent self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 self.width, self.height = w, h self.update() self.ctrl = ctrl = KokoroHopeMaskControl(parent=self, x=100, y=60) for i, c in enumerate(cards): cs = CardSprite(c, parent=ctrl) cs.associated_card = c ctrl.init() btn = Button(parent=self, caption=u'完成', x=w-120, y=15, width=100, height=30) @btn.event def on_click(*a): ilet.done() end_transaction(self.trans) @ctrl.event def on_update(): putback, acquire = self.ctrl.get_result() putback = [c.associated_card for c in putback] acquire = [c.associated_card for c in acquire] if ilet.is_valid(putback, acquire): ilet.set_result(putback, acquire) btn.state = Button.NORMAL else: btn.state = Button.DISABLED b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def process_user_input(self, ilet): g = Game.getgame() me = g.me choices = ilet.mapping[me] for i, c in enumerate(choices): c._choice_index = i w, h = CharacterSorterControl.expected_size(1, ilet.num) w = 20 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, font_size=12, x=x, y=y, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 190), anchor_x='center', anchor_y='center', batch=self.lbls, ) lbl(u'请拖动调整角色的出场顺序', w//2, h-25) parent = self.parent self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 self.width, self.height = w, h self.update() self.sorter = sorter = CharacterSorterControl( ilet.num, ilet.limit, parent=self, x=20, y=60 ) selectors = [] for i, c in enumerate(choices): selectors.append( GirlSelector(c, selectors, parent=sorter) ) sorter.init() btn = Button(parent=self, caption=u'调整完成', x=w-120, y=15, width=100, height=30) @btn.event def on_click(*a, **k): gslist, = self.sorter.get_result() index = [c.choice._choice_index for c in gslist] ilet.set_result(index) ilet.done() end_transaction(self.trans) b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def begin_selection(self): self.selecting = True self.pbar and self.pbar.delete() self.pbar = BigProgressBar( parent=self, x=(self.width-250)//2, y=9, width=250, ) def on_done(*a): # self.inputlet.done() # FIXME: blindly did this. self.inputlet and self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, )
def process_user_input(self, ilet): cards = ilet.cards w, h = RanProphetControl.expected_size() w = 100 + w + 20 h = 60 + h + 50 def lbl(text, x, y): Label( text=text, x=x, y=y, font_size=12, anchor_x='center', anchor_y='center', color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), batch=self.lbls, ) lbl(u'牌堆底', 50, 122) lbl(u'牌堆顶', 50, 277) lbl(u'请拖动调整牌的位置', w//2, h-25) parent = self.parent self.x, self.y = (parent.width - w)//2, (parent.height - h)//2 self.width, self.height = w, h self.update() self.rpc = rpc = RanProphetControl(parent=self, x=100, y=60) for i, c in enumerate(cards): cs = CardSprite(c, parent=rpc) cs.associated_card = c rpc.init() btn = Button(parent=self, caption=u'调整完成', x=w-120, y=15, width=100, height=30) @btn.event def on_click(*a): up, down = self.rpc.get_result() up = [c.associated_card for c in up] down = [c.associated_card for c in down] ilet.set_result(up, down) ilet.done() end_transaction(self.trans) b = BigProgressBar(parent=self, x=100, y=15, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=on_click)
def begin_selection(self): self.pbar = BigProgressBar( parent=self, x=(self.width-250)//2, y=9, width=250, ) def on_done(*a): self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, )
def process_user_input(self, ilet): try: ui_meta = ilet.initiator.ui_meta choose_option_buttons = ui_meta.choose_option_buttons choose_option_prompt = ui_meta.choose_option_prompt if callable(choose_option_prompt): choose_option_prompt = choose_option_prompt(ilet.initiator) if callable(choose_option_buttons): choose_option_buttons = choose_option_buttons(ilet.initiator) except AttributeError: choose_option_buttons = ((u'确定', True), (u'结束', False)) choose_option_prompt = u'UIChooseOption: %s missing ui_meta' % ( ilet.initiator.__class__.__name__) self.confirmbtn = UIActionConfirmButtons( parent=self, x=259, y=4, width=165, height=24, buttons=choose_option_buttons, ) self.progress_bar = b = BigProgressBar(parent=self, x=0, y=0, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=lambda *a: on_confirm(None)) self.label = Label( text=choose_option_prompt, x=125, y=28, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 179), anchor_x='center', anchor_y='bottom', ) @self.confirmbtn.event def on_confirm(val): ilet.set_option(val) ilet.done() end_transaction(self.trans)
def process_user_input(self, ilet): view = self.view self.inputlet = ilet self.confirmbtn = UIActionConfirmButtons( parent=self, x=259, y=4, width=165, height=24, ) self.progress_bar = BigProgressBar(parent=self, x=0, y=0, width=250) self.label = Label( text=u"HEY SOMETHING'S WRONG", x=125, y=28, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 179), anchor_x='center', anchor_y='bottom', ) view.selection_change += self._on_selection_change g = Game.getgame() port = view.player2portrait(g.me) port.equipcard_area.clear_selection() # view.selection_change.notify() # the clear_selection thing will trigger this @self.confirmbtn.event def on_confirm(is_ok, force=False): if is_ok: ilet.set_result(*self.get_result()) elif not force and view.get_selected_skills(): view.reset_selected_skills() return ilet.done() end_transaction(self.trans) self.progress_bar.value = LinearInterp( 1.0, 0.0, ilet.timeout, on_done=lambda *a: on_confirm(False, force=True))
def process_user_input(self, ilet): self.ilet = ilet target = ilet.target card_lists = [(CardList.ui_meta.lookup[cat], getattr(target, cat)) for cat in ilet.categories] self.init(card_lists) self.progress_bar = b = BigProgressBar(parent=self, x=(self.width - 250) // 2, y=7, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=lambda *a: self.cleanup())
def process_user_input(self, ilet): parent = self.parent self.confirmbtn = ConfirmButtons(parent=self, x=259, y=4, width=165, height=24, buttons=((u'确定', True), (u'结束', False))) self.progress_bar = BigProgressBar(parent=self, x=0, y=0, width=250) self.label = Label( text=u"HEY SOMETHING'S WRONG", x=125, y=28, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 179), anchor_x='center', anchor_y='bottom', ) def dispatch_selection_change(): self.confirmbtn.buttons[0].state = Button.DISABLED self.on_selection_change() parent.push_handlers(on_selection_change=dispatch_selection_change) g = Game.getgame() port = parent.player2portrait(g.me) port.equipcard_area.clear_selection() #dispatch_selection_change() # the clear_selection thing will trigger this @self.confirmbtn.event def on_confirm(is_ok): is_ok and ilet.set_result(*self.get_result()) ilet.done() end_transaction(self.trans) self.progress_bar.value = LinearInterp( 1.0, 0.0, ilet.timeout, on_done=lambda *a: on_confirm(False)) self.inputlet = ilet
class UIBaseChooseGirl(Panel, InputHandler): hover_pic = None def __init__(self, trans, *a, **k): self.trans = trans self.pbar = None self.selecting = False g = Game.getgame() choices = trans.mapping[g.me] n_choices = len(choices) cols = 5 if n_choices > 16 else 4 rows = max((n_choices - 1) / cols + 1, 4) w, h = 20 + cols * 160, 51 + rows * 113 + 30 Panel.__init__(self, width=w, height=h, zindex=5, *a, **k) p = self.parent pw, ph = p.width, p.height self.x, self.y = (pw - w) / 2, (ph - h) / 2 self.inputlet = None choices = self.choices = [ c for c in choices if c.char_cls and not getattr(c, 'chosen', False) ] self.selectors = selectors = [] for i, c in enumerate(choices): y, x = divmod(i, cols) x, y = 15 + 160 * x, 45 + 113 * (rows - 1 - y) gs = GirlSelector(c, selectors, parent=self, hover_pic=self.hover_pic, x=x, y=y) @gs.event def on_dblclick(gs=gs): c = gs.choice ilet = self.inputlet if not c.chosen and ilet: ilet.set_choice(c) ilet.done() self.end_selection() selectors.append(gs) self.label = Label(text='等待其他玩家操作', x=w // 2, y=51 + rows * 113, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), anchor_x='center', anchor_y='bottom') def draw(self): Panel.draw(self) self.label.draw() def on_girl_chosen(self, arg): actor, choice = arg for c in self.selectors: if c.choice is choice: c.disable() break self.parent.update_portraits() def begin_selection(self): self.selecting = True self.pbar and self.pbar.delete() self.pbar = BigProgressBar( parent=self, x=(self.width - 250) // 2, y=9, width=250, ) def on_done(*a): # self.inputlet.done() # FIXME: blindly did this. self.inputlet and self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, ) def end_selection(self): self.inputlet = None self.selecting = False self.pbar.delete()
def process_user_input(self, ilet): # Override view = self.view buttons = ((u'确定', 'fire'), (u'结束', 'cancel')) target_act = ilet.initiator.target_act pact = thbactions.ForEach.get_actual_action(target_act) g = Game.getgame() if pact: if g.me.tags['__reject_dontcare'] is pact: ilet.done() end_transaction(self.trans) return buttons = ((u'确定', 'fire'), (u'结束', 'cancel'), (u'此次不再使用', 'dontcare')) self.confirmbtn = UIActionConfirmButtons( parent=self, x=259, y=4, width=165, height=24, buttons=buttons, ) self.progress_bar = BigProgressBar(parent=self, x=0, y=0, width=250) self.label = Label( text=u"HEY SOMETHING'S WRONG", x=125, y=28, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 179), anchor_x='center', anchor_y='bottom', ) view.selection_change += self._on_selection_change port = view.player2portrait(g.me) port.equipcard_area.clear_selection() # view.notify.selection_change.notify() # the clear_selection thing will trigger this @self.confirmbtn.event def on_confirm(v, force=False): if v == 'fire': ilet.set_result(*self.get_result()) elif v == 'cancel' and not force and view.get_selected_skills(): view.reset_selected_skills() return elif v == 'dontcare': g.me.tags['__reject_dontcare'] = pact ilet.done() end_transaction(self.trans) self.progress_bar.value = LinearInterp( 1.0, 0.0, ilet.timeout, on_done=lambda *a: on_confirm('cancel', force=True)) self.inputlet = ilet assert not ilet.candidates self.set_valid_waiter = ev = Event() g = Game.getgame() gevent.spawn_later(0.1 + 0.2 * math.sqrt(g.players.index(g.me)), ev.set) self.set_text(u'自动结算好人卡…') if not RejectCard.ui_meta.has_reject_card(g.me): ilet.done() end_transaction(self.trans) self.view.selection_change.notify()
class UIBaseChooseGirl(Panel, InputHandler): hover_pic = None def __init__(self, trans, *a, **k): self.trans = trans self.pbar = None self.selecting = False g = Game.getgame() choices = trans.mapping[g.me] n_choices = len(choices) cols = 5 if n_choices > 16 else 4 rows = max((n_choices - 1) / cols + 1, 4) w, h = 20 + cols*160, 51 + rows*113 + 30 Panel.__init__(self, width=w, height=h, zindex=5, *a, **k) p = self.parent pw, ph = p.width, p.height self.x, self.y = (pw - w)/2, (ph - h)/2 self.inputlet = None choices = self.choices = [c for c in choices if c.char_cls and not getattr(c, 'chosen', False)] self.selectors = selectors = [] for i, c in enumerate(choices): y, x = divmod(i, cols) x, y = 15 + 160*x, 45 + 113*(rows - 1 - y) gs = GirlSelector(c, selectors, parent=self, hover_pic=self.hover_pic, x=x, y=y) @gs.event def on_dblclick(gs=gs): c = gs.choice ilet = self.inputlet if not c.chosen and ilet: ilet.set_choice(c) ilet.done() self.end_selection() selectors.append(gs) self.label = Label( text='等待其他玩家操作', x=w//2, y=51+rows*113, font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), anchor_x='center', anchor_y='bottom' ) def draw(self): Panel.draw(self) self.label.draw() def on_girl_chosen(self, arg): actor, choice = arg for c in self.selectors: if c.choice is choice: c.disable() break self.parent.update_portraits() def begin_selection(self): self.selecting = True self.pbar and self.pbar.delete() self.pbar = BigProgressBar( parent=self, x=(self.width-250)//2, y=9, width=250, ) def on_done(*a): # self.inputlet.done() # FIXME: blindly did this. self.inputlet and self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, ) def end_selection(self): self.inputlet = None self.selecting = False self.pbar.delete()
def process_user_input(self, ilet): target = ilet.target categories = [getattr(target, i) for i in ilet.categories] h = 40 + len(categories) * 145 + 10 w = 100 + 6 * 93.0 + 30 y = 40 i = 0 for cat in reversed(categories): if not len(cat): h -= 145 # no cards in this category continue Label( text=CardList.ui_meta.lookup[cat.type], font_size=12, color=(255, 255, 160, 255), shadow=(2, 0, 0, 0, 230), x=30, y=y + 62 + 145 * i, anchor_x='left', anchor_y='center', batch=self.lbls, ) ca = DropCardArea( parent=self, x=100, y=y + 145 * i, fold_size=6, width=6 * 93, height=125, ) for c in cat: cs = CardSprite(c, parent=ca) cs.associated_card = c @cs.event def on_mouse_dblclick(x, y, btn, mod, cs=cs): ilet.set_card(cs.associated_card) ilet.done() end_transaction(self.trans) ca.update() i += 1 p = self.parent self.x, self.y = (p.width - w) // 2, (p.height - h) // 2 self.width, self.height = w, h self.update() self.progress_bar = b = BigProgressBar(parent=self, x=(w - 250) // 2, y=7, width=250) b.value = LinearInterp(1.0, 0.0, ilet.timeout, on_done=lambda *a: self.cleanup()) btn = ImageButton( common_res.buttons.close_blue, parent=self, x=w - 20, y=h - 20, ) @btn.event def on_click(): ilet.done()
class UIChooseGirl(Panel, InputHandler): def __init__(self, trans, *a, **k): self.trans = trans self.pbar = None g = Game.getgame() choices = trans.mapping[g.me] w, h = 500 + 1 * 160, 390 + 1 * 113 Panel.__init__(self, width=w, height=h, zindex=5, *a, **k) p = self.parent pw, ph = p.width, p.height self.x, self.y = (pw - w) / 2, (ph - h) / 2 self.inputlet = None choices = self.choices = [ c for c in choices if c.char_cls and not getattr(c, 'chosen', False) ] self.selectors = selectors = [] for i, c in enumerate(choices): y, x = divmod(i, 4) x, y = 15 + 160 * x, 45 + 113 * (3 - y) gs = GirlSelector(c, selectors, parent=self, x=x, y=y) @gs.event def on_dblclick(gs=gs): c = gs.choice ilet = self.inputlet if not c.chosen and ilet: ilet.set_choice(c) ilet.done() self.end_selection() selectors.append(gs) def process_user_input(self, ilet): self.inputlet = ilet self.begin_selection() def on_girl_chosen(self, choice): for c in self.selectors: if c.choice is choice: c.disable() break self.parent.update_portraits() def begin_selection(self): self.pbar and self.pbar.delete() self.pbar = BigProgressBar( parent=self, x=(self.width - 250) // 2, y=9, width=250, ) def on_done(*a): # self.inputlet.done() # FIXME: blindly did this. self.inputlet and self.inputlet.done() self.end_selection() self.pbar.value = LinearInterp( 1.0, 0.0, self.inputlet.timeout, on_done=on_done, ) def end_selection(self): self.inputlet = None self.pbar.delete()