Skip to content

Commit

Permalink
Update menu builder
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDemon99 committed Aug 17, 2023
1 parent d1ac31c commit 7e2dc44
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions EasyMenuBuilder/EasyMenuBuilder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dynamic_properties = ["exp_text", "exp_material", "visible_when", "exp_rect_x", "exp_rect_y", "exp_rect_h", "exp_rect_w", "exp_forecolor_r", "exp_forecolor_g", "exp_forecolor_b", "exp_forecolor_a"]
item_actions = ["onOpen", "onClose", "onEsc", "onFocus", "mouseEnter", "mouseExit", "action"]
dynamic_properties = ["exp_text", "exp_material", "visible_when", "disabled_when", "exp_rect_x", "exp_rect_y", "exp_rect_h", "exp_rect_w", "exp_forecolor_r", "exp_forecolor_g", "exp_forecolor_b", "exp_forecolor_a"]
item_actions = ["execKeyInt", "onOpen", "onClose", "onEsc", "onFocus", "mouseEnter", "mouseExit", "action"]
item_properties = ["name", "rect", "decoration", "autowrapped", "visible", "ownerdraw", "style", "type", "forecolor", "blurWorld", "border", "bordercolor", "background", "textfont", "textalign", "textscale", "textstyle", "text"] + dynamic_properties + item_actions


Expand Down Expand Up @@ -34,6 +34,7 @@ def __init__(self, item='itemDef', name=None, rect=(0, 0, 640, 480, 0, 0), decor
self.mouseExit = SimpleItem('mouseExit', 1)
self.action = SimpleItem('action', 1)
self._itemDefs = []
self._execKeys = []

def blink(self, condition):
self.exp_forecolor_a = f'1 - ( ( {condition} ) * ( ( sin( localclientuimilliseconds( ) / 90 ) ) * 0.65 ) )'
Expand All @@ -43,6 +44,11 @@ def dynamicForecolor(self, index):
self.exp_forecolor_g = f'select(dvarInt("optionType{index}") < 4, 0, select(dvarInt("optionType{index}") < 6, 1, 0.4))'
self.exp_forecolor_b = f'select(dvarInt("optionType{index}") == 4 || dvarInt("optionType{index}") == 5, 1, 0)'

def addExecKeyInt(self, value):
item = SimpleItem(f'execKeyInt {value}', 1)
self._execKeys.append(item)
return item

def add(self, ItemDef):
self._itemDefs.append(ItemDef)

Expand All @@ -54,6 +60,11 @@ def __str__(self):

for name in item_properties:
value = getattr(self, name)

if name == 'execKeyInt':
for i in self._execKeys:
[data.append(' ' + j) for j in str(i).split('\n')]
continue

if value is None:
continue
Expand Down Expand Up @@ -129,16 +140,17 @@ def addDynamicOption(self, rect, index, offset, start_index=0, decoration=0):
_rect[1] = (offset * (index - start_index)) + _rect[1]

if not decoration:
option, onClick = self.addOption(_rect, index, localVarString(f'menu_option{index}'), 1, decoration)
option, onClick = self.addOption(_rect, index, dvarString(f'menu_option{index}'), 1, decoration)
else:
option = self.addOption(_rect, index, localVarString(f'menu_option{index}'), 1, decoration)
option = self.addOption(_rect, index, dvarString(f'menu_option{index}'), 1, decoration)

option.textalign = 10
option.dynamicForecolor(index)
option.visible_when = f'localVarString("menu_option{index}") != "@" && localVarString("menu_option{index}") != "@-" && dvarInt("menu_options_range") > {index}'
option.visible_when = f'dvarstring("menu_option{index}") != "@" && dvarstring("menu_option{index}") != "@-" && dvarInt("menu_options_range") > {index}'

if not decoration:
onClick.visible_when = option.visible_when
onClick.action = SimpleItem('action', 1)
onClick.action.If(option.visible_when + f' && dvarInt("optionType{index}") != 0 && dvarInt("optionType{index}") != 1', scriptmenuresponse(localVarInt('ui_index')), play('mouse_click'), setLocalVarInt('ui_index', index))
return option, onClick
return option

Expand All @@ -158,14 +170,10 @@ def addOption(self, rect, index, text, exp=0, decoration=0):
option.visible_when = f'{text} != ""'

if not decoration:
option.mouseEnter.set = (setLocalVarInt('ui_index', index), play('mouse_click'))
option.mouseExit.set = (setLocalVarInt('ui_index', -1), play('mouse_click'))

onClick = self.addItem(rect=rect, decoration=0, forecolor=None, style=None)
onClick.type = 1
onClick.action.set = (scriptmenuresponse(localVarInt('ui_index')), play('mouse_click'), setLocalVarInt('ui_index', index))
onClick.visible_when = option.visible_when

onClick = self.addItem(rect=rect, decoration=0, forecolor=None, style=None, type=1)
onClick.action.If(option.visible_when, scriptmenuresponse(localVarInt('ui_index')), play('mouse_click'), setLocalVarInt('ui_index', index))
onClick.mouseEnter.set = setLocalVarInt('ui_index', index), play('mouse_click')
onClick.mouseExit.set = setLocalVarInt('ui_index', -1), play('mouse_click')
return option, onClick

return option
Expand Down Expand Up @@ -283,4 +291,10 @@ def scriptmenuresponse(val):
return f'scriptmenuresponse {val};'

def setfocus(val):
return f'setfocus "{val}";'
return f'setfocus "{val}";'

def close(val):
return f'close {val};'

def simulateKeyPress(key):
return f'uiScript simulateKeyPress {key};'

0 comments on commit 7e2dc44

Please sign in to comment.