Class: DSA::LE_Displayer
- Inherits:
-
Gtk::HBox
- Object
- Gtk::HBox
- DSA::LE_Displayer
- Defined in:
- lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb
Constant Summary collapse
- BASE_BG_COLOUR =
#
BASE_BG_COLOUR
#
'darkgreen'
- BASE_FG_COLOUR =
#
BASE_FG_COLOUR
#
'red'
- N_TIMES =
#
N_TIMES
#
11
Instance Attribute Summary collapse
-
#array_for_buttons ⇒ Object
LE_Displayer.array_for_buttons.change_colour.
-
#max_hitpoints ⇒ Object
Returns the value of attribute max_hitpoints.
-
#orientation ⇒ Object
this var you can set.
Instance Method Summary collapse
-
#add_hitpoints(i) ⇒ Object
# === add_hitpoints ========================================================================= #.
-
#change_colours? ⇒ Boolean
# === change_colours?.
-
#colourize(how_many) ⇒ Object
# === colourize ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton ========================================================================= #.
-
#hitpoints? ⇒ Boolean
(also: #hitpoints, #hp?)
# === hitpoints? ========================================================================= #.
-
#initialize(start_hitpoints = 30, base_fg_colour = BASE_FG_COLOUR, button_bg_colour = BASE_BG_COLOUR) ⇒ LE_Displayer
constructor
# === initialize.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#set_hitpoints(n_hp) ⇒ Object
# === set_hitpoints.
-
#sub_hitpoints(i) ⇒ Object
# === sub_hitpoints ========================================================================= #.
Constructor Details
#initialize(start_hitpoints = 30, base_fg_colour = BASE_FG_COLOUR, button_bg_colour = BASE_BG_COLOUR) ⇒ LE_Displayer
#
initialize
Start hitpoints is for 30.
#
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 43 def initialize( start_hitpoints = 30, base_fg_colour = BASE_FG_COLOUR, = BASE_BG_COLOUR ) super() @base_fg_colour = base_fg_colour # either your own, or the BASE_COLOUR constant @bg_color_for_button = @base_bg_colour = @bg_color_for_button reset @max_hitpoints = start_hitpoints.to_i # keeps count of MAX hitpoints @hitpoints = start_hitpoints.to_i # keeps count of current hitpoints connect_skeleton end |
Instance Attribute Details
#array_for_buttons ⇒ Object
LE_Displayer.array_for_buttons.change_colour
29 30 31 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 29 def @array_for_buttons end |
#max_hitpoints ⇒ Object
Returns the value of attribute max_hitpoints.
31 32 33 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 31 def max_hitpoints @max_hitpoints end |
#orientation ⇒ Object
this var you can set
30 31 32 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 30 def orientation @orientation end |
Instance Method Details
#add_hitpoints(i) ⇒ Object
#
add_hitpoints
#
72 73 74 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 72 def add_hitpoints(i) @hitpoints += i.to_i end |
#change_colours? ⇒ Boolean
#
change_colours?
This method will change the colours indirectly, by invoking the colourize() method. Its preferred to use this method instead of the more raw-one below.
#
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 112 def change_colours? result = ((@hitpoints * 100.to_f) / @max_hitpoints).to_i cme("DAS RESULT WAR #{result.to_s}") case result when 100 then colourize(0) when 90..99 then colourize(1) when 80..89 then colourize(2) when 70..79 then colourize(3) when 60..69 then colourize(4) when 50..59 then colourize(5) when 40..49 then colourize(6) when 30..39 then colourize(7) when 20..29 then colourize(8) when 10..19 then colourize(9) when 1..9 then colourize(10) when 0 then colourize(11) end end |
#colourize(how_many) ⇒ Object
#
colourize
#
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 134 def colourize(how_many) if how_many > N_TIMES e 'Careful, param was too high. Was set back to '+N_TIMES.to_s how_many = N_TIMES end # 1) Change the colour of each box to the default background # colour. how_many.times { |counter| # Now invoke change_colour. See below. @array_for_buttons.reverse[counter].change_colour(@base_fg_colour) } # 2) Now, change the last parts to the base colour. (N_TIMES - how_many).times { |counter| @array_for_buttons[counter].change_colour(@base_bg_colour) } end |
#connect_skeleton ⇒ Object
#
connect_skeleton
#
154 155 156 157 158 159 160 161 162 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 154 def connect_skeleton N_TIMES.times { # Add the LE_Buttons. = LE_Button.new(@bg_color_for_button) @array_for_buttons << self.pack_start(,true,true,0) } self.set_size_request(3,10) # hard set end |
#hitpoints? ⇒ Boolean Also known as: hitpoints, hp?
#
hitpoints?
#
167 168 169 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 167 def hitpoints? @hitpoints end |
#reset ⇒ Object
#
reset
#
61 62 63 64 65 66 67 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 61 def reset # ======================================================================= # # === @array_for_buttons # ======================================================================= # @array_for_buttons = [] # here we store our buttons @orientation = :left_to_right end |
#set_hitpoints(n_hp) ⇒ Object
#
set_hitpoints
Hard way method. :)
If you pass 'half' as argument, we set it to half max hitpoints.
If you pass 'rand' as argument, we set a random value of your hitpoints.
#
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 94 def set_hitpoints(n_hp) if n_hp == 'rand' n_hp = rand(@max_hitpoints.to_f)+1 end n_hp = n_hp.to_s if n_hp == 'half' n_hp = (@max_hitpoints.to_f / 2.0).to_i end @hitpoints = n_hp.to_i end |
#sub_hitpoints(i) ⇒ Object
#
sub_hitpoints
#
79 80 81 82 83 |
# File 'lib/games_and_rpg_paradise/gui/gtk2/dsa/lebenspunkte_displayer.rb', line 79 def sub_hitpoints(i) unless (@hitpoints - i.to_i < 0) @hitpoints -= i.to_i end end |