Skip to content

Commit

Permalink
working on stats and races tab.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcuhljr committed Feb 23, 2013
1 parent cba977d commit 05cc162
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
*.db
*.pcf
*.pcf
doc/*
8 changes: 8 additions & 0 deletions campaign.rb
@@ -0,0 +1,8 @@
# Data wrapper for a character

class Campaign
attr_accessor :name, :pointbuy
def initialize()
end

end
2 changes: 1 addition & 1 deletion character.rb
@@ -1,7 +1,7 @@
# Data wrapper for a character

class Character
attr_accessor :name, :player, :alignment
attr_accessor :name, :player, :alignment, :gender
def initialize()
end

Expand Down
20 changes: 19 additions & 1 deletion datacontainer.rb
Expand Up @@ -44,12 +44,30 @@ def create_table_from_file( file, path )
end
end

# Return alignments [name, abbrev, id]
# Returns alignments [name, abbrev, id]

def get_alignments
if @alignments.nil?
@alignments = @db.execute( "Select name, abbrev, id from tblalignments")
end
return @alignments
end

# Returns pointbuys [type, id]

def get_pointbuys
if @pointbuys.nil?
@pointbuys = @db.execute( "Select type, id from tblpointbuys" )
end
return @pointbuys
end

# Returns genders [name, abbrev, id]

def get_genders
if @genders.nil?
@genders = @db.execute( "Select name, abbrev, id from tblgenders" )
end
return @genders
end
end
28 changes: 28 additions & 0 deletions dbsources/attributes.yml
@@ -0,0 +1,28 @@
--- #attributes
tablequery: >
CREATE TABLE tblattributes
(
id int,
name varchar(40),
abbrev varchar(40)
);
attributes:
- name: Strength
abbrev: STR
id: 1
- name: Dexterity
abbrev: DEX
id: 2
- name: Constitution
abbrev: CON
id: 3
- name: Intelligence
abbrev: INT
id: 4
- name: Wisdom
abbrev: WIS
id: 5
- name: Charisma
abbrev: CHA
id: 6
19 changes: 19 additions & 0 deletions dbsources/genders.yml
@@ -0,0 +1,19 @@
--- #genders
tablequery: >
CREATE TABLE tblgenders
(
id int,
name varchar(40),
abbrev varchar(4)
);
genders:
- name: Male
abbrev: M
id: 1
- name: Female
abbrev: F
id: 2
- name: Unspecified
abbrev: UN
id: 3
19 changes: 19 additions & 0 deletions dbsources/pointbuys.yml
@@ -0,0 +1,19 @@
--- #pointbuys
tablequery: >
CREATE TABLE tblpointbuys
(
id int,
type varchar(40)
);
pointbuys:
- type: 10
id: 1
- type: 15
id: 2
- type: 20
id: 3
- type: 25
id: 4
- type: Rolled
id: 5
19 changes: 18 additions & 1 deletion logicprocess.rb
Expand Up @@ -32,11 +32,28 @@ def open_character(filename)
@char = @dm.load(filename)
end

# Return an array of alignments
# Returns an array of alignments

def get_alignments
alignments = []
@dc.get_alignments.each {|alignment| alignments.push(alignment[0]) }
return alignments
end

# Returns an array of point buys

def get_pointbuys
pointbuys = []
@dc.get_pointbuys.each {|pointbuy| pointbuys.push(alignment[0]) }
return pointbuys
end

# Returns an array of genders

def get_genders
genders = []
@dc.get_genders.each {|gender| genders.push(gender[0]) }
return genders
end

end
43 changes: 3 additions & 40 deletions main.rb
Expand Up @@ -6,6 +6,7 @@
require 'logger'
load 'datamanager.rb'
load 'logicprocess.rb'
load 'racestatstab.rb'

# Main GUI for the program, contains all of our UI code.

Expand All @@ -28,6 +29,7 @@ def initialize(logger)

@char_file_filter = Gtk::FileFilter.new
@char_file_filter.add_pattern("*.pcf")
@race_stats_tab = RaceStatsTab.new(@log, @process)

content = Gtk::VBox.new(homogeneous = false, spacing = nil)
@main_content = Gtk::VBox.new(homogeneous = false, spacing = nil)
Expand Down Expand Up @@ -83,7 +85,7 @@ def reset_view

tab_holder = Gtk::Notebook.new

build_race_stats(tab_holder, char)
@race_stats_tab.build_race_stats(tab_holder, char)

tab_holder.append_page(Gtk::Label.new("Lorem Ipsum"), Gtk::Label.new("Other"))

Expand All @@ -92,45 +94,6 @@ def reset_view
@main_content.show_all
end

# build the race and stats tab

def build_race_stats(tab_holder, char)
tab_label = Gtk::Label.new("Race & Stats")

name_label = Gtk::Label.new("Character Name:")
name_entry = Gtk::Entry.new()
name_entry.text = char.name unless char.name.nil?

player_label = Gtk::Label.new("Player Name:")
player_entry = Gtk::Entry.new()
player_entry.text = char.player unless char.player.nil?

alignment_label = Gtk::Label.new("Alignment:")
alignment_entry = Gtk::ComboBox.new(is_text_only = true)
@process.get_alignments.each_with_index do |align_text, index|
alignment_entry.append_text(align_text)
alignment_entry.set_active(index) if align_text == char.alignment
end

race_stats_box = Gtk::VBox.new(homogeneous = false, spacing = nil)
header_row = Gtk::HBox.new(homogeneous = false, spacing = nil)

header_row.pack_start(name_label, false, false, 2)
header_row.pack_start(name_entry, false, false, 2)
header_row.pack_start(player_label, false, false, 2)
header_row.pack_start(player_entry, false, false, 2)
header_row.pack_start(alignment_label, false, false, 2)
header_row.pack_start(alignment_entry, false, false, 2)

name_entry.signal_connect("changed") { |e| char.name = e.text }
player_entry.signal_connect("changed") { |e| char.player = e.text }
alignment_entry.signal_connect("changed") { |e| char.alignment = e.active_text }

race_stats_box.pack_start(header_row, false, false, 0)

tab_holder.append_page(race_stats_box, tab_label)
end

# method for handling the new character menu option and key shortcuts.

def new_character
Expand Down
160 changes: 160 additions & 0 deletions racestatstab.rb
@@ -0,0 +1,160 @@
class RaceStatsTab
def initialize(logger, process)
@log = logger
@process = process;
end

# build the race and stats tab

def build_race_stats(tab_holder, char)
tab_label = Gtk::Label.new("Race & Stats")

race_stats_box = Gtk::VBox.new(homogeneous = false, spacing = nil)
header_row = Gtk::HBox.new(homogeneous = false, spacing = nil)
stats_box = Gtk::Table.new(rows = 7, columns = 6, homogeneous = false)

build_header_row(char, header_row)

race_stats_box.pack_start(header_row, false, false, 0)

build_stats_box(char, stats_box)

race_stats_box.pack_start(stats_box, false, false, 10)

tab_holder.append_page(race_stats_box, tab_label)
end

def build_header_row(char, header_row)
name_label = Gtk::Label.new("Character Name:")
name_entry = Gtk::Entry.new()
name_entry.text = char.name unless char.name.nil?

player_label = Gtk::Label.new("Player Name:")
player_entry = Gtk::Entry.new()
player_entry.text = char.player unless char.player.nil?

alignment_label = Gtk::Label.new("Alignment:")
alignment_entry = Gtk::ComboBox.new(is_text_only = true)
@process.get_alignments.each_with_index do |align_text, index|
alignment_entry.append_text(align_text)
alignment_entry.set_active(index) if align_text == char.alignment
end

gender_label= Gtk::Label.new("Gender:")
gender_entry = Gtk::ComboBox.new(is_text_only = true)
@process.get_genders.each_with_index do |gender_text, index|
gender_entry.append_text(gender_text)
gender_entry.set_active(index) if gender_text == char.gender
end

header_row.pack_start(name_label, false, false, 2)
header_row.pack_start(name_entry, false, false, 2)
header_row.pack_start(player_label, false, false, 2)
header_row.pack_start(player_entry, false, false, 2)
header_row.pack_start(alignment_label, false, false, 2)
header_row.pack_start(alignment_entry, false, false, 2)
header_row.pack_start(gender_label, false, false, 2)
header_row.pack_start(gender_entry, false, false, 2)

name_entry.signal_connect("changed") { |e| char.name = e.text }
player_entry.signal_connect("changed") { |e| char.player = e.text }
alignment_entry.signal_connect("changed") { |e| char.alignment = e.active_text }
gender_entry.signal_connect("changed") { |e| char.gender = e.active_text }
end

def build_stats_box(char, stats_box)

spin_entries = []
spin_entries.push(Gtk::Label.new("Score"))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))
spin_entries.push(Gtk::SpinButton.new(3.0, 90.0, 1.0))

spin_entries.each { |entry|
next unless entry.is_a? Gtk::SpinButton
entry.value = 10
}

labels = []
labels.push(Gtk::Label.new(""))
labels.push(Gtk::Label.new("STR"))
labels.push(Gtk::Label.new("DEX"))
labels.push(Gtk::Label.new("CON"))
labels.push(Gtk::Label.new("INT"))
labels.push(Gtk::Label.new("WIS"))
labels.push(Gtk::Label.new("CHA"))

race_entries = []
race_entries.push(Gtk::Label.new("Race"))
race_entries.push(Gtk::Entry.new())
race_entries.push(Gtk::Entry.new())
race_entries.push(Gtk::Entry.new())
race_entries.push(Gtk::Entry.new())
race_entries.push(Gtk::Entry.new())
race_entries.push(Gtk::Entry.new())

race_entries.each { |entry|
next unless entry.is_a? Gtk::Entry
entry.editable = false
entry.width_chars = 3
}

misc_entries = []
misc_entries.push(Gtk::Label.new("Misc"))
misc_entries.push(Gtk::Entry.new())
misc_entries.push(Gtk::Entry.new())
misc_entries.push(Gtk::Entry.new())
misc_entries.push(Gtk::Entry.new())
misc_entries.push(Gtk::Entry.new())
misc_entries.push(Gtk::Entry.new())

misc_entries.each { |entry|
next unless entry.is_a? Gtk::Entry
entry.editable = false
entry.width_chars = 3
}

total_entries = []
total_entries.push(Gtk::Label.new("Total"))
total_entries.push(Gtk::Entry.new())
total_entries.push(Gtk::Entry.new())
total_entries.push(Gtk::Entry.new())
total_entries.push(Gtk::Entry.new())
total_entries.push(Gtk::Entry.new())
total_entries.push(Gtk::Entry.new())

total_entries.each { |entry|
next unless entry.is_a? Gtk::Entry
entry.editable = false
entry.width_chars = 3
}


bonus_entries = []
bonus_entries.push(Gtk::Label.new("Bonus"))
bonus_entries.push(Gtk::Entry.new())
bonus_entries.push(Gtk::Entry.new())
bonus_entries.push(Gtk::Entry.new())
bonus_entries.push(Gtk::Entry.new())
bonus_entries.push(Gtk::Entry.new())
bonus_entries.push(Gtk::Entry.new())

bonus_entries.each { |entry|
next unless entry.is_a? Gtk::Entry
entry.editable = false
entry.width_chars = 3
}

labels.each_with_index { |entry, index| stats_box.attach(entry, 0, 1, index, index+1, 0, 0, 5, 0) }
spin_entries.each_with_index { |entry, index| stats_box.attach(entry, 1, 2, index, index+1, 0, 0, 5, 0) }
race_entries.each_with_index { |entry, index| stats_box.attach(entry, 2, 3, index, index+1, 0, 0, 5, 0) }
misc_entries.each_with_index { |entry, index| stats_box.attach(entry, 3, 4, index, index+1, 0, 0, 5, 0) }
total_entries.each_with_index { |entry, index| stats_box.attach(entry, 4, 5, index, index+1, 0, 0, 5, 0) }
bonus_entries.each_with_index { |entry, index| stats_box.attach(entry, 5, 6, index, index+1, 0, 0, 5, 0) }

end

end

0 comments on commit 05cc162

Please sign in to comment.