RPGエディタでオリジナル選択肢関数を使う

投稿者:            mini mosmoss 投稿日:2017/01/14 10:37

とりかさんの簡単ウィンドウ関数とラジアンさんのオリジナル選択肢関数を
RPGエディタで使う場合の数値や注意事項、効率的な書き方の記事です



これらの関数を使うことで、文字表示スピード・カーソル/決定などの効果音設定、
ウィンドウベースの変更、メッセージウィンドウ複数同時表示などが実現します

前々々回の記事の制作中のゲーム内で
この処理を使ったメッセージ選択肢を採用してみました
1日進めるとウィンドウベースの変更もできます
どんなもんか見たい人がいたらチェックしてみてください

スクリプト元
http://rmake.jp/published_items/51019/
オリジナル選択肢関数2

最低限クリップしておくスクリプト素材
スクロールバー
選択肢マーク
選択肢バー
makeデフォルトウィンドウの雛形

最低限、開始スクリプトに書いておく関数

・引数から配列を得る関数(cfm_さんの関数)
・簡単ウィンドウ関数とオリジナル選択肢関数のセット
・自分で設定した、スピーク文と選択肢文に当たる関数

#引数から配列を得る関数/引数40個バージョン
#選択肢を作るために使います
#これを使う場合、選択肢40個まで、それ以上作りたいときは下の関数をいじって増やす
def array2(a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39)
 a=createArray()
 if toString(a00)=="null"&&a00!="null" then return a;else pushArray(a,a00);end
 if toString(a01)=="null"&&a01!="null" then return a;else pushArray(a,a01);end
 if toString(a02)=="null"&&a02!="null" then return a;else pushArray(a,a02);end
 if toString(a03)=="null"&&a03!="null" then return a;else pushArray(a,a03);end
 if toString(a04)=="null"&&a04!="null" then return a;else pushArray(a,a04);end
 if toString(a05)=="null"&&a05!="null" then return a;else pushArray(a,a05);end
 if toString(a06)=="null"&&a06!="null" then return a;else pushArray(a,a06);end
 if toString(a07)=="null"&&a07!="null" then return a;else pushArray(a,a07);end
 if toString(a08)=="null"&&a08!="null" then return a;else pushArray(a,a08);end
 if toString(a09)=="null"&&a09!="null" then return a;else pushArray(a,a09);end
 if toString(a10)=="null"&&a10!="null" then return a;else pushArray(a,a10);end
 if toString(a11)=="null"&&a11!="null" then return a;else pushArray(a,a11);end
 if toString(a12)=="null"&&a12!="null" then return a;else pushArray(a,a12);end
 if toString(a13)=="null"&&a13!="null" then return a;else pushArray(a,a13);end
 if toString(a14)=="null"&&a14!="null" then return a;else pushArray(a,a14);end
 if toString(a15)=="null"&&a15!="null" then return a;else pushArray(a,a15);end
 if toString(a16)=="null"&&a16!="null" then return a;else pushArray(a,a16);end
 if toString(a17)=="null"&&a17!="null" then return a;else pushArray(a,a17);end
 if toString(a18)=="null"&&a18!="null" then return a;else pushArray(a,a18);end
 if toString(a19)=="null"&&a19!="null" then return a;else pushArray(a,a19);end
 if toString(a20)=="null"&&a20!="null" then return a;else pushArray(a,a20);end
 if toString(a21)=="null"&&a21!="null" then return a;else pushArray(a,a21);end
 if toString(a22)=="null"&&a22!="null" then return a;else pushArray(a,a22);end
 if toString(a23)=="null"&&a23!="null" then return a;else pushArray(a,a23);end
 if toString(a24)=="null"&&a24!="null" then return a;else pushArray(a,a24);end
 if toString(a25)=="null"&&a25!="null" then return a;else pushArray(a,a25);end
 if toString(a26)=="null"&&a26!="null" then return a;else pushArray(a,a26);end
 if toString(a27)=="null"&&a27!="null" then return a;else pushArray(a,a27);end
 if toString(a28)=="null"&&a28!="null" then return a;else pushArray(a,a28);end
 if toString(a29)=="null"&&a29!="null" then return a;else pushArray(a,a29);end
 if toString(a30)=="null"&&a30!="null" then return a;else pushArray(a,a30);end
 if toString(a31)=="null"&&a31!="null" then return a;else pushArray(a,a31);end
 if toString(a32)=="null"&&a32!="null" then return a;else pushArray(a,a32);end
 if toString(a33)=="null"&&a33!="null" then return a;else pushArray(a,a33);end
 if toString(a34)=="null"&&a34!="null" then return a;else pushArray(a,a34);end
 if toString(a35)=="null"&&a35!="null" then return a;else pushArray(a,a35);end
 if toString(a36)=="null"&&a36!="null" then return a;else pushArray(a,a36);end
 if toString(a37)=="null"&&a37!="null" then return a;else pushArray(a,a37);end
 if toString(a38)=="null"&&a38!="null" then return a;else pushArray(a,a38);end
 if toString(a39)=="null"&&a39!="null" then return a;else pushArray(a,a39);end
 return a
end

## 簡単ウィンドウ関数ここから ##

