Class: Scene_Shop

Inherits:
Scene_MenuBase show all
Defined in:
Scene_Shop.rb

Overview

** Scene_Shop


This class performs shop screen processing.

Instance Method Summary (collapse)

Methods inherited from Scene_MenuBase

#create_background, #create_help_window, #dispose_background, #next_actor, #on_actor_change, #prev_actor, #terminate

Methods inherited from Scene_Base

#check_gameover, #create_main_viewport, #dispose_all_windows, #dispose_main_viewport, #fadeout_all, #main, #perform_transition, #post_start, #pre_terminate, #return_scene, #scene_changing?, #terminate, #transition_speed, #update, #update_all_windows, #update_basic

Instance Method Details

- (Object) activate_buy_window


  • Activate Purchase Window




126
127
128
129
130
# File 'Scene_Shop.rb', line 126

def activate_buy_window
  @buy_window.money = money
  @buy_window.show.activate
  @status_window.show
end

- (Object) activate_sell_window


  • Activate Sell Window




134
135
136
137
138
139
# File 'Scene_Shop.rb', line 134

def activate_sell_window
  @category_window.show
  @sell_window.refresh
  @sell_window.show.activate
  @status_window.hide
end

- (Object) buying_price


  • Get Purchase Price




290
291
292
# File 'Scene_Shop.rb', line 290

def buying_price
  @buy_window.price(@item)
end

- (Object) command_buy


  • Buy

    Command




143
144
145
146
# File 'Scene_Shop.rb', line 143

def command_buy
  @dummy_window.hide
  activate_buy_window
end

- (Object) command_sell


  • Sell

    Command




150
151
152
153
154
155
156
# File 'Scene_Shop.rb', line 150

def command_sell
  @dummy_window.hide
  @category_window.show.activate
  @sell_window.show
  @sell_window.unselect
  @sell_window.refresh
end

- (Object) create_buy_window


  • Create Purchase Window




86
87
88
89
90
91
92
93
94
95
96
# File 'Scene_Shop.rb', line 86

def create_buy_window
  wy = @dummy_window.y
  wh = @dummy_window.height
  @buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
  @buy_window.viewport = @viewport
  @buy_window.help_window = @help_window
  @buy_window.status_window = @status_window
  @buy_window.hide
  @buy_window.set_handler(:ok,     method(:on_buy_ok))
  @buy_window.set_handler(:cancel, method(:on_buy_cancel))
end

- (Object) create_category_window


  • Create Category Window




100
101
102
103
104
105
106
107
108
# File 'Scene_Shop.rb', line 100

def create_category_window
  @category_window = Window_ItemCategory.new
  @category_window.viewport = @viewport
  @category_window.help_window = @help_window
  @category_window.y = @dummy_window.y
  @category_window.hide.deactivate
  @category_window.set_handler(:ok,     method(:on_category_ok))
  @category_window.set_handler(:cancel, method(:on_category_cancel))
end

- (Object) create_command_window


  • Create Command Window




42
43
44
45
46
47
48
49
# File 'Scene_Shop.rb', line 42

def create_command_window
  @command_window = Window_ShopCommand.new(@gold_window.x, @purchase_only)
  @command_window.viewport = @viewport
  @command_window.y = @help_window.height
  @command_window.set_handler(:buy,    method(:command_buy))
  @command_window.set_handler(:sell,   method(:command_sell))
  @command_window.set_handler(:cancel, method(:return_scene))
end

- (Object) create_dummy_window


  • Create Dummy Window




53
54
55
56
57
58
# File 'Scene_Shop.rb', line 53

def create_dummy_window
  wy = @command_window.y + @command_window.height
  wh = Graphics.height - wy
  @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
  @dummy_window.viewport = @viewport
end

- (Object) create_gold_window


  • Create Gold Window




33
34
35
36
37
38
# File 'Scene_Shop.rb', line 33

def create_gold_window
  @gold_window = Window_Gold.new
  @gold_window.viewport = @viewport
  @gold_window.x = Graphics.width - @gold_window.width
  @gold_window.y = @help_window.height
end

- (Object) create_number_window


  • Create Quantity Input Window




62
63
64
65
66
67
68
69
70
# File 'Scene_Shop.rb', line 62

def create_number_window
  wy = @dummy_window.y
  wh = @dummy_window.height
  @number_window = Window_ShopNumber.new(0, wy, wh)
  @number_window.viewport = @viewport
  @number_window.hide
  @number_window.set_handler(:ok,     method(:on_number_ok))
  @number_window.set_handler(:cancel, method(:on_number_cancel))
end

- (Object) create_sell_window


  • Create Sell Window




112
113
114
115
116
117
118
119
120
121
122
# File 'Scene_Shop.rb', line 112

def create_sell_window
  wy = @category_window.y + @category_window.height
  wh = Graphics.height - wy
  @sell_window = Window_ShopSell.new(0, wy, Graphics.width, wh)
  @sell_window.viewport = @viewport
  @sell_window.help_window = @help_window
  @sell_window.hide
  @sell_window.set_handler(:ok,     method(:on_sell_ok))
  @sell_window.set_handler(:cancel, method(:on_sell_cancel))
  @category_window.item_window = @sell_window
