~vbkaisetsu/+junk/renpy-vertical-text

« back to all changes in this revision

Viewing changes to extras/dse/stats.rpy

  • Committer: tom
  • Date: 2006-10-01 14:09:56 UTC
  • Revision ID: svn-v3-trunk1:a20cb6e2-ff0c-0410-a951-e6c088e16c52:renpy%2Ftrunk:148

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
init -100:
2
 
    python:
3
 
 
4
 
        # This class encapsulates a statistic in DSE. Instances of
5
 
        # this class have two properties, .value and .maxvalue. The
6
 
        # .value property is clamped to ensure that it is always in
7
 
        # the range 0 - .maxvalue, inclusive.
8
 
        #
9
 
        # 
10
 
        class Stat(object):
11
 
            
12
 
            #name: string intended to describe the stat in game (e.g. "Intelligence")
13
 
            #startvalue: value the stat starts out with
14
 
            #maxvalue: highest value this stat can reach
15
 
            def __init__(self, name, startvalue, maxvalue):
16
 
                
17
 
                self.name=name
18
 
                self.__value=startvalue
19
 
                self.__maxvalue=maxvalue
20
 
 
21
 
            def __int__(self):
22
 
                return self.__value
23
 
            
24
 
            def __str__(self):
25
 
                return str(self.__value)
26
 
            
27
 
            #sets value and ensures it is within boundaries
28
 
            #0-maxvalue, inclusive.
29
 
            def set(self, new_value):
30
 
                self.__value = new_value
31
 
                self.__value = min(self.__value, self.__maxvalue)
32
 
                self.__value = max(self.__value, 0)
33
 
                
34
 
            #sets maxvalue and ensures value is within the new boundaries
35
 
            def set_max(self, new_value):
36
 
                self.__maxvalue = new_value
37
 
                self.set(self.__value)
38
 
 
39
 
            # Set up properties so the user can directly access value
40
 
            # and maxvalue, and set or set_max is called when they are
41
 
            # updated.
42
 
 
43
 
            value = property(fget = lambda self : self.__value,
44
 
                             fset = set)
45
 
 
46
 
            maxvalue = property(fget = lambda self : self.__maxvalue,
47
 
                                fset = set_max)
48
 
            
49
 
            #allow comparisons to integer
50
 
            def __cmp__(self, other):
51
 
                #correctly raises exception if we try to compare to anything not castable to integer
52
 
                cmp_to = int(other)
53
 
                return cmp(self.__value, cmp_to)
54
 
 
55
 
            # Renders this Stat into the stats window.
56
 
            def render(self):
57
 
                ui.hbox()
58
 
                ui.text(self.name, minwidth=150)
59
 
                ui.bar(600, 20, self.__maxvalue, self.__value, ypos=0.5, yanchor='center')
60
 
                ui.close()
61
 
 
62
 
label stats_show:
63
 
 
64
 
    python hide:
65
 
 
66
 
        # This is the window that the stats are kept in, if any.
67
 
        ui.window(xpos=0,
68
 
                  ypos=0,
69
 
                  xanchor='left',
70
 
                  yanchor='top',
71
 
                  xfill=True,
72
 
                  yminimum=0)
73
 
 
74
 
        ui.vbox()
75
 
 
76
 
        ui.text('Statistics')
77
 
        ui.null(height=10)
78
 
 
79
 
        for i in shown_stats:
80
 
            i.render()
81
 
            
82
 
        ui.close()
83
 
 
84
 
    return