Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xiaoye
mycard
Commits
8031a2a0
Commit
8031a2a0
authored
Jul 18, 2012
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
temp
parent
873082dc
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
582 additions
and
582 deletions
+582
-582
lib/main.rb
lib/main.rb
+132
-132
lib/scene_lobby.rb
lib/scene_lobby.rb
+95
-95
lib/scene_login.rb
lib/scene_login.rb
+46
-46
lib/update.rb
lib/update.rb
+146
-146
lib/window_gameselect.rb
lib/window_gameselect.rb
+103
-103
lib/window_roomlist.rb
lib/window_roomlist.rb
+60
-60
No files found.
lib/main.rb
View file @
8031a2a0
#!/usr/bin/env ruby
#!/usr/bin/env ruby
begin
begin
#定义全局方法
#定义全局方法
def
load_config
(
file
=
"config.yml"
)
def
load_config
(
file
=
"config.yml"
)
require
'yaml'
require
'yaml'
$config
=
YAML
.
load_file
(
"config.yml"
)
rescue
{}
$config
=
YAML
.
load_file
(
"config.yml"
)
rescue
{}
$config
=
{}
unless
$config
.
is_a?
Hash
$config
=
{}
unless
$config
.
is_a?
Hash
$config
[
'bgm'
]
=
true
if
$config
[
'bgm'
].
nil?
$config
[
'bgm'
]
=
true
if
$config
[
'bgm'
].
nil?
$config
[
'screen'
]
||=
{}
$config
[
'screen'
]
||=
{}
$config
[
'screen'
][
'width'
]
||=
1024
$config
[
'screen'
][
'width'
]
||=
1024
$config
[
'screen'
][
'height'
]
||=
640
$config
[
'screen'
][
'height'
]
||=
640
end
end
def
save_config
(
file
=
"config.yml"
)
def
save_config
(
file
=
"config.yml"
)
File
.
open
(
file
,
"w"
)
{
|
file
|
YAML
.
dump
(
$config
,
file
)
}
File
.
open
(
file
,
"w"
)
{
|
file
|
YAML
.
dump
(
$config
,
file
)
}
end
end
def
register_url_protocol
def
register_url_protocol
if
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
if
RUBY_PLATFORM
[
"win"
]
||
RUBY_PLATFORM
[
"ming"
]
require
'win32/registry'
require
'win32/registry'
pwd
=
Dir
.
pwd
.
gsub
(
'/'
,
'\\'
)
pwd
=
Dir
.
pwd
.
gsub
(
'/'
,
'\\'
)
path
=
'"'
+
pwd
+
'\ruby\bin\rubyw.exe" -C"'
+
pwd
+
'" -KU lib/main.rb'
path
=
'"'
+
pwd
+
'\ruby\bin\rubyw.exe" -C"'
+
pwd
+
'" -KU lib/main.rb'
command
=
path
+
' "%1"'
command
=
path
+
' "%1"'
icon
=
'"'
+
pwd
+
'\mycard.exe", 0'
icon
=
'"'
+
pwd
+
'\mycard.exe", 0'
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard'
)
{
|
reg
|
reg
[
'URL Protocol'
]
=
path
.
ljust
path
.
bytesize
unless
(
reg
[
'URL Protocol'
]
==
path
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard'
)
{
|
reg
|
reg
[
'URL Protocol'
]
=
path
.
ljust
path
.
bytesize
unless
(
reg
[
'URL Protocol'
]
==
path
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard\shell\open\command'
)
{
|
reg
|
reg
[
nil
]
=
command
.
ljust
command
.
bytesize
unless
(
reg
[
nil
]
==
command
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard\shell\open\command'
)
{
|
reg
|
reg
[
nil
]
=
command
.
ljust
command
.
bytesize
unless
(
reg
[
nil
]
==
command
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard\DefaultIcon'
)
{
|
reg
|
reg
[
nil
]
=
icon
.
ljust
icon
.
bytesize
unless
(
reg
[
nil
]
==
icon
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'mycard\DefaultIcon'
)
{
|
reg
|
reg
[
nil
]
=
icon
.
ljust
icon
.
bytesize
unless
(
reg
[
nil
]
==
icon
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.ydk'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.ydk'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.yrp'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.yrp'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.deck'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
Win32
::
Registry
::
HKEY_CLASSES_ROOT
.
create
(
'.deck'
)
{
|
reg
|
reg
[
nil
]
=
'mycard'
unless
(
reg
[
nil
]
==
'mycard'
rescue
false
)
}
end
end
end
end
Thread
.
abort_on_exception
=
true
Thread
.
abort_on_exception
=
true
require_relative
'announcement'
require_relative
'announcement'
#读取配置文件
#读取配置文件
load_config
load_config
save_config
save_config
#读取命令行参数
#读取命令行参数
log
=
"log.log"
log
=
"log.log"
log_level
=
"INFO"
log_level
=
"INFO"
profile
=
nil
profile
=
nil
ARGV
.
each
do
|
arg
|
ARGV
.
each
do
|
arg
|
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
=
arg
.
dup
.
force_encoding
(
"UTF-8"
)
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
arg
.
force_encoding
(
"GBK"
)
unless
arg
.
valid_encoding?
case
arg
case
arg
when
/--log=(.*)/
when
/--log=(.*)/
log
.
replace
$1
log
.
replace
$1
when
/--log-level=(.*)/
when
/--log-level=(.*)/
log_level
.
replace
$1
log_level
.
replace
$1
when
/--profile=(.*)/
when
/--profile=(.*)/
profile
=
$1
profile
=
$1
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
when
/^mycard:.*|\.ydk$|\.yrp$|\.deck$/
require_relative
'quickstart'
require_relative
'quickstart'
$scene
=
false
$scene
=
false
when
/register_web_protocol/
when
/register_web_protocol/
register_url_protocol
register_url_protocol
$scene
=
false
$scene
=
false
end
end
end
end
unless
$scene
==
false
unless
$scene
==
false
#初始化SDL
#初始化SDL
require
'sdl'
require
'sdl'
include
SDL
include
SDL
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPMOUSEFOCUS
=
1
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPINPUTFOCUS
=
2
SDL
::
Event
::
APPACTIVE
=
4
SDL
::
Event
::
APPACTIVE
=
4
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
putenv
(
"SDL_VIDEO_CENTERED=1"
);
SDL
.
init
(
INIT_VIDEO
|
INIT_AUDIO
)
SDL
.
init
(
INIT_VIDEO
|
INIT_AUDIO
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
set_caption
(
"MyCard"
,
"MyCard"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
WM
::
icon
=
Surface
.
load
(
"graphics/system/icon.gif"
)
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
$screen
=
Screen
.
open
(
$config
[
'screen'
][
'width'
],
$config
[
'screen'
][
'height'
],
0
,
HWSURFACE
|
(
$config
[
'screen'
][
'fullscreen'
]
?
FULLSCREEN
:
0
))
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1024
)
Mixer
.
open
(
Mixer
::
DEFAULT_FREQUENCY
,
Mixer
::
DEFAULT_FORMAT
,
Mixer
::
DEFAULT_CHANNELS
,
1024
)
Mixer
.
set_volume_music
(
60
)
Mixer
.
set_volume_music
(
60
)
TTF
.
init
TTF
.
init
Thread
.
abort_on_exception
=
true
Thread
.
abort_on_exception
=
true
#初始化日志
#初始化日志
require
'logger'
require
'logger'
if
log
==
"STDOUT"
#调试用
if
log
==
"STDOUT"
#调试用
log
=
STDOUT
log
=
STDOUT
end
end
$log
=
Logger
.
new
(
log
)
$log
=
Logger
.
new
(
log
)
$log
.
level
=
Logger
.
const_get
log_level
$log
.
level
=
Logger
.
const_get
log_level
#性能分析
#性能分析
if
profile
if
profile
if
profile
==
"STDOUT"
if
profile
==
"STDOUT"
profile
=
STDOUT
profile
=
STDOUT
else
else
profile
=
open
(
profile
,
'w'
)
profile
=
open
(
profile
,
'w'
)
end
end
require
'profiler'
require
'profiler'
RubyVM
::
InstructionSequence
.
compile_option
=
{
RubyVM
::
InstructionSequence
.
compile_option
=
{
:trace_instruction
=>
true
,
:trace_instruction
=>
true
,
:specialized_instruction
=>
false
:specialized_instruction
=>
false
}
}
Profiler__
::
start_profile
Profiler__
::
start_profile
end
end
#初始化标题场景
#初始化标题场景
require_relative
'scene_title'
require_relative
'scene_title'
$scene
=
Scene_Title
.
new
$scene
=
Scene_Title
.
new
#自动更新
#自动更新
require_relative
'update'
require_relative
'update'
Update
.
start
Update
.
start
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
require_relative
'dialog'
require_relative
'dialog'
register_url_protocol
rescue
Dialog
.
uac
(
"ruby/bin/rubyw.exe"
,
"-KU lib/main.rb register_web_protocol"
)
register_url_protocol
rescue
Dialog
.
uac
(
"ruby/bin/rubyw.exe"
,
"-KU lib/main.rb register_web_protocol"
)
$log
.
info
(
"main"
)
{
"初始化成功"
}
$log
.
info
(
"main"
)
{
"初始化成功"
}
end
end
rescue
Exception
=>
exception
rescue
Exception
=>
exception
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
)
{
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)
}
open
(
'error-程序出错请到论坛反馈.txt'
,
'w'
)
{
|
f
|
f
.
write
[
exception
.
inspect
,
*
exception
.
backtrace
].
join
(
"
\n
"
)
}
$scene
=
false
$scene
=
false
end
end
#主循环
#主循环
begin
begin
$scene
.
main
while
$scene
$scene
.
main
while
$scene
rescue
Exception
=>
exception
rescue
Exception
=>
exception
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
exception
.
backtrace
.
each
{
|
backtrace
|
break
if
backtrace
=~
/^(.*)\.rb:\d+:in `.*'"$/
}
#由于脚本是从main.rb开始执行的,总会有个能匹配成功的文件
$log
.
fatal
(
$1
)
{
[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)
}.
join
(
"
\n
"
)
}
$log
.
fatal
(
$1
)
{
[
exception
.
inspect
,
*
exception
.
backtrace
].
collect
{
|
str
|
str
.
force_encoding
(
"UTF-8"
)
}.
join
(
"
\n
"
)
}
$game
.
exit
if
$game
$game
.
exit
if
$game
require_relative
'scene_error'
require_relative
'scene_error'
$scene
=
Scene_Error
.
new
$scene
=
Scene_Error
.
new
retry
retry
ensure
ensure
if
profile
if
profile
Profiler__
::
print_profile
(
profile
)
Profiler__
::
print_profile
(
profile
)
profile
.
close
profile
.
close
end
end
$log
.
close
rescue
nil
$log
.
close
rescue
nil
end
end
\ No newline at end of file
lib/scene_lobby.rb
View file @
8031a2a0
#encoding: UTF-8
#encoding: UTF-8
#==============================================================================
#==============================================================================
# Scene_Lobby
# Scene_Lobby
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# 大厅
# 大厅
#==============================================================================
#==============================================================================
class
Scene_Lobby
<
Scene
class
Scene_Lobby
<
Scene
require_relative
'window_userlist'
require_relative
'window_userlist'
require_relative
'window_userinfo'
require_relative
'window_userinfo'
require_relative
'window_roomlist'
require_relative
'window_roomlist'
require_relative
'window_chat'
require_relative
'window_chat'
require_relative
'window_host'
require_relative
'window_host'
require_relative
'window_lobbybuttons'
require_relative
'window_lobbybuttons'
require_relative
'chatmessage'
require_relative
'chatmessage'
require_relative
'scene_duel'
require_relative
'scene_duel'
attr_reader
:chat_window
attr_reader
:chat_window
def
start
def
start
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
-
#{
$config
[
'game'
]
}
-
#{
$game
.
user
.
name
}
(
#{
$game
.
user
.
id
}
)"
,
"MyCard"
)
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
-
#{
$config
[
'game'
]
}
-
#{
$game
.
user
.
name
}
(
#{
$game
.
user
.
id
}
)"
,
"MyCard"
)
$game
.
refresh
$game
.
refresh
@background
=
Surface
.
load
(
"graphics/lobby/background.png"
).
display_format
@background
=
Surface
.
load
(
"graphics/lobby/background.png"
).
display_format
Surface
.
blit
(
@background
,
0
,
0
,
0
,
0
,
$screen
,
0
,
0
)
Surface
.
blit
(
@background
,
0
,
0
,
0
,
0
,
$screen
,
0
,
0
)
@userlist
=
Window_UserList
.
new
(
24
,
204
,
$game
.
users
)
@userlist
=
Window_UserList
.
new
(
24
,
204
,
$game
.
users
)
@roomlist
=
Window_RoomList
.
new
(
320
,
50
,
$game
.
rooms
)
@roomlist
=
Window_RoomList
.
new
(
320
,
50
,
$game
.
rooms
)
@userinfo
=
Window_UserInfo
.
new
(
24
,
24
,
$game
.
user
)
@userinfo
=
Window_UserInfo
.
new
(
24
,
24
,
$game
.
user
)
@host_window
=
Window_LobbyButtons
.
new
(
748
,
18
)
@host_window
=
Window_LobbyButtons
.
new
(
748
,
18
)
@active_window
=
@roomlist
@active_window
=
@roomlist
@chat_window
=
Window_Chat
.
new
(
313
,
$config
[
'screen'
][
'height'
]
-
225
,
698
,
212
)
@chat_window
=
Window_Chat
.
new
(
313
,
$config
[
'screen'
][
'height'
]
-
225
,
698
,
212
)
@count
=
0
@count
=
0
super
super
end
end
def
bgm
def
bgm
"lobby.ogg"
"lobby.ogg"
end
end
def
handle
(
event
)
def
handle
(
event
)
case
event
case
event
when
Event
::
KeyDown
when
Event
::
KeyDown
case
event
.
sym
case
event
.
sym
when
Key
::
UP
when
Key
::
UP
@active_window
.
cursor_up
@active_window
.
cursor_up
when
Key
::
DOWN
when
Key
::
DOWN
@active_window
.
cursor_down
@active_window
.
cursor_down
when
Key
::
F2
when
Key
::
F2
#@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手")
#@joinroom_msgbox = Widget_Msgbox.new("创建房间", "正在等待对手")
#$game.host Room.new(0, $game.user.name)
#$game.host Room.new(0, $game.user.name)
when
Key
::
F3
when
Key
::
F3
#@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
#@joinroom_msgbox = Widget_Msgbox.new("加入房间", "正在加入房间")
#$game.join 'localhost'
#$game.join 'localhost'
when
Key
::
F5
when
Key
::
F5
$game
.
refresh
$game
.
refresh
when
Key
::
F12
when
Key
::
F12
$game
.
exit
$game
.
exit
$scene
=
Scene_Login
.
new
$scene
=
Scene_Login
.
new
end
end
else
else
super
super
end
end
end
end
def
handle_game
(
event
)
def
handle_game
(
event
)
case
event
case
event
when
Game_Event
::
AllUsers
when
Game_Event
::
AllUsers
@userlist
.
items
=
$game
.
users
@userlist
.
items
=
$game
.
users
when
Game_Event
::
AllRooms
when
Game_Event
::
AllRooms
@roomlist
.
items
=
$game
.
rooms
@roomlist
.
items
=
$game
.
rooms
when
Game_Event
::
Join
when
Game_Event
::
Join
join
(
event
.
room
)
join
(
event
.
room
)
when
Game_Event
::
Watch
when
Game_Event
::
Watch
require_relative
'scene_watch'
require_relative
'scene_watch'
$scene
=
Scene_Watch
.
new
(
event
.
room
)
$scene
=
Scene_Watch
.
new
(
event
.
room
)
when
Game_Event
::
Chat
when
Game_Event
::
Chat
@chat_window
.
add
event
.
chatmessage
@chat_window
.
add
event
.
chatmessage
else
else
super
super
end
end
end
end
def
join
(
room
)
def
join
(
room
)
$scene
=
Scene_Duel
.
new
(
room
)
$scene
=
Scene_Duel
.
new
(
room
)
end
end
def
update
def
update
@chat_window
.
update
@chat_window
.
update
@host_window
.
update
@host_window
.
update
@roomlist
.
update
@roomlist
.
update
if
@count
>=
$game
.
refresh_interval
*
60
if
@count
>=
$game
.
refresh_interval
*
60
$game
.
refresh
$game
.
refresh
@count
=
0
@count
=
0
end
end
@count
+=
1
@count
+=
1
super
super
end
end
def
terminate
def
terminate
unless
$scene
.
is_a?
Scene_Lobby
or
$scene
.
is_a?
Scene_Duel
unless
$scene
.
is_a?
Scene_Lobby
or
$scene
.
is_a?
Scene_Duel
$game
.
exit
$game
.
exit
end
end
end
end
end
end
\ No newline at end of file
lib/scene_login.rb
View file @
8031a2a0
#encoding: UTF-8
#encoding: UTF-8
#==============================================================================
#==============================================================================
# ■ Scene_Login
# ■ Scene_Login
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# login
# login
#==============================================================================
#==============================================================================
require_relative
'window_gameselect'
require_relative
'window_gameselect'
require_relative
'window_announcements'
require_relative
'window_announcements'
require_relative
'window_login'
require_relative
'window_login'
require_relative
'scene_replay'
require_relative
'scene_replay'
require_relative
'scene_lobby'
require_relative
'scene_lobby'
class
Scene_Login
<
Scene
class
Scene_Login
<
Scene
def
start
def
start
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
WM
::
set_caption
(
"MyCard v
#{
Update
::
Version
}
"
,
"MyCard"
)
@background
=
Surface
.
load
(
"graphics/login/background.png"
).
display_format
@background
=
Surface
.
load
(
"graphics/login/background.png"
).
display_format
#======================================================
#======================================================
# We'll pay fpr that soon or later.
# We'll pay fpr that soon or later.
#======================================================
#======================================================
if
$config
[
'screen'
][
'height'
]
==
768
if
$config
[
'screen'
][
'height'
]
==
768
@gameselect_window
=
Window_GameSelect
.
new
(
117
,
269
)
@gameselect_window
=
Window_GameSelect
.
new
(
117
,
269
)
elsif
$config
[
'screen'
][
'height'
]
==
640
elsif
$config
[
'screen'
][
'height'
]
==
640
@gameselect_window
=
Window_GameSelect
.
new
(
117
,
134
)
@gameselect_window
=
Window_GameSelect
.
new
(
117
,
134
)
else
else
raise
"无法分辨的分辨率"
raise
"无法分辨的分辨率"
end
end
#======================================================
#======================================================
# ENDS HERE
# ENDS HERE
#======================================================
#======================================================
super
super
end
end
def
update
def
update
@gameselect_window
.
update
@gameselect_window
.
update
super
super
end
end
def
handle_game
(
event
)
def
handle_game
(
event
)
case
event
case
event
when
Game_Event
::
Login
when
Game_Event
::
Login
require_relative
'scene_lobby'
require_relative
'scene_lobby'
$scene
=
Scene_Lobby
.
new
$scene
=
Scene_Lobby
.
new
else
else
super
super
end
end
end
end
#def terminate
#def terminate
# @gameselect_window.destroy
# @gameselect_window.destroy
#end
#end
end
end
\ No newline at end of file
lib/update.rb
View file @
8031a2a0
This diff is collapsed.
Click to expand it.
lib/window_gameselect.rb
View file @
8031a2a0
class
Window_GameSelect
<
Window_List
class
Window_GameSelect
<
Window_List
WLH
=
56
WLH
=
56
def
initialize
(
x
,
y
)
def
initialize
(
x
,
y
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
24
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
24
)
@color
=
[
255
,
255
,
255
]
@color
=
[
255
,
255
,
255
]
@game_color
=
[
47
,
156
,
192
]
@game_color
=
[
47
,
156
,
192
]
@game_stroke_color
=
[
0xFF
,
0xFF
,
0xFF
]
@game_stroke_color
=
[
0xFF
,
0xFF
,
0xFF
]
@items
=
[]
@items
=
[]
Dir
.
glob
(
'lib/**/game.yml'
)
do
|
file
|
Dir
.
glob
(
'lib/**/game.yml'
)
do
|
file
|
game
=
YAML
.
load_file
(
file
)
game
=
YAML
.
load_file
(
file
)
if
game
.
is_a?
(
Hash
)
&&
game
[
"name"
]
if
game
.
is_a?
(
Hash
)
&&
game
[
"name"
]
game
[
'file'
]
||=
'game.rb'
game
[
'file'
]
||=
'game.rb'
game
[
'file'
]
=
File
.
expand_path
(
game
[
'file'
],
File
.
dirname
(
file
))
game
[
'file'
]
=
File
.
expand_path
(
game
[
'file'
],
File
.
dirname
(
file
))
$config
[
game
[
'name'
]]
||=
{}
$config
[
game
[
'name'
]]
||=
{}
@items
<<
game
@items
<<
game
else
else
$log
.
error
"
#{
game
.
inspect
}
读取失败(
#{
file
}
)"
$log
.
error
"
#{
game
.
inspect
}
读取失败(
#{
file
}
)"
end
end
end
end
super
(
x
,
y
,
160
,
@items
.
size
*
WLH
)
super
(
x
,
y
,
160
,
@items
.
size
*
WLH
)
clear
clear
@button
=
Surface
.
load
(
"graphics/login/game_background.png"
)
@button
=
Surface
.
load
(
"graphics/login/game_background.png"
)
#@button.set_alpha(RLEACCEL,255)
#@button.set_alpha(RLEACCEL,255)
self
.
items
=
@items
self
.
items
=
@items
self
.
index
=
@items
.
find_index
{
|
game
|
game
[
"name"
]
==
$config
[
'game'
]}
||
0
self
.
index
=
@items
.
find_index
{
|
game
|
game
[
"name"
]
==
$config
[
'game'
]}
||
0
clicked
clicked
#======================================================
#======================================================
# We'll pay fpr that soon or later.
# We'll pay fpr that soon or later.
#======================================================
#======================================================
if
$config
[
'screen'
][
'height'
]
==
768
if
$config
[
'screen'
][
'height'
]
==
768
@announcements_window
=
Window_Announcements
.
new
(
313
,
265
,
600
,
24
)
@announcements_window
=
Window_Announcements
.
new
(
313
,
265
,
600
,
24
)
elsif
$config
[
'screen'
][
'height'
]
==
640
elsif
$config
[
'screen'
][
'height'
]
==
640
@announcements_window
=
Window_Announcements
.
new
(
313
,
130
,
600
,
24
)
@announcements_window
=
Window_Announcements
.
new
(
313
,
130
,
600
,
24
)
else
else
raise
"无法分辨的分辨率"
raise
"无法分辨的分辨率"
end
end
#======================================================
#======================================================
# ENDS HERE
# ENDS HERE
#======================================================
#======================================================
refresh
refresh
end
end
def
draw_item
(
index
,
status
=
0
)
def
draw_item
(
index
,
status
=
0
)
Surface
.
blit
(
@button
,
@button
.
w
/
3
*
status
,
@game
==
index
?
@button
.
h
/
2
:
0
,
@button
.
w
/
3
,
@button
.
h
/
2
,
@contents
,
0
,
WLH
*
index
)
Surface
.
blit
(
@button
,
@button
.
w
/
3
*
status
,
@game
==
index
?
@button
.
h
/
2
:
0
,
@button
.
w
/
3
,
@button
.
h
/
2
,
@contents
,
0
,
WLH
*
index
)
draw_stroked_text
(
@items
[
index
][
"name"
],
24
,
WLH
*
index
+
14
,
2
)
draw_stroked_text
(
@items
[
index
][
"name"
],
24
,
WLH
*
index
+
14
,
2
)
end
end
def
item_rect
(
index
)
def
item_rect
(
index
)
return
[
0
,
0
,
0
,
0
]
unless
index
return
[
0
,
0
,
0
,
0
]
unless
index
[
0
,
WLH
*
index
,
@button
.
w
/
3
,
@button
.
h
/
2
]
[
0
,
WLH
*
index
,
@button
.
w
/
3
,
@button
.
h
/
2
]
end
end
def
draw_stroked_text
(
text
,
x
,
y
,
size
=
1
)
def
draw_stroked_text
(
text
,
x
,
y
,
size
=
1
)
[[
x
-
size
,
y
-
size
],
[
x
-
size
,
y
],
[
x
-
size
,
y
+
size
],
[[
x
-
size
,
y
-
size
],
[
x
-
size
,
y
],
[
x
-
size
,
y
+
size
],
[
x
,
y
-
size
],
[
x
,
y
+
size
],
[
x
,
y
-
size
],
[
x
,
y
+
size
],
[
x
+
size
,
y
-
size
],
[
x
+
size
,
y
],
[
x
+
size
,
y
+
size
],
[
x
+
size
,
y
-
size
],
[
x
+
size
,
y
],
[
x
+
size
,
y
+
size
],
].
each
{
|
pos
|
@font
.
draw_blended_utf8
(
@contents
,
text
,
pos
[
0
],
pos
[
1
],
*
@game_stroke_color
)}
].
each
{
|
pos
|
@font
.
draw_blended_utf8
(
@contents
,
text
,
pos
[
0
],
pos
[
1
],
*
@game_stroke_color
)}
@font
.
draw_blended_utf8
(
@contents
,
text
,
x
,
y
,
*
@game_color
)
@font
.
draw_blended_utf8
(
@contents
,
text
,
x
,
y
,
*
@game_color
)
end
end
def
mousemoved
(
x
,
y
)
def
mousemoved
(
x
,
y
)
self
.
index
=
(
y
-
@y
)
/
WLH
self
.
index
=
(
y
-
@y
)
/
WLH
end
end
def
index
=
(
index
)
def
index
=
(
index
)
return
if
@index
==
index
# or index.nil?
return
if
@index
==
index
# or index.nil?
if
@index
if
@index
clear
(
*
item_rect
(
@index
))
clear
(
*
item_rect
(
@index
))
draw_item
(
@index
,
0
)
draw_item
(
@index
,
0
)
end
end
@index
=
index
@index
=
index
clear
(
*
item_rect
(
@index
))
clear
(
*
item_rect
(
@index
))
draw_item
(
@index
,
1
)
if
@index
draw_item
(
@index
,
1
)
if
@index
end
end
def
clicked
def
clicked
return
unless
@index
return
unless
@index
load
@items
[
@index
][
"file"
].
encode
(
"GBK"
)
#TODO: load的这种架构微蛋疼,一时想不到更好的方案
load
@items
[
@index
][
"file"
].
encode
(
"GBK"
)
#TODO: load的这种架构微蛋疼,一时想不到更好的方案
$config
[
'game'
]
=
@items
[
@index
][
'name'
]
$config
[
'game'
]
=
@items
[
@index
][
'name'
]
@login_window
.
destroy
if
@login_window
@login_window
.
destroy
if
@login_window
#======================================================
#======================================================
# We'll pay fpr that soon or later.
# We'll pay fpr that soon or later.
#======================================================
#======================================================
if
$config
[
'screen'
][
'height'
]
==
768
if
$config
[
'screen'
][
'height'
]
==
768
@login_window
=
Window_Login
.
new
(
316
,
316
,
$config
[
$config
[
'game'
]][
"username"
],
$config
[
$config
[
'game'
]][
"password"
])
@login_window
=
Window_Login
.
new
(
316
,
316
,
$config
[
$config
[
'game'
]][
"username"
],
$config
[
$config
[
'game'
]][
"password"
])
elsif
$config
[
'screen'
][
'height'
]
==
640
elsif
$config
[
'screen'
][
'height'
]
==
640
@login_window
=
Window_Login
.
new
(
316
,
183
,
$config
[
$config
[
'game'
]][
"username"
],
$config
[
$config
[
'game'
]][
"password"
])
@login_window
=
Window_Login
.
new
(
316
,
183
,
$config
[
$config
[
'game'
]][
"username"
],
$config
[
$config
[
'game'
]][
"password"
])
else
else
raise
"无法分辨的分辨率"
raise
"无法分辨的分辨率"
end
end
#======================================================
#======================================================
# ENDS HERE
# ENDS HERE
#======================================================
#======================================================
@announcements_window
.
refresh
if
@announcements_window
@announcements_window
.
refresh
if
@announcements_window
@game
=
@index
@game
=
@index
refresh
refresh
end
end
def
update
def
update
@login_window
.
update
if
@login_window
@login_window
.
update
if
@login_window
@announcements_window
.
update
if
@announcements_window
@announcements_window
.
update
if
@announcements_window
end
end
#def lostfocus
#def lostfocus
# self.index = nil
# self.index = nil
#end
#end
#def destroy
#def destroy
# @login_window.destroy if @login_window
# @login_window.destroy if @login_window
# super
# super
#end
#end
end
end
lib/window_roomlist.rb
View file @
8031a2a0
#encoding: UTF-8
#encoding: UTF-8
#==============================================================================
#==============================================================================
# ■ Window_Roomitems
# ■ Window_Roomitems
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# 大厅内房间列表
# 大厅内房间列表
#==============================================================================
#==============================================================================
require_relative
'window_scrollable'
require_relative
'window_scrollable'
require_relative
'window_join'
require_relative
'window_join'
class
Window_RoomList
<
Window_Scrollable
class
Window_RoomList
<
Window_Scrollable
attr_reader
:items
attr_reader
:items
WLH
=
48
WLH
=
48
def
initialize
(
x
,
y
,
items
)
def
initialize
(
x
,
y
,
items
)
@button
=
Surface
.
load
(
'graphics/lobby/room.png'
)
@button
=
Surface
.
load
(
'graphics/lobby/room.png'
)
@button
.
set_alpha
(
RLEACCEL
,
255
)
@button
.
set_alpha
(
RLEACCEL
,
255
)
#@background = Surface.load 'graphics/lobby/roomitems.png'
#@background = Surface.load 'graphics/lobby/roomitems.png'
#@contents = Surface.load 'graphics/lobby/roomitems.png'
#@contents = Surface.load 'graphics/lobby/roomitems.png'
super
(
x
,
y
,
@button
.
w
/
3
,
(
$config
[
'screen'
][
'height'
]
-
288
)
/
48
*
48
)
super
(
x
,
y
,
@button
.
w
/
3
,
(
$config
[
'screen'
][
'height'
]
-
288
)
/
48
*
48
)
@item_max
=
0
@item_max
=
0
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
16
)
@font
=
TTF
.
open
(
"fonts/wqy-microhei.ttc"
,
16
)
@color
=
[
0x03
,
0x11
,
0x22
]
@color
=
[
0x03
,
0x11
,
0x22
]
@scrollbar
=
Widget_ScrollBar
.
new
(
self
,
@x
+
@width
,
@y
,
@height
)
@scrollbar
=
Widget_ScrollBar
.
new
(
self
,
@x
+
@width
,
@y
,
@height
)
self
.
items
=
items
self
.
items
=
items
end
end
def
draw_item
(
index
,
status
=
0
)
def
draw_item
(
index
,
status
=
0
)
y
=
item_rect
(
index
)[
1
]
y
=
item_rect
(
index
)[
1
]
room
=
@items
[
index
]
room
=
@items
[
index
]
Surface
.
blit
(
@button
,
@width
*
status
,
room
.
full?
?
WLH
:
0
,
@width
,
WLH
,
@contents
,
0
,
y
)
Surface
.
blit
(
@button
,
@width
*
status
,
room
.
full?
?
WLH
:
0
,
@width
,
WLH
,
@contents
,
0
,
y
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
id
.
to_s
,
24
,
y
+
8
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
id
.
to_s
,
24
,
y
+
8
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
full?
?
"【决斗中】"
:
room
.
private?
?
"【私密房】"
:
"【等待中】"
,
8
,
y
+
24
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
full?
?
"【决斗中】"
:
room
.
private?
?
"【私密房】"
:
"【等待中】"
,
8
,
y
+
24
,
*
@color
)
@font
.
draw_blended_utf8
(
@contents
,
room
.
name
,
128
,
y
+
8
,
*
room
.
color
)
unless
room
.
name
.
empty?
or
room
.
name
.
size
>
100
@font
.
draw_blended_utf8
(
@contents
,
room
.
name
,
128
,
y
+
8
,
*
room
.
color
)
unless
room
.
name
.
empty?
or
room
.
name
.
size
>
100
$log
.
error
(
'标题过长'
)
{
room
.
name
}
if
room
.
name
.
size
>
100
$log
.
error
(
'标题过长'
)
{
room
.
name
}
if
room
.
name
.
size
>
100
@font
.
draw_blended_utf8
(
@contents
,
room
.
player1
.
name
,
128
,
y
+
24
,
*
room
.
player1
.
color
)
if
room
.
player1
and
!
room
.
player1
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player1
.
name
,
128
,
y
+
24
,
*
room
.
player1
.
color
)
if
room
.
player1
and
!
room
.
player1
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player2
.
name
,
320
,
y
+
24
,
*
room
.
player2
.
color
)
if
room
.
player2
and
!
room
.
player2
.
name
.
empty?
@font
.
draw_blended_utf8
(
@contents
,
room
.
player2
.
name
,
320
,
y
+
24
,
*
room
.
player2
.
color
)
if
room
.
player2
and
!
room
.
player2
.
name
.
empty?
room
.
extra
.
each_with_index
do
|
extra
,
index
|
room
.
extra
.
each_with_index
do
|
extra
,
index
|
str
,
color
=
extra
str
,
color
=
extra
@font
.
draw_blended_utf8
(
@contents
,
str
,
300
+
index
*
96
,
y
+
8
,
*
color
)
@font
.
draw_blended_utf8
(
@contents
,
str
,
300
+
index
*
96
,
y
+
8
,
*
color
)
end
end
end
end
def
update
def
update
@join_window
.
update
if
@join_window
and
!
@join_window
.
destroyed?
@join_window
.
update
if
@join_window
and
!
@join_window
.
destroyed?
end
end
def
mousemoved
(
x
,
y
)
def
mousemoved
(
x
,
y
)
return
unless
self
.
include?
(
x
,
y
)
return
unless
self
.
include?
(
x
,
y
)
self
.
index
=
(
y
-
@y
)
/
WLH
+
@scroll
self
.
index
=
(
y
-
@y
)
/
WLH
+
@scroll
end
end
def
clicked
def
clicked
return
unless
@index
and
room
=
@items
[
@index
]
return
unless
@index
and
room
=
@items
[
@index
]
if
room
.
full?
if
room
.
full?
@joinroom_msgbox
=
Widget_Msgbox
.
new
(
"加入房间"
,
"正在加入观战"
)
@joinroom_msgbox
=
Widget_Msgbox
.
new
(
"加入房间"
,
"正在加入观战"
)
$game
.
watch
room
$game
.
watch
room
else
else
if
room
.
private
if
room
.
private
@join_window
=
Window_Join
.
new
(
0
,
0
,
room
)
@join_window
=
Window_Join
.
new
(
0
,
0
,
room
)
else
else
@joinroom_msgbox
=
Widget_Msgbox
.
new
(
"加入房间"
,
"正在加入房间"
)
@joinroom_msgbox
=
Widget_Msgbox
.
new
(
"加入房间"
,
"正在加入房间"
)
$game
.
join
room
$game
.
join
room
end
end
end
end
end
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment