Last active
April 23, 2017 22:59
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local gui = require 'gui' | |
| local dialog = require 'gui.dialogs' | |
| local widgets = require 'gui.widgets' | |
| local guiScript = require 'gui.script' | |
| local utils = require 'utils' | |
| function show_description(type, id) | |
| local unit = df.unit:new() | |
| local scr = df.viewscreen_unitlistst:new() | |
| local act = df.activity_entry:new() | |
| act.id = 9999999 | |
| act.type = 8 | |
| df.global.world.activities.all:insert(#df.global.world.activities.all, act) | |
| unit.social_activities:insert(0,9999999) | |
| local event = df.activity_event_performancest:new() | |
| event.type = type | |
| event.event = id | |
| act.events:insert(0,event) | |
| scr.units[0]:insert(0, unit) | |
| scr.jobs[0]:insert(0, nil) | |
| scr.page = 0 | |
| scr.cursor_pos[0] = 0 | |
| gui.simulateInput(scr, 'UNITJOB_VIEW_JOB') | |
| df.global.world.activities.all:erase(#df.global.world.activities.all-1) | |
| scr.units[0]:erase(0) | |
| unit:delete() | |
| event:delete() | |
| act:delete() | |
| scr:delete() | |
| end | |
| function sort_entries(list) | |
| table.sort(list, function (a,b) | |
| return string.lower(a.text) < string.lower(b.text) | |
| end) | |
| end | |
| PerfViewerUi = defclass(PerfViewerUi, gui.FramedScreen) | |
| PerfViewerUi.ATTRS={ | |
| frame_style = gui.GREY_LINE_FRAME, | |
| frame_title = "Performance Forms Viewer", | |
| } | |
| function PerfViewerUi:init(args) | |
| self.data = { {}, {}, {} } | |
| --self.sel_idx = { {}, {}, {} } | |
| -- poetry | |
| for i,v in ipairs(df.global.world.poetic_forms.all) do | |
| local name = dfhack.TranslateName(v.name, 1) | |
| local t = { text=name, type=1, id=v.id } | |
| table.insert(self.data[1], t) | |
| end | |
| sort_entries(self.data[1]) | |
| -- music | |
| for i,v in ipairs(df.global.world.musical_forms.all) do | |
| local name = dfhack.TranslateName(v.name, 1) | |
| local t = { text=name, type=2, id=v.id } | |
| table.insert(self.data[2], t) | |
| end | |
| sort_entries(self.data[2]) | |
| -- dance | |
| for i,v in ipairs(df.global.world.dance_forms.all) do | |
| local name = dfhack.TranslateName(v.name, 1) | |
| local t = { text=name, type=3, id=v.id } | |
| table.insert(self.data[3], t) | |
| end | |
| sort_entries(self.data[3]) | |
| local helpLabel = widgets.Label{ | |
| frame = { t=1, l=1 }, | |
| text = { | |
| { key="SECONDSCROLL_UP", }, | |
| { key="SECONDSCROLL_DOWN", text=": Scroll left list " }, | |
| { key="STANDARDSCROLL_UP", }, | |
| { key="STANDARDSCROLL_DOWN", text=": Scroll right list " }, | |
| { key="SELECT", text=": View selected " }, | |
| --{ key="LEAVESCREEN", text= ": Exit" }, | |
| } | |
| } | |
| local typesList = widgets.List{ | |
| view_id = "list_types", | |
| choices = { 'Poetic Forms ('..#self.data[1]..')', 'Musical Forms ('..#self.data[2]..')', 'Dances ('..#self.data[3]..')' }, | |
| frame = { l=1, t=3 }, | |
| on_select = self:callback("typeChanged"), | |
| scroll_keys = widgets.SECONDSCROLL, | |
| text_pen = dfhack.pen.parse{ fg=COLOR_DARKGRAY, bg=0 }, | |
| cursor_pen = dfhack.pen.parse{ fg=COLOR_YELLOW, bg=0 }, | |
| } | |
| local mainList=widgets.List{ | |
| view_id = "list_main", | |
| choices = self.data[1], | |
| frame = { l=21, t=3, yalign=0 }, | |
| --on_select = self:callback("itemSelected"), | |
| on_submit = self:callback("viewItem"), | |
| text_pen = dfhack.pen.parse{ fg=COLOR_DARKGRAY, bg=0 }, | |
| cursor_pen = dfhack.pen.parse{ fg=COLOR_YELLOW, bg=0 }, | |
| --edit_below = true, | |
| } | |
| local mainPage = widgets.Panel{ | |
| subviews = { helpLabel, typesList, mainList }, | |
| view_id = 'page_main' | |
| } | |
| local pages = widgets.Pages{ subviews={ mainPage }, view_id="pages" } | |
| self:addviews{ pages } | |
| end | |
| function PerfViewerUi:typeChanged(index,choice,opts) | |
| if not self.subviews.list_main then | |
| return | |
| end | |
| self.subviews.list_main:setChoices(self.data[index]) | |
| self.subviews.list_main:setSelected(1) --self.sel_idx[index]) | |
| end | |
| function PerfViewerUi:itemSelected(index,choice,opts) | |
| if not self.subviews.list_types then | |
| return | |
| end | |
| self.sel_idx[self.subviews.list_types.selected] = index | |
| end | |
| function PerfViewerUi:viewItem(index,choice,opts) | |
| show_description(choice.type, choice.id) | |
| -- otherwise the title would be 'listen to poetry', etc. | |
| dfhack.gui.getCurViewscreen().title = ' '..choice.text..' ' | |
| end | |
| function PerfViewerUi:onInput(keys) | |
| if keys.LEAVESCREEN_ALL then | |
| self:dismiss() | |
| end | |
| if keys.LEAVESCREEN then | |
| self:dismiss() | |
| end | |
| self.super.onInput(self,keys) | |
| end | |
| local screen = PerfViewerUi{target=trg} | |
| screen:show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment