]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_multiplayer_media_screenshot_viewer.qc
3a2f90091267ba92e81bb63fb3a6825441c3093a
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_multiplayer_media_screenshot_viewer.qc
1 #include "dialog_multiplayer_media_screenshot_viewer.qh"
2 #ifndef DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
3 #define DIALOG_MULTIPLAYER_MEDIA_SCREENSHOT_VIEWER_H
4 #include "dialog.qc"
5 CLASS(XonoticScreenshotViewerDialog, XonoticDialog)
6         METHOD(XonoticScreenshotViewerDialog, fill, void(entity));
7         METHOD(XonoticScreenshotViewerDialog, keyDown, float(entity, float, float, float));
8         METHOD(XonoticScreenshotViewerDialog, loadScreenshot, void(entity, string));
9         METHOD(XonoticScreenshotViewerDialog, close, void(entity));
10         ATTRIB(XonoticScreenshotViewerDialog, title, string, "Screenshot Viewer")
11         ATTRIB(XonoticScreenshotViewerDialog, name, string, "ScreenshotViewer")
12         ATTRIB(XonoticScreenshotViewerDialog, intendedWidth, float, 1)
13         ATTRIB(XonoticScreenshotViewerDialog, rows, float, 25)
14         ATTRIB(XonoticScreenshotViewerDialog, columns, float, 4)
15         ATTRIB(XonoticScreenshotViewerDialog, color, vector, SKINCOLOR_DIALOG_SCREENSHOTVIEWER)
16         ATTRIB(XonoticScreenshotViewerDialog, scrList, entity, NULL)
17         ATTRIB(XonoticScreenshotViewerDialog, screenshotImage, entity, NULL)
18         ATTRIB(XonoticScreenshotViewerDialog, slideShowButton, entity, NULL)
19         ATTRIB(XonoticScreenshotViewerDialog, currentScrPath, string, string_null)
20 ENDCLASS(XonoticScreenshotViewerDialog)
21 #endif
22
23 #ifdef IMPLEMENTATION
24 float music_playlist_index_backup;
25 void XonoticScreenshotViewerDialog_loadScreenshot(entity me, string scrImage)
26 {
27         // disable music as it can lag depending on image loading time
28         if(!cvar("menu_screenshotviewer_enablemusic"))
29         if(cvar("music_playlist_index") != 999) // if the playlist isn't paused
30         {
31                 // pause music
32                 if(cvar("music_playlist_index") != -1)
33                 {
34                         music_playlist_index_backup = cvar("music_playlist_index");
35                         cvar_set("music_playlist_sampleposition0", "0");
36                         cvar_set("music_playlist_index", "999");
37                 }
38                 else
39                         localcmd("\ncd pause\n");
40         }
41
42         if (me.currentScrPath == scrImage)
43                 return;
44         if (me.currentScrPath)
45                 strunzone(me.currentScrPath);
46         me.currentScrPath = strzone(scrImage);
47         me.screenshotImage.load(me.screenshotImage, me.currentScrPath);
48         me.frame.setText(me.frame, me.screenshotImage.screenshotTitle);
49 }
50 void prevScreenshot_Click(entity btn, entity me)
51 {
52         me.scrList.goScreenshot(me.scrList, -1);
53 }
54 void nextScreenshot_Click(entity btn, entity me)
55 {
56         me.scrList.goScreenshot(me.scrList, +1);
57 }
58 void increaseZoom_Click(entity btn, entity me)
59 {
60         me.screenshotImage.setZoom(me.screenshotImage, -2, false);
61 }
62 void decreaseZoom_Click(entity btn, entity me)
63 {
64         me.screenshotImage.setZoom(me.screenshotImage, -1/2, false);
65 }
66 void resetZoom_Click(entity btn, entity me)
67 {
68         me.screenshotImage.setZoom(me.screenshotImage, 0, false);
69 }
70 void toggleSlideShow_Click(entity btn, entity me)
71 {
72         if (me.slideShowButton.forcePressed)
73         {
74                 me.scrList.stopSlideShow(me.scrList);
75                 me.slideShowButton.forcePressed = 0;
76         }
77         else
78         {
79                 me.scrList.startSlideShow(me.scrList);
80                 me.slideShowButton.forcePressed = 1;
81         }
82 }
83 float XonoticScreenshotViewerDialog_keyDown(entity me, float key, float ascii, float shift)
84 {
85         switch(key)
86         {
87                 case K_KP_LEFTARROW:
88                 case K_LEFTARROW:
89                         me.scrList.goScreenshot(me.scrList, -1);
90                         return 1;
91                 case K_KP_RIGHTARROW:
92                 case K_RIGHTARROW:
93                         me.scrList.goScreenshot(me.scrList, +1);
94                         return 1;
95                 case K_KP_ENTER:
96                 case K_ENTER:
97                 case K_SPACE:
98                         // we cannot use SPACE/ENTER directly, as in a dialog they are needed
99                         // to press buttons while browsing with only the keyboard
100                         if (shift & S_CTRL)
101                         {
102                                 toggleSlideShow_Click(NULL, me);
103                                 return 1;
104                         }
105                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
106                 default:
107                         if (key == K_MWHEELUP || ascii == '+')
108                         {
109                                 me.screenshotImage.setZoom(me.screenshotImage, -2, (key == K_MWHEELUP));
110                                 return 1;
111                         }
112                         else if (key == K_MWHEELDOWN || ascii == '-')
113                         {
114                                 me.screenshotImage.setZoom(me.screenshotImage, -1/2, (key == K_MWHEELDOWN));
115                                 return 1;
116                         }
117                         if (me.scrList.keyDown(me.scrList, key, ascii, shift))
118                         {
119                                 // keyDown has already changed the selected item
120                                 me.scrList.goScreenshot(me.scrList, 0);
121                                 return 1;
122                         }
123                         return SUPER(XonoticScreenshotViewerDialog).keyDown(me, key, ascii, shift);
124         }
125 }
126 void XonoticScreenshotViewerDialog_close(entity me)
127 {
128         // resume music
129         if(!cvar("menu_screenshotviewer_enablemusic"))
130         if(cvar("music_playlist_index") == 999)
131         {
132                 cvar_set("music_playlist_index", ftos(music_playlist_index_backup));
133         }
134         else
135                 localcmd("\ncd resume\n");
136
137         me.scrList.stopSlideShow(me.scrList);
138         me.slideShowButton.forcePressed = 0;
139         SUPER(XonoticScreenshotViewerDialog).close(me);
140 }
141 void XonoticScreenshotViewerDialog_fill(entity me)
142 {
143         entity e;
144         me.TR(me);
145                 me.TD(me, me.rows - 1, me.columns, e = makeXonoticScreenshotImage());
146                         e.showTitle = 0; // dialog title is enough
147                         me.screenshotImage = e;
148         me.gotoRC(me, me.rows - 1, 0);
149                 me.TDempty(me, 1/20 * me.columns);
150                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("-", '0 0 0'));
151                         e.onClick = decreaseZoom_Click;
152                         e.onClickEntity = me;
153                 me.TD(me, 1, 1/20 * me.columns, e = makeXonoticButton("+", '0 0 0'));
154                         e.onClick = increaseZoom_Click;
155                         e.onClickEntity = me;
156                 me.TD(me, 1, 2/20 * me.columns, e = makeXonoticButton(_("Reset"), '0 0 0'));
157                         e.onClick = resetZoom_Click;
158                         e.onClickEntity = me;
159
160                 me.TDempty(me, 2/20 * me.columns);
161                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Previous"), '0 0 0'));
162                         e.onClick = prevScreenshot_Click;
163                         e.onClickEntity = me;
164                 me.TD(me, 1, 3/20 * me.columns, e = makeXonoticButton(_("Next"), '0 0 0'));
165                         e.onClick = nextScreenshot_Click;
166                         e.onClickEntity = me;
167
168                 me.TDempty(me, 2/20 * me.columns);
169                 me.TD(me, 1, 4/20 * me.columns, e = makeXonoticButton(_("Slide show"), '0 0 0'));
170                         e.onClick = toggleSlideShow_Click;
171                         e.onClickEntity = me;
172                         me.slideShowButton = e;
173 }
174 #endif