/
系統設定畫面.rb
722 lines (679 loc) · 25.7 KB
/
系統設定畫面.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
#encoding:utf-8
=begin
*******************************************************************************************
* Lctseng - 系統設定畫面 *
for RGSS3
Ver 1.01 2013.09.02
原作者:魂(Lctseng),巴哈姆特論壇ID:play123
原文發表於:巴哈姆特RPG製作大師哈拉版
轉載請保留此標籤
個人小屋連結:http://home.gamer.com.tw/homeindex.php?owner=play123
主要功能:
一、設定BGM(ME)、SE(BGS)、亮度的大小
二、具有"重置"功能
更新紀錄:
Ver 1.00 :
日期:2013.08.18
摘要:一、最初版本
更新紀錄:
Ver 1.01 :
日期:2013.09.02
摘要:一、新增重置功能,允許調整各圖示的位置
撰寫摘要:一、此腳本修改或重新定義以下類別:
1.Scene_Base
2.Audio
二、此腳本新定義以下類別和模組:
1.Lctseng::SystemOption
2.Game_SystemOption
3.Scene_SystemOption
4.Spriteset_OptionBar
5.Sprite_OptionArrow
*******************************************************************************************
=end
#*******************************************************************************************
#
# 請勿修改從這裡以下的程式碼,除非你知道你在做什麼!
# DO NOT MODIFY UNLESS YOU KNOW WHAT TO DO !
#
#*******************************************************************************************
#--------------------------------------------------------------------------
# ★ 紀錄腳本資訊
#--------------------------------------------------------------------------
if !$lctseng_scripts
$lctseng_scripts = {}
end
$lctseng_scripts[:system_option] = "1.01"
puts "載入腳本:Lctseng - 系統設定畫面,版本:#{$lctseng_scripts[:system_option]}"
#encoding:utf-8
#==============================================================================
# ■ Lctseng::SystemOption
#------------------------------------------------------------------------------
# 有關系統設定選單的設定
#==============================================================================
module Lctseng
module SystemOption
#--------------------------------------------------------------------------
# ● 顯示條的寬高,配合圖片填寫
#--------------------------------------------------------------------------
Bar_Width = 290
Bar_Height = 43
#--------------------------------------------------------------------------
# ● 顯示條的X座標(全部統一)
#--------------------------------------------------------------------------
Bar_X = 236
#--------------------------------------------------------------------------
# ● 顯示條的Y座標(三個分開)
#--------------------------------------------------------------------------
Bar_Y = [101,193,296]
#--------------------------------------------------------------------------
# ● 箭頭的X座標(全部統一)
#--------------------------------------------------------------------------
ARROW_X = 47
#--------------------------------------------------------------------------
# ● 箭頭的Y座標(四個分開)
#--------------------------------------------------------------------------
ARROW_Y = [99,205,308,384]
end
end
#encoding:utf-8
#==============================================================================
# ■ Audio
#------------------------------------------------------------------------------
# 內建的聲音模組
#==============================================================================
module Audio
#--------------------------------------------------------------------------
# ★ 方法重新定義
#--------------------------------------------------------------------------
class << self
unless @lctseng_for_system_option_on_Audio_alias
alias lctseng_for_system_option_on_Audio_for_Bgm_play bgm_play # 播放背景音樂
alias lctseng_for_system_option_on_Audio_for_me_play me_play # 播放音樂
alias lctseng_for_system_option_on_Audio_for_Bgs_play bgs_play # 播放背景音效
alias lctseng_for_system_option_on_Audio_for_se_play se_play # 播放音效
@lctseng_for_system_option_on_Audio_alias = true
end
end
#--------------------------------------------------------------------------
# ● 設定聲音的大小比率(百分比)
#--------------------------------------------------------------------------
def self.set_sound_rate(rate)
@sound_rate = rate / 100.0
end
#--------------------------------------------------------------------------
# ● 設定音樂的大小比率(百分比)
#--------------------------------------------------------------------------
def self.set_music_rate(rate)
@music_rate = rate / 100.0
end
#--------------------------------------------------------------------------
# ● 設定聲音的大小比率(百分比),含效果
#--------------------------------------------------------------------------
def self.set_sound_rate_with_effect(rate)
old_rate = @sound_rate
old_music = RPG::BGS.last.clone
#puts "原比率:#{old_rate}"
old_music.volume = (old_music.volume / old_rate).round
#puts "原音量:#{old_music.volume}"
RPG::BGS.stop
set_sound_rate(rate)
old_music.volume *= @sound_rate
old_music.volume = 100 if old_music.volume > 100
puts "位置:#{old_music.pos}"
old_music.replay
##
name = 'SoundOptionEffect'
se_play('Audio/SE/' + name)
end
#--------------------------------------------------------------------------
# ● 設定音樂的大小比率(百分比),含效果
#--------------------------------------------------------------------------
def self.set_music_rate_with_effect(rate)
old_rate = @music_rate
old_music = RPG::BGM.last.clone
#puts "原比率:#{old_rate}"
old_music.volume = (old_music.volume / old_rate).round
#puts "原音量:#{old_music.volume}"
RPG::BGM.stop
set_music_rate(rate)
old_music.volume *= @music_rate
old_music.volume = 100 if old_music.volume > 100
puts "位置:#{old_music.pos}"
old_music.pos += 60000
old_music.replay
end
#--------------------------------------------------------------------------
# ● 播放背景音樂
#--------------------------------------------------------------------------
def self.bgm_play(filename,volume = 100,pitch = 100,pos = 0)
if !@music_rate
@music_rate = 1.0
end
volume = (volume * @music_rate).round
lctseng_for_system_option_on_Audio_for_Bgm_play(filename,volume,pitch,pos)
end
#--------------------------------------------------------------------------
# ● 播放音樂
#--------------------------------------------------------------------------
def self.me_play(filename,volume = 100,pitch = 100)
if !@music_rate
@music_rate = 1.0
end
volume = (volume * @music_rate).round
lctseng_for_system_option_on_Audio_for_me_play(filename,volume,pitch)
end
#--------------------------------------------------------------------------
# ● 播放背景音效
#--------------------------------------------------------------------------
def self.bgs_play(filename,volume = 80,pitch = 100,pos = 0)
if !@sound_rate
@sound_rate = 1.0
end
volume = (volume * @sound_rate).round
lctseng_for_system_option_on_Audio_for_Bgs_play(filename,volume,pitch,pos)
end
#--------------------------------------------------------------------------
# ● 播放音效
#--------------------------------------------------------------------------
def self.se_play(filename,volume = 80,pitch = 100)
if !@sound_rate
@sound_rate = 1.0
end
volume = (volume * @sound_rate).round
lctseng_for_system_option_on_Audio_for_se_play(filename,volume,pitch)
end
end
#encoding:utf-8
#==============================================================================
# ■Game_SystemOption
#------------------------------------------------------------------------------
# 管理系統資訊的視窗
#==============================================================================
class Game_SystemOption
#--------------------------------------------------------------------------
# ● 定義實例變數
#--------------------------------------------------------------------------
attr_accessor :volume_music
attr_accessor :volume_sound
attr_accessor :brightness
#--------------------------------------------------------------------------
# ● 初始化對象
#--------------------------------------------------------------------------
def initialize
clear_all_data
end
#--------------------------------------------------------------------------
# ● 重置
#--------------------------------------------------------------------------
def reset
puts "執行重置"
clear_all_data
end
#--------------------------------------------------------------------------
# ● 取得三大資料的陣列型態
#--------------------------------------------------------------------------
def data_array
[@volume_music,@volume_sound,@brightness]
end
#--------------------------------------------------------------------------
# ● 取得三大資料的比率資訊
#--------------------------------------------------------------------------
def data_rates
[@volume_music/100.0,@volume_sound/100.0,@brightness/455.0]
end
#--------------------------------------------------------------------------
# ● 清除所有資料
#--------------------------------------------------------------------------
def clear_all_data
@volume_music = 100
@volume_sound = 100
@brightness = 255
end
#--------------------------------------------------------------------------
# ● 改變音效音量(單位畫格)
#--------------------------------------------------------------------------
def change_sound(value)
@volume_sound += value
if @volume_sound > 100
@volume_sound = 100
elsif @volume_sound < 1
@volume_sound = 1
end
end
#--------------------------------------------------------------------------
# ● 改變音樂音量(單位畫格)
#--------------------------------------------------------------------------
def change_music(value)
@volume_music += value
if @volume_music > 100
@volume_music = 100
elsif @volume_music < 1
@volume_music = 1
end
end
#--------------------------------------------------------------------------
# ● 改變亮度(單位畫格)
#--------------------------------------------------------------------------
def change_brightness(value)
@brightness += value
if @brightness > 455
@brightness = 455
elsif @brightness < 55
@brightness = 55
end
end
end
#encoding:utf-8
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
# 游戲中所有 Scene 類(場景類)的父類
#==============================================================================
class Scene_Base
#--------------------------------------------------------------------------
# ★ 方法重新定義
#--------------------------------------------------------------------------
unless @lctseng_for_system_option_on_Scene_Base_alias
alias lctseng_for_system_option_on_Scene_Base_for_Start start # 開始處理
alias lctseng_for_system_option_on_Scene_Base_for_Terminate terminate # 結束處理
@lctseng_for_system_option_on_Scene_Base_alias = true
end
#--------------------------------------------------------------------------
# ● 開始處理 - 重新定義
#--------------------------------------------------------------------------
def start
set_system_option
lctseng_for_system_option_on_Scene_Base_for_Start
create_brightness_viewport
end
#--------------------------------------------------------------------------
# ● 結束處理 - 重新定義
#--------------------------------------------------------------------------
def terminate
lctseng_for_system_option_on_Scene_Base_for_Terminate
dispose_brightness_viewport
end
#--------------------------------------------------------------------------
# ● 產生亮度調整用顯示端口
#--------------------------------------------------------------------------
def create_brightness_viewport
@viewport_brightness = Viewport.new
@viewport_brightness.z = 5000
adjust_brightness
end
#--------------------------------------------------------------------------
# ● 釋放亮度調整用顯示端口
#--------------------------------------------------------------------------
def dispose_brightness_viewport
@viewport_brightness.dispose
end
#--------------------------------------------------------------------------
# ● 執行修正亮度
#--------------------------------------------------------------------------
def adjust_brightness
minus = @system_data.brightness - 255
@viewport_brightness.tone.red = minus
@viewport_brightness.tone.green = minus
@viewport_brightness.tone.blue = minus
end
#--------------------------------------------------------------------------
# ● 取得系統資訊物件
#--------------------------------------------------------------------------
def system_data_object
@system_data
end
#--------------------------------------------------------------------------
# ● 重設系統資訊
#--------------------------------------------------------------------------
def set_system_option
@system_data = load_system_data
Audio.set_music_rate(@system_data.volume_music)
Audio.set_sound_rate(@system_data.volume_sound)
end
#--------------------------------------------------------------------------
# ● 讀取系統設定資訊
#--------------------------------------------------------------------------
def load_system_data
begin
return load_system_data_directly
rescue
puts "原有資訊不存在,創立新檔案"
data = write_new_data
return data
end
end
#--------------------------------------------------------------------------
# ● 讀取系統設定資訊(直接讀取)
#--------------------------------------------------------------------------
def load_system_data_directly
File.open("SystemOption", "rb") do |file|
puts "正在讀取原有資訊"
return Marshal.load(file)
end
end
#--------------------------------------------------------------------------
# ● 寫入新的系統設定資訊檔案
#--------------------------------------------------------------------------
def write_new_data
new_data = Game_SystemOption.new
File.open("SystemOption", "wb") do |file|
Marshal.dump(new_data, file)
end
return new_data
end
#--------------------------------------------------------------------------
# ● 寫入系統設定資訊檔案
#--------------------------------------------------------------------------
def write_system_data
save_data(system_data_object,"SystemOption")
end
#--------------------------------------------------------------------------
# ● 更新畫面(基礎)
#--------------------------------------------------------------------------
def update_basic
Graphics.update
Input.update
update_all_windows
end
end
#encoding:utf-8
#==============================================================================
# ■ Scene_SystemOption
#------------------------------------------------------------------------------
# 系統選單的管理
#==============================================================================
class Scene_SystemOption < Scene_Base
#--------------------------------------------------------------------------
# ● 開始處理
#--------------------------------------------------------------------------
def start
super
create_back_ground
create_arrow
create_bar
@index = 0
@stop = true
@allow_change = true
end
#--------------------------------------------------------------------------
# ● 產生背景
#--------------------------------------------------------------------------
def create_back_ground
@back_ground = Sprite.new(@viewport)
@back_ground.bitmap = Cache.system("System_Option_Background")
end
#--------------------------------------------------------------------------
# ● 產生箭頭
#--------------------------------------------------------------------------
def create_arrow
@arrow_sprite = Sprite_OptionArrow.new(@viewport)
end
#--------------------------------------------------------------------------
# ● 產生比率條精靈組
#--------------------------------------------------------------------------
def create_bar
@bar_spritesets = []
system_data_object.data_rates.each_with_index do |rate,index|
@bar_spritesets.push(Spriteset_OptionBar.new(index,rate))
end
end
#--------------------------------------------------------------------------
# ● 釋放背景
#--------------------------------------------------------------------------
def dispose_back_ground
@back_ground.bitmap.dispose
@back_ground.dispose
end
#--------------------------------------------------------------------------
# ● 釋放箭頭
#--------------------------------------------------------------------------
def dispose_arrow
@arrow_sprite.dispose
end
#--------------------------------------------------------------------------
# ● 結束處理
#--------------------------------------------------------------------------
def terminate
dispose_back_ground
dispose_arrow
dispose_bar
super
end
#--------------------------------------------------------------------------
# ● 釋放比率
#--------------------------------------------------------------------------
def dispose_bar
@bar_spritesets.each do |sprite|
sprite.dispose
end
end
#--------------------------------------------------------------------------
# ● 更新箭頭
#--------------------------------------------------------------------------
def update_arrow
@arrow_sprite.update_pos(@index)
end
#--------------------------------------------------------------------------
# ● 更新畫面
#--------------------------------------------------------------------------
def update
super
update_command
update_arrow
end
#--------------------------------------------------------------------------
# ● 更新指令
#--------------------------------------------------------------------------
def update_command
if @allow_change
changing = false
if Input.press?(:RIGHT)
changing = true
@stop = false
update_right
elsif Input.press?(:LEFT)
changing = true
@stop = false
update_left
end
if !changing
if !@stop
@stop = true
process_on_stop
end
if Input.trigger?(:B)
write_system_data
return_scene
end
if (Input.trigger?(:C) && @index == 3 )
system_data_object.reset
process_on_stop
update_when_change
adjust_brightness
end
if Input.repeat?(:UP)
@index -= 1
if @index < 0
@index = 3
end
moving = true
elsif Input.repeat?(:DOWN)
@index += 1
@index %= 4
moving = true
end
end
end
end
#--------------------------------------------------------------------------
# ● 停止時的處理
#--------------------------------------------------------------------------
def process_on_stop
case @index
when 0
Audio.set_music_rate_with_effect(system_data_object.volume_music)
when 1
Audio.set_sound_rate_with_effect(system_data_object.volume_sound)
when 3
Audio.set_music_rate_with_effect(system_data_object.volume_music)
Audio.set_sound_rate_with_effect(system_data_object.volume_sound)
end
puts "執行停止"
write_system_data
puts "三項資料:#{system_data_object.data_array}"
end
#--------------------------------------------------------------------------
# ● 更換比率後的更新
#--------------------------------------------------------------------------
def update_when_change
if @index > 2
3.times do |index|
@bar_spritesets[index].update_rate(system_data_object.data_rates[index])
end
else
@bar_spritesets[@index].update_rate(system_data_object.data_rates[@index])
end
end
#--------------------------------------------------------------------------
# ● 更新右移
#--------------------------------------------------------------------------
def update_right
case @index
when 0
system_data_object.change_music(1)
when 1
system_data_object.change_sound(1)
when 2
system_data_object.change_brightness(1)
adjust_brightness
end
update_when_change
end
#--------------------------------------------------------------------------
# ● 更新左移
#-------------------------------------------------------------------------
def update_left
case @index
when 0
system_data_object.change_music(-1)
when 1
system_data_object.change_sound(-1)
when 2
system_data_object.change_brightness(-1)
adjust_brightness
end
update_when_change
end
end
#encoding:utf-8
#==============================================================================
# ■ Spriteset_OptionBar
# 系統設定裡的比率條精靈組
#==============================================================================
class Spriteset_OptionBar
#--------------------------------------------------------------------------
# ● 初始化對象
#--------------------------------------------------------------------------
def initialize(index,rate)
@index = index
@rate = rate
create_viewport
create_sprite
end
#--------------------------------------------------------------------------
# ● 取得顯示端口用的矩形
#--------------------------------------------------------------------------
def get_viewport_rect
ry = Lctseng::SystemOption::Bar_Y[@index]
if !ry
ry = 0
end
return Rect.new(Lctseng::SystemOption::Bar_X,ry,Lctseng::SystemOption::Bar_Width,Lctseng::SystemOption::Bar_Height)
end
#--------------------------------------------------------------------------
# ● 產生顯示端口
#--------------------------------------------------------------------------
def create_viewport
@viewport = Viewport.new(get_viewport_rect)
@viewport.rect.width = Lctseng::SystemOption::Bar_Width * @rate
@viewport.z = 200
end
#--------------------------------------------------------------------------
# ● 產生精靈
#--------------------------------------------------------------------------
def create_sprite
@sprite = Sprite.new(@viewport)
@sprite.bitmap = Cache.system("System_Option_Bar")
end
#--------------------------------------------------------------------------
# ● 更新比率
#--------------------------------------------------------------------------
def update_rate(rate)
@rate = rate
update_viewport
end
#--------------------------------------------------------------------------
# ● 更新顯示端口
#--------------------------------------------------------------------------
def update_viewport
@viewport.rect.width = Lctseng::SystemOption::Bar_Width * @rate
end
#--------------------------------------------------------------------------
# ● 釋放精靈
#--------------------------------------------------------------------------
def dispose_sprite
@sprite.dispose
end
#--------------------------------------------------------------------------
# ● 釋放顯示端口
#--------------------------------------------------------------------------
def dispose_viewport
@viewport.dispose
end
#--------------------------------------------------------------------------
# ● 釋放
#--------------------------------------------------------------------------
def dispose
dispose_sprite
dispose_viewport
end
end
#encoding:utf-8
#==============================================================================
# ■ Sprite_OptionArrow
# 系統設定裡的箭頭精靈
#==============================================================================
class Sprite_OptionArrow < Sprite_Base
#--------------------------------------------------------------------------
# ● 初始化對象
#--------------------------------------------------------------------------
def initialize(viewport = nil)
super(viewport)
self.bitmap = Cache.system("System_Option_Arrow")
self.x = Lctseng::SystemOption::ARROW_X
update_pos(0)
end
#--------------------------------------------------------------------------
# ● 更新畫面
#--------------------------------------------------------------------------
def update
super
end
#--------------------------------------------------------------------------
# ● 釋放
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose if self.bitmap
super
end
#--------------------------------------------------------------------------
# ● 更新位置
#--------------------------------------------------------------------------
def update_pos(index)
ry = Lctseng::SystemOption::ARROW_Y[index]
if !ry
ry = 0
end
self.y = ry
end
end