## SimpleWindow ##
def SWin(WinSpr, FL_Size, XPos, YPos, XSize, YSize)
  ## 元になる画像のID
  ## WinSpr = 203458
  ## 元になる画像の大きさ
  ## FL_Size = 18

  ## 画像スプライト生成
  MyWinNW = createSprite(WinSpr)
  MyWinNE = createSprite(WinSpr)
  MyWinSW = createSprite(WinSpr)
  MyWinSE = createSprite(WinSpr)

  MyWinN2 = createSprite(WinSpr)
  MyWinW2 = createSprite(WinSpr)
  MyWinE2 = createSprite(WinSpr)
  MyWinS2 = createSprite(WinSpr)

  MyWinCNT = createSprite(WinSpr)

  ## 分割利用時のサイズ
  CutSize = FL_Size / 3

  ## 集合画像の設定
  setSpriteRect(MyWinNW, 0, 0, CutSize, CutSize, 0, 0, CutSize, CutSize)
  setSpriteRect(MyWinNE, CutSize * 2, 0, CutSize, CutSize, XSize - CutSize, 0, CutSize, CutSize)
  setSpriteRect(MyWinSW, 0, CutSize * 2, CutSize, CutSize, 0, YSize - CutSize, CutSize, CutSize)
  setSpriteRect(MyWinSE, CutSize * 2, CutSize * 2, CutSize, CutSize, XSize - CutSize, YSize - CutSize, CutSize, CutSize)

  setSpriteRect(MyWinN2, CutSize, 0, CutSize, CutSize, CutSize, 0, XSize - CutSize * 2, CutSize)
  setSpriteRect(MyWinW2, 0, CutSize, CutSize, CutSize, 0, CutSize, CutSize, YSize - CutSize * 2)
  setSpriteRect(MyWinE2, CutSize * 2, CutSize, CutSize, CutSize, XSize - CutSize, CutSize, CutSize, YSize - CutSize * 2)
  setSpriteRect(MyWinS2, CutSize, CutSize * 2, CutSize, CutSize, CutSize, YSize - CutSize, XSize - CutSize * 2, CutSize)

  setSpriteRect(MyWinCNT, CutSize, CutSize, CutSize, CutSize, CutSize, CutSize, XSize - CutSize * 2, YSize - CutSize * 2)

  ## 表示位置の設定
  setSpritePosition(MyWinNW, XPos, YPos)
  setSpritePosition(MyWinNE, XPos, YPos)
  setSpritePosition(MyWinSW, XPos, YPos)
  setSpritePosition(MyWinSE, XPos, YPos)

  setSpritePosition(MyWinN2, XPos, YPos)
  setSpritePosition(MyWinW2, XPos, YPos)
  setSpritePosition(MyWinE2, XPos, YPos)
  setSpritePosition(MyWinS2, XPos, YPos)

  setSpritePosition(MyWinCNT, XPos, YPos)

  arrWin = createArray()
  arrWin[0] = MyWinNW
  arrWin[1] = MyWinNE
  arrWin[2] = MyWinSW
  arrWin[3] = MyWinSE
  arrWin[4] = MyWinN2
  arrWin[5] = MyWinW2
  arrWin[6] = MyWinE2
  arrWin[7] = MyWinS2
  arrWin[8] = MyWinCNT

  return arrWin
end
## SimpleWindow ##

## SimpleWord ##
def SWor(Words, XPos, YPos, XSize, YSize)
  ## 表示する文字列
  ## Words = "trick"

  textID = createText(XPos, YPos, XSize, YSize)
  setText(textID, Words)
  return textID
end
## SimpleWord ##

## DeleteWord ##
def DWor(arrWor)
  deleteText(arrWor)
end
## DeleteWord ##

## DeleteWindow ##
def DWin(arrWin)
  i = 0
  while i < 9
    deleteSprite(arrWin[i])
    i = i + 1
  end
end
## DeleteWindow ##

## DeleteWindowPrint ##
def DWP(arrWP)
  DWin(arrWP)
  DWor(arrWP[9])
end
## DeleteWindowPrint ##

## WindowsPrint ##
def WPri(Words, WinSpr, FL_Size, XPos, YPos, XSize, YSize)
  ## 表示する文字列
  ## Words = "trick"
  SetPX = 13
  SetPY = 4

  s1 = createArray()
  s1 = SWin(WinSpr, FL_Size, XPos, YPos, XSize, YSize)
  t1 = SWor(Words, XPos + SetPX, YPos + SetPY, XSize - (SetPX * 2), YSize - (SetPY * 2))
  #DWor(t1)
  #DWin(s1)
  pushArray(s1, t1)
  return s1
end
## WindowsPrint ##

## 簡単ウィンドウ関数ここまで ##

# ------↓↓ オリジナル選択肢関数 ↓↓------ #

# 設定部分
#ウィンドウの表示領域をRPGエディタ用に設定してあります

# ウィンドウの画像のID
setVariable("oriSpeakWinSprNo", 203458)
setVariable("oriSpeakWinSize", 18) # 3の倍数にしたほうがいい
setVariable("oriSpeakWinSprZOrder", 1000)

# 選択肢関連の画像のID
setVariable("oriSpeakSelectBarSprNo", 228837) # スクロールバー
setVariable("oriSpeakSelectMarkSprNo", 220645) # 選択場所を示すマーク

# speak関数部分の表示領域の設定
setVariable("speakText_x", 28); setVariable("speakText_y", 256)
setVariable("speakText_w", 512-28-28)
setVariable("speakText_l", 5)# 行数

# 選択肢部分の表示領域の設定
setVariable("speakSelect_x", 512-160-32); setVariable("speakSelect_y", 96)
setVariable("speakSelect_w", 160)

# 選択肢の表示部分の最大数
setVariable("speakSelect_maxLen_h", 7) # 縦(3以上)
setVariable("speakSelect_maxLen_w", 7) # 横

# 文字のスピードの設定
# もともとメッセージの表示設定が「0(一度に表示)」の場合は関係ない。
setVariable("speakTextMaxSpeed", 30)
# 選択肢のスクロールスピードの設定
setVariable("speakSelect_maxSpeed", 7)

# オリジナル選択肢関数群

def deleteSpeakText()
  setVariable("existSpeakText", false)
  DWP(getVariable("spriteNo_speakText"))
end

def drawSpeakSelectText()
  if !getVariable("isDraw_speakSelect") then return 0; end
  setVariable("isDraw_speakSelect", false)

  yc = getVariable("speakSelect_yCnt")

  len_h = getVariable("speakSelect_len_h")
  len_w = getVariable("speakSelect_len_w")

  x = getVariable("speakSelect_x"); y = getVariable("speakSelect_y")
  w = getVariable("speakSelect_w")
  h1 = getTextFontSize(); h2 = floor(h1 * 1.18)
  h3 = 6 + (len_h - 1) * h2 + h1 + 6 + 3
  if getVariable("speakSelect_isBar_w") then h4 = h3 + 8; else h4 = h3; end
  if getVariable("speakSelect_isBar_h") then w3 =  w - 8; else w3 =  w; end
  w2 = floor((w3 - 18 - 4) / len_w)

  sID = getVariable("oriSpeakWinSprNo")
  sSize = getVariable("oriSpeakWinSize")
  sz = getVariable("oriSpeakWinSprZOrder")
  ssn = getVariable("speakSelect_selectNo")
  st = getVariable("speakSelect_selectTop")
  sal = getVariable("speakSelect_sArrLen")

  snArr = createArray(); snArr = getVariable("spriteNo_speakSelectBar")
  pArr = createArray(); pArr = getVariable("speakSelect_isPush")

  vn = "spriteNo_speakSelectText"
  if getVariable(vn)[0] == 0
    setVariable(vn, SWin(sID, sSize, x, y, w, h4))
    n = 0; while n < 9
      setSpriteZOrder(getVariable(vn)[n], sz)
    n = n + 1; end
  end
  if getVariable("spriteNo_speakSelected") == 0
    sn = createSprite(getVariable("oriSpeakSelectMarkSprNo"))
    setVariable("spriteNo_speakSelected", sn)
    setSpriteZOrder(sn, sz + 1)
  else
    sn = getVariable("spriteNo_speakSelected")
  end
  setSpriteRect(sn, getVariable("speakSelect_markCnt") * 16, 0, 16, 16, 0, 0, 16, 16)
  if yc != 0
    mpy = (ssn % yc) - (st % yc)
    mpx = floor(ssn / yc) - floor(st / yc) 
  else
    mpy = ssn - st; mpx = 0
  end
  setSpritePosition(sn, x + 5 + mpx * w2, y + 4 + 4 + floor(h1 / 2) - 8 + mpy * h2)

  barSpriteID = getVariable("oriSpeakSelectBarSprNo")
  if getVariable("speakSelect_isBar_h")
    if yc != 0
      pt = (st % yc) / yc; pl = len_h / yc
    else
      pt = st / sal; pl = len_h / sal
    end
    bty = y + 12 + floor((h3 - 24) * pt)
    bly = floor((h3 - 24) * pl)

    if snArr[0][0] == 0
      n = 0; while n < 6
        snArr[0][n] = createSprite(barSpriteID)
        setSpriteZOrder(snArr[0][n], sz + 1)
      n = n + 1;end

      setSpriteRect(snArr[0][0], 6, 0, 6, 1, x + w - 10, y + 11, 6, 1)
      setSpriteRect(snArr[0][1], 6, 1, 6, 4, x + w - 10, y + 12, 6, h3 - 24)
      setSpriteRect(snArr[0][2], 6, 5, 6, 1, x + w - 10, y + h3 - 12, 6, 1)
      setSpriteRect(snArr[0][3], 1, 1, 4, 4, 0, 0, 4, bly)
    end

    if pArr[0] then rx = 0
    else rx = 6; end
    setSpriteRect(snArr[0][4], rx, 0, 6, 6, x + w - 10, y + 4, 6, 6)

    if pArr[2] then rx = 0
    else rx = 6; end
    setSpriteRect(snArr[0][5], rx, 0, 6, 6, x + w - 10, y + h3 - 10, 6, 6)

    setSpritePosition(snArr[0][3], x + w - 9, bty)
  end

  if getVariable("speakSelect_isBar_w")
    btx = x + 12 + floor((w3 - 24) * (floor(st / yc) / floor(sal / yc)))
    blx = floor((w3 - 24) * (len_w / floor(sal / yc)))

    if snArr[1][0] == 0
      n = 0; while n < 6
        snArr[1][n] = createSprite(barSpriteID)
        setSpriteZOrder(snArr[1][n], sz + 1)
      n = n + 1; end

      setSpriteRect(snArr[1][0], 6, 0, 1, 6, x + 11, y + h4 - 10, 1, 6)
      setSpriteRect(snArr[1][1], 7, 0, 4, 6, x + 12, y + h4 - 10, w3 - 24, 6)
      setSpriteRect(snArr[1][2],11, 0, 1, 6, x + w3 - 12, y + h4 - 10, 1, 6)
      setSpriteRect(snArr[1][3], 1, 1, 4, 4, 0, 0, blx, 4)
    end

    if pArr[3] then rx = 0
    else rx = 6; end
    setSpriteRect(snArr[1][4], rx, 0, 6, 6, x + 4, y + h4 - 10, 6, 6)

    if pArr[1] then rx = 0
    else rx = 6; end
    setSpriteRect(snArr[1][5], rx, 0, 6, 6, x + w3 - 10, y + h4 - 10, 6, 6)

    setSpritePosition(snArr[1][3], btx, y + h4 - 9)
  end
end

def deleteSpeakSelectText()
  deleteSpeakText()

  snArr = createArray(); snArr = getVariable("spriteNo_speakSelectBar")
  sn2Arr = createArray(); sn2Arr = getVariable("textID_speakSelectText")

  setVariable("speakSelectText_flg", false)
  setVariable("existSpeakSelectText", false)

  DWin(getVariable("spriteNo_speakSelectText"))
  getVariable("spriteNo_speakSelectText")[0] = 0

  deleteSprite(getVariable("spriteNo_speakSelected"))
  setVariable("spriteNo_speakSelected", 0)

  len = getVariable("speakSelect_len_w") * getVariable("speakSelect_len_h")
  n = 0; while n < len
    DWor(sn2Arr[n])
    sn2Arr[n] = 0
  n = n + 1; end

  n = 0; while n < 2
    m = 0; while m < 6
      if snArr[n][m] != 0
        deleteSprite(snArr[n][m]); snArr[n][m] = 0
      end
    m = m + 1; end
  n = n + 1; end
end

def oriSpeak_drawProcess()
  drawSpeakSelectText()

  drawCanvas()
end

def setTextSpeakText()
  if !getVariable("isSetText_speakText") then return 0; end
  setVariable("isSetText_speakText", false)

#ここに単音の効果音を入れると、文字が増えるたびに再生される
#playSound(44260)

  setText(getVariable("textID_speakText"), getVariable("speakText_word"))
end

