From: TimePath Date: Sun, 16 Aug 2015 12:12:23 +0000 (+1000) Subject: Add description pane X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=63c8d9034f6a0c5fba6466289f5b5e96b339ffb1;p=xonotic%2Fxonotic-data.pk3dir.git Add description pane --- diff --git a/qcsrc/menu/xonotic/dialog_media_guide.qc b/qcsrc/menu/xonotic/dialog_media_guide.qc index af818ad2de..fce5c04a4d 100644 --- a/qcsrc/menu/xonotic/dialog_media_guide.qc +++ b/qcsrc/menu/xonotic/dialog_media_guide.qc @@ -93,17 +93,19 @@ ENDCLASS(MapSource) #include "dialog_media_guide_topics.qc" #include "dialog_media_guide_entries.qc" +#include "dialog_media_guide_description.qc" #include "tab.qc" CLASS(XonoticGuideTab, XonoticTab) ATTRIB(XonoticGuideTab, rows, float, 21) ATTRIB(XonoticGuideTab, columns, float, 6) ATTRIB(XonoticGuideTab, intendedWidth, float, 1) METHOD(XonoticGuideTab, fill, void(entity)) - METHOD(XonoticGuideTab, topicChangeNotify, void(entity)) - METHOD(XonoticGuideTab, topicSelectNotify, void(entity)) + METHOD(XonoticGuideTab, topicChangeNotify, void(entity, entity)) + METHOD(XonoticGuideTab, entryChangeNotify, void(entity, entity)) - ATTRIB(XonoticGuideTab, topicList, entity, NEW(XonoticTopicList, NEW(TopicSource), this)) + ATTRIB(XonoticGuideTab, topicList, entity, NEW(XonoticTopicList, NEW(TopicSource))) ATTRIB(XonoticGuideTab, entryList, entity, NEW(XonoticEntryList, NULL)) + ATTRIB(XonoticGuideTab, descriptionPane, entity, NEW(XonoticGuideDescription)) INIT(XonoticGuideTab) { this.configureDialog(this); @@ -116,32 +118,44 @@ ENDCLASS(XonoticGuideTab) void XonoticGuideTab_fill(entity this) { entity topics = this.topicList; + topics.onChange = XonoticGuideTab_topicChangeNotify; + topics.onChangeEntity = this; entity entries = this.entryList; + entries.onChange = XonoticGuideTab_entryChangeNotify; + entries.onChangeEntity = this; entity filter = entries.stringFilterBox = makeXonoticInputBox(false, string_null); filter.keyDown = MapList_StringFilterBox_keyDown; filter.onChange = MapList_StringFilterBox_Change; filter.onChangeEntity = entries; entries.controlledTextbox = filter; + entity description = this.descriptionPane; - this.gotoRC(this, 0, 0); - this.TD(this, 1, 3 / 2, makeXonoticHeaderLabel(_("Topic"))); + int + col = 0, width = 1.5; + this.gotoRC(this, 0, col); + this.TD(this, 1, width, makeXonoticHeaderLabel(_("Topic"))); this.TR(this); - this.TD(this, this.rows - 1, 3 / 2, topics); + this.TD(this, this.rows - 1, width, topics); - this.gotoRC(this, 0, 3 / 2); - this.setFirstColumn(this, this.currentColumn); - this.TD(this, 1, 2, makeXonoticHeaderLabel(_("Entry"))); + col += width, width = 2; + this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn); + this.TD(this, 1, width, makeXonoticHeaderLabel(_("Entry"))); this.TR(this); - this.TD(this, this.rows - 1 - 1, 2, entries); - - this.gotoRC(this, this.rows - 1, this.firstColumn); + this.TD(this, this.rows - 1 - 1, width, entries); + this.gotoRC(this, this.rows - 1, col); this.TD(this, 1, 0.3, makeXonoticTextLabel(0, _("Filter:"))); - this.TD(this, 1, 2 - 0.3, filter); + this.TD(this, 1, width - 0.3, filter); + + col += width, width = 2.5; + this.gotoRC(this, 0, col); this.setFirstColumn(this, this.currentColumn); + this.TD(this, 1, width, makeXonoticHeaderLabel(_("Description"))); + this.TR(this); + this.TD(this, this.rows - 1, width, description); - this.topicChangeNotify(this); + this.topicChangeNotify(topics, this); } -void XonoticGuideTab_topicChangeNotify(entity this) +void XonoticGuideTab_topicChangeNotify(entity, entity this) { entity topics = this.topicList; entity entries = this.entryList; @@ -155,7 +169,11 @@ void XonoticGuideTab_topicChangeNotify(entity this) entries.refilter(entries); } -void XonoticGuideTab_topicSelectNotify(entity this) { this.setFocus(this, this.entryList); } +void XonoticGuideTab_entryChangeNotify(entity, entity this) +{ + entity desc = this.descriptionPane; + desc.setDescription(desc, sprintf("item %.0f\n", this.entryList.selectedItem)); +} entity MapSource_getEntry(int i) { diff --git a/qcsrc/menu/xonotic/dialog_media_guide_description.qc b/qcsrc/menu/xonotic/dialog_media_guide_description.qc new file mode 100644 index 0000000000..9f8bbb8303 --- /dev/null +++ b/qcsrc/menu/xonotic/dialog_media_guide_description.qc @@ -0,0 +1,23 @@ +#ifndef DIALOG_MEDIA_GUIDE_DESCRIPTION_H +#define DIALOG_MEDIA_GUIDE_DESCRIPTION_H +#include "credits.qc" +CLASS(XonoticGuideDescription, XonoticCreditsList) + ATTRIB(XonoticGuideDescription, description, string, string_null) + METHOD(XonoticGuideDescription, setDescription, void(entity, string)) + void XonoticGuideDescription_setDescription(entity this, string desc) + { + string current = this.description; + if (current) strunzone(current); + this.description = strzone(desc); + int n = tokenizebyseparator(desc, "\n"); + this.nItems = n; + } + + METHOD(XonoticGuideDescription, drawListBoxItem, void(entity, int, vector, bool, bool)) + void XonoticGuideDescription_drawListBoxItem(entity this, int i, vector absSize, bool isSelected, bool isFocused) + { + tokenizebyseparator(this.description, "\n"); + draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0); + } +ENDCLASS(XonoticGuideDescription) +#endif diff --git a/qcsrc/menu/xonotic/dialog_media_guide_entries.qc b/qcsrc/menu/xonotic/dialog_media_guide_entries.qc index eede28ba3f..0cc651ce67 100644 --- a/qcsrc/menu/xonotic/dialog_media_guide_entries.qc +++ b/qcsrc/menu/xonotic/dialog_media_guide_entries.qc @@ -23,6 +23,7 @@ CLASS(XonoticEntryList, XonoticListBox) METHOD(XonoticEntryList, keyDown, float(entity, float, float, float)) METHOD(XonoticEntryList, refilter, void(entity)) METHOD(XonoticEntryList, resizeNotify, void(entity, vector, vector, vector, vector)) + METHOD(XonoticEntryList, setSelected, void(entity, int)) ATTRIB(XonoticEntryList, source, DataSource, NULL) @@ -118,4 +119,10 @@ void XonoticEntryList_resizeNotify(entity this, vector relOrigin, vector relSize this.columnNameOrigin = this.columnPreviewOrigin + this.columnPreviewSize + this.realFontSize.x; this.columnNameSize = 1 - this.columnPreviewSize - 2 * this.realFontSize.x; } + +void XonoticEntryList_setSelected(entity this, int i) +{ + super.setSelected(this, i); + this.onChange(this, this.onChangeEntity); +} #endif diff --git a/qcsrc/menu/xonotic/dialog_media_guide_topics.qc b/qcsrc/menu/xonotic/dialog_media_guide_topics.qc index b3845c67bf..aa68a9451e 100644 --- a/qcsrc/menu/xonotic/dialog_media_guide_topics.qc +++ b/qcsrc/menu/xonotic/dialog_media_guide_topics.qc @@ -18,12 +18,10 @@ CLASS(XonoticTopicList, XonoticListBox) METHOD(XonoticTopicList, setSelected, void(entity, int)) ATTRIB(XonoticTopicList, source, DataSource, NULL) - ATTRIB(XonoticTopicList, listener, entity, NULL) - CONSTRUCTOR(XonoticTopicList, DataSource _source, entity _listener) { + CONSTRUCTOR(XonoticTopicList, DataSource _source) { CONSTRUCT(XonoticTopicList); this.source = _source; - this.listener = _listener; this.nItems = _source.reload(""); this.configureXonoticListBox(this); } @@ -62,13 +60,6 @@ bool XonoticTopicList_keyDown(entity this, float scan, float ascii, float shift) { if (scan == K_ENTER || scan == K_KP_ENTER) { m_play_click_sound(MENU_SOUND_EXECUTE); - entity l = this.listener; - if (l) { - void(entity) func = l.topicSelectNotify; - if (func) { - func(l); - } - } return true; } return super.keyDown(this, scan, ascii, shift); @@ -91,12 +82,6 @@ void XonoticTopicList_resizeNotify(entity this, vector relOrigin, vector relSize void XonoticTopicList_setSelected(entity this, int i) { super.setSelected(this, i); - entity l = this.listener; - if (l) { - void(entity) func = l.topicChangeNotify; - if (func) { - func(l); - } - } + this.onChange(this, this.onChangeEntity); } #endif