Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [DFHack] gui programming tutorial and help  (Read 3460 times)

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
[DFHack] gui programming tutorial and help
« on: January 27, 2015, 03:22:40 pm »

So i wrote a little help/tutorial (to be continued, maybe with something more functional) for gui programming with dfhack. You can find it here

Also i'll try and answer/help any questions in that regard here.

The relevant help section is here: linky

Ideas for future topics, not in any order:
  • making new widgets DONE!
  • direct render/key input
  • overlay screens
  • making new buildings with custom screens
« Last Edit: February 26, 2015, 04:49:18 pm by Warmist »
Logged

expwnent

  • Bay Watcher
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #1 on: January 27, 2015, 03:42:01 pm »

Posting to watch.
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #2 on: January 27, 2015, 03:52:33 pm »

Ah, good. I have some mild experience here.

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #3 on: January 27, 2015, 03:57:51 pm »

next tutorial will explain what the last addition does/means and maybe i'll pick some exact smallish idea to implement (suggestions welcome).

Raidau

  • Bay Watcher
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #4 on: January 27, 2015, 11:08:39 pm »

So i wrote a little help/tutorial (to be continued, maybe with something more functional) for gui programming with dfhack. You can find it here

Also i'll try and answer/help any questions in that regard here.

The relevant help section is here: linky

Awesome! I wished to know how to make those widgets work. Looks like first step toward my mod's main menu :)

BTW is there a way to change character colors within same screen wihout writing it from scratch? EDIT: looks like its all about different pens..

Could you please explain how properly add dynamical stuff like tooltip string for currenly selected choice?
« Last Edit: January 28, 2015, 02:06:36 am by Raidau »
Logged
Marital status manipulator
Custom item descriprions
Natural Balance Mod (2013-2015) development suspended...

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #5 on: January 28, 2015, 04:29:32 pm »

Okay so the idea of tooltip is a bit fuzzy... I mean there is now real "popup window" in dfhack. We could do something fancy but i'm too tired to thing of that, so i'll show how i would do that.
Code: [Select]
function tutorial_screen:init(args)
self:addviews{
widgets.Label{text={{text="Info:"},{text=self:callback("get_tooltip")}},frame={t=1,l=1}},
widgets.List{view_id="my_list",choices={{text='a',tooltip="this is 'a'"},{text='b',tooltip="second leter of alphabet"},{text='c',tooltip="3rd choice"}},frame={t=3,l=1}},
widgets.Label{
text={{text="Exit",key="LEAVESCREEN",frame={b=1,l=1},key_sep="()",on_activate=self:callback('dismiss')}}
}
}
end
function tutorial_screen:get_tooltip()
local _,choice=self.subviews.my_list:getSelected()
return choice.tooltip
end
Again few ways to do it (even when not doing fancy stuff). This way label tries to print second part, and it checks what is in list that is currently selected. List is also modified so it has some more info for each item.

So broken down into parts:
Code: [Select]
widgets.Label{ -- a new label
text={ --text has multiple parts
   {text="Info:"}, --static "Info:" part
   {text=self:callback("get_tooltip")} -- and dynamic part that calls self:get_tooltip (each frame actually...)
},frame={t=1,l=1} --position stuff
},
The function in question is:
Code: [Select]
function tutorial_screen:get_tooltip()
local _,choice=self.subviews.my_list:getSelected() --this returns index and choice. We throw out index but...
return choice.tooltip --... keep the choices tooltip
end
How does that "my_list" happen or why choice has "tooltip" field? By magic of lua ofcourse:
Code: [Select]
widgets.List{ -- again new list
   view_id="my_list", --this is named widget, we can get it by using "self.subviews[name]" format
   choices={ --now we had simple choices, just text, but we can have as complicated as we want (as long as there is "text" field to display)
      {text='a',tooltip="this is 'a'"},
      {text='b',tooltip="second leter of alphabet"},
      {text='c',tooltip="3rd choice"}
   },frame={t=3,l=1}
},

Hope this makes everything clearer. And now i'm going to sleep like dead :)

Meph

  • Bay Watcher
    • View Profile
    • worldbicyclist
Re: [DFHack] gui programming tutorial and help
« Reply #6 on: January 28, 2015, 06:41:12 pm »

While I myself won't be using it, I just wanted to thank you for writing this manual.
Logged
::: ☼Meph Tileset☼☼Map Tileset☼- 32x graphic sets with TWBT :::
::: ☼MASTERWORK DF☼ - A comprehensive mod pack now on Patreon - 250.000+ downloads and counting :::
::: WorldBicyclist.com - Follow my bike tours around the world - 148 countries visited :::

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: [DFHack] gui programming tutorial and help
« Reply #7 on: February 26, 2015, 04:51:01 pm »

NEW! finally got around to finishing a new tutorial. This one about making widgets. Also moved it to new location and new shiny look.

new tutorial

The blog(ish?) here here here here

Happy hacking :)