def setTextSpeakSelect()
  if !getVariable("isSetText_speakSelect") then return 0; end
  setVariable("isSetText_speakSelect", false)

  len_h = getVariable("speakSelect_len_h")
  len_w = getVariable("speakSelect_len_w")

  x = getVariable("speakSelect_x"); y = getVariable("speakSelect_y")
  w = getVariable("speakSelect_w")
  h1 = getTextFontSize(); h2 = floor(h1 * 1.18)
  h3 = 6 + (len_h - 1) * h2 + h1 + 6 + 3
  if getVariable("speakSelect_isBar_w") then h4 = h3 + 8; else h4 = h3; end
  if getVariable("speakSelect_isBar_h") then w3 =  w - 8; else w3 =  w; end
  w2 = floor((w3 - 18 - 4) / len_w)

  yc = getVariable("speakSelect_yCnt")

  s = getVariable("speakSelect_selectTop")
  sArr = createArray(); sArr = getVariable("speakSelect_sArr")
  tIDArr = createArray(); tIDArr = getVariable("textID_speakSelectText")

  n = 0; while n < len_w
    m = 0; while m < len_h
      word = sArr[s + n * yc + m]
      if tIDArr[n * len_h + m] == 0
        tIDArr[n * len_h + m] = SWor(word, x + 18 + n * w2, y + 4 + m * h2, w2, h2 + 2)
      else
        setText(tIDArr[n * len_h + m], word)
      end
    m = m + 1; end
  n = n + 1; end
end

def oriSpeak_setTextProcess()
  setTextSpeakText()
  setTextSpeakSelect()

end

def oriSpeakInit(w)
  setVariable("oriSpeak_drawFlg", false)
  setVariable("oriSpeak_setTextFlg", false)

  setVariable("isDraw_speakSelect", false)
  setVariable("isSetText_speakText", false)
  setVariable("isSetText_speakSelect", false)

  setVariable("speakText_wordArr", createArray())
  setVariable("spriteNo_speakText", createArray())

  setVariable("speakSelectText_flg", false)
  setVariable("existSpeakSelectText", false)
  setVariable("speakSelect_isWaitInput", false)

  arr = splitString(w, ""); len = getArrayLength(arr)

  # メッセージ表示設定(0→一度に全部, 1→1文字ずつ)
  setVariable("speakText_viewMode", getTextViewMode())

  setVariable("existSpeakText", true)
  setVariable("speakText_isWaitInput", false)
  setVariable("time_speakText", 0)

  x = getVariable("speakText_x"); y = getVariable("speakText_y")
  w1 = getVariable("speakText_w")
  h1 = getTextFontSize(); h2 = floor(h1 * 1.18)
  h3 = 6 + (getVariable("speakText_l") - 1) * h2 + h1 + 6 + 3

  sID = getVariable("oriSpeakWinSprNo")
  sSize = getVariable("oriSpeakWinSize")

  setVariable("speakText_len", 0)
  setVariable("spriteNo_speakText", createArray())
  setVariable("spriteNo_speakText", WPri("", sID, sSize, x, y, w1, h3))
  n = 0; while n < 9
    setSpriteZOrder(getVariable("spriteNo_speakText")[n], getVariable("oriSpeakWinSprZOrder"))
  n = n + 1; end
  setVariable("textID_speakText", getVariable("spriteNo_speakText")[9])
  setVariable("oriSpeak_drawFlg", true)
  setVariable("speakText_word", "")
  setVariable("speakText_wordArr", arr)
  setVariable("speakText_wordArrLen", len)
end

def oriSpeakSelectInit(sArr, w, y_count)
  oriSpeakInit(w)

  if !y_count 
    if y_count == 1 then yc = 1
    else yc = 0; end
  else yc = y_count; end
  setVariable("speakSelect_yCnt", yc)

  setVariable("speakSelectText_flg", true)
  setVariable("existSpeakSelectText", false)
  setVariable("speakSelect_isPush", createArray())
  n = 0; while n < 4
    getVariable("speakSelect_isPush")[n] = false
  n = n + 1; end

  setVariable("speakSelect_sArr", createArray())
  setVariable("speakSelect_sArr", sArr)
  sLen = getArrayLength(sArr)
  if yc != 0
    if floor(sLen / yc) != sLen / yc
      l = (floor(sLen / yc) + 1) * yc
      n = sLen; while n < l
        getVariable("speakSelect_sArr")[n] = ""
      n = n + 1; end
      sLen = l
    end
  end
  setVariable("speakSelect_sArrLen", sLen)
  maxLen_h = getVariable("speakSelect_maxLen_h")
  maxLen_w = getVariable("speakSelect_maxLen_w")

  isBar_h = true; isBar_w = true

  if yc != 0
    if yc <= maxLen_h
      len_h = yc; isBar_h = false
    else
      len_h = maxLen_h
    end
    len_w = sLen / yc
    if floor(len_w) != len_w then len_w = len_w + 1; end
    len_w = floor(len_w)
    if len_w <= maxLen_w
      isBar_w = false
    else
      len_w = maxLen_w
    end
  else
    if sLen <= maxLen_h
      len_h = sLen; isBar_h = false
    else
      len_h = maxLen_h
    end
    len_w = 1; isBar_w = false
  end
  setVariable("speakSelect_len_h", len_h)
  setVariable("speakSelect_len_w", len_w)
  setVariable("speakSelect_isBar_h", isBar_h)
  setVariable("speakSelect_isBar_w", isBar_w)

  setVariable("speakSelect_selectNo", 0)
  setVariable("speakSelect_selectTop", 0)

  setVariable("spriteNo_speakSelectText", createArray())
  getVariable("spriteNo_speakSelectText")[0] = 0
  setVariable("textID_speakSelectText", createArray())
  len = getVariable("speakSelect_len_w") * getVariable("speakSelect_len_h")
  n = 0; while n < len
    getVariable("textID_speakSelectText")[n] = 0; n = n + 1
  end
  setVariable("spriteNo_speakSelected", 0)
  vn = "spriteNo_speakSelectBar"
  setVariable(vn, createArray())
  n = 0; while n < 2
    getVariable(vn)[n] = createArray()
    m = 0; while m < 6
      getVariable(vn)[n][m] = 0
    m = m + 1; end
  n = n + 1; end
end

