]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Wrap the description
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 17 Aug 2015 06:16:37 +0000 (16:16 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 17 Aug 2015 06:16:37 +0000 (16:16 +1000)
qcsrc/common/oo.qh
qcsrc/menu/xonotic/dialog_media_guide_description.qc

index b7ed3bbe2e7dff2365097cbde24c72928ba4360f..1e167933512c5ed36aa0147014cdf49305a3de7a 100644 (file)
@@ -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
index 4a09ba4608338795fe7ebb4c3d43c5a9319c215c..33462e52638e13b253e5fecba57ced921d35e091 100644 (file)
@@ -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)