Add fancy water gauge

This commit is contained in:
Jake Funke 2017-03-24 23:27:25 +00:00
parent 4ae7246747
commit 95e583a99d
1 changed files with 17 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import curses
import math
import os
import traceback
import threading
@ -172,19 +173,26 @@ class CursedMenu(object):
self.screen.addstr(12, 9, self.plant_ticks, curses.A_NORMAL)
if not self.plant.dead:
if int(time.time()) <= self.plant.watered_timestamp + 24*3600:
self.screen.addstr(5,13, clear_bar, curses.A_NORMAL)
self.screen.addstr(5,13, " - plant watered today :)", curses.A_NORMAL)
else:
self.screen.addstr(5,13, clear_bar, curses.A_NORMAL)
water_gauge_str = self.water_gauge()
self.screen.addstr(5,14, water_gauge_str, curses.A_NORMAL)
else:
self.screen.addstr(5,13, clear_bar, curses.A_NORMAL)
self.screen.addstr(5,13, " - you can't water a dead plant :(", curses.A_NORMAL)
self.screen.addstr(5,13, " ( RIP )", curses.A_NORMAL)
# This draws cute ascii from files
# draw cute ascii from files
self.draw_plant_ascii(self.plant)
# self.ascii_render("sun.txt",-2,self.maxx-14)
def water_gauge(self):
# build nice looking water gauge
water_left_pct = 1 - ((time.time() - self.plant.watered_timestamp)/86400)
# don't allow negative value
water_left_pct = max(0, water_left_pct)
water_left = int(math.ceil(water_left_pct * 10))
water_string = "(" + (")" * water_left) + ("." * (10 - water_left)) + ") " + str(int(water_left_pct * 100)) + "%"
return water_string
def update_plant_live(self):
# updates plant data on menu screen, live!
while not self.exit:
@ -231,7 +239,7 @@ class CursedMenu(object):
if user_in in up_keys: # up arrow
self.selected -=1
# modulo to wrap around
# modulo to wrap menu cursor
self.selected = self.selected % len(self.options)
return
@ -281,9 +289,6 @@ class CursedMenu(object):
# Clear page before drawing next
self.clear_info_pane()
self.infotoggle = 0
self.screen.refresh()
else:
self.screen.refresh()
def get_plant_description(self, this_plant):
output_text = ""
@ -308,7 +313,7 @@ class CursedMenu(object):
"The seedling shakes in the wind.",
"You can make out a tiny leaf - or is that a thorn?",
"You can feel the seedling looking back at you.",
"You kiss your seedling good night.",
"You blow a kiss to your seedling.",
"You think about all the seedlings who came before it.",
"You and your seedling make a great team.",
"Your seedling grows slowly and quietly.",