end

- (Object) create_status_window


  • Create Status Window




74
75
76
77
78
79
80
81
82
# File 'Scene_Shop.rb', line 74

def create_status_window
  wx = @number_window.width
  wy = @dummy_window.y
  ww = Graphics.width - wx
  wh = @dummy_window.height
  @status_window = Window_ShopStatus.new(wx, wy, ww, wh)
  @status_window.viewport = @viewport
  @status_window.hide
end

- (Object) currency_unit


Get Currency Unit




284
285
286
# File 'Scene_Shop.rb', line 284

def currency_unit
  @gold_window.currency_unit
end

- (Object) do_buy(number)


  • Execute Purchase




239
240
241
242
# File 'Scene_Shop.rb', line 239

def do_buy(number)
  $game_party.lose_gold(number * buying_price)
  $game_party.gain_item(@item, number)
end

- (Object) do_sell(number)


  • Execute Sale




246
247
248
249
# File 'Scene_Shop.rb', line 246

def do_sell(number)
  $game_party.gain_gold(number * selling_price)
  $game_party.lose_item(@item, number)
end

- (Object) end_number_input


  • Exit Quantity Input




253
254
255
256
257
258
259
260
261
# File 'Scene_Shop.rb', line 253

def end_number_input
  @number_window.hide
  case @command_window.current_symbol
  when :buy
    activate_buy_window
  when :sell
    activate_sell_window
  end
end

- (Object) max_buy


  • Get Maximum Quantity Buyable




265
266
267
268
# File 'Scene_Shop.rb', line 265

def max_buy
  max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  buying_price == 0 ? max : [max, money / buying_price].min
end

- (Object) max_sell


  • Get Maximum Quantity Sellable




272
273
274
# File 'Scene_Shop.rb', line 272

def max_sell
  $game_party.item_number(@item)
end

- (Object) money


  • Get Party Gold




278
279
280
# File 'Scene_Shop.rb', line 278

def money
  @gold_window.value
end

- (Object) on_buy_cancel


  • Buy [Cancel]




169
170
171
172
173
174
175
176
# File 'Scene_Shop.rb', line 169

def on_buy_cancel
  @command_window.activate
  @dummy_window.show
  @buy_window.hide
  @status_window.hide
  @status_window.item = nil
  @help_window.clear
end

- (Object) on_buy_ok


  • Buy [OK]




160
161
162
163
164
165
# File 'Scene_Shop.rb', line 160

def on_buy_ok
  @item = @buy_window.item
  @buy_window.hide
  @number_window.set(@item, max_buy, buying_price, currency_unit)
  @number_window.show.activate
end

- (Object) on_category_cancel


  • Category [Cancel]




187
188
189
190
191
192
# File 'Scene_Shop.rb', line 187

def on_category_cancel
  @command_window.activate
  @dummy_window.show
  @category_window.hide
  @sell_window.hide
end

- (Object) on_category_ok


  • Category [OK]




180
181
182
183
# File 'Scene_Shop.rb', line 180

def on_category_ok
  activate_sell_window
  @sell_window.select(0)
end

- (Object) on_number_cancel


  • Quantity Input [Cancel]




232
233
234
235
# File 'Scene_Shop.rb', line 232

def on_number_cancel
  Sound.play_cancel
  end_number_input
end

- (Object) on_number_ok


  • Quantity Input [OK]




217
218
219
220
221
222
223
224
225
226
227
228
# File 'Scene_Shop.rb', line 217

def on_number_ok
  Sound.play_shop
  case @command_window.current_symbol
  when :buy
    do_buy(@number_window.number)
  when :sell
    do_sell(@number_window.number)
  end
  end_number_input
  @gold_window.refresh
  @status_window.refresh
end

- (Object) on_sell_cancel


  • Sell [Cancel]




208
209
210
211
212
213
# File 'Scene_Shop.rb', line 208

def on_sell_cancel
  @sell_window.unselect
  @category_window.activate
  @status_window.item = nil
  @help_window.clear
end

- (Object) on_sell_ok


  • Sell [OK]




196
197
198
199
200
201
202
203
204
# File 'Scene_Shop.rb', line 196

def on_sell_ok
  @item = @sell_window.item
  @status_window.item = @item
  @category_window.hide
  @sell_window.hide
  @number_window.set(@item, max_sell, selling_price, currency_unit)
  @number_window.show.activate
  @status_window.show
end

- (Object) prepare(goods, purchase_only)


  • Prepare




11
12
13
14
# File 'Scene_Shop.rb', line 11

def prepare(goods, purchase_only)
  @goods = goods
  @purchase_only = purchase_only
end

- (Object) selling_price


  • Get Sale Price




296
297
298
# File 'Scene_Shop.rb', line 296

def selling_price
  @item.price / 2
end

- (Object) start


  • Start Processing




18
19
20
21
22
23
24
25
26
27
28
29
# File 'Scene_Shop.rb', line 18

def start
  super
  create_help_window
  create_gold_window
  create_command_window
  create_dummy_window
  create_number_window
  create_status_window
  create_buy_window
  create_category_window
  create_sell_window
end