def timeProcess_speakText()
  if !getVariable("existSpeakText") then return 0; end
  if getVariable("speakText_isWaitInput") then return 0; end
  if getVariable("existSpeakSelectText") then return 0; end

  itv = 1000 / getVariable("speakTextMaxSpeed")
  time = getVariable("getTime"); dif = time - getVariable("time_speakText")
  if dif < itv then return 0; end
  if dif > itv * 1.2 then time = time - floor(itv * 0.2)
  else time = time - floor(dif - itv); end

  wArr = createArray(); wArr = getVariable("speakText_wordArr")
  len = getVariable("speakText_len")
  w2 = "speakText_wordArrLen"
  
  if getVariable("speakText_viewMode") == 1
    ff = true
    w3 = ""
    n = 0; while n < 8


      w3 = w3 + wArr[len + n]; n = n + 1
    end
    if w3 == "_F_WAIT_"
      setVariable("speakText_isWaitInput", true); ff = false
      m = len + 8
      while m < getVariable(w2)
        wArr[m - n] = wArr[m]; m = m + 1
      end
      setVariable(w2, getVariable(w2) - n)
    end
    addWord = wArr[len]; addLen = 1
  else
    addWord = ""; addLen = 0
    flg = true; ff = true
    while flg
      w3 = ""
      n = 0; while n < 8
        w3 = w3 + wArr[len + addLen + n]; n = n + 1
      end
      if w3 == "_F_WAIT_"
        setVariable("speakText_isWaitInput", true); ff = false
        m = len + addLen + 8
        while m < getVariable(w2)
          wArr[m - n] = wArr[m]; m = m + 1
        end
        setVariable(w2, getVariable(w2) - n)
        flg = false
      else
        addWord = addWord + wArr[len + addLen]; addLen = addLen + 1
      end
      if len + addLen == getVariable(w2) then flg = false; end
    end
    if addLen == 0 then ff = false; end
  end

  if ff
    setVariable("time_speakText", time)
    setVariable("speakText_word", getVariable("speakText_word") + addWord)
    setVariable("speakText_len", len + addLen)
    setVariable("isSetText_speakText", true)
    setVariable("oriSpeak_setTextFlg", true)
    if getVariable("speakText_len") == getVariable(w2)
      setVariable("speakText_isWaitInput", true)
    end
  end
end

def timeProcess_speakSelect()
  if !getVariable("existSpeakSelectText") then return 0; end

  time = getVariable("getTime")

  itv = 1000 / 8; dif = time - getVariable("speakSelect_markCntTime")
  if dif > itv
    if dif > itv * 1.2 then time1 = time - floor(itv * 0.2)
    else time1 = time - floor(dif - itv); end

    setVariable("speakSelect_markCntTime", time1)
    setVariable("speakSelect_markCnt", (getVariable("speakSelect_markCnt") + 1) % 8)
    setVariable("isDraw_speakSelect", true); setVariable("oriSpeak_drawFlg", true)
  end

  len_h = getVariable("speakSelect_len_h")
  len_w = getVariable("speakSelect_len_w")

  yc = getVariable("speakSelect_yCnt")

  pArr = createArray(); pArr = getVariable("speakSelect_isPush")

  flg = false
  if    pArr[2] then x0 =  0; y0 =  1; flg = true
  elsif pArr[0] then x0 =  0; y0 = -1; flg = true
  elsif pArr[1] then x0 =  1; y0 =  0; flg = true
  elsif pArr[3] then x0 = -1; y0 =  0; flg = true
  end
  if flg && getVariable("speakSelect_isWaitInput")
    itv = 1000 / getVariable("speakSelect_maxSpeed")
    dif = time - getVariable("speakSelect_selectTime")
    if dif > itv
      if dif > itv * 1.2 then time1 = time - floor(itv * 0.2)
      else time1 = time - floor(dif - itv); end
      saLen = getVariable("speakSelect_sArrLen")
      if yc != 0
        syLen = yc; sxLen = floor(saLen / syLen)
      else
        syLen = saLen; sxLen = 1
      end

      sn = getVariable("speakSelect_selectNo")
      sn_a = sn % syLen; sn_b = floor(sn / syLen)
      if y0 == 0
        if (((x0 == -1) && (sn_b != 0)) || ((x0 == 1) && (sn_b != sxLen - 1)))
          setVariable("speakSelect_selectNo", sn + x0 * syLen)
          setVariable("speakSelect_selectTime", time1)
          setVariable("speakSelect_markCnt", 0)
        end
      else
        if (((y0 == -1) && (sn_a != 0)) || ((y0 == 1) && (sn_a != syLen - 1)))
          setVariable("speakSelect_selectNo", sn + y0)
          setVariable("speakSelect_selectTime", time1)
          setVariable("speakSelect_markCnt", 0)
        end
      end

      st = getVariable("speakSelect_selectTop"); st0 = st
      if (x0 == -1) && (sn_b != 0) && (floor(st / syLen) == sn_b)
        st0 = st - syLen
      elsif (x0 == 1) && (sn_b != sxLen - 1) && (floor(st / syLen) + len_w - 1 == sn_b)
        st0 = st + syLen
      elsif (y0 == -1) && (sn_a != 0) && ((st % syLen) == sn_a)
        st0 = st - 1
      elsif (y0 == 1) && (sn_a != syLen - 1) && ((st % syLen) + len_h - 1 == sn_a)
        st0 = st + 1
      end
      setVariable("speakSelect_selectTop", st0)

      setVariable("isSetText_speakSelect", true); setVariable("oriSpeak_setTextFlg", true)
      setVariable("isDraw_speakSelect", true); setVariable("oriSpeak_drawFlg", true)
    end
  end
end

def oriSpeak_timeProcess()
  setVariable("getTime", getTime())

  timeProcess_speakText()
  timeProcess_speakSelect()
end

def oriSpeak_inputFlgInit()
  setVariable("isMouseDown", false)
  setVariable("isMouseMove", false)
  setVariable("isKeyDown", false)
  setVariable("keyDownName", "NULL")
end

def oriSpeak_setInput()
  oriSpeak_inputFlgInit()
  takeInput()
  if isMouseDown()
    setVariable("isMouseDown", true); setVariable("mousePoint", getMousePosition())
    setVariable("isMousePressed", true) 
  elsif isMouseMove()
    setVariable("isMouseMove", true); setVariable("mousePoint", getMousePosition())
  elsif isMouseUp()
    setVariable("isMousePressed", false)
  else
    w = createArray()
    w = splitString("UP,DOWN,LEFT,RIGHT,ENTER", ",")
    wLen = getArrayLength(w)
    n = 0
    while n < wLen
      if isKeyDown(w[n])
        setVariable("isKeyDown", true); setVariable("keyDownName", w[n])
        setVariable("isKeyPressed", true); setVariable("keyPressedName", w[n])
        return 0
      end
      if isKeyUp(w[n])
        if getVariable("keyPressedName") == w[n]
          setVariable("isKeyPressed", false); setVariable("keyPressedName", "NULL")
        end
        return 0
      end
      n = n + 1
    end
  end
