Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello β I'm @olemoritz on Twitter.
Disable object while action in progress?
-
good day Pythonistas!
hello everyone!
Code provided is not actual code but best representation of functionalityGoal:
Disable custom button class
UIButton
while animation is in progress.Attempt:
i tried using a boolean in the class containing the object getting animated to check activity.
class Menu(Sprite): def __init__(self,texture=ASSETS('menu-bg'), inAction=False, *args, **kwargs): super().__init__(texture=texture, *args, **kwargs) self.Action_is_runing = inAction self.onScreen = False def Toggle(self, sender=None): if(self.Action_is_runing): return False elif(self.onScreen): #close menu #at the end of Action Sequince we set sender.enabledb=true else: #open window #at the end of Action Sequince we set sender.enabledb=true class UIButton(sprite): def __init__(self, texture=ASSETS('button-io'), enabled=True, action=None, *args, **kwargs): super().__init__(texture=texture, *args, **kwargs) self.enabled = enabled self.action = action def RunAction(self): if(self.enabled): self.action(sender=self) self.enabled = False def CheckTouch(self, touch): tl = touch.location if(self.enabled): if(tl in self.frame): self.RunAction()
Logically this should work but if i press the button before the actionsvare finihed it starts a new set t the current Transform.. at firstthe resaults were funny.. but now its just fustrating.. anyone have an idea? if you need the actual code ill provide it its just in that "in development" kind of condition lol
-
Update.
here is the raw script i had to replace mybassets with built in so everything looks kinda funny but the green square on the right is the open close buton. the small x in the window is a close buton and the blue one on top does nothing lol ... sorry for the mess im very mesy during core development then i cean up as i go... i know im bad lol. well here it is..
@stephen said:
from scene import * from gameObject import GameObject from colors import * import sound, random, math, time, os A = Action w,h=get_screen_size() PHONE_TEST=0 FONT=('Papyrus', 18) if PHONE_TEST: SCALE=0.5 else: SCALE=1.0 def ColorPhase(curVal, maxVal, node, reversed): p=round(100*curVal/maxVal, 1) if reversed: if p <= 10: node.color=green() elif p <= 20: node.color=lime() elif p <= 30: node.color=yellow() elif p <= 50: node.color=mango() elif p <= 70: node.color=orange() elif p <= 90: node.color=strawberry() else: node.color=red() else: if p <= 10: node.color=red() elif p <= 20: node.color=strawberry() elif p <= 30: node.color=orange() elif p <= 50: node.color=mango() elif p <= 70: node.color=yellow() elif p <= 90: node.color=lime() else: node.color=green() ''' ::Tick:: Acts as a bridge from Gameloop object to other objects that need regular pdates. Properties val β€ Time between frames 'DeltaTime' last_tick β€ val for last Tick objects_to_update β€ ist of updated class'. Managed Objects must have an Update() method (case sensitive) Methods dt β€ Returns current Tick rounded to 3 decimal places set β€ Sets Tick.val to gameloop delta size β€ Returns amount of objects being updated add β€ Add object to be updated _update β€ update loop to update every Tick.intervals LabelNode from Pythonista's scene module to display Tick info on screen. ''' class Tick: val=0.0 last_tick=0.0 intervals=1.0 objects_to_update=[] label=LabelNode(text='Tick: ', color=(0.0, 0.0, 0.0, 1.0), size=Size(50, 35), anchor_point=(0.0, 0.0)) @classmethod def dt(cls): return round(cls.val, 3) @classmethod def set(cls, val): cls.last_tick=cls.val cls.val=val if cls.val < cls.last_tick: cls.label.color=(0.0, 0.75, 0.0) cls.label.text=f'Tick: {cls.dt()}' else: cls.label.color=(0.75, 0.0, 0.0) cls.label.text=f'Tick: {cls.dt()}' @classmethod def size(cls): return len(cls.objects_to_update) @classmethod def Add(cls, object): cls.objects_to_update.append(object) @classmethod def _update(cls, GameLoop): cls.set(GameLoop.dt) if cls.objects_to_update: for child in cls.objects_to_update: child.update(cls.dt, GameLoop) class Listener: def __init__(self, node, reaction): self.node=node self.reaction=reaction self.eventFired=False self.area=self.node.parent.point_to_scene(self.node.position) self.posX, self.posY=self.node.position self.rect=Rect(self.area[0], self.area[1], self.node.size[0], self.node.size[1]) class EventManager: def __init__(self): self.listeners=list([]) Tick.Add(self) def AddListener(self, node, func): self.listeners.append(Listener(node, func)) def update(self, dt, gl): pass def touch_began(self, touch): for l in self.listeners: p=l.node.parent.point_from_scene(touch.location) if(p in l.node.frame): if(l.node.tag == 'UIButton'): l.reaction(l.node) def touch_moved(self, touch): pass def touch_ended(self, touch): pass EM=EventManager() class Animation: @classmethod def Exit_ScaleFadeRotate_0_0(cls, node, a, t, i, x, y): def void(): pass node.run_action( A.group(A.sequence( A.wait(t*2), A.call(void)), A.fade_to(a, t/100*75, i), A.scale_x_to(a, t/100*75, i), A.rotate_by(0.75, t/100*75, i), A.move_to(x, y, t/100*80, i)), 'inv-toggle') @classmethod def Enter_ScaleFadeRotate_0_0(cls, node, a, t, i, x, y): def void(): pass node.run_action( A.group(A.sequence( A.wait(t/100*120), A.call(void)), A.fade_to(a, t/100*75, i), A.scale_x_to(a, t/100*75, i), A.rotate_by(-0.75, t/100*75, i), A.move_to(x, y, t/100*80, i)), 'inv-toggle') class Assets: def __init__(self): self.cached=dict({}) self.CacheAssets() def __call__(self, name): return self.cached[name] def PrintCache(self): for (k, v) in self.cached.items(): print(f'{k}\n\t{v}\n{"*"*42}') def CacheAssets(self): return # bypassed to prevent any exceptions id=0 for r, d, f in os.walk(os.getcwd()+'/assets/'): for file in f: if file.endswith(".png"): id+=1 if '%' in file: name=file.split('%')[0] self.cached[name] = Texture(os.path.join(r, file)) else: self.cached[f'{id}'] = Texture(os.path.join(r, file)) ASSETS=Assets() #α°ααα α°α‘α±αααα‘α±α’α²αα0α±αααα±α±α‘α°ααα αα²α£α³α³ααααα³α³α£α²α²α’ααα²αα³αα£α΄α΄α΄5αα€α€αα€αα³α’α£αα€αΈααΈαα·ααΈα©# class Level: def __init__(self,cur_val=1, max_val=100, is_player=False, cur_xp=0, cur_sp=0, *args, **kwargs): self.curVal=cur_val self.maxVal=max_val self.isPlayer=is_player if self.isPlayer: self.xpTable=list([]) self.spTable=list([]) self._generate_tables() self.curXP=cur_xp self.xpGoalForLevel=self.xpTable[self.curVal-1] self.curSP=cur_sp self.hasSkillPoints=self.curSP > 0 def _generate_tables(self): for lvl in range(1, 101): if lvl%2==0 and lvl >= 8: self.spTable.append(int(1.7*(1+ 0.035)**(lvl/2))) else: self.spTable.append(0) if lvl < 20: self.xpTable.append(int(45*(1+0.2)**lvl)) elif lvl < 40: self.xpTable.append(int(45*(1+0.22)**lvl)) elif lvl < 60: self.xpTable.append(int(45*(1+0.24)**lvl)) elif lvl < 80: self.xpTable.append(int(45*(1+0.26)**lvl)) else: self.xpTable.append(int(45*(1+0.28)**lvl)) def UIPanel(parent, x=w, y=h, w=200, h=100, children=[]): tex=Texture('pzl:Button1')#ASSETS('panel') n=SpriteNode( tex, position=Point(x-w, y-h), size=Size(w, h), anchor_point=(0.0, 0.0), parent=parent) i=1 for child in children: n.add_child(child) child.position=Point(10, h-(child.size[1]*i)-10) i+=1 return n class Pool(Node): def __init__(self, pNode, value, *args, **kwargs): self.inCombat=False self.auto_fill_val=3 self.auto_fill_at_ticks=2 self.auto_fill_tick_cnt=0 self.pNode=None self.max_val=value self.cur_val=value self.pos_effects=list() self.neg_effects=list() self.isEmpty=False self.isMaxed=True pNode.add_child(self) def update(self, dt, gl): pass def reduce(self, val): cv=self.cur_val mv=self.max_val #dur=self.duration self.cur_val=(cv-val) if (cv-val) > 0 else 0 self.isEmpty=True if self.cur_val <= 0 else False def increase(self, val): cv=self.cur_val mv=self.max_val #dur=self.duration self.cur_val=(cv+val) if (cv+val) <= self.max_val else self.max_val self.isMaxed=True if self.cur_val >= mv else False class Skill: def __init__(self, *args, **keargs): self.id=id self.name=name self.icon=icon self.curVal=cur_val self.maxVal=max_val pass class Health(Pool): def __init__(self, pNode, value, *args, **kwargs): Pool.__init__(self, pNode, value, *args, **kwargs) Tick.Add(self) self.display=LabelNode(text=f'HP: {self.cur_val} / {self.max_val}', size=Size(150, 35), position=Point(10, 10), anchor_point=(0.0, 0.0)) self.display.color=(0.0, 0.0, 0.0, 1.0) def __call__(self): return self.display def update(self, dt, gl): if not self.inCombat: self.auto_fill_tick_cnt+=1 if self.auto_fill_tick_cnt == self.auto_fill_at_ticks: self.increase(self.auto_fill_val) self.auto_fill_tick_cnt=0 self.display.text=f'HP: {self.cur_val} / {self.max_val}' pass class Mana(Pool): def __init__(self, pNode, value, *args, **kwargs): Pool.__init__(self, pNode, value, *args, **kwargs) Tick.Add(self) self.display=LabelNode(text=f'MP: {self.cur_val} / {self.max_val}', size=Size(150, 35), position=Point(10, 10), anchor_point=(0.0, 0.0)) self.display.color=(0.0, 0.0, 0.0, 1.0) def __call__(self): return self.display def update(self, dt, gl): self.display.text=f'MP: {self.cur_val} / {self.max_val}' pass class Sprite(SpriteNode): def __init__( self,texture, tag, parent, hidden=False, anchor_point=(0.0, 0.0), *args, **kwargs): self.tag=tag self.anchor_point=anchor_point self._hidden=hidden self.alpha=1.0 if self._hidden else 0.0 self.parentNode=parent super().__init__(texture=texture, parent=parent, *args, **kwargs) @property def hidden(self): return self._hidden @hidden.setter def hidden(self, value): self._hidden=value self.alpha=0.0 if self._hidden else 1.0 class UIButton(SpriteNode): def __init__( self, tag='UIButton', bgTexture=None, color=white(), border='border-thick', borderColor=gray(), accessoryColor=green(), icon=None, accessory='astrisk', anchor_point=(0.0, 0.0), font=FONT[0], fontSize=FONT[1], parent=None, x=0, y=0, w=64, h=64, action=None, text='', enabled=True, *args, **kwargs): self.tag=tag self.enabled=enabled self.text=text self.font=font self.texture= Texture(bgTexture)#ASSETS(bgTexture) self.border=border self.borderColor=borderColor self.icon=icon self.accessory=accessory self.showAccesory=False self.accessoryColor=accessoryColor self.components=dict({}) self.fontSize=fontSize self.parentNode=parent self.x, self.y, self.w, self.h=x, y, w, h self.rect=Rect(x, y, w, h) self.position=Point(x, y) self.size=Size(w, h) self.action=action self.anchor_point=anchor_point super().__init__(texture=self.texture, parent=parent, *args, **kwargs) self._Setup(self.border, self.icon, self.accessory, self.components) EM.AddListener(self, self.action) def _Setup(self, b, i, a, c): if b != None: c['border']=Sprite( texture=Texture('spc:PowerupBlue'),#ASSETS(b), tag=f'{self.tag}):border', size=self.size, parent=self, z_position=5, color=self.borderColor) if a != None: c['accessory']=Sprite( texture=Texture('spc:Star1'),#None,#ASSETS(a), tag=f'{self.tag}):accessory', size=self.size/100*10, position=Point(self.w/100*10, self.h/100*80), parent=self, z_position=4, color=self.accessoryColor, hidden=True) c['accessory'].hidden=False if i != None: c['icon']=Sprite( texture=Texture('plc:Gem_Green'),#ASSETS(i), tag=f'{self.tag}):icon', size=self.size, parent=self, z_position=3) if self.text: c['label']=LabelNode( text=self.text, font=FONT, anchor_point=(0.5, 0.5), color=light_blue(), position=Point(self.w/2, self.h/2-10), parent=self, z_position=10) def ButtonAction(self): if self.enabled: self.alpha=0.25 self.action() self.enabled=False else: return False #β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«β«# class Quality: COMMON=gray() UNCOMMON=light_blue() RARE=blue() EPIC=purple() COLLECTION=sandy() ELDER=orange() QUEST=yellow() class ItemType: JUNK=0 CONSUMABLE=1 MATERIAL=2 EQUIPMENT=3 AMMUNITION=4 COLLECTABLE=5 class Effect: def __init__(self, id='', name='', effected_attribute=None, duration=0, value=1): self.id=id self.name=name self.effected_attribute=effected_attribute self.duration=duration self.value=value def End(self): del self def Start(self): pass class Item: def __init__(self, name='', quality=Quality.COMMON, id=None, weight=1.0, itemType=ItemType.JUNK, icon=None, isStackable=False, isTradable=False, currentDurability=None, maxDurability=None, isBroken=False, isRepairable=False, maxStack=64, currentStack=64, value=1, usesLeft=1, effect=None, isEffectBearing=False, effectDuration=3.0, repairCost=None, *args, **kwargs): self.id=id self.name=name self.icon=icon self.weight=weight self.valve=value self.repairCost=repairCost self.quality=quality self.itemType=itemType self.maxDur=maxDurability self.maxStack=maxStack self.curStack=currentStack self.curDur=currentDurability self.isStackable=isStackable self.isTradable=isTradable self.isBroken=isBroken self.isRepairable=isRepairable self.isEffectBearing=isEffectBearing self.usesLeft=usesLeft self.effect=effect self.effectDuration=effectDuration def Remove(self): del self def Verbose(self): for k, v in self.__dict__.items(): print(k, v) def Used(self): if self.usesLeft > 1: self.used -=1 if self.usesLeft<= 1: print(f'{self.name} depletee..') self.Remove() def UseEffect(self): if self.isEffectBearing: if self.usesLeft <= 0: print(f'Remaining Effect Uses At or Below 0 Prior To Use.\n', f'Item removed...') self.Remove() elif self.usesLeft - 1 == 0: self.effect.Start() self.Remove() else: self.usesLeft-=1 self.effect.Start() print(f'Item {self.id} has no effect.', f'Item.isEffectBearing::{self.isEffectBearing}') class Slot(SpriteNode): def __init__(self, item=None, x=0, y=0, w=32, h=32, *args, **kwargs): self.tag='Slot' self.item=item self.hasItem=self.item != None self.child_nodes=[] self.durBarHeight=78.4 self.showStack=False self.displayDurability=False self.w=w self.h=h self.x=x self.y=y if self.hasItem: self.icon=None self.border=None self.stack=None self.dur_bg=None self.dur_val=None self.Setup() self.Refresh() super().__init__(texture=self.texture, size=self.size, *args, **kwargs) def SetupChildren(self, data): ir=data.quality ii=data.icon stacking=data.isStackable self.icon=Sprite( Texture('plf:SwordSilver'),#ASSETS(ii), 'icon', anchor_point=(0.0, 0.0), parent=self, size=self.size, z_position=2) if self.icon not in self.child_nodes: self.child_nodes.append(self.icon) self.border=Sprite( Texture('plf:Tile_BoxCrate'),#ASSETS(f'border'), 'Quality border', color=ir, anchor_point=(0.0, 0.0), parent=self, size=self.size, z_position=0, alpha = 1.0) if self.border not in self.child_nodes: self.child_nodes.append(self.border) self.bg=Sprite( Texture('plf:Tile_BoxCoin'),#ASSETS(f'bg'),'background', anchor_point=(0.0, 0.0), parent=self, size=self.size, z_position=1, alpha = 1.0, color=dark_gray()) if self.bg not in self.child_nodes: self.child_nodes.append(self.bg) if stacking: self.stack=LabelNode( f'{data.curStack}', font=('Marker Felt', 18), color=white(), anchor_point=(0.0, 0.0), parent=self, z_position=3, position=Point(5, self.size[1]-24)) self.child_nodes.append(self.stack) if data.itemType == ItemType.EQUIPMENT: if(self.item.curDur > self.item.maxDur): self.item.curDur=self.item.maxDur bh=self.size.h-24 perc=100*self.item.curDur/self.item.maxDur self.dur_val=Sprite( None, 'dur green', anchor_point=(0.0, 0.0), position=Point(self.size.w-26.5, 12), parent=self, size=Size(15, bh/100*perc), z_position=2, color=green()) ColorPhase(self.item.curDur, self.item.maxDur, self.dur_val, 0) self.child_nodes.append(self.dur_val) def Setup(self): if self.item is None: self.texture=Texture('plf:Tile_BoxItem')#ASSETS('comon-slot') return item=self.item if item.isStackable: self.showStack=True if item.itemType==ItemType.EQUIPMENT: self.displayDurability=True self.SetupChildren(self.item) self.Refresh() def Break(self): self.border.texture=Texture('plf:Tile_LockRed')#ASSETS('red-slot') self.border.size=Size(self.w, self.h) self.border.z_position=11 self.item.isBroken=True self.border.run_action(a.repeat(a.sequence(a.fade_to(0.0, 1.0), a.fade_to(1.0, 0.75)), -1), 'a:broken-strobe') self.dur_val.color=purple() self.remove_all_actions() self.dur_val.run_action(a.scale_y_to(1, 0.01, TIMING_EASE_OUT), 'a:degrade') def RepairEquipment(self, tool): if self.item.isBroken: #TODO Make Message possinly needs npc repair return self.item.curDur+=tool.value tool.used() def DamageEquipment(self, val): if self.item.isBroken: #TODO Make Message return if (self.item.curDur - val > 0): self.item.curDur=self.item.curDur-val perc= 100*self.item.curDur/self.item.maxDur newScale=(perc*self.dur_val.y_scale)/100 self.dur_val.run_action(a.scale_y_to(newScale, 1.0, TIMING_EASE_OUT), 'a:degrade') ColorPhase(self.item.curDur, self.item.maxDur, self.dur_val, 0) else: self.item.curDur=0 self.Break() def Refresh(self): if self.hasItem: if self.showStack and self: self.stack.text=str(self.item.curStack) if self.displayDurability: cd=self.item.curDur md=self.item.maxDur class Inventory(SpriteNode): def __init__(self, isPlayer=False, parent=None, *args, **kwargs): self.tag='Inventory' self.coin=0 self.hasNewItem=False self.slotX=4 self.slotY=5 self.margin=12 self.headSpace=70 self.slotbuffer=0 self.isPlayer=isPlayer self.anchor_point=(0.0, 0.0) self.slots=list([]) self.texture=Texture('card:BackGreen1')#ASSETS('menu-bg') self.scale=SCALE self.size=Size(w/100*60, h/100*55) self.weight=0.0 self.max_weight=50.0 self.overEncumbered=self.weight>=self.max_weight self.position=Point(w/2-self.size[0]/2, h/2-self.size[1]/2) self.bags=list() self.weightDisplay=LabelNode( f'β {self.weight}β±{self.max_weight}α', font=(FONT[0], 15),parent=self, position=Point(self.size[0]/100*20, self.size[1]/1000*923), color=green()) self.coinDisplay=LabelNode( f'β² {self.coin}', font=(FONT[0], 20),parent=self, position=Point(self.size[0]/100*55, self.size[1]/1000*925), color=toon_yellow()) self.closeButton=Sprite(Texture('plf:HudX'),#ASSETS('close-icon'), 'UIButton', parent=self, size=Size(30, 30), position=Point(self.size.w-20, self.size.h-19), anchor_point=(1.0, 1.0), color=dark_red()) self.viewing=True self.alpha=0.0 self.Toggle() if isPlayer: Tick.Add(self) super().__init__( texture=self.texture, parent=parent, *args, **kwargs) self.Reload() EM.AddListener(self.closeButton, self.Toggle) def touch_began(self, touch): pass def touch_moved(self, touch): pass def touch_ended(self, touch): pass def __call__(self): print(len(self.slots)) def Reload(self): iw, ih=self.size # sx=iw/self.slotX # sy=ih/self.slotY sx=(iw-self.margin*2-42)/self.slotX sy=(ih-self.margin-self.headSpace)/self.slotY for y in range(self.slotY): for x in range(self.slotX): s=Slot(parent=self, x=x, y=y, anchor_point=(0.0, 0.0)) sw=iw/1000*72+(sx)*x sh=ih/1000*758+(sy)*-y s.size=Size(sx, sy) s.w, s.h, = sx, sy s.position=Point(sw, sh-10) self.slots.append(s) ColorPhase(self.weight, self.max_weight, self.weightDisplay, 1) def GainWeight(self, iw): cw=self.weight mw=self.max_weight if cw+iw <= mw: self.weight+=round(iw) else: self.weight=mw self.overEncumbered=True self.weightDisplay.text=f'{self.weight}β±{self.max_weight}α' ColorPhase(self.weight, self.max_weight, self.weightDisplay, 1) def Add(self, item): free_slot=None self.VerifySlotState() if (self.overEncumbered and item.weight > 0): #TODO Add Messag return False if (item.weight+self.weight > self.max_weight): #TODO Add Messge return False for s in self.slots: if (s.hasItem == False): # or s == None or s.item == None): if (free_slot == None): free_slot=s continue if (item.isStackable): if (s.item.id != item.id and s.item is not None): pass if (s.item.id == item.id): print(s.item.name) if free_slot: free_slot.item=item free_slot.alpha=1.0 free_slot.hasItem=True free_slot.Setup() print('added item') return True def VerifySlotState(self): for s in self.slots: if s.item is None: s.alpha=0.25 else: s.alpha=1.0 def Toggle(self, sender=None): self.viewing = not self.viewing t=1 i=TIMING_EASE_BACK_IN_OUT a = 1.0 if self.viewing else 0.0 x = w/2-self.size[0]/2 if self.viewing else 0.0 y = h/2-self.size[1]/2 if self.viewing else 0.0 if(self.viewing): if(sender != None): if(not sender.components['accessory'].hidden): sender.components['accessory'].hidden = True Animation.Exit_ScaleFadeRotate_0_0(self, a, t, i, x, y) else: Animation.Enter_ScaleFadeRotate_0_0(self, a, t, i, x, y) ColorPhase(self.weight, self.max_weight, self.weightDisplay, 1) def RemoveItem(self, item): pass def update(self, dt, gl): if not self.viewing: pass if (self.weight >= self.max_weight) and (not self.overEncumbered): #TODO Add Messge6 self.overEncumbered=True ColorPhase(self.weight, self.max_weight, self.weightDisplay, 1) ''' name='', quality=Quality.COMMON, id=None, weight=1.0, itemType=ItemType.JUNK, icon=None, isStackable=False, isTradable=True, currentDurability=None, maxDurability=None, isBroken=False, isRepairable=True, maxStack=64, currentStack=8, value=1, usesLeft=1, effect=None, isEffectBearing=True, effectDuration=3.0, repairCost=None, ''' def TrainingShortSword(): return Item( id=0, name='Training Short Sword', currentDurability=63, maxDurability=72, value=3, quality=Quality.COMMON, itemType=ItemType.EQUIPMENT, weight=4.3, icon='plf:SwordBronze')#'training-short-sword' ) def OakLog(n=1): return Item( id=1, name='Oak Logs', isStackable=True, currentStack=n, maxStack=16, value=2, quality=Quality.COMMON, itemType=ItemType.MATERIAL, weight=1.0, icon='spc:MeteorBrownBig3')#'oak-logs' ) def GrantItem(sender, item=OakLog()): sender.parent.inv.Add(item) ''' UIButton(SpriteNode) self, tag='UIButton', bgTexture=None,color=white(), border='border-thick', borderColor=gray(), accessoryColor=green(), icon=None, accessory='astrisk', font=FONT[0], fontSize=FONT[1], parent=None, x=0, y=0, w=64, h=64, action=None, text='', *args, **kwargs ''' class UserInterface: def __init__(self, s): self.nodes=list([]) self.inventoryButton=UIButton( bgTexture='plf:ShieldGold',#'tan-bg', borderColor=orange(), icon='inv-button', parent=s, x=s.size[0]-128-10, y=s.size[1]/2-64, w=128, h=128, action=s.inv.Toggle) self.ItemButton=UIButton(text='Add Item', bgTexture='plf:Tile_DoorOpen_mid',#'std-button', borderColor=blue(), parent=s, x=s.size[0]/2-50, y=s.size[1]-45, w=100, h=40, action=GrantItem) class UIMenu(Sprite): def __init__(slf, *args, **kwargs): self.bg=Texture('plf:Tile_BrickGrey')#ASSETS('menu-bg') super().__init__(*args, **kwargs) class GameLoop (Scene): def __init__(self, *args, **kwargs): self.awake() super().__init__(*args, **kwargs) def awake(self): pass def setup(self): self.background_color=(0.82, 0.93, 1.0) self.i=0.0 self.inv=Inventory(isPlayer=True, parent=self) self.inv.Add(TrainingShortSword()) self.inv.Add(OakLog()) #EM.AddListener(self.inv.closeButton, self.inv.Toggle) self.gui=UserInterface(self) self.hp=Health(pNode=self, value=100) self.mp=Mana(self, 150) self.panel=UIPanel(self, children=[Tick.label, self.hp(), self.mp()]) self.scale=SCALE # movement self.isWalking=False def Test(self): print('main') def did_change_size(self): pass def walk(self): pass def update(self): self.i+=self.dt if self.i > .50: Tick._update(self) self.i=0.0 def touch_began(self, touch): EM.touch_began(touch) self.inv.touch_began(touch) #self.inv.Add(self.ti1) #self.inv.slots[0].DamageEquipment(17) def touch_moved(self, touch): EM.touch_moved(touch) def touch_ended(self, touch): EM.touch_ended(touch) self.inv.touch_ended(touch) pass if __name__ == '__main__': run(GameLoop(), show_fps=True)
-
One approach would be that in your button action, set the button enabled=False. After your action is complete, set enabled=True. If you are using Actions, you can use an Action.Sequence with an Action.call at the end. To avoid having the keep track of which buttonala need to be reenabled, just use a local def completion that gets sent to the action.
def action(sender): sender.enabled=False def completion(): sender.enabled=True # then create your action, with the above completion as the final Action.call
-
Thanks @JonB ill give this a try right now. do you think, in this case, i should hande all this in
Toggle
of Inventory or keep the Animation Class and do it there? -
@JonB This worked wonderfully ππ€ after adding the local functions and Action calls i just just needed to check if
UIButton
was enabled inside my EventManager otherwise for some reson it would bypass the dissabled block if i did aif node.enabled:
check anywhere else. which i think is odd but i guess the EventManager is the best place for it anyway..Thanks Again!
note: posted code will stay up for anyone needed it for themselves. normally if i get a solution after posting such a large script i would remove old posts that were irrelevant so save scrollinh
@stephen said:
class EventManager: β― def touch_began(self, touch): for l in self.listeners: p=l.node.parent.point_from_scene(touch.location) if(p in l.node.frame): if(l.node.enabled): l.reaction(l.node) #In Animation class GAnimation: def __init__(self): pass def Enter_ScaleFadeRotate_0_0(self, node, a, t, i, x, y): def Started(): node.button.enabled=False node.button.alpha=0.25 def Completed(): node.button.enabled=True node.button.alpha=1.0 node.run_action(A.sequence( A.call(Started), A.group( A.fade_to(a, t/100*75, i), A.scale_x_to(a, t/100*75, i), A.rotate_by(-0.75, t/100*75, i), A.move_to(x, y, t/100*80, i)), A.call(Completed))) def Exit_ScaleFadeRotate_0_0(self, node, a, t, i, x, y): def Started(): node.button.enabled=False node.button.alpha=0.25 def Completed(): node.button.enabled=True node.button.alpha=1.0 node.run_action(A.sequence( A.call(Started), A.group( A.fade_to(a, t/100*75, i), A.scale_x_to(a, t/100*75, i), A.rotate_by(0.75, t/100*75, i), A.move_to(x, y, t/100*80, i)), A.call(Completed)))