Skip to content

Commit

Permalink
Merge pull request #17 from elanthia-online/revert-16-revert-14-dr-cu…
Browse files Browse the repository at this point in the history
…stomizations

feat: DragonRealms fork features
  • Loading branch information
mrhoribu authored May 25, 2024
2 parents 0b4ccff + 20b6a07 commit ac4c5f8
Show file tree
Hide file tree
Showing 7 changed files with 694 additions and 7 deletions.
398 changes: 395 additions & 3 deletions profanity.rb

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion templates/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ This layout will dynamically resize windows to an extent
<key id='page_down' action='scroll_current_window_down_page'/>
<key id='up' action='previous_command'/>
<key id='down' action='next_command'/>
<key id='ctrl+up' action='send_last_command'/>
<key id='num_enter' action='send_last_command'/>
<key id='num_1' macro='\xsw\r'/>
<key id='num_2' macro='\xs\r'/>
<key id='num_3' macro='\xse\r'/>
<key id='num_4' macro='\xw\r'/>
<key id='num_5' macro='\xout\r'/>
<key id='num_6' macro='\xe\r'/>
<key id='num_7' macro='\xnw\r'/>
<key id='num_8' macro='\xn\r'/>
<key id='num_9' macro='\xne\r'/>
<key id='alt+up' action='send_second_last_command'/>
<key id='resize' action='resize'/>

Expand Down
11 changes: 10 additions & 1 deletion templates/original.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@
<key id='page_down' action='scroll_current_window_down_page'/>
<key id='up' action='previous_command'/>
<key id='down' action='next_command'/>
<key id='ctrl+up' action='send_last_command'/>
<key id='num_enter' action='send_last_command'/>
<key id='num_1' macro='\xsw\r'/>
<key id='num_2' macro='\xs\r'/>
<key id='num_3' macro='\xse\r'/>
<key id='num_4' macro='\xw\r'/>
<key id='num_5' macro='\xout\r'/>
<key id='num_6' macro='\xe\r'/>
<key id='num_7' macro='\xnw\r'/>
<key id='num_8' macro='\xn\r'/>
<key id='num_9' macro='\xne\r'/>
<key id='alt+up' action='send_second_last_command'/>
<key id='resize' action='resize'/>
<key id='ctrl+d' macro='\\xstance defensive\\r'/>
Expand Down
11 changes: 10 additions & 1 deletion templates/tysong.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ Includes preset highlight colors for merchants/GMs/staff, wizards, sorcerers, em
<key id='page_down' action='scroll_current_window_down_page'/>
<key id='up' action='previous_command'/>
<key id='down' action='next_command'/>
<key id='ctrl+up' action='send_last_command'/>
<key id='num_enter' action='send_last_command'/>
<key id='num_1' macro='\xsw\r'/>
<key id='num_2' macro='\xs\r'/>
<key id='num_3' macro='\xse\r'/>
<key id='num_4' macro='\xw\r'/>
<key id='num_5' macro='\xout\r'/>
<key id='num_6' macro='\xe\r'/>
<key id='num_7' macro='\xnw\r'/>
<key id='num_8' macro='\xn\r'/>
<key id='num_9' macro='\xne\r'/>
<key id='alt+up' action='send_second_last_command'/>
<key id='resize' action='resize'/>

Expand Down
159 changes: 159 additions & 0 deletions ui/exp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
class Skill
def initialize(name, ranks, percent, mindstate)
@name = name
@ranks = ranks
@percent = percent
@mindstate = mindstate
end

def to_s
format('%8s:%5d %2s%% [%2s/34]', @name, @ranks, @percent, @mindstate)
end

def to_str
format('%8s:%5d %2s%% [%2s/34]', @name, @ranks, @percent, @mindstate)
end
end

class ExpWindow < Curses::Window
attr_reader :color_stack, :buffer
attr_accessor :scrollbar, :indent_word_wrap, :layout, :time_stamp

@@list = []

def self.list
@@list
end

def initialize(*args)
@skills = {}
@open = false
@@list.push(self)
super(*args)
end

