カレンダー



現在の日付をもとにカレンダーを作成、今日の日付を赤色で表示します。

学園系RPGとか、シミュレーション系のゲームで使えるかも・・・!?

※カレンダーをゲットするだけならなにも要りませんが、表示の際はdraw_text拡張 カスタムが必要です。

変更点
まだなし

#==============================================================================
# ■ カレンダー By 貪藻矢射妥←
# 
#  カレンダーを作ってみました。
#   
#==============================================================================
# 更新っぽいもの
# まだなし

module CALENDAR
  def get_cal(y=0, m=0)
    # 空なら現在の年月を使う
    t = Time.now
    y = t.year if y == 0
    m = t.month if m == 0
    
    list = []
    date = Time.local(y, m, 1)
    # 各月の日数の配列
    days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    # うるう年なら2月の日数+1
    days[1] += 1 if leap?(y)
    # 「月 年」をセンタリングして表示
    #list.push("\\c[s]" + date.strftime("%B %Y").center(20) + "\\c[0]\n")
    # 曜日
    list.push("日 月 火 水 木 金 土\n")
    # 一日の表示位置を調整
    offset = date.wday % 7
    weeks = "   " * offset
    1.upto(days[m-1]) {|n|
      if n == t.day
        weeks += "\\c[2]" + n.to_s.rjust(2) + "\\c[0] "
      else
        weeks += n.to_s.rjust(2) + " "
      end
      # 土曜なら改行
      if(offset + n) % 7 == 0
        weeks += "\n"
        list.push(weeks)
        weeks = ""
      end
    }
    list.push(weeks)
    
    return list
  end
  
  def leap?(year)
    if (year % 4 == 0 && year % 100 != 0) || year % 400 == 0
      return true
    else
      return false
    end
  end
end
〜使い方〜 カレンダーを使いたいclassにて include CALENDAR を追加。 描画させたい場所 にて cal_list = get_cal(あるいはget_cal(年, 月)) for text in cal_list draw_shadow_text([x, y, width, height], transfer(text), color, dflg) end を、追加。 これだけです。 ※描画させた時の日付からカレンダーを制作するので、ゲームプレイ中に、日付が変わった際、再描画を  行わない限り前日の日付が紅く表示されたままとなります。

戻る