Skip to content

Commit

Permalink
feat(ui): improve unit assignment UX
Browse files Browse the repository at this point in the history
* if client slots are below amount, amount slots will be incremented
* if amount is below client, client slots will be decremented

#38
  • Loading branch information
Wrycu committed Mar 29, 2020
1 parent f69f200 commit ad25d96
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions ui/eventmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ def action():
def descramble_one(self, task: typing.Type[UnitType], unit_type: UnitType) -> typing.Callable:
def action():
entry = self.scramble_entries[task][unit_type][0] # type: Entry
value = entry.get()
client_slots = int(self.scramble_entries[task][unit_type][1].get())
value = int(entry.get()) - 1

entry.delete(0, len(value))
entry.insert(0, str(max(int(value) - 1, 0)))
if client_slots > value:
self.client_minus_one(task, unit_type)()

entry.delete(0, END)
entry.insert(0, str(max(value, 0)))

return action

Expand All @@ -169,10 +173,14 @@ def add_ca_slot(self):
def client_plus_one(self, task: typing.Type[Task], unit_type: UnitType) -> typing.Callable:
def action():
entry = self.scramble_entries[task][unit_type][1] # type: Entry
value = entry.get()
amount = int(value and value or "0")
entry.delete(0, END)
entry.insert(0, str(amount+1))
current_slots = int(self.scramble_entries[task][unit_type][0].get())
max_slots = self.base.total_units_of_type(unit_type)
value = int(entry.get()) + 1
if value <= max_slots:
if value > current_slots:
self.scramble_one(task, unit_type)()
entry.delete(0, END)
entry.insert(0, str(value))
return action

def client_minus_one(self, task: typing.Type[UnitType], unit_type: UnitType) -> typing.Callable:
Expand Down

0 comments on commit ad25d96

Please sign in to comment.