end

def inputProcess_speak()
  flg = false
  if getVariable("isKeyDown") && (getVariable("keyDownName") == "ENTER")
    flg = true
  elsif getVariable("isMouseDown")
    flg = true
  end

  if flg
    if getVariable("existSpeakText") && getVariable("speakText_isWaitInput")
      setVariable("speakText_isWaitInput", false)
      setVariable("time_speakText", getVariable("getTime"))

      if getVariable("speakText_len") == getVariable("speakText_wordArrLen")
        if getVariable("speakSelectText_flg")
          setVariable("existSpeakSelectText", true)
          setVariable("isSetText_speakSelect", true); setVariable("oriSpeak_setTextFlg", true)
          setVariable("isDraw_speakSelect", true); setVariable("oriSpeak_drawFlg", true)
          setVariable("speakSelect_isWaitInput", true)
          setVariable("speakSelect_selectTime", getTime() - 1000)
          setVariable("speakSelect_markCnt", 0)
          setVariable("speakSelect_markCntTime", getTime())

          oriSpeak_inputFlgInit()
        else
          deleteSpeakText(); setVariable("oriSpeak_drawFlg", true)
          setVariable("oriSpeakLoop", false)
        end
      end
    end
  end
end

def inputProcess_speakSelect()
  if getVariable("existSpeakSelectText") && getVariable("speakSelect_isWaitInput")
  else return 0; end

  len_h = getVariable("speakSelect_len_h")
  len_w = getVariable("speakSelect_len_w")

  x = getVariable("speakSelect_x"); y = getVariable("speakSelect_y")
  w = getVariable("speakSelect_w")
  h1 = getTextFontSize(); h2 = floor(h1 * 1.18)
  h3 = 6 + (len_h - 1) * h2 + h1 + 6 + 3
  if getVariable("speakSelect_isBar_w") then h4 = h3 + 8; else h4 = h3; end
  if getVariable("speakSelect_isBar_h") then w3 =  w - 8; else w3 =  w; end
  w2 = floor((w3 - 18 - 4) / len_w)
  
  isBar_w = getVariable("speakSelect_isBar_w")
  isBar_h = getVariable("speakSelect_isBar_h")

  yc = getVariable("speakSelect_yCnt")

  st = getVariable("speakSelect_selectTop")
  saLen = getVariable("speakSelect_sArrLen")
  if yc != 0
    syLen = yc; sxLen = floor(saLen / syLen)
  else
    syLen = saLen; sxLen = 1
  end

  flg1 = false; flg2 = false
  if getVariable("isKeyDown") && (getVariable("keyDownName") == "ENTER")
    flg1 = true
  elsif getVariable("isMouseDown") || getVariable("isMouseMove")
    mpx = getVariable("mousePoint")[0]; mpy = getVariable("mousePoint")[1]
    if (mpx >= x + 18) && (mpx < x + 18 + len_w * w2)
      if (mpy >= y + 4) && (mpy < y + 4 + len_h * h2)
        snx = floor(st / syLen) + floor((mpx - x - 18) / w2)
        sny = (st % syLen) + floor((mpy - y - 4) / h2)
        setVariable("speakSelect_selectNo", snx * syLen + sny)
        setVariable("speakSelect_selectTime", getTime())
        setVariable("speakSelect_markCnt", 0)
        if getVariable("isMouseDown")
          flg1 = true
        elsif getVariable("isMouseMove")
          flg2 = true
        end
      end
    end
  end

  if flg1
    dw = getVariable("speakSelect_sArr")[getVariable("speakSelect_selectNo")]
    if dw == ""
    else
      setVariable("speakSelect_isWaitInput", false)
      deleteSpeakSelectText(); setVariable("oriSpeak_drawFlg", true)
      setVariable("oriSpeakLoop", false)
      return 0
    end
  elsif flg2
    setVariable("isSetText_speakSelect", true); setVariable("oriSpeak_setTextFlg", true)
    setVariable("isDraw_speakSelect", true); setVariable("oriSpeak_drawFlg", true)
    return 0
  end

  pArr = createArray(); pArr = getVariable("speakSelect_isPush")
  n = 0; while n < 4
    pArr[n] = false; n = n + 1
  end

  if getVariable("isKeyPressed")
    case getVariable("keyPressedName")
    when "DOWN"  pArr[2] = true
    when "UP"    pArr[0] = true
    when "RIGHT" pArr[1] = true
    when "LEFT"  pArr[3] = true
    end
  elsif getVariable("isMousePressed")
    mpx = getVariable("mousePoint")[0]; mpy = getVariable("mousePoint")[1]

    if isBar_h
      if (mpx >= x + w - 11) && (mpx < x + w - 3)
        if (mpy >= y + 4) && (mpy < y + 12)
          pArr[0] = true
        elsif (mpy >= y + h3 - 11) && (mpy < y + h3 - 3)
          pArr[2] = true
        end
      end
    end
    if isBar_w
      if (mpy >= y + h4 - 11) && (mpy < y + h4 - 3)
        if (mpx >= x + 4) && (mpx < x + 12)
          pArr[3] = true
        elsif (mpx >= x + w3 - 11) && (mpx < x + w3 - 3)
          pArr[1] = true
        end
      end
    end
  end
end

def oriSpeak_inputProcess()
  inputProcess_speak()
  inputProcess_speakSelect()
end

def oriSpeakLoop()
  setBaseTime()

  inputFlg = false

  setVariable("isMousePressed", false)
  setVariable("isKeyPressed", false); setVariable("keyPressedName", "NULL")

  startInput()
  setVariable("oriSpeakLoop", true)
  while getVariable("oriSpeakLoop")
    if hasInput()
      oriSpeak_setInput()
      oriSpeak_inputProcess()

      inputFlg = false
      if hasInput()
        oriSpeak_setInput()
        while hasInput()
          oriSpeak_setInput()
        end
        inputFlg = true
      end
    elsif inputFlg
      inputFlg = false
      oriSpeak_inputProcess()
    end

    oriSpeak_timeProcess()

    if getVariable("oriSpeak_drawFlg")
      setVariable("oriSpeak_drawFlg", false)
      oriSpeak_drawProcess()
      waitTime(30)
    end
    if getVariable("oriSpeak_setTextFlg")
      setVariable("oriSpeak_setTextFlg", false)
      oriSpeak_setTextProcess()
    end
  end
  endInput()
