From 4d6735b2a93cfa7becd5a6f5ed6d7b627fd5a7c7 Mon Sep 17 00:00:00 2001 From: soul2 <1052986332@qq.com> Date: Wed, 7 Sep 2022 10:43:09 +0800 Subject: [PATCH] init commit --- broadcast2.j | 24 +++++++++++++++++++ struct/broadcast.j | 53 ++++++++++++++++++++++++++++++++++++++++ struct/line.j | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 broadcast2.j create mode 100644 struct/broadcast.j create mode 100644 struct/line.j diff --git a/broadcast2.j b/broadcast2.j new file mode 100644 index 0000000..3033b40 --- /dev/null +++ b/broadcast2.j @@ -0,0 +1,24 @@ +library broadcast2 initializer InitBroadcast2 + + /** + * 播片系统 + * 为剧情设计 + * 当前版本仅涉及文本显示对话功能 + * + * 版本: 2.01 + * By Soul2 + */ + + #define SayPointX 0.62 + #define SayPointY - 0.5 + + #include "struct/broadcast.j" + + #undef SayPointX + #undef SayPointY + + function InitBroadcast2 takes nothing returns nothing + // init something + endfunction + +endlibrary \ No newline at end of file diff --git a/struct/broadcast.j b/struct/broadcast.j new file mode 100644 index 0000000..11f5521 --- /dev/null +++ b/struct/broadcast.j @@ -0,0 +1,53 @@ +#include "line.j" +struct Broadcast + + timer recorder + real progress + real tick + integer progressLine + Line array lines[100] + integer lineLength = 0 + string name + + static method create takes string name returns thistype + local thistype b = thistype.allocate() + set b.name = name + set b.lineLength = 0 + set b.recorder = null + set b.progress = 0 + set b.progressLine = 0 + return b + endmethod + + method getLength takes nothing returns integer + return this.lineLength + endmethod + + method add takes Line line returns thistype + set this.lines[this.lineLength] = line + set this.lineLength = this.lineLength + 1 + return this + endmethod + + method ready takes real tick returns thistype + set this.recorder = CreateTimer() + set this.tick = tick + return this + endmethod + + method nextTick takes nothing returns real + if this.getLength() == 0 then + return - 4000 // 当前播片没有台词,立即结束 + endif + if this.progress >= this.lines[this.progressLine].begin then + call this.lines[this.progressLine].say() + set this.progressLine = this.progressLine + 1 + if this.progressLine >= this.getLength() then + return - 2000 // 播片台词播放完毕 + endif + endif + set this.progress = this.progress + this.tick + return this.progress // 正常运行返回当前播片进度 + endmethod + +endstruct diff --git a/struct/line.j b/struct/line.j new file mode 100644 index 0000000..3357d53 --- /dev/null +++ b/struct/line.j @@ -0,0 +1,60 @@ +struct Line + unit speaker + string speakerName + string content + integer begin + integer end + integer enemy + + static method create takes integer begin, integer end returns thistype + local thistype l = thistype.allocate() + set l.begin = begin + set l.end = end + return l + endmethod + + method foe takes nothing returns thistype + set this.enemy = 1 + return this + endmethod + + method setSpeak takes string speakerName, string content returns thistype + set this.speakerName = speakerName + set this.content = content + return this + endmethod + + method setSpeak2 takes unit speaker, string content returns thistype + set this.speaker = speaker + set this.content = content + return this + endmethod + + method getSpeaker takes integer enemy returns string + local string color = "|cff00ff00" + if enemy == 1 then + set color = "|cffff4000" + endif + if this.speaker != null then + if IsUnitType(this.speaker, UNIT_TYPE_HERO) then + return color + GetHeroProperName(this.speaker) + "|r" + else + return color + GetUnitName(this.speaker) + "|r" + endif + else + return color + this.speakerName + "|r" + endif + endmethod + + + method say takes nothing returns thistype + local string speaker = this.getSpeaker(this.enemy) + call DisplayTimedTextToPlayer(Player(0), SayPointX, SayPointY, this.getDuration(), speaker + ": " + this.content) + return this + endmethod + + method getDuration takes nothing returns real + return I2R(this.end - this.begin) + endmethod + +endstruct