12 currentList=elementsToCreate
20 listitems=args[i:i+jlen]
23 elif type==
'space' or type==
'width' or type==
'height':
35 elif type==
'button' or type==
'buttonspr':
40 width=float(args[i+1])
41 height=float(args[i+2])
51 elif type==
'text' or type==
"textwidth":
59 elif type==
'textinput':
61 initialvalue=
str(args[i+1])
65 currentList=elementsToCreate
71 return elementsToCreate
75 text_height = Base.GetTextHeight(
'|',
tuple([font_size]*3))*1.05
83 return GUI.GUIRect(x,y,wid,hei,
'normalized_biased_scaled')
90 numid=DialogBox.Item.next_id=DialogBox.Item.next_id+1
107 self.gui_element.show()
108 self.gui_element.draw()
111 self.gui_element.hide()
112 self.gui_element.undraw()
117 DialogBox.Item.__init__(self)
130 DialogBox.Item.__init__(self,id)
132 return (self.
numlines+1) * (text_height+0.005)
134 values.append(self.
id)
135 sel = self.picker.selection
139 values.append(self.picker.items[sel].data)
141 self.picker.scroll(
'up')
143 screen_loc =
makeRect(x,y-.5*text_height,wid-0.05,hei-text_height)
147 textcolor =input_color , textbgcolor =screen_bgcolor,
148 selectedbgcolor=screen_bgcolor_nc, selectedcolor=screen_color, owner=owner,
149 textfontsize =font_size)
151 self.gui_element.children.append(self.
picker)
154 screen_loc =
makeRect(x+wid-0.05, y, 0.05, text_height)
156 clickHandler=
lambda b,p:self.picker.viewMove(-3),textfontsize=font_size)
157 scroll_up.setCaption(
' /\\ ')
158 self.gui_element.children.append(scroll_up)
160 screen_loc =
makeRect(x+wid-0.05, y-hei+1.5*text_height, 0.05, text_height)
162 clickHandler=
lambda b,p:self.picker.viewMove(3), textfontsize=font_size)
163 scroll_down.setCaption(
' \\/ ')
164 self.gui_element.children.append(scroll_down)
168 DialogBox.Item.draw(self)
174 DialogBox.Item.__init__(self)
176 return text_height*(1+self.text.count(
"\n"))
182 color=screen_color, fontsize=font_size,
194 DialogBox.Item.__init__(self,id)
196 return self.
hei+text_height
200 button.owner.handleButton(self.
id)
202 screen_loc=
makeRect(x+text_height/4.,y-text_height/2.,wid-text_height/2.,self.
hei)
206 textfontsize=font_size,textbgcolor=
GUI.GUIColor(0.3,0.,0.,.5))
208 self.gui_element.setCaption(
' '+self.
text)
214 DialogBox.Item.__init__(self,id)
218 values.append(self.
id)
219 values.append(self.gui_element.getText())
221 textarea.owner.close(
not textarea.canceled)
225 color=input_color,fontsize=font_size,bgcolor=screen_bgcolor,focusbutton=
True,owner=owner)
232 DialogBox.Item.__init__(self)
235 for el
in self.
items:
242 for el
in self.
items:
245 return reduce(max,map(
lambda x:x.height(),self.
items))
252 for it
in self.
items:
258 avgwid = (wid-totalwid) / num_variable
259 for it
in self.
items:
263 it.create(owner,room,x,y,w,hei)
266 childs.append(it.gui_element)
267 self.gui_element.children = childs
270 for it
in self.
items:
272 return DialogBox.Item.draw(self)
274 for it
in self.
items:
276 return DialogBox.Item.undraw(self)
284 DialogBox.Item.next_id+=1
298 totalheight+=el.height()
315 size=rect.getHotRect()
335 if key == 13
or key == 10:
341 if not VS.isserver():
348 map(
lambda x:x.undraw(), self.
elements)
351 if not VS.isserver():
353 GUI.GUIRootSingleton.keyTarget=self
359 map(
lambda x:x.draw(), self.
elements)
367 inputs[data[i]] = data[i+1]
369 return action, inputs
371 _gui_has_initted=
False
374 global _gui_has_initted
381 room=Base.GetCurRoom()
382 if not _gui_has_initted:
384 _gui_has_initted=
True
387 GUI.GUIRootSingleton.broadcastMessage(
'draw',
None)
393 def myCallback(db,data):
394 def serverCallback(data):
399 dialog(args, myCallback, Base.GetCurRoom())
403 items = [
"height",0.05,
"row"]
405 items += [
"width",(width-0.25)/2.,
407 "width",(width-0.25)/2.]
408 elif len(buttons)==2:
409 items += [
"button",buttons[0],
"width",(width-0.5),
"button",buttons[1]]
410 elif len(buttons)==3:
411 items += [
"button",buttons[0],
"width",(width-0.75)/2.,
412 "button",buttons[1],
"width",(width-0.75)/2.,
416 items += [
"button",b]
420 def alert(message, callback=None, width=1.0, buttonText='OK'):
421 def dbcallback(db,data):
427 dialog([
"width",width,
"text",message] +
button_row(width, buttonText), dbcallback)
429 def confirm(message, callback, width=1.0, buttons=(
'Cancel',
'OK')):
430 def dbcallback(db,data):
434 if data[0]!=buttons[0]
and data[0]!=
"Cancel":
439 dialog([
"width",width,
"text",message] +
button_row(width, *buttons), dbcallback)