end

def oriSpeakText(w)
  oriSpeakInit(w)
  oriSpeakLoop()
end

def oriSpeakSelect(arr, w, y_count)
  oriSpeakSelectInit(arr, w, y_count)
  oriSpeakLoop()

  arr = createArray()
  arr[0] = getVariable("speakSelect_selectNo")
  arr[1] = getVariable("speakSelect_sArr")[arr[0]]

  return arr
end

def oriSpeakSelect_PassNumber(digits)
  numArr = createArray()
  n = 0; while n < digits
    numArr[n] = ""; n = n + 1
  end

  sArr1 = createArray(); sArr1 = splitString("0,1,2,3,4,5,6,7,8,9", ",")
  sArr2 = createArray(); sArr2 = splitString("0,1,2,3,4,5,6,7,8,9,←", ",")
  retArr = createArray()
  vmFlg = false; vm = getTextViewMode()

  d = 0
  while d < digits
    word = digits + " 桁の番号を入力してください。\n" + joinArray(numArr, ",")
    if d == 0 then retArr = oriSpeakSelect(sArr1, word)
    else retArr = oriSpeakSelect(sArr2, word)
    end
    if retArr[1] == "←" then numArr[d - 1] = ""; d = d - 1
    else numArr[d] = retArr[0]; d = d + 1
    end
    if !vmFlg then setTextViewMode(0); vmFlg = false; end
  end

  setTextViewMode(vm)

  number = 0
  n = 0; while n < digits
    number = number * 10 + numArr[n]; n = n + 1
  end
  return number
end

def oriSpeakSelect_PassWord(maxCharCnt)
  wordArr = createArray()
  n = 0; while n < maxCharCnt
    wordArr[n] = ""; n = n + 1
  end

  sWord = createArray()

sWord[0] = << EOS
平,,あ,い,う,え,お,,は,ひ,ふ,へ,ほ,,が,ぎ,ぐ,げ,ご,,ぁ,ぃ,ぅ,ぇ,ぉ
片,,か,き,く,け,こ,,ま,み,む,め,も,,ざ,じ,ず,ぜ,ぞ,,ゃ,,ゅ,,ょ
数,,さ,し,す,せ,そ,,や,,ゆ,,よ,,だ,ぢ,づ,で,ど,,っ,,,,
英,,た,ち,つ,て,と,,ら,り,る,れ,ろ,,ば,び,ぶ,べ,ぼ,,ー,、,。,,
記,,な,に,ぬ,ね,の,,わ,,を,,ん,,ぱ,ぴ,ぷ,ぺ,ぽ,,,,,,
戻,終,,,,,,,,,,,,,,,,,,,,,,,
EOS

sWord[1] = << EOS
平,,ア,イ,ウ,エ,オ,,ハ,ヒ,フ,ヘ,ホ,,ガ,ギ,グ,ゲ,ゴ,,ァ,ィ,ゥ,ェ,ォ
片,,カ,キ,ク,ケ,コ,,マ,ミ,ム,メ,モ,,ザ,ジ,ズ,ゼ,ゾ,,ャ,,ュ,,ョ
数,,サ,シ,ス,セ,ソ,,ヤ,,ユ,,ヨ,,ダ,ヂ,ヅ,デ,ド,,ッ,,,,
英,,タ,チ,ツ,テ,ト,,ラ,リ,ル,レ,ロ,,バ,ビ,ブ,ベ,ボ,,ー,,,,
記,,ナ,ニ,ヌ,ネ,ノ,,ワ,,ヲ,,ン,,パ,ピ,プ,ペ,ポ,,,,,,
戻,終,,,,,,,,,,,,,,,,,,,,,,,
EOS

sWord[2] = << EOS
平,,0,5
片,,1,6
数,,2,7
英,,3,8
記,,4,9
戻,終,,
EOS

sWord[3] = << EOS
平,,a,b,c,d,e,f,,A,B,C,D,E,F
片,,g,h,i,j,k,l,,G,H,I,J,K,L
数,,m,n,o,p,q,r,,M,N,O,P,Q,R
英,,s,t,u,v,w,x,,S,T,U,V,W,X
記,,y,z,,,,,,Y,Z,,,,
戻,終,,,,,,,,,,,,,
EOS

sWord[4] = << EOS
平,,(,=,$,<,,~
片,,),+,%,>,.,
数,,!,-,&,{,[,空
英,,?,*,|,},],
記,,_,/,^,@,,
戻,終,,,,,,
EOS

  sArr = createArray()
  sArr2 = createArray()

  n = 0; while n < 5
    sArr[n] = createArray(); sArr[n] = splitString(sWord[n], "")
    len = getArrayLength(sArr[n])

    # 改行を除く
    m = 0; while m < len
      if sArr[n][m] == "\n"
        if m != len - 1 then sArr[n][m] = ","; else sArr[n][m] = ""; end
      end
    m = m + 1; end
    sWord[n] = joinArray(sArr[n], "")
    sArr[n] = splitString(sWord[n], ","); len = getArrayLength(sArr[n])

    # 縦横の並びを逆にする
    sArr2[n] = createArray()
    m = 0; while m < len
      sArr2[n][m] = sArr[n][(len / 6) * (m % 6) + floor(m / 6)]
    m = m + 1; end
  n = n + 1; end

  sArr2[4][36] = ","
  sArr2[4][40] = "\\"
  sArr2[4][43] = "\""

  retArr = createArray()
  vmFlg = false; vm = getTextViewMode()
  loopFlg = true
  st = 0

  d = 0
  while loopFlg
    word = "入力してください。" + d + " 文字入力中。(最大 " + maxCharCnt + " 文字まで)\n" + joinArray(wordArr, "")
    retArr = oriSpeakSelect(sArr2[st], word, 6)

    case retArr[1]
    when "戻" if d > 0 then wordArr[d - 1] = ""; d = d - 1; end
    when "終" loopFlg = false
    when "平" st = 0
    when "片" st = 1
    when "数" st = 2
    when "英" st = 3
    when "記" st = 4
    when "空" wordArr[d] = " "; d = d + 1
    else      wordArr[d] = retArr[1]; d = d + 1
    end

    if !vmFlg then setTextViewMode(0); vmFlg = false; end
    if d == maxCharCnt
      word = joinArray(wordArr, "") + " でいいですか?"
      retArr = oriSpeakSelect(splitString("はい,いいえ", ","), word)
      if retArr[0] == 0 then loopFlg = false
      else wordArr[d - 1] = ""; d = d - 1
      end
    end
  end

  setTextViewMode(vm)

  retWord = joinArray(wordArr, "")
  return retWord
