From 5ac0ba43e6ceb0592b0c23cb63ffd9a57c9c18c7 Mon Sep 17 00:00:00 2001 From: TimePath Date: Mon, 17 Aug 2015 16:16:37 +1000 Subject: [PATCH] Wrap the description --- qcsrc/common/oo.qh | 2 ++ .../xonotic/dialog_media_guide_description.qc | 25 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/qcsrc/common/oo.qh b/qcsrc/common/oo.qh index b7ed3bbe2e..1e16793351 100644 --- a/qcsrc/common/oo.qh +++ b/qcsrc/common/oo.qh @@ -118,7 +118,9 @@ STATIC_INIT(RegisterClasses) { RegisterClasses(); } #define _vtbl NULL CLASS(Object, ); METHOD(Object, describe, string(entity this)) + string Object_describe(entity) { return string_null; } METHOD(Object, display, void(entity this, void(string name, string icon) returns)) + void Object_display(entity, void(string, string)) { } ENDCLASS(Object) #undef spawn_static #undef spawn_1 diff --git a/qcsrc/menu/xonotic/dialog_media_guide_description.qc b/qcsrc/menu/xonotic/dialog_media_guide_description.qc index 4a09ba4608..33462e5263 100644 --- a/qcsrc/menu/xonotic/dialog_media_guide_description.qc +++ b/qcsrc/menu/xonotic/dialog_media_guide_description.qc @@ -5,6 +5,9 @@ CLASS(XonoticGuideDescription, XonoticListBox) ATTRIB(XonoticGuideDescription, rowsPerItem, float, 1) ATTRIB(XonoticGuideDescription, selectionDoesntMatter, bool, true) + METHOD(XonoticGuideDescription, setDescription, void(entity, string)) + ATTRIB(XonoticGuideDescription, description, string, string_null) + METHOD(XonoticGuideDescription, resizeNotify, void(entity, vector, vector, vector, vector)) void XonoticGuideDescription_resizeNotify(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize) { @@ -13,27 +16,37 @@ CLASS(XonoticGuideDescription, XonoticListBox) this.realFontSize_y = this.fontSize / (absSize.y * this.itemHeight); this.realFontSize_x = this.fontSize / (absSize.x * (1 - this.controlWidth)); this.realUpperMargin = 0.5 * (1 - this.realFontSize.y); + this.setDescription(this, this.description); } INIT(XonoticGuideDescription) { this.configureXonoticListBox(this); } - ATTRIB(XonoticGuideDescription, description, string, string_null) - METHOD(XonoticGuideDescription, setDescription, void(entity, string)) + ATTRIB(XonoticGuideDescription, descriptionWrapped, string, string_null) void XonoticGuideDescription_setDescription(entity this, string desc) { string current = this.description; - if (current) strunzone(current); + if (current && current != desc) strunzone(current); this.description = strzone(desc); - int n = tokenizebyseparator(desc, "\n"); - this.nItems = n; + + string currentWrapped = this.descriptionWrapped; + if (currentWrapped) strunzone(currentWrapped); + string wrapped = ""; + for (getWrappedLine_remaining = desc; getWrappedLine_remaining; ) { + // FIXME: calculate this + string s = getWrappedLine(1.275, this.realFontSize, draw_TextWidth_WithColors); + wrapped = sprintf("%s\n%s", wrapped, s); + } + this.descriptionWrapped = strzone(wrapped); + + this.nItems = tokenizebyseparator(wrapped, "\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"); + tokenizebyseparator(this.descriptionWrapped, "\n"); draw_Text(this.realUpperMargin * eY, argv(i), this.realFontSize, '1 1 1', 1, 0); } ENDCLASS(XonoticGuideDescription) -- 2.39.2