1 // This file is part of GtkEveMon.
2 //
3 // GtkEveMon is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // You should have received a copy of the GNU General Public License
9 // along with GtkEveMon. If not, see <http://www.gnu.org/licenses/>.
10
11 #include <gtkmm.h>
12
13 #include "util/helpers.h"
14 #include "api/apiskilltree.h"
15 #include "gtkdefines.h"
16 #include "guiskill.h"
17
GuiSkill(void)18 GuiSkill::GuiSkill (void)
19 : desc_buffer(Gtk::TextBuffer::create()), skill_desc(desc_buffer)
20 {
21 this->skill_desc.set_wrap_mode(Gtk::WRAP_WORD);
22 this->skill_desc.set_editable(false);
23 this->skill_name.set_selectable(true);
24 this->skill_name.set_halign(Gtk::ALIGN_START);
25 this->group_name.set_selectable(true);
26 this->group_name.set_halign(Gtk::ALIGN_START);
27 this->skill_attribs.set_selectable(true);
28 this->skill_attribs.set_halign(Gtk::ALIGN_START);
29 this->skill_id.set_halign(Gtk::ALIGN_END);
30 this->group_id.set_halign(Gtk::ALIGN_END);
31
32 Gtk::Label* skill_name_desc = MK_LABEL("Skill name:");
33 Gtk::Label* group_name_desc = MK_LABEL("Skill group:");
34 Gtk::Label* skill_attribs_desc = MK_LABEL("Attributes:");
35 skill_name_desc->set_halign(Gtk::ALIGN_START);
36 group_name_desc->set_halign(Gtk::ALIGN_START);
37 skill_attribs_desc->set_halign(Gtk::ALIGN_START);
38
39 Gtk::Table* info_table = MK_TABLE(3, 3);
40 info_table->set_col_spacings(5);
41 info_table->set_row_spacings(5);
42 info_table->attach(*skill_name_desc, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK);
43 info_table->attach(*group_name_desc, 0, 1, 1, 2, Gtk::FILL, Gtk::SHRINK);
44 info_table->attach(*skill_attribs_desc, 0, 1, 2, 3, Gtk::FILL, Gtk::SHRINK);
45 info_table->attach(this->skill_name, 1, 2, 0, 1,
46 Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK);
47 info_table->attach(this->group_name, 1, 2, 1, 2,
48 Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK);
49 info_table->attach(this->skill_attribs, 1, 3, 2, 3,
50 Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK);
51 info_table->attach(this->skill_id, 2, 3, 0, 1, Gtk::FILL);
52 info_table->attach(this->group_id, 2, 3, 1, 2, Gtk::FILL);
53
54 Gtk::Box* desc_separator = MK_HBOX(5);
55 desc_separator->pack_start(*MK_HSEP, true, true, 0);
56 desc_separator->pack_start(*MK_LABEL("Description"), false, false, 0);
57 desc_separator->pack_start(*MK_HSEP, true, true, 0);
58
59 Gtk::ScrolledWindow* desc_scwin = Gtk::manage(new Gtk::ScrolledWindow);
60 desc_scwin->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
61 desc_scwin->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
62 desc_scwin->add(this->skill_desc);
63
64 Gtk::Box* skill_vbox = MK_VBOX(5);
65 skill_vbox->set_border_width(5);
66 skill_vbox->pack_start(*info_table, false, false, 0);
67 skill_vbox->pack_start(*desc_separator, false, false, 0);
68 skill_vbox->pack_start(*desc_scwin, true, true, 0);
69
70 Gtk::Frame* info_frame = MK_FRAME0;
71 info_frame->set_shadow_type(Gtk::SHADOW_OUT);
72 info_frame->add(*skill_vbox);
73
74 Gtk::Button* close_but = MK_BUT0;
75 close_but->set_image_from_icon_name("window-close", Gtk::ICON_SIZE_BUTTON);
76 Gtk::Box* button_box = MK_HBOX(5);
77 button_box->pack_start(*MK_HSEP, true, true, 0);
78 button_box->pack_start(*close_but, false, false, 0);
79
80 Gtk::Box* main_vbox = MK_VBOX(5);
81 main_vbox->set_border_width(5);
82 main_vbox->pack_start(*info_frame, true, true, 0);
83 main_vbox->pack_end(*button_box, false, false, 0);
84
85 close_but->signal_clicked().connect(sigc::mem_fun(*this, &WinBase::close));
86
87 this->add(*main_vbox);
88 this->set_title("Skill Details");
89 this->set_default_size(350, 300);
90 this->show_all();
91 }
92
93 /* ---------------------------------------------------------------- */
94
95 void
set_skill(int skill_id)96 GuiSkill::set_skill (int skill_id)
97 {
98 this->skill_id.set_text("ID " + Helpers::get_string_from_int(skill_id));
99 this->group_id.set_text("---");
100 this->group_name.set_text("---");
101 this->skill_attribs.set_text("---");
102
103 ApiSkill const* skill = 0;
104 ApiSkillGroup const* group = 0;
105 try
106 {
107 ApiSkillTreePtr tree = ApiSkillTree::request();
108 skill = tree->get_skill_for_id(skill_id);
109 if (skill != 0)
110 group = tree->get_group_for_id(skill->group);
111 }
112 catch (...)
113 {
114 }
115
116 if (skill == 0)
117 {
118 this->skill_name.set_text("Unknown skill!");
119 return;
120 }
121
122 this->skill_name.set_text(skill->name + " ("
123 + Helpers::get_string_from_int(skill->rank) + ")");
124 this->skill_attribs.set_text(ApiSkillTree::get_attrib_name(skill->primary)
125 + std::string(" / ") + ApiSkillTree::get_attrib_name(skill->secondary));
126 this->desc_buffer->set_text(skill->desc);
127
128 int group_id = skill->group;
129 this->group_id.set_text("ID " + Helpers::get_string_from_int(group_id));
130 if (group == 0)
131 {
132 this->group_name.set_text("Unknown group!");
133 return;
134 }
135 this->group_name.set_text(group->name);
136
137 this->set_title("Skill Details: " + skill->name + " ("
138 + Helpers::get_string_from_int(skill->rank) + ")");
139 }
140