end
# ------↑↑ オリジナル選択肢関数 ↑↑------ #

#スピーク文関数
#nameは喋っている人の名前 
#a~dはそれぞれ1~4行目のテキスト、""でくくられた文字列
#この関数では名前とメッセージ内容含めて5行までしか書けない
#オリジナル選択肢関数内の数値も5行のメッセージを想定して設定した

def hanasu(name, a,b,c,d)
s=name+"\n「"+a+"」"
if b
b= "\n "+b
s=name+"\n「"+a+b+"」"
end
if c
c= "\n "+c
s=name+"\n「"+a+b+c+"」"
end
if d
d= "\n "+d
s=name+"\n「"+a+b+c+d+"」"
end
#↓これを書かないと枠が表示されない
setCanvasVisible(true)
oriSpeakText(s)
end

#選択肢関数
#aには選択肢の配列、bには""でくくられた文字列
def choice(a,b) 
#c =speakWithSelectArray(a, b)
#↓これを書かないと枠が表示されない
setCanvasVisible(true)
no=getArrayLength(a)
c=oriSpeakSelect(a, b, no)
#c[0]には選択肢の配列のインデックス
#c[1]には選んだ選択肢に入っている文字列が入っている
#配列で返すとややこしいのでc[0]だけ返すように書いてある
d=c[0]
return d
end


実際のエディタには例えば次のように書く
   hanasu("メイド","私はウィンドウベースの変更を","担当しております") #スピーク文に当たる関数
   a=array2("はい","いいえ") #選択肢の準備
   case choice(a,"メイド\n「ウィンドウベースを変更なさいますか?」") #選択肢をcaseで使う場合
   when 0#はいを選択
      window_choice=array2(1,2,3,"やめる")
      w=choice(window_choice,"メイド\n「ウィンドウ番号を選んでください」") #選択肢をifで使う場合
      if w==3 #やめるを選択
      hanasu("メイド","ウィンドウベースの変更を","中止しました")
      else #やめる以外を選択
        case w
        when 0 #1を選択
          setVariable("oriSpeakWinSprNo", 203458) # ウィンドウの画像のID
          setVariable("oriSpeakWinSize", 18) # ウィンドウの画像のサイズ 3の倍数にしたほうがいい
        when 1 #2を選択
          setVariable("oriSpeakWinSprNo", 310480) # ウィンドウの画像のID
          setVariable("oriSpeakWinSize", 90) # ウィンドウの画像のサイズ # 3の倍数にしたほうがいい 
        when 2 #3を選択
          setVariable("oriSpeakWinSprNo", 310487) # ウィンドウの画像のID
          setVariable("oriSpeakWinSize", 60) # ウィンドウの画像のサイズ # 3の倍数にしたほうがいい 
        else
        end #case
      hanasu("メイド","ウィンドウベースを","変更しました")
      end #if
   when 1 #いいえを選択
   end # case


注意点1
選択肢の配列の一番最初(配列[0])の中身に半角数字の0を設定すると
その選択肢を選ぶことができない(条件はちゃんと突き止めていない)
(カーソルオンでマークが移動するがクリックしても決定扱いにならない)
この場合、英字のオーか全角数字の0で代用するなどの工夫が必要
配列の中に何も入っていない時に選択肢を選べないようにする仕様が関係している?

注意点2.1
キャンパスがビジブルになっていないと文字だけ表示されて枠が表示されない
RPGエディタでは頻繁にキャンパスがリセットされるため、
確実に簡単に枠を表示したい場合、スピーク文を表示するだけの関数を自分で作って
その中にキャンパスをビジブルにする処理を入れたほうがいい

注意点2.2
選択肢も同様の理由で自分で選択肢関数を作ったほうがいい
選択肢に使う配列を用意する際には
cfm_さんの引数から配列を得る関数が便利なので使ったほうがいい

注意点2.3
メッセージを複数立ち上げる時は簡単ウィンドウ関数を使うが、頻繁に使用する場合、
これも同様に、自分で関数を作って中にキャンパスビジブル処理を書いたほうが手間が少ない

注意点3
画面テキストはデフォルトのフェードアウトよりも下のレイヤーにあるので、
デフォルト機能で画面を黒くフェードアウトさせてその上にこの関数で作ったメッセージを表示させることができない
一色フェードアウトをしてその上からメッセージウィンドウ・テキストを表示させるには
cfm_さんのフルカラー画像を使う必要がある

アイデア
オリジナル選択肢関数は見ての通り長い関数です
開始スクリプトに書く場合、他の処理を書いたり編集するのに煩わしくなる場合があるほか
変数や関数をたくさん設定しているゲームの場合はそもそも関数が入りきらない可能性もあります
そこで、大方のゲームに必要な機能を作り終わるまでは
hanasu()関数やchoice()関数の中に普通のspeak(s)やspeakWithSelectArray(a, b)を書いておき
後から関数をコピペ、あるいはコピペできるか検討し可能なら、
oriSpeakText(s)やoriSpeakSelect(a,b,no)に書き換えるという方法がいいかもしれません

コメントする

コメントするには、ログインする必要があります。

コメント一覧

Cdv30200 aoi icon mini aoihikawa(投稿日:2017/01/14 16:58, 履歴)
ぐっと華やかになりますね
            mini mosmoss(投稿日:2017/01/14 18:43, 履歴)
よく目にするものなので、
プレイヤーが好きなウィンドウを選べたら
楽しんでもらえるのではないかと思って
使ってみたかったんです(^ω^)