def delete_skill
return unless @current_skill

@skills.delete(@current_skill)
redraw
@current_skill = ''
end

def set_current(skill)
@current_skill = skill
end

def add_string(text, _line_colors)
return unless text =~ %r{(.+):\s*(\d+) (\d+)% \[\s*(\d+)/34\]}

# if text =~ /(\w+(\s\w+)?)<\/d>:\s+(\d+)(?:\s+)(\d{1,2}|100)%\s+\[\s?(\d+)\/34\]/
name = ::Regexp.last_match(1).strip
ranks = ::Regexp.last_match(2)
percent = ::Regexp.last_match(3)
mindstate = ::Regexp.last_match(4)

skill = Skill.new(name, ranks, percent, mindstate)
@skills[@current_skill] = skill
redraw
@current_skill = ''
end

def skill_group_color(skill)
armor = ['Shield', 'Lt Armor', 'Chain', 'Brig', 'Plate', 'Defend', 'Convict']

weapon = %w[Parry SE LE 2HE SB LB 2HB Slings Bows Crossbow Staves Polearms LT HT Brawling Offhand Melee Missile
Expert]

magic = %w[Magic IF IM Attune Arcana TM Aug Debil Util Warding Sorcery Astro Summon Theurgy]

survival = %w[Evasion Athletic Perc Stealth Locks Thievery FA Outdoors Skinning BS Scouting Than Backstab]

lore = %w[Forging Eng Outfit Alchemy Enchant Scholar Mech Appraise Perform Tactics BardLore Empathy Trading]

if armor.include? skill
'00FF00' # green
elsif weapon.include? skill
'00FFFF' # cyan
elsif magic.include? skill
'FF0000' # red
elsif survival.include? skill
'FF00FF' # magenta
elsif lore.include? skill
'FFFF00' # yellow
end
end

def mindstate_color(mindstate)
if mindstate == 0
'FFFFFF' # white
elsif (1..10).member?(mindstate)
'00FFFF' # cyan
elsif (11..20).member?(mindstate)
'00FF00' # green
elsif (21..30).member?(mindstate)
'FFFF00' # yellow
elsif (31..34).member?(mindstate)
'FF0000' # red
end
end

def add_skill(skill, skill_colors = [])
SETTINGS_LOCK.synchronize do
HIGHLIGHT.each_pair do |regex, colors|
pos = 0
while (match_data = skill.match(regex, pos))
h = {
start: match_data.begin(0),
end: match_data.end(0),
fg: colors[0],
bg: colors[1],
ul: colors[2]
}
skill_colors.push(h)
pos = match_data.end(0)
end
end
end

# addstr skill
part = [0, skill.length]
skill_colors.each do |h|
part.push(h[:start])
part.push(h[:end])
end
part.uniq!
part.sort!
for i in 0...(part.length - 1)
str = skill[part[i]...part[i + 1]]
color_list = skill_colors.find_all { |h| (h[:start] <= part[i]) and (h[:end] >= part[i + 1]) }
if color_list.empty?
addstr str
noutrefresh
else
color_list = color_list.sort_by { |h| h[:end] - h[:start] }
fg = color_list.map { |h| h[:fg] }.find { |foreground| !foreground.nil? }
bg = color_list.map { |h| h[:bg] }.find { |background| !background.nil? }
ul = color_list.map { |h| h[:ul] == 'true' }.find { |underline| underline }
attron(color_pair(get_color_pair_id(fg, bg)) | (ul ? Curses::A_UNDERLINE : Curses::A_NORMAL)) do
addstr str
noutrefresh
end
end
end
end

def redraw
clear
setpos(0, 0)

@skills.sort.each do |_name, skill|
# addstr skill.to_s + "\n"
add_skill(skill.to_s)
# addstr(skill)
addstr("\n")
noutrefresh
end
noutrefresh
end
end
108 changes: 108 additions & 0 deletions ui/perc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
class PercWindow < Curses::Window
attr_reader :color_stack, :buffer
attr_accessor :scrollbar, :indent_word_wrap, :layout, :time_stamp

