|
本帖最后由 jy02785317 于 2010-8-18 11:00 编辑
效果图
(出自苍龙逐日半即时版)
function say(s,pid,flag,name) --个人新对话
使用方法:
s,对话文本
pid,说话人物id(主要决定头像,以及显示人名),可以留空,留空时默认为0
flag,对话显示位置,同dos版,可以留空
name,显示人物名,可以留空,留空时使用说话人物的名字。
对话文本中可以有控制字符,如下:
--暂停,任意键后继续,p
--控制颜色 R=redG=goldB=blackW=whiteO=orange
--控制字符显示速度0-9
--控制字体ASDF(需要在源码中先配置字体路径,如果不会请勿使用)
--控制换行H分页P
源码如下
- --新对话方式
- --加入控制字符
- --暂停,任意键后继续,p
- --控制颜色 R=redG=goldB=blackW=whiteO=orange
- --控制字符显示速度0-9
- --控制字体ASDF
- --控制换行H分页P
- --N代表自己n代表主角
- function say(s,pid,flag,name) --个人新对话
- local picw=130; --最大头像图片宽高
- local pich=130;
- local talkxnum=18; --对话一行字数
- local talkynum=3; --对话行数
- local dx=2;
- local dy=2;
- local boxpicw=picw+10;
- local boxpich=pich+10;
- local boxtalkw=talkxnum*CC.DefaultFont+10;
- local boxtalkh=boxpich-27;
- pid=pid or 0
- if flag==nil then
- if pid==0 then
- flag=1
- else
- flag=0
- end
- end
- name=name or JY.Person[pid]["姓名"]
- local talkBorder=(pich-talkynum*CC.DefaultFont)/(talkynum+1);
- --显示头像和对话的坐标
- local xy={ [0]={headx=dx,heady=dy,
- talkx=dx+boxpicw+2,talky=dy+27,
- namex=dx+boxpicw+2,namey=dy,
- showhead=1},--左上
- {headx=CC.ScreenW-1-dx-boxpicw,heady=CC.ScreenH-dy-boxpich,
- talkx=CC.ScreenW-1-dx-boxpicw-boxtalkw-2,talky= CC.ScreenH-dy-boxpich+27,
- namex=CC.ScreenW-1-dx-boxpicw-96,namey=CC.ScreenH-dy-boxpich,
- showhead=1},--右下
- {headx=dx,heady=dy,
- talkx=dx+boxpicw-43,talky=dy+27,
- namex=dx+boxpicw+2,namey=dy,
- showhead=0},--上中
- {headx=CC.ScreenW-1-dx-boxpicw,heady=CC.ScreenH-dy-boxpich,
- talkx=CC.ScreenW-1-dx-boxpicw-boxtalkw-2,talky= CC.ScreenH-dy-boxpich+27,
- namex=CC.ScreenW-1-dx-boxpicw-96,namey=CC.ScreenH-dy-boxpich,
- showhead=1},
- {headx=CC.ScreenW-1-dx-boxpicw,heady=dy,
- talkx=CC.ScreenW-1-dx-boxpicw-boxtalkw-2,talky=dy+27,
- namex=CC.ScreenW-1-dx-boxpicw-96,namey=dy,
- showhead=1},--右上
- {headx=dx,heady=CC.ScreenH-dy-boxpich,
- talkx=dx+boxpicw+2,talky=CC.ScreenH-dy-boxpich+27,
- namex=dx+boxpicw+2,namey=CC.ScreenH-dy-boxpich,
- showhead=1}, --左下
- }
- if flag<0 or flag>5 then
- flag=0;
- end
- local headid=pid--JY.Person[pid]["头像代号"]
- if xy[flag].showhead==0 then
- headid=-1;
- end
- if CONFIG.KeyRepeat==0 then
- lib.EnableKeyRepeat(0,CONFIG.KeyRepeatInterval);
- end
- lib.GetKey();
-
- local function readstr(str)
- local T1={"0","1","2","3","4","5","6","7","8","9"}
- local T2={{"R",C_RED},{"G",C_GOLD},{"B",C_BLACK},{"W",C_WHITE},{"O",C_ORANGE}}
- local T3={{"H",CC.FontNameSong},{"S",CC.FontNameHei},{"F",CC.FontName}}
- --美观起见,针对不同字体同一行显示,需要微调y坐标,以及字号
- --以默认的字体为标准,启体需下移,细黑需上移
- for i=0,9 do
- if T1[i+1]==str then return 1,i*50 end
- end
- for i=1,5 do
- if T2[i][1]==str then return 2,T2[i][2] end
- end
- for i=1,3 do
- if T3[i][1]==str then return 3,T3[i][2] end
- end
- return 0
- end
-
- local function mydelay(t)
- if t<=0 then return end
- lib.ShowSurface(0)
- lib.Delay(t)
- end
-
- local page,cy,cx=0,0,0
- local color,t,font=C_WHITE,0,CC.FontName
- while string.len(s)>1 do
- if page==0 then --新的一页,清屏,显示头像
- Cls()
- if headid>=0 then
- DrawBox(xy[flag].headx, xy[flag].heady, xy[flag].headx + boxpicw, xy[flag].heady + boxpich,C_WHITE);
- DrawBox(xy[flag].namex,xy[flag].namey,xy[flag].namex+96,xy[flag].namey+24,C_WHITE)
- MyDrawString(xy[flag].namex,xy[flag].namex+96,xy[flag].namey+1,name,C_ORANGE,21)
- local w,h=lib.PicGetXY(1,headid*2);
- local x=(picw-w)/2;
- local y=(pich-h)/2;
- lib.PicLoadCache(1,headid*2,xy[flag].headx+5+x,xy[flag].heady+5+y,1);
- end
- DrawBox(xy[flag].talkx, xy[flag].talky, xy[flag].talkx +boxtalkw, xy[flag].talky + boxtalkh,C_WHITE);
- page=1
- end
- local str
- str=string.sub(s,1,1)
- if str=='*' then
- str='H'
- s=string.sub(s,2,-1)
- else
- str=string.sub(s,1,2)
- s=string.sub(s,3,-1)
- end
- --开始控制逻辑
- if str=="H" then
- cx=0
- cy=cy+1
- if cy==3 then
- cy=0
- page=0
- end
- elseif str=="P" then
- cx=0
- cy=0
- page=0
- elseif str=="p" then
- ShowScreen();
- WaitKey();
- lib.Delay(100)
- elseif str=="N" then
- s=JY.Person[pid]["姓名"]..s
- elseif str=="n" then
- s=JY.Person[0]["姓名"]..s
- else
- local kz1,kz2=readstr(str)
- if kz1==1 then
- t=kz2
- elseif kz1==2 then
- color=kz2
- elseif kz1==3 then
- font=kz2
- else
- lib.DrawStr(xy[flag].talkx+CC.DefaultFont*cx+5,
- xy[flag].talky+(CC.DefaultFont+talkBorder)*cy+talkBorder-8,
- str,color,CC.DefaultFont,font,0,0)
- mydelay(t)
- cx=cx+1
- if cx==talkxnum then
- cx=0
- cy=cy+1
- if cy==talkynum then
- cy=0
- page=0
- end
- end
- end
- end
- --如果换页,则显示,等待按键
- if page==0 or string.len(s)<2 then
- ShowScreen();
- WaitKey();
- lib.Delay(100)
- end
- end
- if CONFIG.KeyRepeat==0 then
- lib.EnableKeyRepeat(CONFIG.KeyRepeatDelay,CONFIG.KeyRepeatInterval);
- end
- Cls();
- end
复制代码 |
|