赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 25775 |
最后登录 | 2007-4-13 |
在线时间 | 0 小时 |
Lv1.梦旅人 (禁止发言)
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 0 小时
- 注册时间
- 2006-10-5
- 帖子
- 75
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
某轮乱用职权后的留言:
建议诸位看看第2页LZ的回帖,恩,思路比成品重要!
[LINE]1,#dddddd[/LINE]
前几天想做一个仿《大话西游IIoline》商店,区别于RM传统商店的是:呼出商店时不是场景切换,而是弹出一个对话框!
![]()
详细点击 大话商店
这一过程发现RMXP的UI库极不成熟,只能说还没成型,修改和扩展都十分麻烦,而且不通用!!
我在论坛上看到不少修改的例子,基本上很多是作者自己修改了大半个系统,这些脚本的复用很成问题。
这个商店我写了几个UI组件:窗口,按钮,标签
有一个比较简单的更新、描绘和事件处理机制,还不是很成熟
不知道有没有人对UI库感兴趣的,有人一起干的话,重写一个简单UI库也不会很长时间,1周左右应该拿得出最初版本了。
联系我:QQ 307358033 [email protected]
Benavii 叫我PM美兽殿{/gg}是谁?我才上6R没几天{/fd}{/bz}
懒得打字,随便帖一个脚本(这个脚本是不能单独运行的{/gg}还没整理好...就不放上来了)...
- #----------------------------------------------------------------------------
- # ■ 弹出式商店--PopupShop
- # @author: kylixs
- # @date : 2007-3
- # @e-mail: [email protected]
- # @qq : 307358033
- # @website: [url]http://bbs.javarpg.cn[/url]
- #-----------------------------------------------------------------------------
- class PopupShop < AyinWindow
-
- def initialize(shop_goods)
- super("购买",210,5)
- add_ignore_rect(Rect.new(19,44,306,204))
- # 购买按钮
- @btn_buy=Button.new(["购买按钮1","购买按钮2","购买按钮3"])
- @btn_buy.action = Proc.new{
- buy_action()
- # 关闭商店
- # close()
- }
- add(@btn_buy,150,390)
- # 单价
- @lbl_price = Label.new("",140,16)
- @lbl_price.font.bold = true
- add(@lbl_price,142,271)
- # 数量
- @lbl_num = Label.new("",140,16)
- @lbl_num.font.bold = true
- add(@lbl_num,142,299)
- # 总价
- @lbl_cost = Label.new("",140,16)
- @lbl_cost.font.bold = true
- add(@lbl_cost,142,326)
- # 现金
- @lbl_cash = Label.new("",140,16)
- @lbl_cash.font.bold = true
- add(@lbl_cash,142,354)
- # 实例变量
- @shop_goods = shop_goods
- # 物品提示窗口
- @tooltip = Tooltip.new
- @number = 0
- @index = -1
- @item = nil
- @data = []
- @cell_bg = $game_temp.cell_selected_background
- $game_temp.message_window_showing = true
- $game_system.map_interpreter.message_waiting = true
-
- init_shop
- update
- end
- #--------------------------------------------------------------------------
- # ● 释放
- #--------------------------------------------------------------------------
- def dispose
- $game_temp.message_window_showing = false
- $game_system.map_interpreter.message_waiting = false
- @tooltip.dispose
- super
- end
-
- #--------------------------------------------------------------------------
- # ● 更新画面/事件等
- #--------------------------------------------------------------------------
- def update
- super
- if self.closed?
- return
- end
- @tooltip.update
- #更新相关标签
- update_labels()
- # 选择商品
- index = select_goods
- item = nil
- if index > -1
- item = @data[index]
- end
-
- x,y = Mouse.get_mouse_pos
- @tooltip.set_item(item)
- @tooltip.x = x
- @tooltip.y = y + 32
-
- if Mouse.trigger?(Mouse::LEFT)
- if item != nil
- # 选中一个项目
- if(@item == item )
- @number += 1
- else
- @number = 1
- @index = index
- @item = item
- end
- end
- Mouse.update
- elsif Mouse.trigger?(Mouse::RIGHT)
- # 减少商品数量
- if index == @index && @number > 0
- @number -= 1
- end
- Mouse.update
- elsif Input.trigger?(Input::C)
- @btn_buy.click()
- Input.update
- end
- return
- end
- #--------------------------------------------------------------------------
- # ● 更新商店相关的数据
- #--------------------------------------------------------------------------
- def update_labels
- if(@item != nil)
- @lbl_price.set_text(@item.price.to_s)
- @lbl_num.set_text(@number.to_s)
- cost = @number * @item.price
- @lbl_cost.font.color = (cost > $game_party.gold ? short_gold_color : normal_color)
- @lbl_cost.set_text(cost.to_s)
- else
- @lbl_price.set_text("")
- @lbl_num.set_text("")
- @lbl_cost.set_text("")
- end
- end
-
- #--------------------------------------------------------------------------
- # ● 选择商品
- #--------------------------------------------------------------------------
- def select_goods
- x,y = get_mouse_pos
- x -= 19 #top
- y -= 44 #left
- if( x < 0 || x > 306 || y < 0 || y > 204)
- return -1
- end
- col = x/51
- row = y/51
- index = row * 6 + col
- # 所在单元格是否有商品
- if index >= @data.size
- return -1
- end
- return index
- end
- #--------------------------------------------------------------------------
- # ● 减少商品数量
- #--------------------------------------------------------------------------
- def reduce_num
-
- end
- #--------------------------------------------------------------------------
- # ● 购买处理
- #--------------------------------------------------------------------------
- def buy_action
- #未选中物品或者数量为0
- if @item == nil || @number == 0
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- # 金钱不足时
- cost = @number * @item.price
- if( cost > $game_party.gold)
- # 演奏冻结 SE
- $game_system.se_play($data_system.buzzer_se)
- return
- end
- $game_party.lose_gold(cost)
- case @item
- when RPG::Item
- $game_party.gain_item(@item.id, @number)
- when RPG::Weapon
- $game_party.gain_weapon(@item.id, @number)
- when RPG::Armor
- $game_party.gain_armor(@item.id, @number)
- end
- # 刷新各窗口
- init_shop
- end
- #--------------------------------------------------------------------------
- # ● 初始化商店
- #--------------------------------------------------------------------------
- def init_shop
- @data = []
- for goods_item in @shop_goods
- case goods_item[0]
- when 0
- item = $data_items[goods_item[1]]
- when 1
- item = $data_weapons[goods_item[1]]
- when 2
- item = $data_armors[goods_item[1]]
- end
- if item != nil
- @data.push(item)
- end
- end
- @lbl_cash.font.color = get_gold_color($game_party.gold)
- @lbl_cash.set_text($game_party.gold.to_s)
- @number = 0
- end
- #--------------------------------------------------------------------------
- # ● 描绘商品
- #--------------------------------------------------------------------------
- def paint_goods
- # 如果项目数不是 0 就生成位图、描绘全部项目
- @item_max = @data.size
- if @item_max > 0
- # 选中单元格背景
- if( @index >=0 && @index <@item_max)
- x,y = get_item_pos(@index)
- self.contents.blt(x-1,y-1,@cell_bg,@cell_bg.rect)
- end
- for i in 0...@item_max
- draw_item(i)
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 描绘项目
- # index :项目编号
- #--------------------------------------------------------------------------
- def draw_item(index)
- item = @data[index]
- # 获取物品所持数
- case item
- when RPG::Item
- number = $game_party.item_number(item.id)
- when RPG::Weapon
- number = $game_party.weapon_number(item.id)
- when RPG::Armor
- number = $game_party.armor_number(item.id)
- end
- # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
- # 除此之外的情况设置为无效文字色
- if item.price <= $game_party.gold and number < 99
- self.contents.font.color = normal_color
- else
- self.contents.font.color = disabled_color
- end
-
- x,y = get_item_pos(index)
- bitmap = RPG::Cache.icon(item.icon_name)
- opacity = self.contents.font.color == normal_color ? 255 : 128
- x += (50 - bitmap.width)/2
- y += (50 - bitmap.height)/2
- self.contents.blt(x, y , bitmap, bitmap.rect, opacity)
- end
-
- def paint()
- super
- paint_goods
- end
-
- def get_item_pos(index)
- col = index % 6
- row = index / 6
- x = 19 + col * 51
- y = 44 + row * 51
- return x,y
- end
- end
复制代码
PS: 第一次在6R发帖....
|
|