@@list = []

def ExpWindow.list
@@list
end

def initialize(*args)
@buffer = []
@buffer_pos = 0
@max_buffer_size = 250
@indent_word_wrap = true
@@list.push(self)
super(*args)
end

def add_line(line, line_colors = [])
part = [0, line.length]
line_colors.each do |h|
part.push(h[:start])
part.push(h[:end])
end
part.uniq!
part.sort!
for i in 0...(part.length - 1)
str = line[part[i]...part[i + 1]]
color_list = line_colors.find_all { |h| (h[:start] <= part[i]) and (h[:end] >= part[i + 1]) }
if color_list.empty?
addstr str + "\n" unless str.chomp.empty?
noutrefresh
else
# shortest length highlight takes precedence when multiple highlights cover the same substring
# fixme: allow multiple highlights on a substring when one specifies fg and the other specifies bg
color_list = color_list.sort_by { |h| h[:end] - h[:start] }
fg = color_list.map { |h| h[:fg] }.find { |foreground| !foreground.nil? }
bg = color_list.map { |h| h[:bg] }.find { |background| !background.nil? }
ul = color_list.map { |h| h[:ul] == 'true' }.find { |underline| underline }
attron(color_pair(get_color_pair_id(fg, bg)) | (ul ? Curses::A_UNDERLINE : Curses::A_NORMAL)) do
addstr str + "\n" unless str.chomp.empty?
noutrefresh
end
end
noutrefresh
end
end

def add_string(string, string_colors = [])
while (line = string.slice!(/^.{2,#{maxx - 1}}(?=\s|$)/)) or (line = string.slice!(0, (maxx - 1)))
line_colors = []
for h in string_colors
line_colors.push(h.dup) if h[:start] < line.length
h[:end] -= line.length
h[:start] = [(h[:start] - line.length), 0].max
end
string_colors.delete_if { |highlight| highlight[:end] < 0 }
line_colors.each { |highlight| highlight[:end] = [highlight[:end], line.length].min }
@buffer.unshift([line, line_colors])
@buffer.pop if @buffer.length > @max_buffer_size
if @buffer_pos == 0
add_line(line, line_colors)
# addstr "\n"
else
@buffer_pos += 1
scroll(1) if @buffer_pos > (@max_buffer_size - maxy)
update_scrollbar
end
break if string.chomp.empty?

if @indent_word_wrap
if string[0, 1] == ' '
string = " #{string}"
string_colors.each do |highlight|
highlight[:end] += 1
# Never let the highlighting hang off the edge -- it looks weird
highlight[:start] += highlight[:start] == 0 ? 2 : 1
end
else
string = "#{string}"
string_colors.each do |highlight|
highlight[:end] += 2
highlight[:start] += 2
end
end
elsif string[0, 1] == ' '
string = string[1, string.length]
string_colors.each do |highlight|
highlight[:end] -= 1
highlight[:start] -= 1
end
end
end
end

def redraw
clear
setpos(0, 0)
noutrefresh
end

def clear_window
clear
setpos(0, 0)
noutrefresh
end
end
3 changes: 2 additions & 1 deletion ui/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TextWindow < Curses::Window
attr_reader :color_stack, :buffer
attr_accessor :scrollbar, :indent_word_wrap, :layout
attr_accessor :scrollbar, :indent_word_wrap, :layout, :time_stamp

@@list = Array.new

Expand Down Expand Up @@ -57,6 +57,7 @@ def add_string(string, string_colors = Array.new)
#
# word wrap string, split highlights if needed so each wrapped line is independent, update buffer, update window if needed
#
string += " [#{Time.now.hour.to_s.rjust(2, '0')}:#{Time.now.min.to_s.rjust(2, '0')}]" if @time_stamp && string && !string.chomp.empty?
while (line = string.slice!(/^.{2,#{maxx - 1}}(?=\s|$)/)) or (line = string.slice!(0, (maxx - 1)))
line_colors = Array.new
for h in string_colors
Expand Down

0 comments on commit ac4c5f8

Please sign in to comment.